mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
Add pascal test
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@606 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -313,4 +313,5 @@
|
|||||||
0.3.8 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
0.3.8 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
|
||||||
* Added a test case to verify the Pascal P-Code interpreter
|
* Added a test case to verify the Pascal P-Code interpreter
|
||||||
|
* Added /dev/zero
|
||||||
|
|
||||||
|
|||||||
@@ -963,6 +963,7 @@ Other memory:
|
|||||||
0.3.8 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
0.3.8 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
|
||||||
* Added a test case to verify the Pascal P-Code interpreter
|
* Added a test case to verify the Pascal P-Code interpreter
|
||||||
|
* Added /dev/zero
|
||||||
</pre></ul>
|
</pre></ul>
|
||||||
|
|
||||||
<table width ="100%">
|
<table width ="100%">
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|||||||
|
|
||||||
CSRCS =
|
CSRCS =
|
||||||
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
||||||
CSRCS += dev_null.c serial.c lowconsole.c
|
CSRCS += dev_null.c dev_zero.c serial.c lowconsole.c
|
||||||
endif
|
endif
|
||||||
CSRCS += $(NET_CSRCS)
|
CSRCS += $(NET_CSRCS)
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|||||||
+17
-17
@@ -1,7 +1,7 @@
|
|||||||
/************************************************************
|
/****************************************************************************
|
||||||
* dev_null.c
|
* drivers/dev_null.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* notice, this list of conditions and the following disclaimer in
|
* notice, this list of conditions and the following disclaimer in
|
||||||
* the documentation and/or other materials provided with the
|
* the documentation and/or other materials provided with the
|
||||||
* distribution.
|
* distribution.
|
||||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
* used to endorse or promote products derived from this software
|
* used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
@@ -31,15 +31,15 @@
|
|||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/************************************************************
|
/****************************************************************************
|
||||||
* Compilation Switches
|
* Compilation Switches
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
@@ -48,16 +48,16 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <nuttx/fs.h>
|
#include <nuttx/fs.h>
|
||||||
|
|
||||||
/************************************************************
|
/****************************************************************************
|
||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static ssize_t devnull_read(struct file *, char *, size_t);
|
static ssize_t devnull_read(struct file *, char *, size_t);
|
||||||
static ssize_t devnull_write(struct file *, const char *, size_t);
|
static ssize_t devnull_write(struct file *, const char *, size_t);
|
||||||
|
|
||||||
/************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static struct file_operations devnull_fops =
|
static struct file_operations devnull_fops =
|
||||||
{
|
{
|
||||||
@@ -69,9 +69,9 @@ static struct file_operations devnull_fops =
|
|||||||
0 /* ioctl */
|
0 /* ioctl */
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static ssize_t devnull_read(struct file *filp, char *buffer, size_t len)
|
static ssize_t devnull_read(struct file *filp, char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
@@ -83,9 +83,9 @@ static ssize_t devnull_write(struct file *filp, const char *buffer, size_t len)
|
|||||||
return len; /* Say that everything was written */
|
return len; /* Say that everything was written */
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void devnull_register(void)
|
void devnull_register(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
############################################################################
|
||||||
|
# examples/pashello/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/.config
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
|
||||||
|
CFLAGS += -I$(TOPDIR)/pcode/include -I$(TOPDIR)/pcode/insn/include
|
||||||
|
|
||||||
|
ASRCS =
|
||||||
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
|
CSRCS = pashello.c device.c
|
||||||
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
OBJS = $(AOBJS) $(COBJS)
|
||||||
|
|
||||||
|
BIN = lib$(CONFIG_EXAMPLE)$(LIBEXT)
|
||||||
|
|
||||||
|
all: $(BIN)
|
||||||
|
|
||||||
|
$(AOBJS): %$(OBJEXT): %.S
|
||||||
|
$(call ASSEMBLE, $<, $@)
|
||||||
|
|
||||||
|
$(COBJS): %$(OBJEXT): %.c
|
||||||
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
|
$(BIN): $(OBJS)
|
||||||
|
@( for obj in $(OBJS) ; do \
|
||||||
|
$(call ARCHIVE, $@, $${obj}); \
|
||||||
|
done ; )
|
||||||
|
|
||||||
|
.depend: Makefile $(SRCS)
|
||||||
|
@$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
@touch $@
|
||||||
|
|
||||||
|
depend: .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(BIN) *~ .*.swp
|
||||||
|
$(call CLEAN)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
@rm -f Make.dep .depend
|
||||||
|
|
||||||
|
-include Make.dep
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
README
|
||||||
|
^^^^^^
|
||||||
|
|
||||||
|
hello.pas
|
||||||
|
|
||||||
|
This is a sample "Hello, World!" Pascal Program
|
||||||
|
|
||||||
|
hello.pex
|
||||||
|
|
||||||
|
This is the compiled, linked P-Code executable that results
|
||||||
|
when hello.pas is compiled.
|
||||||
|
|
||||||
|
hello.h
|
||||||
|
|
||||||
|
This file defines an initialized C array holds a copy of
|
||||||
|
hello.pex. This file as created by:
|
||||||
|
|
||||||
|
xxd -i hello.pex >hello.h
|
||||||
|
|
||||||
|
mkhello.sh
|
||||||
|
|
||||||
|
This is a scripts that can be used to rebuild both hello.pex
|
||||||
|
and hello.h.
|
||||||
|
|
||||||
|
device.c
|
||||||
|
|
||||||
|
The hello.pex file must be provided to the interpreter as a file
|
||||||
|
in the file system. Normally this would be done using real storage
|
||||||
|
medium. In this example, we will use device.c:
|
||||||
|
|
||||||
|
device.c implements a simple device driver. Reads from this device
|
||||||
|
will access the in-memory copy of hello.pex This device driver is
|
||||||
|
registered as /dev/pashello in the psuedo filesystem.
|
||||||
|
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/pashello/device.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Compilation Switches
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <nuttx/fs.h>
|
||||||
|
|
||||||
|
#include "hello.h"
|
||||||
|
#include "pashello.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static ssize_t hello_read(struct file *, char *, size_t);
|
||||||
|
static ssize_t hello_write(struct file *, const char *, size_t);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static struct file_operations hello_fops =
|
||||||
|
{
|
||||||
|
0, /* open */
|
||||||
|
0, /* close */
|
||||||
|
hello_read, /* read */
|
||||||
|
0, /* write */
|
||||||
|
0, /* seek */
|
||||||
|
0 /* ioctl */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static ssize_t hello_read(struct file *filp, char *buffer, size_t len)
|
||||||
|
{
|
||||||
|
off_t offset = filp->f_pos; /* Start read position */
|
||||||
|
ssize_t nread = 0; /* Bytes read -- assume EOF */
|
||||||
|
|
||||||
|
/* Make sure that the offset is within the .pex file */
|
||||||
|
|
||||||
|
if (offset < hello_pex_len)
|
||||||
|
{
|
||||||
|
/* Make sure the the read does not extend beyond the .pex file */
|
||||||
|
|
||||||
|
nread = len;
|
||||||
|
if (nread + offset > hello_pex_len)
|
||||||
|
{
|
||||||
|
nread = hello_pex_len - offset;
|
||||||
|
}
|
||||||
|
memcpy(buffer, &hello_pex[offset], nread);
|
||||||
|
}
|
||||||
|
return nread;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void hello_register(void)
|
||||||
|
{
|
||||||
|
(void)register_driver("/dev/hello", &hello_fops, 0444, NULL);
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
unsigned char hello_pex[] = {
|
||||||
|
0x50, 0x4f, 0x46, 0x46, 0x01, 0x01, 0x00, 0x00, 0x14, 0x00, 0x05, 0x00,
|
||||||
|
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
|
||||||
|
0x01, 0x06, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x7c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00,
|
||||||
|
0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x00, 0x00,
|
||||||
|
0x0f, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||||
|
0x06, 0x00, 0x08, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xa0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||||
|
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00,
|
||||||
|
0x38, 0x00, 0x00, 0x00, 0xb1, 0x00, 0x00, 0x74, 0x0e, 0xf9, 0x00, 0x00,
|
||||||
|
0x25, 0xb5, 0xff, 0xfc, 0xf9, 0x00, 0x00, 0x20, 0x3f, 0x48, 0x65, 0x6c,
|
||||||
|
0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x21, 0x21, 0x00,
|
||||||
|
0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x48, 0x45, 0x4c,
|
||||||
|
0x4c, 0x4f, 0x00, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x61, 0x73,
|
||||||
|
0x00, 0x2e, 0x74, 0x65, 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, 0x64, 0x61,
|
||||||
|
0x74, 0x61, 0x00, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x74, 0x61, 0x62, 0x00,
|
||||||
|
0x2e, 0x6c, 0x69, 0x6e, 0x65, 0x6e, 0x6f, 0x00, 0x2e, 0x73, 0x74, 0x72,
|
||||||
|
0x74, 0x61, 0x62, 0x00
|
||||||
|
};
|
||||||
|
unsigned int hello_pex_len = 232;
|
||||||
@@ -1,5 +1,23 @@
|
|||||||
program hello(output);
|
unsigned char hello_pex[] = {
|
||||||
begin
|
0x50, 0x4f, 0x46, 0x46, 0x01, 0x01, 0x00, 0x00, 0x14, 0x00, 0x05, 0x00,
|
||||||
writeln('Hello world!!!');
|
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
|
||||||
end.
|
0x01, 0x06, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x7c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00,
|
||||||
|
0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x00, 0x00,
|
||||||
|
0x0f, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||||
|
0x06, 0x00, 0x08, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xa0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||||
|
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00,
|
||||||
|
0x38, 0x00, 0x00, 0x00, 0xb1, 0x00, 0x00, 0x74, 0x0e, 0xf9, 0x00, 0x00,
|
||||||
|
0x25, 0xb5, 0xff, 0xfc, 0xf9, 0x00, 0x00, 0x20, 0x3f, 0x48, 0x65, 0x6c,
|
||||||
|
0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x21, 0x21, 0x00,
|
||||||
|
0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x48, 0x45, 0x4c,
|
||||||
|
0x4c, 0x4f, 0x00, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x61, 0x73,
|
||||||
|
0x00, 0x2e, 0x74, 0x65, 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, 0x64, 0x61,
|
||||||
|
0x74, 0x61, 0x00, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x74, 0x61, 0x62, 0x00,
|
||||||
|
0x2e, 0x6c, 0x69, 0x6e, 0x65, 0x6e, 0x6f, 0x00, 0x2e, 0x73, 0x74, 0x72,
|
||||||
|
0x74, 0x61, 0x62, 0x00
|
||||||
|
};
|
||||||
|
unsigned int hello_pex_len = 232;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
############################################################################
|
############################################################################
|
||||||
# mkhello.sh
|
# examples/pashello/mkhello.sh
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
# Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
@@ -44,6 +44,7 @@ PLINK=${BINDIR}/plink
|
|||||||
PRUN=${BINDIR}/prun
|
PRUN=${BINDIR}/prun
|
||||||
|
|
||||||
PASFILENAME=hello.pas
|
PASFILENAME=hello.pas
|
||||||
|
OUFILE=hello.h
|
||||||
STRSTKSZ=1024
|
STRSTKSZ=1024
|
||||||
|
|
||||||
function sanity_check ()
|
function sanity_check ()
|
||||||
@@ -127,8 +128,14 @@ function test_hello ()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function make_include ()
|
||||||
|
{
|
||||||
|
xxd -i hello.pex >hello.pas
|
||||||
|
}
|
||||||
|
|
||||||
sanity_check
|
sanity_check
|
||||||
compile_hello
|
compile_hello
|
||||||
rm *.o *.o1 *.lst *.err
|
rm *.o *.o1 *.lst *.err
|
||||||
test_hello
|
test_hello
|
||||||
|
make_include
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/pashello/pashello.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <debug.h>
|
||||||
|
|
||||||
|
#include "pexec.h"
|
||||||
|
#include "pedefs.h"
|
||||||
|
#include "pashello.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_PASHELLO_VARSTACKSIZE
|
||||||
|
# define CONFIG_PASHELLO_VARSTACKSIZE 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_PASHELLO_STRSTACKSIZE
|
||||||
|
# define CONFIG_PASHELLO_STRSTACKSIZE 128
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* 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
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* user_initialize
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void user_initialize(void)
|
||||||
|
{
|
||||||
|
/* Register the /dev/hello driver */
|
||||||
|
|
||||||
|
hello_register();
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* user_start
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int user_start(int argc, FAR char *argv[])
|
||||||
|
{
|
||||||
|
FAR struct pexec_s *st;
|
||||||
|
|
||||||
|
/* Load the POFF file */
|
||||||
|
|
||||||
|
st = pload("/dev/hello", CONFIG_PASHELLO_VARSTACKSIZE, CONFIG_PASHELLO_STRSTACKSIZE);
|
||||||
|
if (!st)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "user_start: ERROR: Could not load /dev/hello\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
printf("user_start: /dev/hello Loaded\n");
|
||||||
|
|
||||||
|
/* And start program execution */
|
||||||
|
|
||||||
|
prun(st);
|
||||||
|
|
||||||
|
/* Clean up resources used by the interpreter */
|
||||||
|
|
||||||
|
pexec_release(st);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/pashello/pashello.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __EXAMPLES_PASHELLO_H
|
||||||
|
#define __EXAMPLES_PASHELLO_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define errno *get_errno_ptr()
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Defined in device.c */
|
||||||
|
|
||||||
|
extern void hello_register(void);
|
||||||
|
|
||||||
|
#endif /* __EXAMPLES_PASHELLO_H */
|
||||||
Reference in New Issue
Block a user