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. --- apps/examples/pashello/Kconfig | 17 +++++++++++ apps/examples/pashello/pashello.c | 63 +++++++++------------------------------ apps/examples/pashello/pashello.h | 2 +- 3 files changed, 32 insertions(+), 50 deletions(-) (limited to 'apps/examples') diff --git a/apps/examples/pashello/Kconfig b/apps/examples/pashello/Kconfig index 5591d6b5b..c13490677 100644 --- a/apps/examples/pashello/Kconfig +++ b/apps/examples/pashello/Kconfig @@ -6,8 +6,25 @@ config EXAMPLES_PASHELLO bool "Pascal \"Hello, World!\" example" default n + depends on INTERPRETERS_PCODE + select INTERPRETERS_PRUN ---help--- Enable the Pascal \"Hello, World!\" example if EXAMPLES_PASHELLO + +config EXAMPLES_PASHELLO_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 EXAMPLES_PASHELLO_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. + endif diff --git a/apps/examples/pashello/pashello.c b/apps/examples/pashello/pashello.c index 8f9fc8b22..50c61d48c 100644 --- a/apps/examples/pashello/pashello.c +++ b/apps/examples/pashello/pashello.c @@ -43,20 +43,18 @@ #include #include -#include "pexec.h" -#include "pedefs.h" -#include "pashello.h" +#include /**************************************************************************** * Definitions ****************************************************************************/ -#ifndef CONFIG_PASHELLO_VARSTACKSIZE -# define CONFIG_PASHELLO_VARSTACKSIZE 1024 +#ifndef CONFIG_EXAMPLES_PASHELLO_VARSTACKSIZE +# define CONFIG_EXAMPLES_PASHELLO_VARSTACKSIZE 1024 #endif -#ifndef CONFIG_PASHELLO_STRSTACKSIZE -# define CONFIG_PASHELLO_STRSTACKSIZE 128 +#ifndef CONFIG_EXAMPLES_PASHELLO_STRSTACKSIZE +# define CONFIG_EXAMPLES_PASHELLO_STRSTACKSIZE 128 #endif /**************************************************************************** @@ -67,33 +65,6 @@ * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: prun - * - * Description: - * This function executes the P-Code program until a stopping condition - * is encountered. - * - ****************************************************************************/ - -static void prun(FAR struct pexec_s *st) -{ - int errcode; - - for (;;) - { - /* Execute the instruction; Check for exceptional conditions */ - - errcode = pexec(st); - if (errcode != eNOERROR) break; - } - - if (errcode != eEXIT) - { - printf("Runtime error 0x%02x -- Execution Stopped\n", errcode); - } -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -105,29 +76,23 @@ static void prun(FAR struct pexec_s *st) int pashello_main(int argc, FAR char *argv[]) { FAR struct pexec_s *st; + int exitcode = EXIT_SUCCESS; + int ret; /* Register the /dev/hello driver */ hello_register(); - /* Load the POFF file */ + /* Execute the POFF file */ - st = pload("/dev/hello", CONFIG_PASHELLO_VARSTACKSIZE, CONFIG_PASHELLO_STRSTACKSIZE); - if (!st) + ret = prun("/dev/hello", CONFIG_EXAMPLES_PASHELLO_VARSTACKSIZE, + CONFIG_EXAMPLES_PASHELLO_STRSTACKSIZE); + if (ret < 0) { - fprintf(stderr, "pashello_main: ERROR: Could not load /dev/hello\n"); - exit(1); + fprintf(stderr, "pashello_main: ERROR: Execution failed\n"); + exitcode = EXIT_FAILURE; } - printf("pashello_main: /dev/hello Loaded\n"); - printf("pashello_main: Interpreter started:\n"); - - /* And start program execution */ - - prun(st); - - /* Clean up resources used by the interpreter */ printf("pashello_main: Interpreter terminated"); - pexec_release(st); - return 0; + return exitcode; } diff --git a/apps/examples/pashello/pashello.h b/apps/examples/pashello/pashello.h index ac5f99fbe..6a550764c 100644 --- a/apps/examples/pashello/pashello.h +++ b/apps/examples/pashello/pashello.h @@ -50,6 +50,6 @@ /* Defined in device.c */ -extern void hello_register(void); +void hello_register(void); #endif /* __EXAMPLES_PASHELLO_H */ -- cgit v1.2.3