summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-05-09 08:52:11 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-05-09 08:52:11 -0600
commitb373fc5405bc34fe4889a67d9a856c9228ae1240 (patch)
tree4dcde4ad339f61611ef2a291d3e52644d91ea4a8 /nuttx
parent56078d9f356c73497be755f6a912b7d2da6c66e8 (diff)
downloadnuttx-b373fc5405bc34fe4889a67d9a856c9228ae1240.tar.gz
nuttx-b373fc5405bc34fe4889a67d9a856c9228ae1240.tar.bz2
nuttx-b373fc5405bc34fe4889a67d9a856c9228ae1240.zip
Create P-Code execution helper in apps/interpreters/prun; The P-Code binary format is functional except that there are still some modularity and kernel build issues that need to be addressed.
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/ChangeLog9
-rw-r--r--nuttx/binfmt/Kconfig2
-rw-r--r--nuttx/binfmt/libpcode/Kconfig14
-rw-r--r--nuttx/binfmt/libpcode/README.txt67
-rw-r--r--nuttx/binfmt/pcode.c26
-rw-r--r--nuttx/configs/sim/pashello/defconfig1
-rw-r--r--nuttx/configs/xtrs/pashello/defconfig1
-rw-r--r--nuttx/configs/z16f2800100zcog/pashello/defconfig1
-rw-r--r--nuttx/configs/z80sim/pashello/defconfig1
9 files changed, 117 insertions, 5 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 5ce7417cb..e635e8f02 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -7314,3 +7314,12 @@
STM32162 Medium+ density parts (plus miscellaneous other improvements to
the original STM32151 logic). From Jussi Kivilinna and Sami Pelkonen
(2014-5-8).
+ * binfmt/binfmt_dumpmodule.c, binfmt_loadmodule.c, binfmt_unloadmdoule.c,
+ builtin.c, elf.c, nxflat.c, pcode.c, and include/nuttx/binfmt/binfmt.h:
+ Extend the binfmt interface to handle error conditions where format-specific
+ binfmt clean-up is needed in the event of error conditions. This is needed
+ by the P-Code binfmt (2014-5-8).
+ * binfmt/libpcode, pcode.c, include/nuttx/poff.h, and binfmt/pcode.h:
+ Now uses apps/interpreters/prun and is basically functional. More work
+ is needed because (1) it is too coupled with apps/ and (2) will not work
+ with CONFIG_NUTTX_KERNEL (2014-5-9). \ No newline at end of file
diff --git a/nuttx/binfmt/Kconfig b/nuttx/binfmt/Kconfig
index 4c99b8b2c..17a42cb5c 100644
--- a/nuttx/binfmt/Kconfig
+++ b/nuttx/binfmt/Kconfig
@@ -66,7 +66,7 @@ endif
config PCODE
bool "Support P-Code Applications"
default n
- depends on INTERPRETERS_PCODE
+ depends on INTERPRETERS_PCODE && INTERPRETERS_PRUN && (!NUTTX_KERNEL || EXPERIMENTAL)
---help---
Enable support for interpreted P-Code binaries. P-Code binaries are
generated by the NuttX Pascal compiler.
diff --git a/nuttx/binfmt/libpcode/Kconfig b/nuttx/binfmt/libpcode/Kconfig
index 03255ffab..b09f6795e 100644
--- a/nuttx/binfmt/libpcode/Kconfig
+++ b/nuttx/binfmt/libpcode/Kconfig
@@ -15,6 +15,20 @@ config PCODE_PRIORITY
---help---
This is the task_priority that will be used when starting P-code interpreter.
+config PCODE_VARSTACKSIZE
+ int "P-code variable stack size"
+ default 1024
+ ---help---
+ This size of the P-Code variable storage area to be allocated by the
+ P-Code runtime.
+
+config PCODE_STRSTACKSIZE
+ int "P-code string stack size"
+ default 128
+ ---help---
+ This size of the P-Code string stack area to be allocated by the
+ P-Code runtime.
+
config PCODE_TEST_FS
bool "Mount a test file system"
depends on FS_ROMFS && !DISABLE_MOUNTPOINT
diff --git a/nuttx/binfmt/libpcode/README.txt b/nuttx/binfmt/libpcode/README.txt
index b7f896da0..7c6ae8ff2 100644
--- a/nuttx/binfmt/libpcode/README.txt
+++ b/nuttx/binfmt/libpcode/README.txt
@@ -49,3 +49,70 @@ Files include in this directory include:
xxd -g 1 -i romfs.img >romfs.h
then cleaned up with an editor to conform with NuttX coding standards.
+
+Test Configuration
+------------------
+Here is a simple test configuration using the NuttX simulator:
+
+1. Install the sim/nsh configuration:
+
+ cd tools
+ ./configure.sh sim/nsh
+ cd ..
+
+2. Install p-code virtual machine as described above.
+
+3. Modify the configuration using 'make menuconfig'. Change the following
+ selections:
+
+ This enables general BINFMT support:
+
+ CONFIG_DEBUG_BINFMT=y
+ CONFIG_BINFMT_EXEPATH=y
+
+ This enables building of the P-Code virtual machine:
+
+ CONFIG_INTERPRETERS_PCODE=y
+
+ This enables building the PCODE binary format
+
+ CONFIG_PCODE=y
+ CONFIG_PCODE_PRIORITY=100
+ CONFIG_PCODE_STACKSIZE=2048
+
+ This enables building and mount a test filesystem:
+
+ CONFIG_PCODE_TEST_FS=y
+ CONFIG_PCODE_TEST_DEVMINOR=3
+ CONFIG_PCODE_TEST_DEVPATH="/dev/ram3"
+ CONFIG_PCODE_TEST_MOUNTPOINT="/bin"
+
+ Debug options can also be enabled with:
+
+ CONFIG_DEBUG=y
+ CONFIG_DEBUG_BINFMT=y
+ CONFIG_DEBUG_VERBOSE=y
+
+4. In lieu of a a real test application, this Quick'n'Dirty patch can be used
+ to initialize the P-Code binary format:
+
+ @@ -115,6 +115,7 @@ const struct symtab_s CONFIG_EXECFUNCS_SYMTAB[1];
+ /****************************************************************************
+ * Name: nsh_main
+ ****************************************************************************/
+ +int pcode_initialize(void);
+
+ int nsh_main(int argc, char *argv[])
+ {
+ @@ -143,6 +144,7 @@ int nsh_main(int argc, char *argv[])
+ exitval = 1;
+ }
+ #endif
+ +(void)pcode_initialize();
+
+ /* Initialize the NSH library */
+
+5. Then after building nuttx.exe you should be able to run the P-Code hello
+ world example like:
+
+ nsh> hello.pex
diff --git a/nuttx/binfmt/pcode.c b/nuttx/binfmt/pcode.c
index 0a187ec81..3c816b212 100644
--- a/nuttx/binfmt/pcode.c
+++ b/nuttx/binfmt/pcode.c
@@ -47,6 +47,8 @@
#include <errno.h>
#include <debug.h>
+#include <apps/interpreters/prun.h>
+
#include <nuttx/kmalloc.h>
#include <nuttx/poff.h>
#include <nuttx/fs/ramdisk.h>
@@ -78,6 +80,14 @@
# error CONFIG_SCHED_ONEXIT is required
#endif
+#ifndef CONFIG_PCODE_VARSTACKSIZE
+# define CONFIG_PCODE_VARSTACKSIZE 1024
+#endif
+
+#ifndef CONFIG_PCODE_STRSTACKSIZE
+# define CONFIG_PCODE_STRSTACKSIZE 128
+#endif
+
#ifdef CONFIG_PCODE_TEST_FS
# ifndef CONFIG_FS_ROMFS
# error You must select CONFIG_FS_ROMFS in your configuration file
@@ -255,19 +265,27 @@ static int pcode_proxy(int argc, char **argv)
if (ret < 0)
{
bdbg("ERROR: on_exit failed: %d\n", errno);
+ kfree(fullpath);
return EXIT_FAILURE;
}
/* Load the P-code file and execute it */
- /* We don't need the fullpath now */
+ ret = prun(fullpath, CONFIG_PCODE_VARSTACKSIZE, CONFIG_PCODE_STRSTACKSIZE);
+
+ /* We no longer need the fullpath */
kfree(fullpath);
- /* Execute the P-code file and execute it */
+ /* Check the result of the interpretation */
+
+ if (ret < 0)
+ {
+ bdbg("ERROR: Execution failed\n");
+ return EXIT_FAILURE;
+ }
- bdbg("ERROR: Not implemented\n");
- return EXIT_FAILURE;
+ return EXIT_SUCCESS;
}
#else
# error Missing logic for the case of CONFIG_NUTTX_KERNEL
diff --git a/nuttx/configs/sim/pashello/defconfig b/nuttx/configs/sim/pashello/defconfig
index 508e32e38..3cbaa445d 100644
--- a/nuttx/configs/sim/pashello/defconfig
+++ b/nuttx/configs/sim/pashello/defconfig
@@ -449,6 +449,7 @@ CONFIG_EXAMPLES_PASHELLO=y
#
# CONFIG_INTERPRETERS_FICL is not set
CONFIG_INTERPRETERS_PCODE=y
+CONFIG_INTERPRETERS_PRUN=y
#
# Network Utilities
diff --git a/nuttx/configs/xtrs/pashello/defconfig b/nuttx/configs/xtrs/pashello/defconfig
index 06c63a3ea..89497efe7 100644
--- a/nuttx/configs/xtrs/pashello/defconfig
+++ b/nuttx/configs/xtrs/pashello/defconfig
@@ -367,6 +367,7 @@ CONFIG_EXAMPLES_PASHELLO=y
#
# CONFIG_INTERPRETERS_FICL is not set
CONFIG_INTERPRETERS_PCODE=y
+CONFIG_INTERPRETERS_PRUN=y
#
# Network Utilities
diff --git a/nuttx/configs/z16f2800100zcog/pashello/defconfig b/nuttx/configs/z16f2800100zcog/pashello/defconfig
index b9a5cc618..644cdf9e1 100644
--- a/nuttx/configs/z16f2800100zcog/pashello/defconfig
+++ b/nuttx/configs/z16f2800100zcog/pashello/defconfig
@@ -404,6 +404,7 @@ CONFIG_EXAMPLES_PASHELLO=y
#
# CONFIG_INTERPRETERS_FICL is not set
CONFIG_INTERPRETERS_PCODE=y
+CONFIG_INTERPRETERS_PRUN=y
#
# Network Utilities
diff --git a/nuttx/configs/z80sim/pashello/defconfig b/nuttx/configs/z80sim/pashello/defconfig
index 7952e0f6f..1b5e1b38f 100644
--- a/nuttx/configs/z80sim/pashello/defconfig
+++ b/nuttx/configs/z80sim/pashello/defconfig
@@ -366,6 +366,7 @@ CONFIG_EXAMPLES_PASHELLO=y
#
# CONFIG_INTERPRETERS_FICL is not set
CONFIG_INTERPRETERS_PCODE=y
+CONFIG_INTERPRETERS_PRUN=y
#
# Network Utilities