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.

This commit is contained in:
Gregory Nutt 2014-05-09 08:52:11 -06:00
parent 898e59f112
commit ed2e4a15dc
9 changed files with 117 additions and 5 deletions

View file

@ -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).

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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 */
bdbg("ERROR: Not implemented\n");
return EXIT_FAILURE;
if (ret < 0)
{
bdbg("ERROR: Execution failed\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
#else
# error Missing logic for the case of CONFIG_NUTTX_KERNEL

View file

@ -449,6 +449,7 @@ CONFIG_EXAMPLES_PASHELLO=y
#
# CONFIG_INTERPRETERS_FICL is not set
CONFIG_INTERPRETERS_PCODE=y
CONFIG_INTERPRETERS_PRUN=y
#
# Network Utilities

View file

@ -367,6 +367,7 @@ CONFIG_EXAMPLES_PASHELLO=y
#
# CONFIG_INTERPRETERS_FICL is not set
CONFIG_INTERPRETERS_PCODE=y
CONFIG_INTERPRETERS_PRUN=y
#
# Network Utilities

View file

@ -404,6 +404,7 @@ CONFIG_EXAMPLES_PASHELLO=y
#
# CONFIG_INTERPRETERS_FICL is not set
CONFIG_INTERPRETERS_PCODE=y
CONFIG_INTERPRETERS_PRUN=y
#
# Network Utilities

View file

@ -366,6 +366,7 @@ CONFIG_EXAMPLES_PASHELLO=y
#
# CONFIG_INTERPRETERS_FICL is not set
CONFIG_INTERPRETERS_PCODE=y
CONFIG_INTERPRETERS_PRUN=y
#
# Network Utilities