summaryrefslogtreecommitdiff
path: root/apps/system
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-05-09 12:30:07 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-05-09 12:30:07 -0600
commit2992f82c56ff672531fd152c89e783c6fc2daec0 (patch)
tree9c640841e6e562f9e98e154ea68d97cb2c211f45 /apps/system
parentdb7257ad4894df88a59100a8849b156029fbcf21 (diff)
downloadnuttx-2992f82c56ff672531fd152c89e783c6fc2daec0.tar.gz
nuttx-2992f82c56ff672531fd152c89e783c6fc2daec0.tar.bz2
nuttx-2992f82c56ff672531fd152c89e783c6fc2daec0.zip
Move prun from interpreters/ to system/; And an NSH built-in appliation that can be used to execute P-Code files from the NSH command line
Diffstat (limited to 'apps/system')
-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
4 files changed, 234 insertions, 3 deletions
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;
+}