From b373fc5405bc34fe4889a67d9a856c9228ae1240 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 May 2014 08:52:11 -0600 Subject: 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. --- nuttx/binfmt/Kconfig | 2 +- nuttx/binfmt/libpcode/Kconfig | 14 +++++++++ nuttx/binfmt/libpcode/README.txt | 67 ++++++++++++++++++++++++++++++++++++++++ nuttx/binfmt/pcode.c | 26 +++++++++++++--- 4 files changed, 104 insertions(+), 5 deletions(-) (limited to 'nuttx/binfmt') 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 #include +#include + #include #include #include @@ -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 -- cgit v1.2.3