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
This commit is contained in:
parent
758ea38cf1
commit
c53bad01cf
@ -914,3 +914,8 @@
|
|||||||
* apps/interpreters/prun and apps/include/interpreters/prun.h: Broke out
|
* apps/interpreters/prun and apps/include/interpreters/prun.h: Broke out
|
||||||
the P-code execution logic from apps/examples/pashello and moved it to
|
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).
|
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).
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-Processor Definitions
|
* Pre-Processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -67,7 +67,7 @@ CONFIGURED_APPS += system/nxplayer
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_SYSTEM_PRUN),y)
|
ifeq ($(CONFIG_SYSTEM_PRUN),y)
|
||||||
CONFIGURED_APPS += sysem/prun
|
CONFIGURED_APPS += system/prun
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_SYSTEM_RAMTEST),y)
|
ifeq ($(CONFIG_SYSTEM_RAMTEST),y)
|
||||||
|
@ -8,7 +8,10 @@ config SYSTEM_PRUN
|
|||||||
default n
|
default n
|
||||||
depends on INTERPRETERS_PCODE
|
depends on INTERPRETERS_PCODE
|
||||||
---help---
|
---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
|
if SYSTEM_PRUN
|
||||||
|
|
||||||
@ -17,6 +20,38 @@ config SYSTEM_PEXEC
|
|||||||
default n
|
default n
|
||||||
---help---
|
---help---
|
||||||
Generates an NSH built-in task that may be used to execute P-Code
|
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
|
||||||
|
endif
|
||||||
|
@ -48,9 +48,20 @@ CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \
|
|||||||
"$(APPDIR)$(DELIM)interpreters$(DELIM)pcode$(DELIM)include" \
|
"$(APPDIR)$(DELIM)interpreters$(DELIM)pcode$(DELIM)include" \
|
||||||
"$(APPDIR)$(DELIM)interpreters$(DELIM)pcode$(DELIM)insn$(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 =
|
ASRCS =
|
||||||
CSRCS = prun.c
|
CSRCS = prun.c
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SYSTEM_PEXEC),y)
|
||||||
|
CSRCS += pexec_main.c
|
||||||
|
endif
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
@ -86,7 +97,18 @@ $(COBJS): %$(OBJEXT): %.c
|
|||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||||
@touch .built
|
@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:
|
context:
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
context:
|
||||||
|
endif
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
.depend: Makefile $(SRCS)
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
174
system/prun/pexec_main.c
Normal file
174
system/prun/pexec_main.c
Normal file
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user