summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/ChangeLog.txt5
-rw-r--r--apps/include/prun.h2
-rw-r--r--apps/system/Make.defs2
-rw-r--r--apps/system/prun/Kconfig39
-rw-r--r--apps/system/prun/Makefile22
-rw-r--r--apps/system/prun/pexec_main.c174
-rw-r--r--nuttx/binfmt/libpcode/README.txt34
7 files changed, 275 insertions, 3 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index b4ab12f0b..2bc6275cb 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -914,3 +914,8 @@
* apps/interpreters/prun and apps/include/interpreters/prun.h: Broke out
the P-code execution logic from apps/examples/pashello and moved it to
these directorit where it can be used more generally (2014-5-9).
+ * apps/system/prun and apps/include/interpreters/pexec_main.c: Move the
+ P-Code execution logic from apps/interpreters/prun to
+ apps/system/prun; Add pexec_main.c which is an NSH built-in
+ application that can be used to run P-Code programs from the NSH
+ command line (2014-5-9).
diff --git a/apps/include/prun.h b/apps/include/prun.h
index d440fb3d6..c768ee7f8 100644
--- a/apps/include/prun.h
+++ b/apps/include/prun.h
@@ -42,6 +42,8 @@
#include <nuttx/config.h>
+#include <sys/types.h>
+
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
diff --git a/apps/system/Make.defs b/apps/system/Make.defs
index af20390a5..5242dd977 100644
--- a/apps/system/Make.defs
+++ b/apps/system/Make.defs
@@ -67,7 +67,7 @@ CONFIGURED_APPS += system/nxplayer
endif
ifeq ($(CONFIG_SYSTEM_PRUN),y)
-CONFIGURED_APPS += sysem/prun
+CONFIGURED_APPS += system/prun
endif
ifeq ($(CONFIG_SYSTEM_RAMTEST),y)
diff --git a/apps/system/prun/Kconfig b/apps/system/prun/Kconfig
index 131a7b2aa..61ce1bcd9 100644
--- a/apps/system/prun/Kconfig
+++ b/apps/system/prun/Kconfig
@@ -8,7 +8,10 @@ config SYSTEM_PRUN
default n
depends on INTERPRETERS_PCODE
---help---
- Build the Pascal P-Code interpreter / Virtual machine
+ Build the Pascal P-Code interpreter / Virtual machine. This selection
+ just builds a library of P-Code-related functions as described in
+ include/apps/prun.h. This selection is also necessary to enable other
+ P-Code related features.
if SYSTEM_PRUN
@@ -17,6 +20,38 @@ config SYSTEM_PEXEC
default n
---help---
Generates an NSH built-in task that may be used to execute P-Code
- from the NSH command line.
+ files from the NSH command line. For example:
+ nsh> pexec /bin/hello.pex
+ Hello, World!
+
+if SYSTEM_PEXEC
+
+config SYSTEM_PEXEC_STACKSIZE
+ int "P-code interpreter stack size"
+ default 2048
+ ---help---
+ This is the stack size that will be used when starting P-code interpreter.
+
+config SYSTEM_PEXEC_PRIORITY
+ int "P-code interpreter priority"
+ default 100
+ ---help---
+ This is the task_priority that will be used when starting P-code interpreter.
+
+config SYSTEM_PEXEC_VARSTACKSIZE
+ int "P-code variable stack size (default)"
+ default 1024
+ ---help---
+ This default size of the P-Code variable storage area to be allocated by the
+ P-Code runtime.
+
+config SYSTEM_PEXEC_STRSTACKSIZE
+ int "P-code string stack size (default)"
+ default 128
+ ---help---
+ This default size of the P-Code string stack area to be allocated by the
+ P-Code runtime.
+
+endif
endif
diff --git a/apps/system/prun/Makefile b/apps/system/prun/Makefile
index 63fc1ad74..6d5d0a768 100644
--- a/apps/system/prun/Makefile
+++ b/apps/system/prun/Makefile
@@ -48,9 +48,20 @@ CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \
"$(APPDIR)$(DELIM)interpreters$(DELIM)pcode$(DELIM)include" \
"$(APPDIR)$(DELIM)interpreters$(DELIM)pcode$(DELIM)insn$(DELIM)include"}
+CONFIG_SYSTEM_PEXEC_STACKSIZE ?= 1536
+CONFIG_SYSTEM_PEXEC_PRIORITY ?= 100
+
+APPNAME = pexec
+PRIORITY = $(CONFIG_SYSTEM_PEXEC_PRIORITY)
+STACKSIZE = $(CONFIG_SYSTEM_PEXEC_STACKSIZE)
+
ASRCS =
CSRCS = prun.c
+ifeq ($(CONFIG_SYSTEM_PEXEC),y)
+CSRCS += pexec_main.c
+endif
+
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
@@ -86,7 +97,18 @@ $(COBJS): %$(OBJEXT): %.c
$(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
+ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
+ifeq ($(CONFIG_SYSTEM_PEXEC),y)
+$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
+ $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
+
+context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
+else
context:
+endif
+else
+context:
+endif
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
diff --git a/apps/system/prun/pexec_main.c b/apps/system/prun/pexec_main.c
new file mode 100644
index 000000000..0b6b61939
--- /dev/null
+++ b/apps/system/prun/pexec_main.c
@@ -0,0 +1,174 @@
+/****************************************************************************
+ * system/prun/pexec_main.c
+ *
+ * Copyright (C) 2013 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <apps/prun.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SYSTEM_PEXEC_VARSTACKSIZE
+# define CONFIG_SYSTEM_PEXEC_VARSTACKSIZE 1024
+#endif
+
+#ifndef CONFIG_SYSTEM_PEXEC_STRSTACKSIZE
+# define CONFIG_SYSTEM_PEXEC_STRSTACKSIZE 128
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void show_usage(FAR const char *progname, int errcode)
+{
+ fprintf(stderr, "USAGE: %s [OPTIONS] <filename>\n", progname);
+ fprintf(stderr, "\nWhere:\n");
+ fprintf(stderr, "\t<filename> is the full path to the P-Code file to be executed\n");
+ fprintf(stderr, "\nand OPTIONS include the following:\n");
+ fprintf(stderr, "\t-v <varsize>: Variable memory size to use. Default: %d\n",
+ CONFIG_SYSTEM_PEXEC_VARSTACKSIZE);
+ fprintf(stderr, "\t-s <strsize>: String stack size to use. Default: %d\n",
+ CONFIG_SYSTEM_PEXEC_STRSTACKSIZE);
+ fprintf(stderr, "\t-h: Show this text and exit\n");
+ exit(errcode);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int pexec_main(int argc, FAR char **argv)
+{
+ FAR char *filename = NULL;
+ FAR char *endptr;
+ long varsize = CONFIG_SYSTEM_PEXEC_VARSTACKSIZE;
+ long strsize = CONFIG_SYSTEM_PEXEC_STRSTACKSIZE;
+ long tmp;
+ int option;
+ int ret;
+
+ /* Parse input parameters */
+
+ while ((option = getopt(argc, argv, ":v:s:h")) != ERROR)
+ {
+ switch (option)
+ {
+ case 'h':
+ show_usage(argv[0], EXIT_SUCCESS);
+ break;
+
+ case 'v':
+ tmp = strtol(optarg, &endptr, 10);
+ if (tmp < 0)
+ {
+ fprintf(stderr, "ERROR: Variable memory size out of range: %ld\n", tmp);
+ show_usage(argv[0], EXIT_FAILURE);
+ }
+ else
+ {
+ varsize = tmp;
+ }
+ break;
+
+
+ case 's':
+ tmp = strtol(optarg, &endptr, 10);
+ if (tmp < 0)
+ {
+ fprintf(stderr, "ERROR: String stack size out of range: %ld\n", tmp);
+ show_usage(argv[0], EXIT_FAILURE);
+ }
+ else
+ {
+ strsize = tmp;
+ }
+ break;
+
+ case ':':
+ fprintf(stderr, "ERROR: Missing required argument\n");
+ show_usage(argv[0], EXIT_FAILURE);
+ break;
+
+ default:
+ case '?':
+ fprintf(stderr, "ERROR: Unrecognized option\n");
+ show_usage(argv[0], EXIT_FAILURE);
+ break;
+ }
+ }
+
+ /* There should be one final parameters remaining on the command line */
+
+ if (optind >= argc)
+ {
+ fprintf(stderr, "ERROR: Missing required <filename> argument\n");
+ show_usage(argv[0], EXIT_FAILURE);
+ }
+
+ filename = argv[optind];
+ optind++;
+
+ if (optind < argc)
+ {
+ fprintf(stderr, "ERROR: Garbage at the end of the command line\n");
+ show_usage(argv[0], EXIT_FAILURE);
+ }
+
+ /* Execute the P-Code file */
+
+ ret = prun(filename, varsize, strsize);
+ if (ret < 0)
+ {
+ int errval = errno;
+ DEBUGASSERT(errval > 0);
+
+ fprintf(stderr, "ERROR: P-Code execution failed: %d %d\n", ret, errval);
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/nuttx/binfmt/libpcode/README.txt b/nuttx/binfmt/libpcode/README.txt
index f42a4f54f..d8fcc7f32 100644
--- a/nuttx/binfmt/libpcode/README.txt
+++ b/nuttx/binfmt/libpcode/README.txt
@@ -120,3 +120,37 @@ Here is a simple test configuration using the NuttX simulator:
world example like:
nsh> hello.pex
+
+Issues
+------
+
+1. As implemented now, there is a tight coupling between the nuttx/directory
+ and the apps/ directory. That should not be the case; the nuttx/ logic
+ should be completely independent of apps/ logic (but not vice versa).
+
+2. The current implementation will not work in the CONFIG_KERNEL_BUILD.
+ This is because of the little proxy logic (function pcode_proxy() in the
+ file pcode.c). (a) That logic would attempt to link with P-code logic
+ that resides in user space. That will not work. And (2) that proxy
+ would be started in user mode but in the kernel address space which will
+ certainly crash immediately.
+
+The general idea to fix both of these problems is as follows:
+
+1. Eliminate the pcode_proxy. Instead start a P-Code execution program that
+ resides in the file system. That P-Code execution program already
+ exists. It is in apps/system/prun. This program should be built as,
+ say, an ELF binary and installed in a file system.
+
+2. Add a configuration setting that gives the full path to where the pexec
+ program is stored in the filesystem.
+
+3. Modify the logic so that the P-Code execution program runs (instead of
+ the requested program) an it received the full path the the P-Code file
+ on the command line. This might be accomplished by simply modifying the
+ argv[] structure in the struct binary_s instance.
+
+4. Add a task start hook to the program. Here is where we can setup up the
+ on_exit() function that will clean up after the P-Code program terminates.
+
+There are many other smaller issues to be resolved, but those are the main ones.