summaryrefslogtreecommitdiff
path: root/misc/pascal/libpoff
diff options
context:
space:
mode:
Diffstat (limited to 'misc/pascal/libpoff')
-rw-r--r--misc/pascal/libpoff/Make.defs49
-rw-r--r--misc/pascal/libpoff/Makefile47
-rw-r--r--misc/pascal/libpoff/pfdbgcontainer.c105
-rw-r--r--misc/pascal/libpoff/pfdbgdiscard.c94
-rw-r--r--misc/pascal/libpoff/pfdbginfo.c157
-rw-r--r--misc/pascal/libpoff/pfdhdr.c182
-rw-r--r--misc/pascal/libpoff/pfdreloc.c107
-rw-r--r--misc/pascal/libpoff/pfdsymbol.c116
-rw-r--r--misc/pascal/libpoff/pfhandle.c195
-rw-r--r--misc/pascal/libpoff/pfiprog.c92
-rw-r--r--misc/pascal/libpoff/pfirodata.c102
-rw-r--r--misc/pascal/libpoff/pflabel.c284
-rw-r--r--misc/pascal/libpoff/pflineno.c333
-rw-r--r--misc/pascal/libpoff/pfprivate.h172
-rw-r--r--misc/pascal/libpoff/pfproghandle.c127
-rw-r--r--misc/pascal/libpoff/pfrdbgfunc.c130
-rw-r--r--misc/pascal/libpoff/pfread.c318
-rw-r--r--misc/pascal/libpoff/pfrelease.c94
-rw-r--r--misc/pascal/libpoff/pfrfname.c116
-rw-r--r--misc/pascal/libpoff/pfrhdr.c117
-rw-r--r--misc/pascal/libpoff/pfrlineno.c127
-rw-r--r--misc/pascal/libpoff/pfrprog.c91
-rw-r--r--misc/pascal/libpoff/pfrrawlineno.c110
-rw-r--r--misc/pascal/libpoff/pfrrawreloc.c107
-rw-r--r--misc/pascal/libpoff/pfrseek.c115
-rw-r--r--misc/pascal/libpoff/pfrstring.c90
-rw-r--r--misc/pascal/libpoff/pfrsymbol.c107
-rw-r--r--misc/pascal/libpoff/pfsymhandle.c127
-rw-r--r--misc/pascal/libpoff/pftprog.c224
-rw-r--r--misc/pascal/libpoff/pftsymbol.c188
-rw-r--r--misc/pascal/libpoff/pfwdbgfunc.c173
-rw-r--r--misc/pascal/libpoff/pfwfname.c145
-rw-r--r--misc/pascal/libpoff/pfwhdr.c115
-rw-r--r--misc/pascal/libpoff/pfwlineno.c164
-rw-r--r--misc/pascal/libpoff/pfwprog.c127
-rw-r--r--misc/pascal/libpoff/pfwreloc.c161
-rw-r--r--misc/pascal/libpoff/pfwrite.c477
-rw-r--r--misc/pascal/libpoff/pfwrodata.c192
-rw-r--r--misc/pascal/libpoff/pfwstring.c217
-rw-r--r--misc/pascal/libpoff/pfwsymbol.c151
-rw-r--r--misc/pascal/libpoff/pfxprog.c95
-rw-r--r--misc/pascal/libpoff/pfxrodata.c94
-rw-r--r--misc/pascal/libpoff/pofferr.c93
43 files changed, 6427 insertions, 0 deletions
diff --git a/misc/pascal/libpoff/Make.defs b/misc/pascal/libpoff/Make.defs
new file mode 100644
index 000000000..68ed47e4e
--- /dev/null
+++ b/misc/pascal/libpoff/Make.defs
@@ -0,0 +1,49 @@
+############################################################################
+# libpoff/Make.defs
+# NuttX runtime makefile fragment
+#
+# 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.
+#
+############################################################################
+
+POFF_ASRCS =
+POFF_CSRCS = pfhandle.c pfproghandle.c pftprog.c \
+ pfsymhandle.c pftsymbol.c pofferr.c \
+ pfwhdr.c pfwrodata.c pfwsymbol.c pfwfname.c \
+ pfwprog.c pfwlineno.c pfwdbgfunc.c pfwreloc.c pfwstring.c \
+ pfwrite.c pfrhdr.c pfrsymbol.c pfrfname.c \
+ pfrprog.c pfrlineno.c pfrdbgfunc.c pfrrawlineno.c \
+ pfrrawreloc.c pfrstring.c pfread.c pfrseek.c \
+ pfrelease.c pfdbgcontainer.c pfdbgdiscard.c \
+ pfxprog.c pfxrodata.c pfiprog.c pfirodata.c \
+ pfdhdr.c pfdsymbol.c pfdreloc.c pflabel.c \
+ pflineno.c pfdbginfo.c
+L \ No newline at end of file
diff --git a/misc/pascal/libpoff/Makefile b/misc/pascal/libpoff/Makefile
new file mode 100644
index 000000000..ece3ccb16
--- /dev/null
+++ b/misc/pascal/libpoff/Makefile
@@ -0,0 +1,47 @@
+# ----------------------------------------------------------------------
+# libpoff/Makefile
+# ----------------------------------------------------------------------
+
+# ----------------------------------------------------------------------
+# Directories
+
+PASCAL = ${shell pwd}/..
+
+include $(PASCAL)/Make.config
+include $(PASCAL)/Make.defs
+
+INCDIR = $(PASCAL)/include
+LIBDIR = $(PASCAL)/lib
+
+# ----------------------------------------------------------------------
+# Objects and targets
+
+LIBPOFFSRCS = pfhandle.c pfproghandle.c pftprog.c \
+ pfsymhandle.c pftsymbol.c pofferr.c \
+ pfwhdr.c pfwrodata.c pfwsymbol.c pfwfname.c \
+ pfwprog.c pfwlineno.c pfwdbgfunc.c pfwreloc.c pfwstring.c \
+ pfwrite.c pfrhdr.c pfrsymbol.c pfrfname.c \
+ pfrprog.c pfrlineno.c pfrdbgfunc.c pfrrawlineno.c \
+ pfrrawreloc.c pfrstring.c pfread.c pfrseek.c \
+ pfrelease.c pfdbgcontainer.c pfdbgdiscard.c \
+ pfxprog.c pfxrodata.c pfiprog.c pfirodata.c \
+ pfdhdr.c pfdsymbol.c pfdreloc.c pflabel.c \
+ pflineno.c pfdbginfo.c
+LIBPOFFOBJS = $(LIBPOFFSRCS:.c=.o)
+
+all: libpoff.a
+.PHONY: all libpoff.a clean
+
+$(OBJS): %.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+$(LIBDIR)/libpoff.a: $(LIBPOFFOBJS)
+ $(RM) $@
+ $(AR) $(ARFLAGS) $@ $^
+
+libpoff.a: $(LIBDIR)/libpoff.a
+
+clean:
+ $(RM) libpoff.a *.o core *~
+
+# ----------------------------------------------------------------------
diff --git a/misc/pascal/libpoff/pfdbgcontainer.c b/misc/pascal/libpoff/pfdbgcontainer.c
new file mode 100644
index 000000000..15057745b
--- /dev/null
+++ b/misc/pascal/libpoff/pfdbgcontainer.c
@@ -0,0 +1,105 @@
+/**********************************************************************
+ * pfrdbgcontainer.c
+ * Create/destroy debug info container.
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+poffLibDebugFuncInfo_t *poffCreateDebugInfoContainer(uint32 nparms)
+{
+ poffLibDebugFuncInfo_t *pDebugFuncInfo;
+ int wAllocSize = SIZEOFDEBUFINFO(nparms);
+
+ pDebugFuncInfo = (poffLibDebugFuncInfo_t*)malloc(wAllocSize);
+ if (!pDebugFuncInfo)
+ {
+ fatal(eNOMEMORY);
+ return NULL;
+ }
+
+ memset(pDebugFuncInfo, 0, wAllocSize);
+ return pDebugFuncInfo;
+}
+
+/***********************************************************************/
+
+void poffReleaseDebugFuncContainer(poffLibDebugFuncInfo_t *pDebugFuncInfo)
+{
+ if (pDebugFuncInfo)
+ {
+ free(pDebugFuncInfo);
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfdbgdiscard.c b/misc/pascal/libpoff/pfdbgdiscard.c
new file mode 100644
index 000000000..0b80e9f45
--- /dev/null
+++ b/misc/pascal/libpoff/pfdbgdiscard.c
@@ -0,0 +1,94 @@
+/**********************************************************************
+ * pfdbgdiscard.c
+ * Discard debug function information
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "keywords.h" /* Standard types */
+
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+void poffDiscardDebugFuncInfo(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* Deallocate any buffered data */
+
+ if (poffInfo->debugFuncTable)
+ {
+ free(poffInfo->debugFuncTable);
+ }
+
+ /* And erase any knowledge of the debug info */
+
+ poffInfo->debugFuncSection.sh_size = 0;
+ poffInfo->debugFuncTable = NULL;
+ poffInfo->debugFuncTableAlloc = 0;
+ poffInfo->debugFuncIndex = 0;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfdbginfo.c b/misc/pascal/libpoff/pfdbginfo.c
new file mode 100644
index 000000000..3de279b91
--- /dev/null
+++ b/misc/pascal/libpoff/pfdbginfo.c
@@ -0,0 +1,157 @@
+/**********************************************************************
+ * pdbginfo.c
+ * Manage debug information
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+static poffLibDebugFuncInfo_t *g_pDebugInfoHead = NULL;
+static poffLibDebugFuncInfo_t *g_pDebugInfoTail = NULL;
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+void poffReadDebugFuncInfoTable(poffHandle_t handle)
+{
+ poffLibDebugFuncInfo_t *pDebugInfo;
+
+ /* Read all function debug information into a link list */
+
+ while ((pDebugInfo = poffGetDebugFuncInfo(handle)) != NULL)
+ {
+ if (!g_pDebugInfoHead)
+ {
+ g_pDebugInfoHead = pDebugInfo;
+ }
+ else
+ {
+ g_pDebugInfoTail->next = pDebugInfo;
+ }
+ g_pDebugInfoTail = pDebugInfo;
+ }
+}
+
+/***********************************************************************/
+
+poffLibDebugFuncInfo_t *poffFindDebugFuncInfo(uint32 offset)
+{
+ poffLibDebugFuncInfo_t *pDebugInfo;
+
+ /* Search the list for an entry with PC==offset */
+
+ for (pDebugInfo = g_pDebugInfoHead; pDebugInfo;
+ pDebugInfo = pDebugInfo->next)
+ {
+ if (pDebugInfo->value == offset)
+ {
+ return pDebugInfo;
+ }
+ }
+ return NULL;
+}
+
+/***********************************************************************/
+
+void poffReplaceDebugFuncInfo(poffHandle_t handle)
+{
+ poffLibDebugFuncInfo_t *pDebugInfo;
+
+ /* Discard any existing debug info in the POFF object */
+
+ poffDiscardDebugFuncInfo(handle);
+
+ /* Then add all of the buffered debug info into the object */
+
+ for (pDebugInfo = g_pDebugInfoHead; pDebugInfo;
+ pDebugInfo = pDebugInfo->next)
+ {
+ (void)poffAddDebugFuncInfo(handle, pDebugInfo);
+
+ }
+}
+
+/***********************************************************************/
+
+void poffReleaseDebugFuncInfoTable(void)
+{
+ poffLibDebugFuncInfo_t *pDebugInfo;
+ poffLibDebugFuncInfo_t *pNextDebugInfo;
+
+ /* Release the bufferred debug information */
+
+ pDebugInfo = g_pDebugInfoHead;
+ while (pDebugInfo)
+ {
+ pNextDebugInfo = pDebugInfo->next;
+ poffReleaseDebugFuncContainer(pDebugInfo);
+ pDebugInfo = pNextDebugInfo;
+ }
+
+ g_pDebugInfoHead = NULL;
+ g_pDebugInfoTail = NULL;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfdhdr.c b/misc/pascal/libpoff/pfdhdr.c
new file mode 100644
index 000000000..4e674a6a5
--- /dev/null
+++ b/misc/pascal/libpoff/pfdhdr.c
@@ -0,0 +1,182 @@
+/**********************************************************************
+ * pfdhdr.c
+ * Dump the contents of POFF file and section headers
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "keywords.h" /* Standard types */
+#include "pfprivate.h" /* POFF private definitions */
+#include "pofflib.h" /* Public interfaces */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Constant Data
+ **********************************************************************/
+
+static const char *poffFhTypes[FHT_NTYPES] =
+{
+ "NONE ", /* Shouldn't happen */
+ "EXEC ", /* Pascal program executable */
+ "SHLIB ", /* Pascal shared library */
+ "PROGRAM ", /* Pascal program object */
+ "UNIT " /* Pascal unit object */
+};
+
+static const char *poffShTypes[SHT_NTYPES] =
+{
+ "NULL ", /* Shouldn't happen */
+ "PROGDATA", /* Program data */
+ "SYMTAB ", /* Symbol table */
+ "STRTAB ", /* String table */
+ "REL ", /* Relocation data */
+ "FILETAB ", /* File table */
+ "LINENO ", /* Line number data */
+ "DEBUG " /* Func/Proc debug data */
+};
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+static void poffDumpSectionHeader(poffHandle_t handle,
+ poffSectionHeader_t *shdr,
+ FILE *outFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ fprintf(outFile, "%-10s %8s 0x%02x 0x%04x 0x%08lx 0x%08lx %ld\n",
+ poffGetString(poffInfo, shdr->sh_name),
+ poffShTypes[shdr->sh_type], shdr->sh_flags,
+ shdr->sh_entsize, shdr->sh_addr, shdr->sh_offset,
+ shdr->sh_size);
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+void poffDumpFileHeader(poffHandle_t handle, FILE *outFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ fprintf(outFile, "\nPOFF File Header:\n");
+ fprintf(outFile, " fh_ident: %c%c%c%c\n",
+ poffInfo->fileHeader.fh_ident[0], poffInfo->fileHeader.fh_ident[1],
+ poffInfo->fileHeader.fh_ident[2], poffInfo->fileHeader.fh_ident[3]);
+ fprintf(outFile, " fh_version: %d\n", poffInfo->fileHeader.fh_version);
+ fprintf(outFile, " fh_type: %s\n",
+ poffFhTypes[poffInfo->fileHeader.fh_type]);
+ fprintf(outFile, " fh_shsize: %d\n", poffInfo->fileHeader.fh_shsize);
+ fprintf(outFile, " fh_shnum: %d\n", poffInfo->fileHeader.fh_shnum);
+ fprintf(outFile, " fh_name: %s\n",
+ poffGetString(poffInfo, poffInfo->fileHeader.fh_name));
+ fprintf(outFile, " fh_entry: 0x%08lx\n", poffInfo->fileHeader.fh_entry);
+ fprintf(outFile, " fh_shoff: 0x%08lx\n", poffInfo->fileHeader.fh_shoff);
+}
+
+/***********************************************************************/
+
+void poffDumpSectionHeaders(poffHandle_t handle, FILE *outFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ fprintf(outFile, "\nPOFF Section Headers:\n");
+ fprintf(outFile, "NAME TYPE FLAG ENTSZE ADDRESS OFFSET SIZE\n");
+
+ if (poffInfo->progSection.sh_size > 0)
+ {
+ poffDumpSectionHeader(handle, &poffInfo->progSection, outFile);
+ }
+
+ if (poffInfo->roDataSection.sh_size > 0)
+ {
+ poffDumpSectionHeader(handle, &poffInfo->roDataSection, outFile);
+ }
+
+ if (poffInfo->symbolTableSection.sh_size > 0)
+ {
+ poffDumpSectionHeader(handle, &poffInfo->symbolTableSection, outFile);
+ }
+
+ if (poffInfo->stringTableSection.sh_size > 0)
+ {
+ poffDumpSectionHeader(handle, &poffInfo->stringTableSection, outFile);
+ }
+
+ if (poffInfo->relocSection.sh_size > 0)
+ {
+ poffDumpSectionHeader(handle, &poffInfo->relocSection, outFile);
+ }
+
+ if (poffInfo->fileNameTableSection.sh_size > 0)
+ {
+ poffDumpSectionHeader(handle, &poffInfo->fileNameTableSection, outFile);
+ }
+
+ if (poffInfo->lineNumberSection.sh_size > 0)
+ {
+ poffDumpSectionHeader(handle, &poffInfo->lineNumberSection, outFile);
+ }
+
+ if (poffInfo->debugFuncSection.sh_size > 0)
+ {
+ poffDumpSectionHeader(handle, &poffInfo->debugFuncSection, outFile);
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfdreloc.c b/misc/pascal/libpoff/pfdreloc.c
new file mode 100644
index 000000000..732419fd4
--- /dev/null
+++ b/misc/pascal/libpoff/pfdreloc.c
@@ -0,0 +1,107 @@
+/**********************************************************************
+ * pfdreloc.c
+ * Dump contents of a POFF file reloc table
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "keywords.h" /* Standard types */
+#include "pfprivate.h" /* POFF private definitions */
+#include "pofflib.h" /* Public interfaces */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Constant Data
+ **********************************************************************/
+
+static const char *poffRelocationTypes[RLT_NTYPES] =
+{
+ "NULL", /* Shouldn't happen */
+ "PCAL", /* Procedure/Function call */
+ "LDST", /* Load from stack base */
+};
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+void poffDumpRelocTable(poffHandle_t handle, FILE *outFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffRelocation_t *prel;
+ uint32 index;
+
+ fprintf(outFile, "\nPOFF Relocation Table:\n");
+ fprintf(outFile, "RELO SYMBOL SECTION\n");
+ fprintf(outFile, "TYPE TBL INDEX DATA OFFSET\n");
+
+ for (index = 0;
+ index < poffInfo->relocSection.sh_size;
+ index += poffInfo->relocSection.sh_entsize)
+ {
+ prel = (poffRelocation_t*)&poffInfo->relocTable[index];
+
+ fprintf(outFile, "%-6s 0x%08lx 0x%08lx\n",
+ poffRelocationTypes[RLI_TYPE(prel->rl_info)],
+ RLI_SYM(prel->rl_info),
+ prel->rl_offset);
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfdsymbol.c b/misc/pascal/libpoff/pfdsymbol.c
new file mode 100644
index 000000000..aa7aa1474
--- /dev/null
+++ b/misc/pascal/libpoff/pfdsymbol.c
@@ -0,0 +1,116 @@
+/**********************************************************************
+ * pfdsymbol.c
+ * Dump contents of a POFF file symbol table
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "keywords.h" /* Standard types */
+#include "pfprivate.h" /* POFF private definitions */
+#include "pofflib.h" /* Public interfaces */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Constant Data
+ **********************************************************************/
+
+static const char *poffSymTypes[STT_NTYPES] =
+{
+ "NULL ", /* Shouldn't happen */
+ "DATA ", /* Stack data */
+ "RODATA", /* Read-only data */
+ "PROC ", /* Symbol table */
+ "FUNC " /* String table */
+};
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+void poffDumpSymbolTable(poffHandle_t handle, FILE *outFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffSymbol_t *psym;
+ uint32 index;
+
+ fprintf(outFile, "\nPOFF Symbol Table:\n");
+ fprintf(outFile, "NAME "
+ "TYPE "
+ "FLAG "
+ "ALGN "
+ "VALUE "
+ "SIZE\n");
+
+ for (index = 0;
+ index < poffInfo->symbolTableSection.sh_size;
+ index += poffInfo->symbolTableSection.sh_entsize)
+ {
+ psym = (poffSymbol_t*)&poffInfo->symbolTable[index];
+
+ fprintf(outFile, "%-20s %6s 0x%02x 0x%02x 0x%08lx 0x%08lx\n",
+ poffGetString(poffInfo, psym->st_name),
+ poffSymTypes[psym->st_type],
+ psym->st_flags,
+ psym->st_align,
+ psym->st_value,
+ psym->st_size);
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfhandle.c b/misc/pascal/libpoff/pfhandle.c
new file mode 100644
index 000000000..458d63182
--- /dev/null
+++ b/misc/pascal/libpoff/pfhandle.c
@@ -0,0 +1,195 @@
+/**********************************************************************
+ * pfhandle.c
+ * POFF library global variables
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "keywords.h" /* Standard types */
+#include "pfprivate.h" /* POFF private definitions */
+#include "pofflib.h" /* Public interfaces */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Set all global data structures to a known state */
+
+poffHandle_t poffCreateHandle(void)
+{
+ poffInfo_t *poffInfo;
+
+ /* Create a new POFF handle */
+
+ poffInfo = (poffInfo_t*)malloc(sizeof(poffInfo_t));
+ if (poffInfo != NULL)
+ {
+ /* Set everthing to zero */
+
+ memset(poffInfo, 0, sizeof(poffInfo_t));
+
+ /* Initialize POFF file header */
+
+ poffInfo->fileHeader.fh_ident[FHI_MAG0] = FHI_POFF_MAG0;
+ poffInfo->fileHeader.fh_ident[FHI_MAG1] = FHI_POFF_MAG1;
+ poffInfo->fileHeader.fh_ident[FHI_MAG2] = FHI_POFF_MAG2;
+ poffInfo->fileHeader.fh_ident[FHI_MAG3] = FHI_POFF_MAG3;
+ poffInfo->fileHeader.fh_version = FHV_CURRENT;
+ poffInfo->fileHeader.fh_shsize = sizeof(poffSectionHeader_t);
+ poffInfo->fileHeader.fh_shoff = sizeof(poffFileHeader_t);
+
+ /* Initialize the program section header */
+
+ poffInfo->progSection.sh_type = SHT_PROGDATA;
+ poffInfo->progSection.sh_flags = SHF_ALLOC | SHF_EXEC;
+
+ /* Initialize the initialized data section header */
+
+ poffInfo->roDataSection.sh_type = SHT_PROGDATA;
+ poffInfo->roDataSection.sh_flags = SHF_WRITE | SHF_ALLOC;
+
+ /* Initialize the symbol table section header */
+
+ poffInfo->symbolTableSection.sh_type = SHT_SYMTAB;
+ poffInfo->symbolTableSection.sh_entsize = sizeof(poffSymbol_t);
+
+ /* Initialize the string table section header */
+
+ poffInfo->stringTableSection.sh_type = SHT_STRTAB;
+
+ /* Initialize the relocation table section header */
+
+ poffInfo->relocSection.sh_type = SHT_REL;
+ poffInfo->relocSection.sh_entsize = sizeof(poffRelocation_t);
+
+ /* Initialize the file table section header */
+
+ poffInfo->fileNameTableSection.sh_type = SHT_FILETAB;
+ poffInfo->fileNameTableSection.sh_entsize = sizeof(poffFileTab_t);
+
+ /* Initialize the line number section header */
+
+ poffInfo->lineNumberSection.sh_type = SHT_LINENO;
+ poffInfo->lineNumberSection.sh_entsize = sizeof(poffLineNumber_t);
+
+ /* Initialize the debug function info section header */
+
+ poffInfo->debugFuncSection.sh_type = SHT_DEBUG;
+ poffInfo->debugFuncSection.sh_entsize = sizeof(poffDebugFuncInfo_t);
+ }
+ return poffInfo;
+}
+
+/***********************************************************************/
+
+void poffDestroyHandle(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* Free all of the allocated, in-memory data */
+
+ if (poffInfo->progSectionData)
+ free(poffInfo->progSectionData);
+
+ if (poffInfo->roDataSectionData)
+ free(poffInfo->roDataSectionData);
+
+ if (poffInfo->symbolTable)
+ free(poffInfo->symbolTable);
+
+ if (poffInfo->stringTable)
+ free(poffInfo->stringTable);
+
+ if (poffInfo->relocTable)
+ free(poffInfo->relocTable);
+
+ if (poffInfo->fileNameTable)
+ free(poffInfo->fileNameTable);
+
+ if (poffInfo->lineNumberTable)
+ free(poffInfo->lineNumberTable);
+
+ if (poffInfo->debugFuncTable)
+ free(poffInfo->debugFuncTable);
+
+ /* Free the container */
+
+ free(handle);
+}
+
+/***********************************************************************/
+
+void poffResetAccess(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* Reset read/write indices */
+
+ poffInfo->symbolIndex = 0;
+ poffInfo->progSectionIndex = 0;
+ poffInfo->relocIndex = 0;
+ poffInfo->fileNameIndex = 0;
+ poffInfo->lineNumberIndex = 0;
+ poffInfo->debugFuncIndex = 0;
+}
+
+/***********************************************************************/
+
diff --git a/misc/pascal/libpoff/pfiprog.c b/misc/pascal/libpoff/pfiprog.c
new file mode 100644
index 000000000..2d175db4b
--- /dev/null
+++ b/misc/pascal/libpoff/pfiprog.c
@@ -0,0 +1,92 @@
+/**********************************************************************
+ * pfiprog.c
+ * Insert program data int a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+void poffInsertProgramData(poffHandle_t handle,
+ ubyte *progData, uint32 progSize)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* If there is already program data in the container, discard it. */
+
+ if (poffInfo->progSectionData) free(poffInfo->progSectionData);
+
+ /* Then, insert the new program data */
+
+ poffInfo->progSection.sh_size = progSize;
+ poffInfo->progSectionData = progData;
+ poffInfo->progSectionAlloc = progSize;
+ poffInfo->progSectionIndex = 0;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfirodata.c b/misc/pascal/libpoff/pfirodata.c
new file mode 100644
index 000000000..2d4679ada
--- /dev/null
+++ b/misc/pascal/libpoff/pfirodata.c
@@ -0,0 +1,102 @@
+/**********************************************************************
+ * pfirodata.c
+ * Append program read-only data to a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+void poffAppendRoData(poffHandle_t handle,
+ ubyte *roData, uint32 roDataSize)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ ubyte *tmp;
+ uint32 newSize;
+
+ if ((roData) && (roDataSize))
+ {
+ /* Reallocate the read-only data */
+
+ newSize = poffInfo->roDataSection.sh_size + roDataSize;
+ tmp = (ubyte*)realloc(poffInfo->roDataSectionData, newSize);
+ if (!tmp) fatal(eNOMEMORY);
+
+ /* Add the new data to the new allocation */
+
+ memcpy(&tmp[poffInfo->roDataSection.sh_size], roData, roDataSize);
+
+ /* Add the new allocation to the read-only section */
+
+ poffInfo->roDataSection.sh_size = newSize;
+ poffInfo->roDataSectionData = tmp;
+ poffInfo->roDataSectionAlloc = newSize;
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pflabel.c b/misc/pascal/libpoff/pflabel.c
new file mode 100644
index 000000000..e322fbb5c
--- /dev/null
+++ b/misc/pascal/libpoff/pflabel.c
@@ -0,0 +1,284 @@
+/**********************************************************************
+ * pflabel.c
+ * Label resolution logic
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "keywords.h"
+#include "pdefs.h"
+#include "pedefs.h"
+#include "perr.h"
+#include "poff.h"
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+#define INITIAL_DEFINED_ALLOCATION (1024*sizeof(optDefinedLabelRef_t))
+#define DEFINED_INCREMENT (256*sizeof(optDefinedLabelRef_t))
+
+#define INITIAL_UNDEFINED_ALLOCATION (1024*sizeof(optUndefinedLabelRef_t))
+#define UNDEFINED_INCREMENT (256*sizeof(optUndefinedLabelRef_t))
+
+/**********************************************************************
+ * Private Types
+ **********************************************************************/
+
+struct optDefinedLabelRef_s
+{
+ uint32 label;
+ uint32 pc;
+};
+typedef struct optDefinedLabelRef_s optDefinedLabelRef_t;
+
+struct optUndefinedLabelRef_s
+{
+ uint32 label;
+ uint32 symIndex;
+};
+typedef struct optUndefinedLabelRef_s optUndefinedLabelRef_t;
+
+/**********************************************************************
+ * Private Data
+ **********************************************************************/
+
+static optDefinedLabelRef_t *definedLabelRefs = NULL;
+static uint32 definedLabelRefAlloc = 0;
+static uint32 nDefinedLabelRefs = 0;
+
+static optUndefinedLabelRef_t *undefinedLabelRefs = NULL;
+static uint32 undefinedLabelRefAlloc = 0;
+static uint32 nUndefinedLabelRefs = 0;
+
+/**********************************************************************
+ * Private Function Prototypes
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Inline Functions
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Functions
+ **********************************************************************/
+
+/**********************************************************************/
+
+static void poffCheckDefinedLabelAlloc(void)
+{
+ /* Has the label reference table been allocated */
+
+ if (!definedLabelRefs)
+ {
+ /* No, allocate it now */
+
+ definedLabelRefs = (optDefinedLabelRef_t*)
+ malloc(INITIAL_DEFINED_ALLOCATION);
+
+ if (!definedLabelRefs)
+ {
+ fatal(eNOMEMORY);
+ }
+ definedLabelRefAlloc = INITIAL_DEFINED_ALLOCATION;
+ }
+}
+
+/**********************************************************************/
+
+static void poffCheckDefinedLabelRealloc(void)
+{
+ /* Check if there is room for the new data */
+
+ if (((nDefinedLabelRefs + 1)*sizeof(optDefinedLabelRef_t)) >
+ definedLabelRefAlloc)
+ {
+ uint32 newAlloc = definedLabelRefAlloc + DEFINED_INCREMENT;
+ void *tmp;
+
+ /* Reallocate the label reference tabel */
+
+ tmp = realloc(definedLabelRefs, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ definedLabelRefAlloc = newAlloc;
+ definedLabelRefs = (optDefinedLabelRef_t*)tmp;
+ }
+}
+
+/**********************************************************************/
+
+static void poffCheckUndefinedLabelAlloc(void)
+{
+ /* Has the label reference table been allocated */
+
+ if (!undefinedLabelRefs)
+ {
+ /* No, allocate it now */
+
+ undefinedLabelRefs = (optUndefinedLabelRef_t*)
+ malloc(INITIAL_UNDEFINED_ALLOCATION);
+
+ if (!undefinedLabelRefs)
+ {
+ fatal(eNOMEMORY);
+ }
+ undefinedLabelRefAlloc = INITIAL_UNDEFINED_ALLOCATION;
+ }
+}
+
+/**********************************************************************/
+
+static void poffCheckUndefinedLabelRealloc(void)
+{
+ /* Check if there is room for the new data */
+
+ if (((nUndefinedLabelRefs + 1)*sizeof(optUndefinedLabelRef_t)) >
+ undefinedLabelRefAlloc)
+ {
+ uint32 newAlloc = undefinedLabelRefAlloc + UNDEFINED_INCREMENT;
+ void *tmp;
+
+ /* Reallocate the label reference tabel */
+
+ tmp = realloc(undefinedLabelRefs, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ undefinedLabelRefAlloc = newAlloc;
+ undefinedLabelRefs = (optUndefinedLabelRef_t*)tmp;
+ }
+}
+
+/**********************************************************************/
+
+/**********************************************************************
+ * Global Functions
+ **********************************************************************/
+
+/**********************************************************************/
+
+void poffAddToDefinedLabelTable(uint32 label, uint32 pc)
+{
+ /* Make sure we have memory to do this. If not, we will crash */
+
+ poffCheckDefinedLabelAlloc();
+ poffCheckDefinedLabelRealloc();
+
+ /* Add the label to the table */
+
+ definedLabelRefs[nDefinedLabelRefs].label = label;
+ definedLabelRefs[nDefinedLabelRefs].pc = pc;
+ nDefinedLabelRefs++;
+}
+
+/**********************************************************************/
+
+void poffAddToUndefinedLabelTable(uint32 label, uint32 symIndex)
+{
+ /* Make sure we have memory to do this. If not, we will crash */
+
+ poffCheckUndefinedLabelAlloc();
+ poffCheckUndefinedLabelRealloc();
+
+ /* Add the label to the table */
+
+ undefinedLabelRefs[nUndefinedLabelRefs].label = label;
+ undefinedLabelRefs[nUndefinedLabelRefs].symIndex = symIndex;
+ nUndefinedLabelRefs++;
+}
+
+/**********************************************************************/
+
+int poffGetSymIndexForUndefinedLabel(uint32 label)
+{
+ int i;
+
+ for (i = 0; i < nUndefinedLabelRefs; i++)
+ {
+ if (undefinedLabelRefs[i].label == label)
+ {
+ return undefinedLabelRefs[i].symIndex;
+ }
+ }
+ return -1;
+}
+
+/**********************************************************************/
+
+int poffGetPcForDefinedLabel(uint32 label)
+{
+ int i;
+
+ for (i = 0; i < nDefinedLabelRefs; i++)
+ {
+ if (definedLabelRefs[i].label == label)
+ {
+ return definedLabelRefs[i].pc;
+ }
+ }
+ return -1;
+}
+
+/**********************************************************************/
+
+void poffReleaseLabelReferences(void)
+{
+ if (definedLabelRefs)
+ {
+ free(definedLabelRefs);
+ }
+ if (undefinedLabelRefs)
+ {
+ free(undefinedLabelRefs);
+ }
+}
+
+/**********************************************************************/
+
diff --git a/misc/pascal/libpoff/pflineno.c b/misc/pascal/libpoff/pflineno.c
new file mode 100644
index 000000000..647194643
--- /dev/null
+++ b/misc/pascal/libpoff/pflineno.c
@@ -0,0 +1,333 @@
+/**********************************************************************
+ * pflineno.c
+ * Manage line number information
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+#define INITIAL_LINENUMBER_TABLE_SIZE 2048*sizeof(poffLibLineNumber_t)
+#define LINENUMBER_TABLE_INCREMENT 512*sizeof(poffLibLineNumber_t)
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+static poffLibLineNumber_t *lineNumberTable;
+static uint32 nLineNumbers;
+static uint32 lineNumberTableAlloc;
+static uint32 prevLineNumberIndex;
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+static inline void poffCheckLineNumberAllocation(void)
+{
+ /* Check if we have allocated a line number buffer yet */
+
+ if (!lineNumberTable)
+ {
+ /* No, allocate it now */
+
+ lineNumberTable = (poffLibLineNumber_t*)
+ malloc(INITIAL_LINENUMBER_TABLE_SIZE);
+
+ if (!lineNumberTable)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ lineNumberTableAlloc = INITIAL_LINENUMBER_TABLE_SIZE;
+ nLineNumbers = 0;
+ }
+}
+
+/***********************************************************************/
+
+static inline void poffCheckLineNumberReallocation(void)
+{
+ if ((nLineNumbers +1) * sizeof(poffLibLineNumber_t) > lineNumberTableAlloc)
+ {
+ uint32 newAlloc = lineNumberTableAlloc + LINENUMBER_TABLE_INCREMENT;
+ void *tmp;
+
+ /* Reallocate the line number buffer */
+
+ tmp = realloc(lineNumberTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ lineNumberTableAlloc = newAlloc;
+ lineNumberTable = (poffLibLineNumber_t*)tmp;
+ }
+}
+
+/***********************************************************************/
+/* Add a line number to the line number table. */
+
+static void poffAddLineNumberToTable(poffLibLineNumber_t *lineno)
+{
+ /* Verify that the line number table has been allocated */
+
+ poffCheckLineNumberAllocation();
+
+ /* Verify that the line number table is large enough to hold
+ * information about another line.
+ */
+
+ poffCheckLineNumberReallocation();
+
+ /* Save the line number information in the line number table */
+
+ lineNumberTable[nLineNumbers] = *lineno;
+ nLineNumbers++;
+}
+
+/***********************************************************************/
+/* Discard any unused memory */
+
+static void poffDiscardUnusedAllocation(void)
+{
+ uint32 newAlloc = nLineNumbers * sizeof(poffLibLineNumber_t);
+ void *tmp;
+
+ /* Was a line number table allocated? And, if so, are there unused
+ * entries?
+ */
+
+ if ((lineNumberTable) && (nLineNumbers < lineNumberTableAlloc))
+ {
+ /* Reallocate the line number buffer */
+
+ tmp = realloc(lineNumberTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ lineNumberTableAlloc = newAlloc;
+ lineNumberTable = (poffLibLineNumber_t*)tmp;
+ }
+}
+
+/***********************************************************************/
+/* "The comparison function must return an integer less than, equal to,
+ * or greater than zero if the first argument is considered to be
+ * respectively less than, equal to, or greater than the second. If two
+ * members compare as equal, their order in the sorted array is undefined."
+ */
+
+static int poffCompareLineNumbers(const void *pv1, const void *pv2)
+{
+ register poffLibLineNumber_t *ln1 = (poffLibLineNumber_t*)pv1;
+ register poffLibLineNumber_t *ln2 = (poffLibLineNumber_t*)pv2;
+
+ if (ln1->offset < ln2->offset) return -1;
+ else if (ln1->offset > ln2->offset) return 1;
+ else return 0;
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+void poffReadLineNumberTable(poffHandle_t handle)
+{
+ poffLibLineNumber_t lineno;
+ sint32 offset;
+
+ /* Initialize global variables */
+
+ prevLineNumberIndex = 0;
+
+ /* Create a table of line number information */
+
+ do
+ {
+ offset = poffGetLineNumber(handle, &lineno);
+ if (offset >= 0)
+ {
+ poffAddLineNumberToTable(&lineno);
+ }
+ }
+ while (offset >= 0);
+
+ /* Discard any memory that is not being used */
+
+ poffDiscardUnusedAllocation();
+
+ /* Sort the table by offset */
+
+ qsort(lineNumberTable, nLineNumbers,
+ sizeof(poffLibLineNumber_t), poffCompareLineNumbers);
+}
+
+/***********************************************************************/
+
+poffLibLineNumber_t *poffFindLineNumber(uint32 offset)
+{
+ uint32 firstLineNumberIndex;
+ uint32 lastLineNumberIndex;
+ uint32 lineNumberIndex;
+
+ /* Was a line number table allocated? */
+
+ if (!lineNumberTable) return NULL;
+
+ /* We used the last returned line number entry as a hint to speed
+ * up the next search. We don't know how the line numbers will
+ * be searched but most likely, they will be searched ina a sequence
+ * of ascending offsets. In that case, a dumb linear search
+ * would be better than what we are trying to do here. we are
+ * trying to support fast random access.
+ */
+
+ if (lineNumberTable[prevLineNumberIndex].offset <= offset)
+ {
+ firstLineNumberIndex = prevLineNumberIndex;
+ lastLineNumberIndex = nLineNumbers - 1;
+ }
+ else
+ {
+ firstLineNumberIndex = 0;
+ lastLineNumberIndex = prevLineNumberIndex;
+ }
+
+ /* Search until firstLineNumberIndex and firstLineNumberIndex+1
+ * contain the searched for offset. Exact matches may or may
+ * not occur.
+ */
+
+ lineNumberIndex = firstLineNumberIndex;
+ while (firstLineNumberIndex != lastLineNumberIndex)
+ {
+ /* Look at the midpoint index. This will be biased toward
+ * the lower index due to truncation. This means that
+ * can always be assured that as long as firstLineNumberIndex !=
+ * lastLineNumberIndex, then lineNumberIndex+1 is valid. We
+ * exploit this fact below.
+ */
+
+ lineNumberIndex = (firstLineNumberIndex + lastLineNumberIndex) >> 1;
+
+ /* If the offset at the midpoint is greater than the sought
+ * for offset, then we can safely set the upper search index
+ * to the midpoint.
+ */
+
+ if (lineNumberTable[lineNumberIndex].offset > offset)
+ lastLineNumberIndex = lineNumberIndex;
+
+ /* If we have an exact match, we break out of the loop now */
+
+ else if (lineNumberTable[lineNumberIndex].offset == offset)
+ break;
+
+ /* If the next entry is an offset greater then the one we
+ * are searching for, then we can break out of the loop now.
+ * We know that lineNumberIndex+1 is a valid index (see above).
+ */
+
+ else if (lineNumberTable[lineNumberIndex + 1].offset > offset)
+ break;
+
+ /* Otherwise, we safely do the following */
+
+ else
+ firstLineNumberIndex = lineNumberIndex + 1;
+ }
+
+ /* Check that we terminated the loop with a valid line number
+ * match. This should only fail if all of the line numbers in the
+ * table have offsets greater than the one in the table. If we
+ * could not find a match, return NULL.
+ */
+
+ if (lineNumberTable[lineNumberIndex].offset > offset)
+ {
+ prevLineNumberIndex = 0;
+ return NULL;
+ }
+ else
+ {
+ prevLineNumberIndex = lineNumberIndex;
+ return &lineNumberTable[lineNumberIndex];
+ }
+}
+
+/***********************************************************************/
+
+void poffReleaseLineNumberTable(void)
+{
+ if (lineNumberTable)
+ free(lineNumberTable);
+
+ lineNumberTable = NULL;
+ nLineNumbers = 0;
+ lineNumberTableAlloc = 0;
+ prevLineNumberIndex = 0;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfprivate.h b/misc/pascal/libpoff/pfprivate.h
new file mode 100644
index 000000000..3bcdf89dc
--- /dev/null
+++ b/misc/pascal/libpoff/pfprivate.h
@@ -0,0 +1,172 @@
+/***************************************************************************
+ * pfprivate.h
+ * Contains command, internal, private definitions used by
+ * the POFF library. These were not intended for exportation.
+ *
+ * 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 __PFPRIVATE_H
+#define __PFPRIVATE_H
+
+/***************************************************************************
+ * Compilation Switches
+ ***************************************************************************/
+
+/***************************************************************************
+ * Included Files
+ ***************************************************************************/
+
+#include "keywords.h"
+#include "poff.h"
+
+/***************************************************************************
+ * Definitions
+ ***************************************************************************/
+
+#define INITIAL_STRING_TABLE_SIZE 4096
+#define STRING_TABLE_INCREMENT 1024
+
+#define INITIAL_SYMBOL_TABLE_SIZE 256*sizeof(poffSymbol_t)
+#define SYMBOL_TABLE_INCREMENT 64*sizeof(poffSymbol_t)
+
+#define INITIAL_FILENAME_TABLE_SIZE 64*sizeof(poffFileTab_t)
+#define FILENAME_TABLE_INCREMENT 64*sizeof(poffFileTab_t)
+
+#define INITIAL_RELOC_TABLE_SIZE 128*sizeof(poffRelocation_t)
+#define RELOC_TABLE_INCREMENT 64*sizeof(poffRelocation_t)
+
+#define INITIAL_LINENUMBER_TABLE_SIZE 2048*sizeof(poffLineNumber_t)
+#define LINENUMBER_TABLE_INCREMENT 512*sizeof(poffLineNumber_t)
+
+#define INITIAL_DEBUGFUNC_TABLE_SIZE 128*sizeof(poffDebugFuncInfo_t)
+#define DEBUGFUNC_TABLE_INCREMENT 64*sizeof(poffDebugFuncInfo_t)
+
+#define INITIAL_PROG_SECTION_SIZE 8096
+#define PROG_SECTION_INCREMENT 2048
+
+#define INITIAL_RODATA_SECTION_SIZE 4096
+#define RODATA_SECTION_INCREMENT 1024
+
+#define HAVE_PROGRAM_SECTION (poffInfo->progSection.sh_size > 0)
+#define HAVE_RODATA_SECTION (poffInfo->roDataSection.sh_size > 0)
+#define HAVE_SYMBOL_TABLE (poffInfo->symbolTableSection.sh_size > 0)
+#define HAVE_STRING_TABLE (poffInfo->stringTableSection.sh_size > 0)
+#define HAVE_RELOC_SECTION (poffInfo->relocSection.sh_size > 0)
+#define HAVE_FILE_TABLE (poffInfo->fileNameTableSection.sh_size > 0)
+#define HAVE_LINE_NUMBER (poffInfo->lineNumberSection.sh_size > 0)
+#define HAVE_DEBUG_SECTION (poffInfo->debugFuncSection.sh_size > 0)
+
+/***************************************************************************
+ * Public Types
+ ***************************************************************************/
+
+struct poffInfo_s
+{
+ /* POFF file header */
+
+ poffFileHeader_t fileHeader;
+
+ /* Section headers: */
+
+ poffSectionHeader_t progSection;
+ poffSectionHeader_t roDataSection;
+ poffSectionHeader_t symbolTableSection;
+ poffSectionHeader_t stringTableSection;
+ poffSectionHeader_t relocSection;
+ poffSectionHeader_t fileNameTableSection;
+ poffSectionHeader_t lineNumberSection;
+ poffSectionHeader_t debugFuncSection;
+
+ /* In-memory section data */
+
+ ubyte *progSectionData;
+ ubyte *roDataSectionData;
+ ubyte *symbolTable;
+ char *stringTable;
+ ubyte *relocTable;
+ poffFileTab_t *fileNameTable;
+ ubyte *lineNumberTable;
+ ubyte *debugFuncTable;
+
+ /* Current allocation sizes. Used only on writing to determine if
+ * in-memory has been allocated and how much memory has been allocated
+ * in case the buffer needs to be re-allocated.
+ */
+
+ uint32 progSectionAlloc;
+ uint32 roDataSectionAlloc;
+ uint32 symbolTableAlloc;
+ uint32 stringTableAlloc;
+ uint32 relocAlloc;
+ uint32 fileNameTableAlloc;
+ uint32 lineNumberTableAlloc;
+ uint32 debugFuncTableAlloc;
+
+ /* Current buffer indices. These are used on reading data sequentially
+ * from the in-memory section data.
+ */
+
+ uint32 progSectionIndex;
+ uint32 symbolIndex;
+ uint32 relocIndex;
+ uint32 fileNameIndex;
+ uint32 lineNumberIndex;
+ uint32 debugFuncIndex;
+};
+typedef struct poffInfo_s poffInfo_t;
+
+struct poffProgInfo_s
+{
+ uint32 progSectionSize;
+ uint32 progSectionAlloc;
+ ubyte *progSectionData;
+};
+typedef struct poffProgInfo_s poffProgInfo_t;
+
+struct poffSymInfo_s
+{
+ uint32 symbolTableSize;
+ uint32 symbolTableAlloc;
+ ubyte *symbolTable;
+};
+typedef struct poffSymInfo_s poffSymInfo_t;
+
+/***************************************************************************
+ * Public Variables
+ ***************************************************************************/
+
+/***************************************************************************
+ * Public Function Prototypes
+ ***************************************************************************/
+
+#endif /* __PFPRIVATE_H */
diff --git a/misc/pascal/libpoff/pfproghandle.c b/misc/pascal/libpoff/pfproghandle.c
new file mode 100644
index 000000000..fe5aa7fb2
--- /dev/null
+++ b/misc/pascal/libpoff/pfproghandle.c
@@ -0,0 +1,127 @@
+/**********************************************************************
+ * pfproghandle.c
+ * POFF temporary progdata support
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* Pascal error codes */
+
+#include "pfprivate.h" /* POFF private definitions */
+#include "pofflib.h" /* Public interfaces */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Set all global data structures to a known state */
+
+poffProgHandle_t poffCreateProgHandle(void)
+{
+ poffProgInfo_t *poffProgInfo;
+
+ /* Create a new POFF handle */
+
+ poffProgInfo = (poffProgInfo_t*)malloc(sizeof(poffProgInfo_t));
+ if (poffProgInfo != NULL)
+ {
+ /* Set everthing to zero */
+
+ memset(poffProgInfo, 0, sizeof(poffProgInfo_t));
+ }
+ return poffProgInfo;
+}
+
+/***********************************************************************/
+
+void poffDestroyProgHandle(poffProgHandle_t handle)
+{
+ /* Free all of the allocated, in-memory data */
+
+ poffResetProgHandle(handle);
+
+ /* Free the container */
+
+ free(handle);
+}
+
+/***********************************************************************/
+
+void poffResetProgHandle(poffProgHandle_t handle)
+{
+ poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)handle;
+
+ /* Free all of the allocated, in-memory data */
+
+ if (poffProgInfo->progSectionData)
+ {
+ free(poffProgInfo->progSectionData);
+ }
+
+ /* Reset everything to the initial state */
+
+ poffProgInfo->progSectionData = NULL;
+ poffProgInfo->progSectionSize = 0;
+ poffProgInfo->progSectionAlloc = 0;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrdbgfunc.c b/misc/pascal/libpoff/pfrdbgfunc.c
new file mode 100644
index 000000000..da944de98
--- /dev/null
+++ b/misc/pascal/libpoff/pfrdbgfunc.c
@@ -0,0 +1,130 @@
+/**********************************************************************
+ * pfrdbgfunc.c
+ * Read debug function information from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+poffLibDebugFuncInfo_t *poffGetDebugFuncInfo(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffDebugFuncInfo_t *pDebugInfo;
+ poffDebugArgInfo_t *pArgInfo;
+ poffLibDebugFuncInfo_t *pRet;
+ uint32 debugFuncIndex;
+ int i;
+
+ /* Check if there is another debug entgry in the table to be had */
+
+ debugFuncIndex = poffInfo->debugFuncIndex;
+
+ if (debugFuncIndex + sizeof(poffDebugFuncInfo_t) >=
+ poffInfo->debugFuncSection.sh_size)
+ {
+ /* Return NULL to signal the end of the list */
+
+ return NULL;
+ }
+
+ /* Get a reference to the debug function entry */
+
+ pDebugInfo = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[debugFuncIndex];
+
+ /* Allocate a container */
+
+ pRet = poffCreateDebugInfoContainer(pDebugInfo->df_nparms);
+
+ /* Return the debug function information */
+
+ pRet->value = pDebugInfo->df_value;
+ pRet->retsize = pDebugInfo->df_size;
+ pRet->nparms = pDebugInfo->df_nparms;
+
+ /* Return the size of each parameter */
+
+ debugFuncIndex += sizeof(poffDebugFuncInfo_t);
+ for (i = 0; i < pRet->nparms; i++)
+ {
+ pArgInfo = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[debugFuncIndex];
+ pRet->argsize[i] = pArgInfo->da_size;
+ debugFuncIndex += sizeof(poffDebugArgInfo_t);
+ }
+
+ /* Set up for the next read */
+
+ poffInfo->debugFuncIndex = debugFuncIndex;
+ return pRet;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfread.c b/misc/pascal/libpoff/pfread.c
new file mode 100644
index 000000000..890612888
--- /dev/null
+++ b/misc/pascal/libpoff/pfread.c
@@ -0,0 +1,318 @@
+/**********************************************************************
+ * pfread.c
+ * POFF library global variables
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* Pascal error definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+static uint16 poffReadFileHeader(poffHandle_t handle, FILE *poffFile);
+static uint16 poffReadSectionHeaders(poffHandle_t handle, FILE *poffFile);
+static uint16 poffReadSectionData(poffSectionHeader_t *shdr,
+ ubyte **sdata, FILE *poffFile);
+static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile);
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Read and verify the POFF file header */
+
+static uint16 poffReadFileHeader(poffHandle_t handle, FILE *poffFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ size_t entriesRead;
+
+ /* Seek to the beginning of the file */
+
+ if (fseek(poffFile, 0, SEEK_SET) != 0)
+ {
+ return ePOFFREADERROR;
+ }
+
+ /* Read the POFF file header */
+
+ entriesRead = fread(&poffInfo->fileHeader, sizeof(poffFileHeader_t),
+ 1, poffFile);
+ if (entriesRead != 1)
+ {
+ return ePOFFREADERROR;
+ }
+
+ /* Verify that this is a valid POFF header */
+
+ if ((poffInfo->fileHeader.fh_ident[FHI_MAG0] != FHI_POFF_MAG0) ||
+ (poffInfo->fileHeader.fh_ident[FHI_MAG1] != FHI_POFF_MAG1) ||
+ (poffInfo->fileHeader.fh_ident[FHI_MAG2] != FHI_POFF_MAG2) ||
+ (poffInfo->fileHeader.fh_ident[FHI_MAG3] != FHI_POFF_MAG3) ||
+ (poffInfo->fileHeader.fh_version != FHV_CURRENT))
+ {
+ return ePOFFBADFORMAT;
+ }
+ return eNOERROR;
+}
+
+/***********************************************************************/
+/* Read and verify all of the POFF section headers */
+
+static uint16 poffReadSectionHeaders(poffHandle_t handle, FILE *poffFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffSectionHeader_t sectionHeader;
+ long offset;
+ size_t entriesRead;
+ int i;
+
+ offset = poffInfo->fileHeader.fh_shoff;
+
+ for (i = 0; i < poffInfo->fileHeader.fh_shnum; i++)
+ {
+ /* Seek to the beginning of the next section header */
+
+ if (fseek(poffFile, offset, SEEK_SET) != 0)
+ {
+ return ePOFFREADERROR;
+ }
+
+ /* Read the section header */
+
+ entriesRead = fread(&sectionHeader, sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesRead != 1)
+ {
+ return ePOFFREADERROR;
+ }
+
+ /* Copy the section header to the correct location */
+
+ switch (sectionHeader.sh_type)
+ {
+ case SHT_PROGDATA : /* Program data */
+ if ((sectionHeader.sh_flags & SHF_EXEC) != 0)
+ poffInfo->progSection = sectionHeader;
+ else
+ poffInfo->roDataSection = sectionHeader;
+ break;
+
+ case SHT_SYMTAB : /* Symbol table */
+ poffInfo->symbolTableSection = sectionHeader;
+ break;
+
+ case SHT_STRTAB : /* String table */
+ poffInfo->stringTableSection = sectionHeader;
+ break;
+
+ case SHT_REL : /* Relocation data */
+ poffInfo->relocSection = sectionHeader;
+ break;
+
+ case SHT_FILETAB : /* File table */
+ poffInfo->fileNameTableSection = sectionHeader;
+ break;
+
+ case SHT_LINENO : /* Line number data */
+ poffInfo->lineNumberSection = sectionHeader;
+ break;
+
+ case SHT_DEBUG : /* Debug function info data */
+ poffInfo->debugFuncSection = sectionHeader;
+ break;
+
+ default:
+ return ePOFFREADERROR;
+ }
+
+ /* Get the offset to the next section */
+
+ offset += poffInfo->fileHeader.fh_shsize;
+ }
+ return eNOERROR;
+}
+
+/***********************************************************************/
+/* Read and buffer all of the POFF section data */
+
+static uint16 poffReadSectionData(poffSectionHeader_t *shdr,
+ ubyte **sdata, FILE *poffFile)
+{
+ size_t entriesRead;
+
+ /* Seek to the beginning of the section data */
+
+ if (fseek(poffFile, shdr->sh_offset, SEEK_SET) != 0)
+ {
+ return ePOFFREADERROR;
+ }
+
+ /* Allocate memory to hold the section data */
+
+ *sdata = (char*)malloc(shdr->sh_size);
+ if (*sdata == NULL)
+ {
+ return eNOMEMORY;
+ }
+
+ /* Read the section data */
+
+ entriesRead = fread(*sdata, 1, shdr->sh_size, poffFile);
+ if (entriesRead != shdr->sh_size)
+ {
+ return ePOFFREADERROR;
+ }
+ return eNOERROR;
+}
+
+/***********************************************************************/
+/* Read and buffer all of the POFF section data */
+
+static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint16 retval = eNOERROR;
+
+ if (HAVE_PROGRAM_SECTION)
+ {
+ retval = poffReadSectionData(&poffInfo->progSection,
+ (ubyte**)&poffInfo->progSectionData,
+ poffFile);
+ }
+
+ if ((retval == eNOERROR) && (HAVE_RODATA_SECTION))
+ {
+ retval = poffReadSectionData(&poffInfo->roDataSection,
+ (ubyte**)&poffInfo->roDataSectionData,
+ poffFile);
+ }
+
+ if ((retval == eNOERROR) && (HAVE_SYMBOL_TABLE))
+ {
+ retval = poffReadSectionData(&poffInfo->symbolTableSection,
+ (ubyte**)&poffInfo->symbolTable,
+ poffFile);
+ }
+
+ if ((retval == eNOERROR) && (HAVE_STRING_TABLE))
+ {
+ retval = poffReadSectionData(&poffInfo->stringTableSection,
+ (ubyte**)&poffInfo->stringTable,
+ poffFile);
+ }
+
+ if ((retval == eNOERROR) && (HAVE_RELOC_SECTION))
+ {
+ retval = poffReadSectionData(&poffInfo->relocSection,
+ (ubyte**)&poffInfo->relocTable,
+ poffFile);
+ }
+
+ if ((retval == eNOERROR) && (HAVE_FILE_TABLE))
+ {
+ retval = poffReadSectionData(&poffInfo->fileNameTableSection,
+ (ubyte**)&poffInfo->fileNameTable,
+ poffFile);
+ }
+
+ if ((retval == eNOERROR) && (HAVE_LINE_NUMBER))
+ {
+ retval = poffReadSectionData(&poffInfo->lineNumberSection,
+ (ubyte**)&poffInfo->lineNumberTable,
+ poffFile);
+ }
+
+ if ((retval == eNOERROR) && (HAVE_DEBUG_SECTION))
+ {
+ retval = poffReadSectionData(&poffInfo->debugFuncSection,
+ (ubyte**)&poffInfo->debugFuncTable,
+ poffFile);
+ }
+
+ return retval;
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Set all global data structures to a known state */
+
+uint16 poffReadFile(poffHandle_t handle, FILE *poffFile)
+{
+ uint16 retVal;
+
+ /* Read the POFF header file */
+
+ retVal = poffReadFileHeader(handle, poffFile);
+ if (retVal == eNOERROR)
+ {
+ retVal = poffReadSectionHeaders(handle, poffFile);
+ if (retVal == eNOERROR)
+ {
+ retVal = poffReadAllSectionData(handle, poffFile);
+ }
+ }
+ return retVal;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrelease.c b/misc/pascal/libpoff/pfrelease.c
new file mode 100644
index 000000000..8b8b3d123
--- /dev/null
+++ b/misc/pascal/libpoff/pfrelease.c
@@ -0,0 +1,94 @@
+/**********************************************************************
+ * pfrelease.c
+ * Program data manipulations on POFF temporary object
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "keywords.h" /* Standard types */
+
+#include "pfprivate.h" /* POFF private definitions */
+#include "pofflib.h" /* Public interfaces */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+void poffReleaseProgData(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* Discard any existing program section data */
+
+ if (poffInfo->progSectionData)
+ {
+ free(poffInfo->progSectionData);
+ poffInfo->progSectionData = NULL;
+ }
+
+ /* Indicate that there is no program data */
+
+ poffInfo->progSection.sh_size = 0;
+ poffInfo->progSectionAlloc = 0;
+ poffInfo->progSectionIndex = 0;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrfname.c b/misc/pascal/libpoff/pfrfname.c
new file mode 100644
index 000000000..70a788316
--- /dev/null
+++ b/misc/pascal/libpoff/pfrfname.c
@@ -0,0 +1,116 @@
+/**********************************************************************
+ * pfrfname.c
+ * Read file name data from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+sint32 poffGetFileName(poffHandle_t handle, const char **fname)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint32 stringTableIndex;
+ uint32 fileNameIndex;
+
+ /* First, check if there is another file name in the table to be had.
+ * This check is a little sloppy in that it assumes the the size in
+ * in the header is an even multiple of file name table entries
+ */
+
+ fileNameIndex = poffInfo->fileNameIndex;
+ if (fileNameIndex * sizeof(poffFileTab_t) >=
+ poffInfo->fileNameTableSection.sh_size)
+ {
+ /* Return -1 to signal the end of the list */
+
+ *fname = NULL;
+ return -1;
+ }
+ else
+ {
+ /* Get the string table index from the file name table */
+
+ stringTableIndex = (uint32)poffInfo->fileNameTable[fileNameIndex];
+
+ /* Return the file name */
+
+ *fname = poffGetString(handle, stringTableIndex);
+
+ /* Set up for the next read */
+
+ poffInfo->fileNameIndex++;
+ return fileNameIndex;
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrhdr.c b/misc/pascal/libpoff/pfrhdr.c
new file mode 100644
index 000000000..ca153c83e
--- /dev/null
+++ b/misc/pascal/libpoff/pfrhdr.c
@@ -0,0 +1,117 @@
+/**********************************************************************
+ * pfrhdr.c
+ * Read info from a POFF file header
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Get the type of the file from the POFF file header */
+
+ubyte poffGetFileType(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ return poffInfo->fileHeader.fh_type;
+}
+
+/***********************************************************************/
+/* Get the machine architecture from the POFF file header */
+
+ubyte poffGetArchitecture(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ return poffInfo->fileHeader.fh_arch;
+}
+
+/***********************************************************************/
+/* Get the program entry point */
+
+uint32 poffGetEntryPoint(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ return poffInfo->fileHeader.fh_entry;
+}
+
+/***********************************************************************/
+/* Return the name associated with the file in the file header */
+
+const char *poffGetFileHdrName(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ return poffGetString(handle, poffInfo->fileHeader.fh_name);
+}
+
+/***********************************************************************/
+
+uint32 poffGetRoDataSize(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ return poffInfo->roDataSection.sh_size;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrlineno.c b/misc/pascal/libpoff/pfrlineno.c
new file mode 100644
index 000000000..d1ec2a5f2
--- /dev/null
+++ b/misc/pascal/libpoff/pfrlineno.c
@@ -0,0 +1,127 @@
+/**********************************************************************
+ * pfrlineno.c
+ * Read line number data from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+sint32 poffGetLineNumber(poffHandle_t handle, poffLibLineNumber_t *lineno)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffLineNumber_t *pln;
+ uint32 stringTableIndex;
+ uint32 lineNumberIndex;
+
+ /* First, check if there is another line number in the table to be had.
+ * This check is a little sloppy in that it assumes the the size in
+ * in the header is an even multiple of line number table entries
+ */
+
+ lineNumberIndex = poffInfo->lineNumberIndex;
+ if (lineNumberIndex >= poffInfo->lineNumberSection.sh_size)
+ {
+ /* Return -1 to signal the end of the list */
+
+ memset(lineno, 0, sizeof(poffLibLineNumber_t));
+ return -1;
+ }
+ else
+ {
+ /* Get a reference to the line number record */
+
+ pln = (poffLineNumber_t*)&poffInfo->lineNumberTable[lineNumberIndex];
+
+ /* Get the filename table index */
+
+ if (pln->ln_fileno * sizeof(poffFileTab_t) >
+ poffInfo->fileNameTableSection.sh_size)
+ {
+ fatal(ePOFFCONFUSION);
+ }
+ stringTableIndex = (uint32)poffInfo->fileNameTable[pln->ln_fileno];
+
+ /* Return the line number information */
+
+ lineno->lineno = pln->ln_lineno;
+ lineno->offset = pln->ln_poffset;
+ lineno->filename = poffGetString(handle, stringTableIndex);
+
+ /* Set up for the next read */
+
+ poffInfo->lineNumberIndex += poffInfo->lineNumberSection.sh_entsize;
+ return lineNumberIndex;
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrprog.c b/misc/pascal/libpoff/pfrprog.c
new file mode 100644
index 000000000..d1df10d5e
--- /dev/null
+++ b/misc/pascal/libpoff/pfrprog.c
@@ -0,0 +1,91 @@
+/**********************************************************************
+ * pfrprog.c
+ * Read program data from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+int poffGetProgByte(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ int retval = EOF;
+
+ /* Check if there is more data that has not yet been read */
+
+ if ((poffInfo->progSectionIndex < poffInfo->progSection.sh_size) &&
+ (poffInfo->progSectionData != NULL))
+ {
+ retval = (int)poffInfo->progSectionData[poffInfo->progSectionIndex];
+ poffInfo->progSectionIndex++;
+ }
+ return retval;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrrawlineno.c b/misc/pascal/libpoff/pfrrawlineno.c
new file mode 100644
index 000000000..7d3aa1ab0
--- /dev/null
+++ b/misc/pascal/libpoff/pfrrawlineno.c
@@ -0,0 +1,110 @@
+/**********************************************************************
+ * pfrrawlineno.c
+ * Read raw line number data from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+sint32 poffGetRawLineNumber(poffHandle_t handle, poffLineNumber_t *lineno)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint32 lineNumberIndex;
+
+ /* First, check if there is another line number in the table to be had.
+ * This check is a little sloppy in that it assumes the the size in
+ * in the header is an even multiple of line number table entries
+ */
+
+ lineNumberIndex = poffInfo->lineNumberIndex;
+ if (lineNumberIndex >= poffInfo->lineNumberSection.sh_size)
+ {
+ /* Return -1 to signal the end of the list */
+
+ memset(lineno, 0, sizeof(poffLineNumber_t));
+ return -1;
+ }
+ else
+ {
+ /* Copy the raw line number information to the user */
+
+ *lineno = *(poffLineNumber_t*)&poffInfo->lineNumberTable[lineNumberIndex];
+
+ /* Set up for the next read */
+
+ poffInfo->lineNumberIndex += poffInfo->lineNumberSection.sh_entsize;
+ return lineNumberIndex;
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrrawreloc.c b/misc/pascal/libpoff/pfrrawreloc.c
new file mode 100644
index 000000000..143830d4e
--- /dev/null
+++ b/misc/pascal/libpoff/pfrrawreloc.c
@@ -0,0 +1,107 @@
+/**********************************************************************
+ * pfrrawreloc.c
+ * Read raw relocation data from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+sint32 poffGetRawRelocation(poffHandle_t handle, poffRelocation_t *lineno)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint32 relocIndex;
+
+ /* First, check if there is another relocation in the table to be had. */
+
+ relocIndex = poffInfo->relocIndex;
+ if (relocIndex >= poffInfo->relocSection.sh_size)
+ {
+ /* Return -1 to signal the end of the list */
+
+ memset(lineno, 0, sizeof(poffRelocation_t));
+ return -1;
+ }
+ else
+ {
+ /* Copy the raw line number information to the user */
+
+ *lineno = *(poffRelocation_t*)&poffInfo->relocTable[relocIndex];
+
+ /* Set up for the next read */
+
+ poffInfo->relocIndex += poffInfo->relocSection.sh_entsize;
+ return relocIndex;
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrseek.c b/misc/pascal/libpoff/pfrseek.c
new file mode 100644
index 000000000..ea0b9c0aa
--- /dev/null
+++ b/misc/pascal/libpoff/pfrseek.c
@@ -0,0 +1,115 @@
+/**********************************************************************
+ * pfrseek.c
+ * Seek to a position in buffered program data from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+sint32 poffProgTell(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ sint32 retval = -1;
+
+ /* Check if there is more data that has not yet been read */
+
+ if (poffInfo->progSectionData != NULL)
+ {
+ retval = poffInfo->progSectionIndex;
+ }
+ return retval;
+}
+
+/***********************************************************************/
+
+int poffProgSeek(poffHandle_t handle, uint32 offset)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ int retval = -1;
+
+ /* Check if there is more data that has not yet been read */
+
+ if ((offset < poffInfo->progSection.sh_size) &&
+ (poffInfo->progSectionData != NULL))
+ {
+ poffInfo->progSectionIndex = offset;
+ retval = offset;
+ }
+ return retval;
+}
+
+/***********************************************************************/
+
+uint32 poffGetProgSize(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ return poffInfo->progSection.sh_size;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrstring.c b/misc/pascal/libpoff/pfrstring.c
new file mode 100644
index 000000000..666da886a
--- /dev/null
+++ b/misc/pascal/libpoff/pfrstring.c
@@ -0,0 +1,90 @@
+/**********************************************************************
+ * pfrstring.c
+ * Read a string from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+const char *poffGetString(poffHandle_t handle, uint32 index)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ if ((index < poffInfo->stringTableSection.sh_size) &&
+ (poffInfo->stringTable != NULL))
+ {
+ return &poffInfo->stringTable[index];
+ }
+ else
+ {
+ return "<NULL>";
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfrsymbol.c b/misc/pascal/libpoff/pfrsymbol.c
new file mode 100644
index 000000000..dc76e524d
--- /dev/null
+++ b/misc/pascal/libpoff/pfrsymbol.c
@@ -0,0 +1,107 @@
+/**********************************************************************
+ * pfrsymbol
+ * Read symbols from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+sint32 poffGetSymbol(poffHandle_t handle, poffLibSymbol_t *symbol)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffSymbol_t *psym;
+ uint32 index;
+
+ /* First, check if there is another symbol in the table to be had.
+ * This check is a little sloppy in that it assumes the the size in
+ * in the section header is an even multiple of symbol table entries
+ */
+
+ index = poffInfo->symbolIndex;
+ if (index >= poffInfo->symbolTableSection.sh_size)
+ {
+ memset(symbol, 0, sizeof(poffLibSymbol_t));
+ return -1;
+ }
+ else
+ {
+ psym = (poffSymbol_t*)&poffInfo->symbolTable[index];
+ symbol->type = psym->st_type;
+ symbol->align = psym->st_align;
+ symbol->flags = psym->st_flags;
+ symbol->name = poffGetString(handle, psym->st_name);
+ symbol->value = psym->st_value;
+ symbol->size = psym->st_size;
+
+ poffInfo->symbolIndex += poffInfo->symbolTableSection.sh_entsize;
+ return index / poffInfo->symbolTableSection.sh_entsize;
+ }
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfsymhandle.c b/misc/pascal/libpoff/pfsymhandle.c
new file mode 100644
index 000000000..819fb2a17
--- /dev/null
+++ b/misc/pascal/libpoff/pfsymhandle.c
@@ -0,0 +1,127 @@
+/**********************************************************************
+ * pfsymhandle.c
+ * POFF temporary symdata support
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* Pascal error codes */
+
+#include "pfprivate.h" /* POFF private definitions */
+#include "pofflib.h" /* Public interfaces */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Set all global data structures to a known state */
+
+poffSymHandle_t poffCreateSymHandle(void)
+{
+ poffSymInfo_t *poffSymInfo;
+
+ /* Create a new POFF handle */
+
+ poffSymInfo = (poffSymInfo_t*)malloc(sizeof(poffSymInfo_t));
+ if (poffSymInfo != NULL)
+ {
+ /* Set everthing to zero */
+
+ memset(poffSymInfo, 0, sizeof(poffSymInfo_t));
+ }
+ return poffSymInfo;
+}
+
+/***********************************************************************/
+
+void poffDestroySymHandle(poffSymHandle_t handle)
+{
+ /* Free all of the allocated, in-memory data */
+
+ poffResetSymHandle(handle);
+
+ /* Free the container */
+
+ free(handle);
+}
+
+/***********************************************************************/
+
+void poffResetSymHandle(poffSymHandle_t handle)
+{
+ poffSymInfo_t *poffSymInfo = (poffSymInfo_t*)handle;
+
+ /* Free all of the allocated, in-memory data */
+
+ if (poffSymInfo->symbolTable)
+ {
+ free(poffSymInfo->symbolTable);
+ }
+
+ /* Reset everything to the initial state */
+
+ poffSymInfo->symbolTable = NULL;
+ poffSymInfo->symbolTableSize = 0;
+ poffSymInfo->symbolTableAlloc = 0;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pftprog.c b/misc/pascal/libpoff/pftprog.c
new file mode 100644
index 000000000..875e99b38
--- /dev/null
+++ b/misc/pascal/libpoff/pftprog.c
@@ -0,0 +1,224 @@
+/**********************************************************************
+ * pftprog.c
+ * Program data manipulations on POFF temporary object
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* Pascal error codes */
+
+#include "pfprivate.h" /* POFF private definitions */
+#include "pofflib.h" /* Public interfaces */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+static uint16 poffCheckProgAlloc(poffProgInfo_t *poffProgInfo)
+{
+ if (!poffProgInfo->progSectionData)
+ {
+ /* No, allocate it now */
+
+ poffProgInfo->progSectionData = (char*)malloc(INITIAL_PROG_SECTION_SIZE);
+ if (!poffProgInfo->progSectionData)
+ {
+ return eNOMEMORY;
+ }
+
+ poffProgInfo->progSectionSize = 0;
+ poffProgInfo->progSectionAlloc = INITIAL_PROG_SECTION_SIZE;
+ }
+ return eNOERROR;
+}
+
+static uint16 poffCheckProgRealloc(poffProgInfo_t *poffProgInfo, uint16 len)
+{
+ /* Check if there is room for the new data */
+
+ if (poffProgInfo->progSectionSize + len > poffProgInfo->progSectionAlloc)
+ {
+ uint32 newAlloc =
+ poffProgInfo->progSectionAlloc + PROG_SECTION_INCREMENT;
+ void *tmp;
+
+ /* Make certain that this is big enough (it should be) */
+
+ while (poffProgInfo->progSectionSize + len > newAlloc)
+ {
+ newAlloc += PROG_SECTION_INCREMENT;
+ }
+
+ /* Reallocate the program data section buffer */
+
+ tmp = realloc(poffProgInfo->progSectionData, newAlloc);
+ if (!tmp)
+ {
+ return eNOMEMORY;
+ }
+
+ /* And set the new size */
+
+ poffProgInfo->progSectionAlloc = newAlloc;
+ poffProgInfo->progSectionData = (ubyte*)tmp;
+ }
+ return eNOERROR;
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+uint16 poffAddTmpProgByte(poffProgHandle_t handle, ubyte progByte)
+{
+ poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)handle;
+ uint16 errCode;
+
+ /* Check if we have allocated a program section buffer yet */
+
+ errCode = poffCheckProgAlloc(poffProgInfo);
+ if (errCode != eNOERROR)
+ {
+ return errCode;
+ }
+
+ /* Check if there is room for the new byte */
+
+ errCode = poffCheckProgRealloc(poffProgInfo, 1);
+ if (errCode != eNOERROR)
+ {
+ return errCode;
+ }
+
+ /* Copy program data byte into the program data buffer */
+
+ poffProgInfo->progSectionData[poffProgInfo->progSectionSize] = progByte;
+
+ /* Set the new size of the string table */
+
+ poffProgInfo->progSectionSize++;
+ return eNOERROR;
+}
+
+/***********************************************************************/
+
+uint16 poffWriteTmpProgBytes(ubyte *buffer, uint32 nbytes,
+ poffProgHandle_t handle)
+
+{
+ poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)handle;
+ uint16 errCode;
+
+ /* Check if we have allocated a program section buffer yet */
+
+ errCode = poffCheckProgAlloc(poffProgInfo);
+ if (errCode != eNOERROR)
+ {
+ return errCode;
+ }
+
+ /* Check if there is room for the new data */
+
+ errCode = poffCheckProgRealloc(poffProgInfo, nbytes);
+ if (errCode != eNOERROR)
+ {
+ return errCode;
+ }
+
+ /* Copy program data byte into the program data buffer */
+
+ memcpy(&poffProgInfo->progSectionData[poffProgInfo->progSectionSize],
+ buffer, nbytes);
+
+ /* Set the new size of the string table */
+
+ poffProgInfo->progSectionSize += nbytes;
+ return eNOERROR;
+}
+
+/***********************************************************************/
+
+void poffReplaceProgData(poffHandle_t handle, poffProgHandle_t progHandle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)progHandle;
+
+ /* Discard any existing program section data */
+
+ if (poffInfo->progSectionData)
+ {
+ free(poffInfo->progSectionData);
+ }
+
+ /* Replace the program section data with the tmp data */
+
+ poffInfo->progSectionData = poffProgInfo->progSectionData;
+ poffInfo->progSection.sh_size = poffProgInfo->progSectionSize;
+ poffInfo->progSectionAlloc = poffProgInfo->progSectionAlloc;
+
+ /* Reset the read index */
+
+ poffInfo->progSectionIndex = 0;
+
+ /* Then nullify the tmp data */
+
+ poffProgInfo->progSectionData = NULL;
+ poffProgInfo->progSectionSize = 0;
+ poffProgInfo->progSectionAlloc = 0;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pftsymbol.c b/misc/pascal/libpoff/pftsymbol.c
new file mode 100644
index 000000000..32eb375dd
--- /dev/null
+++ b/misc/pascal/libpoff/pftsymbol.c
@@ -0,0 +1,188 @@
+/**********************************************************************
+ * pftsymbol.c
+ * Write symbol information to a temporary container
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Add a symbol to the symbol table section data. Returns index value
+ * associated with the symbol entry in the symbol table section data.
+ */
+
+uint32 poffAddTmpSymbol(poffHandle_t handle, poffSymHandle_t symHandle,
+ poffLibSymbol_t *symbol)
+{
+ poffSymInfo_t *poffSymInfo = (poffSymInfo_t*)symHandle;
+ poffSymbol_t *psym;
+ uint32 st_name;
+ uint32 index;
+
+ /* Add the name to the string table. Note: We are probably re-writing
+ * the string table and so the string probably already exists in the
+ * string table. We are counting of the string table logic's abililty
+ * avoid duplicated strings to keep from adding trash to the string
+ * table.
+ */
+
+ st_name = poffAddString(handle, symbol->name);
+
+ /* Check if we have allocated a symbol table buffer yet */
+
+ if (!poffSymInfo->symbolTable)
+ {
+ /* No, allocate it now */
+
+ poffSymInfo->symbolTable = (ubyte*)malloc(INITIAL_SYMBOL_TABLE_SIZE);
+ if (!poffSymInfo->symbolTable)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ poffSymInfo->symbolTableSize = 0;
+ poffSymInfo->symbolTableAlloc = INITIAL_SYMBOL_TABLE_SIZE;
+ }
+
+ /* Check if there is room for a new symbol */
+
+ if (poffSymInfo->symbolTableSize + sizeof(poffSymbol_t) >
+ poffSymInfo->symbolTableAlloc)
+ {
+ uint32 newAlloc = poffSymInfo->symbolTableAlloc + SYMBOL_TABLE_INCREMENT;
+ ubyte *tmp;
+
+ /* Reallocate the file name buffer */
+
+ tmp = (ubyte*)realloc(poffSymInfo->symbolTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ poffSymInfo->symbolTableAlloc = newAlloc;
+ poffSymInfo->symbolTable = tmp;
+ }
+
+ /* Save the new symbol information in the symbol table data */
+
+ index = poffSymInfo->symbolTableSize;
+ psym = (poffSymbol_t*)&poffSymInfo->symbolTable[index];
+
+ psym->st_type = symbol->type;
+ psym->st_align = symbol->align;
+ psym->st_flags = symbol->flags;
+ psym->st_pad = 0;
+ psym->st_name = st_name;
+ psym->st_value = symbol->value;
+ psym->st_size = symbol->size;
+
+ /* Set the new size of the file name table */
+
+ poffSymInfo->symbolTableSize += sizeof(poffSymbol_t);
+ return index;
+}
+
+/***********************************************************************/
+
+void poffReplaceSymbolTable(poffHandle_t handle, poffSymHandle_t symHandle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffSymInfo_t *poffSymInfo = (poffSymInfo_t*)symHandle;
+
+ /* Discard any existing symbol table */
+
+ if (poffInfo->symbolTable)
+ {
+ free(poffInfo->symbolTable);
+ }
+
+ /* Replace the symram section data with the tmp data */
+
+ poffInfo->symbolTable = poffSymInfo->symbolTable;
+ poffInfo->symbolTableSection.sh_size = poffSymInfo->symbolTableSize;
+ poffInfo->symbolTableSection.sh_entsize = sizeof(poffSymbol_t);
+ poffInfo->symbolTableAlloc = poffSymInfo->symbolTableAlloc;
+
+ /* Reset the read index */
+
+ poffInfo->symbolIndex = 0;
+
+ /* Then nullify the tmp data */
+
+ poffSymInfo->symbolTable = NULL;
+ poffSymInfo->symbolTableSize = 0;
+ poffSymInfo->symbolTableAlloc = 0;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwdbgfunc.c b/misc/pascal/libpoff/pfwdbgfunc.c
new file mode 100644
index 000000000..9f3b35d39
--- /dev/null
+++ b/misc/pascal/libpoff/pfwdbgfunc.c
@@ -0,0 +1,173 @@
+/**********************************************************************
+ * pfwdbgfunc.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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+static void poffCheckDebugFuncInfoAllocation(poffInfo_t *poffInfo)
+{
+ /* Check if we have allocated a line number buffer yet */
+
+ if (!poffInfo->debugFuncTable)
+ {
+ /* No, allocate it now */
+
+ poffInfo->debugFuncTable = (ubyte*)
+ malloc(INITIAL_DEBUGFUNC_TABLE_SIZE);
+
+ if (!poffInfo->debugFuncTable)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ poffInfo->debugFuncSection.sh_size = 0;
+ poffInfo->debugFuncTableAlloc = INITIAL_DEBUGFUNC_TABLE_SIZE;
+ }
+}
+
+/***********************************************************************/
+
+static void poffCheckDebugFuncInfoReallocation(poffInfo_t *poffInfo, uint32 nparms)
+{
+ uint32 needed = sizeof(poffDebugFuncInfo_t) + nparms*sizeof(poffDebugArgInfo_t);
+ if (poffInfo->debugFuncSection.sh_size + needed > poffInfo->debugFuncTableAlloc)
+ {
+ uint32 newAlloc =
+ poffInfo->debugFuncTableAlloc +
+ DEBUGFUNC_TABLE_INCREMENT;
+
+ void *tmp;
+
+ /* Reallocate the line number buffer */
+
+ tmp = realloc(poffInfo->debugFuncTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ poffInfo->debugFuncTableAlloc = newAlloc;
+ poffInfo->debugFuncTable = (ubyte*)tmp;
+ }
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Add a debug inforamtion to the debug func table. Returns the index
+ * associated with the line number entry in the line number table.
+ */
+
+uint32 poffAddDebugFuncInfo(poffHandle_t handle,
+ poffLibDebugFuncInfo_t *pContainer)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffDebugFuncInfo_t *pFuncInfo;
+ poffDebugArgInfo_t *pArgInfo;
+ uint32 funcInfoIndex;
+ uint32 argInfoIndex;
+ int i;
+
+ /* Verify that the debug info table has been allocated */
+
+ poffCheckDebugFuncInfoAllocation(poffInfo);
+
+ /* Verify that the debug infotable is large enough to hold
+ * information about function
+ */
+
+ poffCheckDebugFuncInfoReallocation(poffInfo, pContainer->nparms);
+
+ /* Save the information in the debug func info table */
+
+ funcInfoIndex = poffInfo->debugFuncSection.sh_size;
+ pFuncInfo = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[funcInfoIndex];
+
+ pFuncInfo->df_value = pContainer->value;
+ pFuncInfo->df_size = pContainer->retsize;
+ pFuncInfo->df_nparms = pContainer->nparms;
+
+ argInfoIndex = funcInfoIndex + sizeof(poffDebugFuncInfo_t);
+ for (i = 0; i < pContainer->nparms; i++)
+ {
+ pArgInfo = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[argInfoIndex];
+ pArgInfo->da_size = pContainer->argsize[i];
+ argInfoIndex += sizeof(poffDebugArgInfo_t);
+ }
+
+ /* Set the new size of the debug func info table */
+
+ poffInfo->debugFuncSection.sh_size = argInfoIndex;
+ return funcInfoIndex;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwfname.c b/misc/pascal/libpoff/pfwfname.c
new file mode 100644
index 000000000..d5d051e7e
--- /dev/null
+++ b/misc/pascal/libpoff/pfwfname.c
@@ -0,0 +1,145 @@
+/**********************************************************************
+ * pfwfname.c
+ * Write filename data to a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Add a file name to the file table. Returns file number index value
+ * and NOT the byte offset associated with the file name entry in the
+ * file name section.
+ */
+
+uint32 poffAddFileName(poffHandle_t handle, const char *name)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffFileTab_t ft;
+ uint32 index;
+
+ /* Add the name to the string table */
+
+ ft = (poffFileTab_t)poffAddString(poffInfo, name);
+
+ /* Add string table offset to the file table
+ *
+ * Check if we have allocated a filename table buffer yet
+ */
+
+ if (!poffInfo->fileNameTable)
+ {
+ /* No, allocate it now */
+
+ poffInfo->fileNameTable = (poffFileTab_t*)malloc(INITIAL_FILENAME_TABLE_SIZE);
+ if (!poffInfo->fileNameTable)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ poffInfo->fileNameTableSection.sh_size = 0;
+ poffInfo->fileNameTableAlloc = INITIAL_FILENAME_TABLE_SIZE;
+ }
+
+ /* Check if there is room for the new file name index */
+
+ if (poffInfo->fileNameTableSection.sh_size + sizeof(poffFileTab_t)>
+ poffInfo->fileNameTableAlloc)
+ {
+ uint32 newAlloc = poffInfo->fileNameTableAlloc + FILENAME_TABLE_INCREMENT;
+ void *tmp;
+
+ /* Reallocate the file name buffer */
+
+ tmp = realloc(poffInfo->fileNameTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ poffInfo->fileNameTableAlloc = newAlloc;
+ poffInfo->fileNameTable = (poffFileTab_t*)tmp;
+ }
+
+ /* Save the index in the file name table */
+
+ index = poffInfo->fileNameTableSection.sh_size / sizeof(poffFileTab_t);
+ poffInfo->fileNameTable[index] = ft;
+
+ /* Set the new size of the file name table */
+
+ poffInfo->fileNameTableSection.sh_size += sizeof(poffFileTab_t);
+ return index;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwhdr.c b/misc/pascal/libpoff/pfwhdr.c
new file mode 100644
index 000000000..80f040131
--- /dev/null
+++ b/misc/pascal/libpoff/pfwhdr.c
@@ -0,0 +1,115 @@
+/**********************************************************************
+ * pfwhdr.c
+ * Write to POFF file file and section headers
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Add the type of the file to the POFF file header */
+
+void poffSetFileType(poffHandle_t handle, ubyte fh_type,
+ uint16 nfiles, const char *name)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* Save the type in the file header */
+
+ poffInfo->fileHeader.fh_type = fh_type;
+
+ /* Save the associated name in the string table */
+
+ poffInfo->fileHeader.fh_name = poffAddString(poffInfo, name);
+}
+
+/***********************************************************************/
+/* Add the machine architecture to the POFF file header */
+
+void poffSetArchitecture(poffHandle_t handle, ubyte fh_arch)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* Save the type in the file header */
+
+ poffInfo->fileHeader.fh_arch = fh_arch;
+}
+
+/***********************************************************************/
+/* Set the program entry point */
+
+void poffSetEntryPoint(poffHandle_t handle, uint32 entryPoint)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffInfo->fileHeader.fh_entry = entryPoint;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwlineno.c b/misc/pascal/libpoff/pfwlineno.c
new file mode 100644
index 000000000..f7f4b9954
--- /dev/null
+++ b/misc/pascal/libpoff/pfwlineno.c
@@ -0,0 +1,164 @@
+/**********************************************************************
+ * pfwlineno.c
+ * Write line number data to a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+static void poffCheckLineNumberAllocation(poffInfo_t *poffInfo)
+{
+ /* Check if we have allocated a line number buffer yet */
+
+ if (!poffInfo->lineNumberTable)
+ {
+ /* No, allocate it now */
+
+ poffInfo->lineNumberTable = (ubyte*)
+ malloc(INITIAL_LINENUMBER_TABLE_SIZE);
+
+ if (!poffInfo->lineNumberTable)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ poffInfo->lineNumberSection.sh_size = 0;
+ poffInfo->lineNumberTableAlloc = INITIAL_LINENUMBER_TABLE_SIZE;
+ }
+}
+
+/***********************************************************************/
+
+static void poffCheckLineNumberReallocation(poffInfo_t *poffInfo)
+{
+ if (poffInfo->lineNumberSection.sh_size + sizeof(poffLineNumber_t) >
+ poffInfo->lineNumberTableAlloc)
+ {
+ uint32 newAlloc =
+ poffInfo->lineNumberTableAlloc +
+ LINENUMBER_TABLE_INCREMENT;
+
+ void *tmp;
+
+ /* Reallocate the line number buffer */
+
+ tmp = realloc(poffInfo->lineNumberTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ poffInfo->lineNumberTableAlloc = newAlloc;
+ poffInfo->lineNumberTable = (ubyte*)tmp;
+ }
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Add a line number to the line number table. Returns index value
+ * associated with the line number entry in the line number table.
+ */
+
+uint32 poffAddLineNumber(poffHandle_t handle,
+ uint16 lineNumber, uint16 fileNumber,
+ uint32 progSectionDataOffset)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffLineNumber_t *pln;
+ uint32 index;
+
+ /* Verify that the line number table has been allocated */
+
+ poffCheckLineNumberAllocation(poffInfo);
+
+ /* Verify that the line number table is large enough to hold
+ * information about another line.
+ */
+
+ poffCheckLineNumberReallocation(poffInfo);
+
+ /* Save the line number information in the line number table */
+
+ index = poffInfo->lineNumberSection.sh_size;
+ pln = (poffLineNumber_t*)&poffInfo->lineNumberTable[index];
+
+ pln->ln_lineno = lineNumber;
+ pln->ln_fileno = fileNumber;
+ pln->ln_poffset = progSectionDataOffset;
+
+ /* Set the new size of the line number table */
+
+ poffInfo->lineNumberSection.sh_size += sizeof(poffLineNumber_t);
+ return index;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwprog.c b/misc/pascal/libpoff/pfwprog.c
new file mode 100644
index 000000000..2078fecef
--- /dev/null
+++ b/misc/pascal/libpoff/pfwprog.c
@@ -0,0 +1,127 @@
+/**********************************************************************
+ * pfwprog.c
+ * Write program data to a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+void poffAddProgByte(poffHandle_t handle, ubyte progByte)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* Check if we have allocated a program section buffer yet */
+
+ if (!poffInfo->progSectionData)
+ {
+ /* No, allocate it now */
+
+ poffInfo->progSectionData = (char*)malloc(INITIAL_PROG_SECTION_SIZE);
+ if (!poffInfo->progSectionData)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ poffInfo->progSection.sh_size = 0;
+ poffInfo->progSectionAlloc = INITIAL_STRING_TABLE_SIZE;
+ }
+
+ /* Check if there is room for the new string */
+
+ if (poffInfo->progSection.sh_size + 1 > poffInfo->progSectionAlloc)
+ {
+ uint32 newAlloc = poffInfo->progSectionAlloc + PROG_SECTION_INCREMENT;
+ void *tmp;
+
+ /* Reallocate the program data section buffer */
+
+ tmp = realloc(poffInfo->progSectionData, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ poffInfo->progSectionAlloc = newAlloc;
+ poffInfo->progSectionData = (ubyte*)tmp;
+ }
+
+ /* Copy program data byte into the program data buffer */
+
+ poffInfo->progSectionData[poffInfo->progSection.sh_size] = progByte;
+
+ /* Set the new size of the string table */
+
+ poffInfo->progSection.sh_size++;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwreloc.c b/misc/pascal/libpoff/pfwreloc.c
new file mode 100644
index 000000000..1b347ab37
--- /dev/null
+++ b/misc/pascal/libpoff/pfwreloc.c
@@ -0,0 +1,161 @@
+/**********************************************************************
+ * pfwreloc.c
+ * Write relocation data to a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+static void poffCheckRelocationAllocation(poffInfo_t *poffInfo)
+{
+ /* Check if we have allocated a line number buffer yet */
+
+ if (!poffInfo->relocTable)
+ {
+ /* No, allocate it now */
+
+ poffInfo->relocTable = (ubyte*)malloc(INITIAL_RELOC_TABLE_SIZE);
+ if (!poffInfo->relocTable)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ poffInfo->relocSection.sh_size = 0;
+ poffInfo->relocAlloc = INITIAL_RELOC_TABLE_SIZE;
+ }
+}
+
+/***********************************************************************/
+
+static void poffCheckRelocationReallocation(poffInfo_t *poffInfo)
+{
+ if (poffInfo->relocSection.sh_size + sizeof(poffRelocation_t) >
+ poffInfo->relocAlloc)
+ {
+ uint32 newAlloc =
+ poffInfo->relocAlloc +
+ RELOC_TABLE_INCREMENT;
+
+ void *tmp;
+
+ /* Reallocate the line number buffer */
+
+ tmp = realloc(poffInfo->relocTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ poffInfo->relocAlloc = newAlloc;
+ poffInfo->relocTable = (ubyte*)tmp;
+ }
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Add a relocation to the relocation table. Returns index value
+ * associated with the relocation entry in the relocation table.
+ */
+
+uint32 poffAddRelocation(poffHandle_t handle,
+ ubyte relocType, uint32 symIndex,
+ uint32 sectionDataOffset)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffRelocation_t *prl;
+ uint32 index;
+
+ /* Verify that the relocation table has been allocated */
+
+ poffCheckRelocationAllocation(poffInfo);
+
+ /* Verify that the relocation table is large enough to hold
+ * information about another relocation.
+ */
+
+ poffCheckRelocationReallocation(poffInfo);
+
+ /* Save the relocation information in the relocation table */
+
+ index = poffInfo->relocSection.sh_size;
+ prl = (poffRelocation_t*)&poffInfo->relocTable[index];
+
+ prl->rl_info = RLI_MAKE(symIndex, relocType);
+ prl->rl_offset = sectionDataOffset;
+
+ /* Set the new size of the line number table */
+
+ poffInfo->relocSection.sh_size += sizeof(poffRelocation_t);
+ return index;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwrite.c b/misc/pascal/libpoff/pfwrite.c
new file mode 100644
index 000000000..75eac9497
--- /dev/null
+++ b/misc/pascal/libpoff/pfwrite.c
@@ -0,0 +1,477 @@
+/**********************************************************************
+ * pfwrite.c
+ * Write a POFF file
+ *
+ * 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 <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+static uint16 poffCountSections(poffHandle_t handle);
+static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile);
+static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile);
+static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile);
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+static uint16 poffCountSections(poffHandle_t handle)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint16 nSections = 1; /* We always write the string table */
+
+ /* Count each other section that has stored data */
+
+ if (HAVE_PROGRAM_SECTION)
+ nSections++;
+
+ if (HAVE_RODATA_SECTION)
+ nSections++;
+
+ if (HAVE_SYMBOL_TABLE)
+ nSections++;
+
+ if (HAVE_RELOC_SECTION)
+ nSections++;
+
+ if (HAVE_FILE_TABLE)
+ nSections++;
+
+ if (HAVE_LINE_NUMBER)
+ nSections++;
+
+ if (HAVE_DEBUG_SECTION)
+ nSections++;
+
+ return nSections;
+}
+
+/***********************************************************************/
+
+static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ size_t entriesWritten;
+
+ /* Get the number of section structures following the file header */
+
+ poffInfo->fileHeader.fh_shnum = poffCountSections(handle);
+
+ /* Write the POFF file header */
+
+ entriesWritten = fwrite(&poffInfo->fileHeader, sizeof(poffFileHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write POFF header: %s\n", strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+}
+
+/***********************************************************************/
+
+static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+
+ /* The data starts immediately after the file header and the array
+ * of section headers.
+ */
+
+ uint32 dataOffset = poffInfo->fileHeader.fh_shoff +
+ poffInfo->fileHeader.fh_shnum * poffInfo->fileHeader.fh_shsize;
+ size_t entriesWritten;
+
+ /* Write the program section header (if we have one) */
+
+ if (HAVE_PROGRAM_SECTION)
+ {
+ /* Add the name of the section to the string table */
+
+ poffInfo->progSection.sh_name = poffAddString(handle, ".text");
+ poffInfo->progSection.sh_offset = dataOffset;
+ dataOffset += poffInfo->progSection.sh_size;
+
+ /* Then write the section header to the output file */
+
+ entriesWritten = fwrite(&poffInfo->progSection,
+ sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write program section header: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the initialized read-only data section header (if we have one) */
+
+ if (HAVE_RODATA_SECTION)
+ {
+ /* Add the name of the section to the string table */
+
+ poffInfo->roDataSection.sh_name = poffAddString(handle, ".rodata");
+ poffInfo->roDataSection.sh_offset = dataOffset;
+ dataOffset += poffInfo->roDataSection.sh_size;
+
+ /* Then write the section header to the output file */
+
+ entriesWritten = fwrite(&poffInfo->roDataSection,
+ sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write data section header: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the symbol table section header (if we have one) */
+
+ if (HAVE_SYMBOL_TABLE)
+ {
+ /* Add the name of the section to the string table */
+
+ poffInfo->symbolTableSection.sh_name = poffAddString(handle, ".symtab");
+ poffInfo->symbolTableSection.sh_offset = dataOffset;
+ dataOffset += poffInfo->symbolTableSection.sh_size;
+
+ /* Then write the section header to the output file */
+
+ entriesWritten = fwrite(&poffInfo->symbolTableSection,
+ sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write symbol table section header: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the relocation table section header (if we have one) */
+
+ if (HAVE_RELOC_SECTION)
+ {
+ /* Add the name of the section to the string table */
+
+ poffInfo->relocSection.sh_name = poffAddString(handle, ".rel");
+ poffInfo->relocSection.sh_offset = dataOffset;
+ dataOffset += poffInfo->relocSection.sh_size;
+
+ /* Then write the section header to the output file */
+
+ entriesWritten = fwrite(&poffInfo->relocSection,
+ sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write relocation section header: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the file table section header (if we have one) */
+
+ if (HAVE_FILE_TABLE)
+ {
+ /* Add the name of the section to the string table */
+
+ poffInfo->fileNameTableSection.sh_name = poffAddString(handle, ".filetab");
+ poffInfo->fileNameTableSection.sh_offset = dataOffset;
+ dataOffset += poffInfo->fileNameTableSection.sh_size;
+
+ /* Then write the section header to the output file */
+
+ entriesWritten = fwrite(&poffInfo->fileNameTableSection,
+ sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write file table section header: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the line number section header (if we have one) */
+
+ if (HAVE_LINE_NUMBER)
+ {
+ /* Add the name of the section to the string table */
+
+ poffInfo->lineNumberSection.sh_name = poffAddString(handle, ".lineno");
+ poffInfo->lineNumberSection.sh_offset = dataOffset;
+ dataOffset += poffInfo->lineNumberSection.sh_size;
+
+ /* Then write the section header to the output file */
+
+ entriesWritten = fwrite(&poffInfo->lineNumberSection,
+ sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write line number section header: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the debug function info section header (if we have one) */
+
+ if (HAVE_DEBUG_SECTION)
+ {
+ /* Add the name of the section to the string table */
+
+ poffInfo->debugFuncSection.sh_name = poffAddString(handle, ".dbgfunc");
+ poffInfo->debugFuncSection.sh_offset = dataOffset;
+ dataOffset += poffInfo->debugFuncSection.sh_size;
+
+ /* Then write the section header to the output file */
+
+ entriesWritten = fwrite(&poffInfo->debugFuncSection,
+ sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write debug section header: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the string table section header LAST (because we may have
+ * added strings with the above logic.
+ */
+
+ /* Add the name of the section to the string table */
+
+ poffInfo->stringTableSection.sh_name = poffAddString(handle, ".strtab");
+ poffInfo->stringTableSection.sh_offset = dataOffset;
+ dataOffset += poffInfo->stringTableSection.sh_size;
+
+ /* Then write the section header to the output file */
+
+ entriesWritten = fwrite(&poffInfo->stringTableSection,
+ sizeof(poffSectionHeader_t),
+ 1, poffFile);
+ if (entriesWritten != 1)
+ {
+ errmsg("Failed to write string table section header: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+}
+
+/***********************************************************************/
+
+static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ size_t entriesWritten;
+
+ /* Write the program section data (if we have one) */
+
+ if (HAVE_PROGRAM_SECTION)
+ {
+ if (!poffInfo->progSectionData) fatal(ePOFFCONFUSION);
+
+ entriesWritten = fwrite(poffInfo->progSectionData, sizeof(ubyte),
+ poffInfo->progSection.sh_size, poffFile);
+ if (entriesWritten != poffInfo->progSection.sh_size)
+ {
+ errmsg("Failed to write program data: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the read-only data section data (if we have one) */
+
+ if (HAVE_RODATA_SECTION)
+ {
+ if (!poffInfo->roDataSectionData) fatal(ePOFFCONFUSION);
+
+ entriesWritten = fwrite(poffInfo->roDataSectionData, sizeof(ubyte),
+ poffInfo->roDataSection.sh_size, poffFile);
+ if (entriesWritten != poffInfo->roDataSection.sh_size)
+ {
+ errmsg("Failed to write initialized data: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the symbol table section data (if we have one) */
+
+ if (HAVE_SYMBOL_TABLE)
+ {
+ if (!poffInfo->symbolTable) fatal(ePOFFCONFUSION);
+
+ entriesWritten = fwrite(poffInfo->symbolTable, sizeof(ubyte),
+ poffInfo->symbolTableSection.sh_size, poffFile);
+ if (entriesWritten != poffInfo->symbolTableSection.sh_size)
+ {
+ errmsg("Failed to write symbol table data: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the relocation table section data (if we have one) */
+
+ if (HAVE_RELOC_SECTION)
+ {
+ if (!poffInfo->relocTable) fatal(ePOFFCONFUSION);
+
+ entriesWritten = fwrite(poffInfo->relocTable, sizeof(ubyte),
+ poffInfo->relocSection.sh_size, poffFile);
+ if (entriesWritten != poffInfo->relocSection.sh_size)
+ {
+ errmsg("Failed to write relocation data: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the file table section data (if we have one) */
+
+ if (HAVE_FILE_TABLE)
+ {
+ if (!poffInfo->fileNameTable) fatal(ePOFFCONFUSION);
+
+ entriesWritten = fwrite(poffInfo->fileNameTable, sizeof(ubyte),
+ poffInfo->fileNameTableSection.sh_size,
+ poffFile);
+ if (entriesWritten != poffInfo->fileNameTableSection.sh_size)
+ {
+ errmsg("Failed to write filename table data: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the line number section data (if we have one) */
+
+ if (HAVE_LINE_NUMBER)
+ {
+ if (!poffInfo->lineNumberTable) fatal(ePOFFCONFUSION);
+
+ entriesWritten = fwrite(poffInfo->lineNumberTable, sizeof(ubyte),
+ poffInfo->lineNumberSection.sh_size,
+ poffFile);
+ if (entriesWritten != poffInfo->lineNumberSection.sh_size)
+ {
+ errmsg("Failed to write line number table data: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the line number section data (if we have one) */
+
+ if (HAVE_DEBUG_SECTION)
+ {
+ if (!poffInfo->debugFuncTable) fatal(ePOFFCONFUSION);
+
+ entriesWritten = fwrite(poffInfo->debugFuncTable, sizeof(ubyte),
+ poffInfo->debugFuncSection.sh_size,
+ poffFile);
+ if (entriesWritten != poffInfo->debugFuncSection.sh_size)
+ {
+ errmsg("Failed to write debug table data: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+ }
+
+ /* Write the string table section data LAST (because we may have
+ * added strings with the above logic.
+ */
+
+ if (!poffInfo->stringTable) fatal(ePOFFCONFUSION);
+
+ entriesWritten = fwrite(poffInfo->stringTable, sizeof(ubyte),
+ poffInfo->stringTableSection.sh_size, poffFile);
+ if (entriesWritten != poffInfo->stringTableSection.sh_size)
+ {
+ errmsg("Failed to write string table data: %s\n",
+ strerror(errno));
+ fatal(ePOFFWRITEERROR);
+ }
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+void poffWriteFile(poffHandle_t handle, FILE *poffFile)
+{
+ poffWriteFileHeader(handle, poffFile);
+ poffWriteSectionHeaders(handle, poffFile);
+ poffWriteSectionData(handle, poffFile);
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwrodata.c b/misc/pascal/libpoff/pfwrodata.c
new file mode 100644
index 000000000..5882462b4
--- /dev/null
+++ b/misc/pascal/libpoff/pfwrodata.c
@@ -0,0 +1,192 @@
+/**********************************************************************
+ * pfwrodata.c
+ * Write to the RODATA section of a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+static uint16 poffCheckRoDataAlloc(poffInfo_t *poffInfo)
+{
+ if (!poffInfo->roDataSectionData)
+ {
+ /* No, allocate it now */
+
+ poffInfo->roDataSectionData = (char*)malloc(INITIAL_RODATA_SECTION_SIZE);
+ if (!poffInfo->roDataSectionData)
+ {
+ return eNOMEMORY;
+ }
+
+ poffInfo->roDataSection.sh_size = 0;
+ poffInfo->roDataSectionAlloc = INITIAL_RODATA_SECTION_SIZE;
+ }
+ return eNOERROR;
+}
+
+static uint16 poffCheckRoDataRealloc(poffInfo_t *poffInfo, uint16 len)
+{
+ /* Check if there is room for the new data */
+
+ if (poffInfo->roDataSection.sh_size + len > poffInfo->roDataSectionAlloc)
+ {
+ uint32 newAlloc;
+ void *tmp;
+
+ /* Make certain that this is big enough (it should be) */
+
+ newAlloc = poffInfo->roDataSectionAlloc + RODATA_SECTION_INCREMENT;
+ while (poffInfo->roDataSection.sh_size + len > newAlloc)
+ {
+ newAlloc += RODATA_SECTION_INCREMENT;
+ }
+
+ /* Reallocate the roDataram data section buffer */
+
+ tmp = realloc(poffInfo->roDataSectionData, newAlloc);
+ if (!tmp)
+ {
+ return eNOMEMORY;
+ }
+
+ /* And set the new size */
+
+ poffInfo->roDataSectionAlloc = newAlloc;
+ poffInfo->roDataSectionData = (ubyte*)tmp;
+ }
+ return eNOERROR;
+}
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+#if 0 /* Not used */
+uint32 poffAddRoDataByte(poffHandle_t handle, ubyte dataByte)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint32 offset;
+ uint16 errCode;
+
+ /* Check if we have allocated a data section buffer yet */
+
+ errCode = poffCheckRoDataAlloc(poffInfo);
+ if (errCode != eNOERROR)
+ {
+ fatal(errCode);
+ }
+
+ /* Check if there is room for a new byte */
+
+ errCode = poffCheckRoDataRealloc(poffInfo, 1);
+
+ /* Copy data section byte into the data section buffer */
+
+ offset = poffInfo->roDataSection.sh_size;
+ poffInfo->roDataSectionData[offset] = dataByte;
+
+ /* Set the new size of the string table */
+
+ poffInfo->roDataSection.sh_size++;
+ return offset;
+}
+#endif
+
+/***********************************************************************/
+
+uint32 poffAddRoDataString(poffHandle_t handle, const char *string)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint32 len;
+ uint32 offset;
+ uint16 errCode;
+
+ /* Check if we have allocated a data section buffer yet */
+
+ errCode = poffCheckRoDataAlloc(poffInfo);
+ if (errCode != eNOERROR)
+ {
+ fatal(errCode);
+ }
+
+ /* Check if there is room for a new byte */
+
+ len = strlen(string) + 1;
+ errCode = poffCheckRoDataRealloc(poffInfo, len);
+
+ /* Copy data section byte into the data section buffer */
+
+ offset = poffInfo->roDataSection.sh_size;
+ memcpy(&poffInfo->roDataSectionData[offset], string, len);
+
+ /* Set the new size of the string table */
+
+ poffInfo->roDataSection.sh_size += len;
+ return offset;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwstring.c b/misc/pascal/libpoff/pfwstring.c
new file mode 100644
index 000000000..b1b066e7b
--- /dev/null
+++ b/misc/pascal/libpoff/pfwstring.c
@@ -0,0 +1,217 @@
+/**********************************************************************
+ * pfwstring.c
+ * Write string table data a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Search the string table for an occurrence of the indicates string.
+ * If found, return the offset in the string table to the string; if
+ * not found, return -1.
+ */
+
+sint32 poffFindString(poffHandle_t handle, const char *string)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ char *sptr = poffInfo->stringTable;
+ uint32 offset;
+
+ /* Has the string table been allocated yet? */
+
+ if (!poffInfo->stringTable) return -1;
+
+ /* Handle the NULL string case. Offset zero is reserved for the NULL
+ * string and for the zero-size string.
+ */
+
+ if (!string) return 0;
+
+ /* Okay, we will have to search the table */
+
+ for (offset = 0;
+ offset < poffInfo->stringTableSection.sh_size;
+ offset += (strlen(sptr) + 1))
+ {
+ /* Get a pointer at this offset into the string table */
+
+ sptr = &poffInfo->stringTable[offset];
+
+ /* Check if the strings match. If so, return the offset */
+
+ if (strcmp(sptr, string) == 0) return offset;
+ }
+
+ /* The string does not exist in the string table */
+
+ return -1;
+}
+
+/***********************************************************************/
+/***********************************************************************/
+/* Add a string to the string table and return the offset to the
+ * string storage location in the string table section data.
+ */
+
+uint32 poffAddString(poffHandle_t handle, const char *string)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ sint32 index;
+ int len;
+
+ /* Check if we have allocated a string table buffer yet */
+
+ if (!poffInfo->stringTable)
+ {
+ /* No, allocate it now */
+
+ poffInfo->stringTable = (char*)malloc(INITIAL_STRING_TABLE_SIZE);
+ if (!poffInfo->stringTable)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* Index 0 is reserved for the NULL string */
+
+ poffInfo->stringTable[0] = '\0';
+ poffInfo->stringTableSection.sh_size = 1;
+ poffInfo->stringTableAlloc = INITIAL_STRING_TABLE_SIZE;
+ }
+
+ /* Check if the string is already defined in the string table.
+ * This is very time consuming, but guaratees that we do not keep
+ * duplicate strings in the string table.
+ */
+
+ index = poffFindString(handle, string);
+ if (index < 0)
+ {
+ /* The string was not found in the string table. Check for the
+ * NULL string. In this case, return index == 0. NOTE: This
+ * check is pointless. If this is any kind of NULL string, then
+ * poffFindString will have returned index == 0.
+ */
+
+ if ((string == NULL) || ((len = strlen(string)) <= 0))
+ {
+ index = 0;
+ }
+ else
+ {
+ /* Increment the length to include the null terminator */
+
+ len++;
+
+ /* Check if there is room for the new string */
+
+ if (poffInfo->stringTableSection.sh_size + len >
+ poffInfo->stringTableAlloc)
+ {
+ uint32 newAlloc =
+ poffInfo->stringTableAlloc + STRING_TABLE_INCREMENT;
+ void *tmp;
+
+ /* Make sure that the new string will fit in the new allocation
+ * size (shouldn't happen)
+ */
+
+ while (poffInfo->stringTableSection.sh_size + len > newAlloc)
+ newAlloc += STRING_TABLE_INCREMENT;
+
+ /* Reallocate the string buffer */
+
+ tmp = realloc(poffInfo->stringTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ poffInfo->stringTableAlloc = newAlloc;
+ poffInfo->stringTable = (char*)tmp;
+ }
+
+ /* Copy the string into the string table */
+
+ index = poffInfo->stringTableSection.sh_size;
+ memcpy(&poffInfo->stringTable[index], string, len);
+
+ /* Set the new size of the string table */
+
+ poffInfo->stringTableSection.sh_size += len;
+ }
+ }
+ return index;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwsymbol.c b/misc/pascal/libpoff/pfwsymbol.c
new file mode 100644
index 000000000..b0bbbaa6e
--- /dev/null
+++ b/misc/pascal/libpoff/pfwsymbol.c
@@ -0,0 +1,151 @@
+/**********************************************************************
+ * pfwsymbol.c
+ * Write symbol information to a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+/* Add a symbol to the symbol table section data. Returns index value
+ * associated with the symbol entry in the symbol table section data.
+ */
+
+uint32 poffAddSymbol(poffHandle_t handle, poffLibSymbol_t *symbol)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ poffSymbol_t *psym;
+ uint32 st_name;
+ uint32 index;
+
+ /* Add the name to the string table */
+
+ st_name = poffAddString(poffInfo, symbol->name);
+
+ /* Check if we have allocated a symbol table buffer yet */
+
+ if (!poffInfo->symbolTable)
+ {
+ /* No, allocate it now */
+
+ poffInfo->symbolTable = (ubyte*)malloc(INITIAL_SYMBOL_TABLE_SIZE);
+ if (!poffInfo->symbolTable)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ poffInfo->symbolTableSection.sh_size = 0;
+ poffInfo->symbolTableAlloc = INITIAL_SYMBOL_TABLE_SIZE;
+ }
+
+ /* Check if there is room for a new symbol */
+
+ if (poffInfo->symbolTableSection.sh_size +
+ poffInfo->symbolTableSection.sh_entsize >
+ poffInfo->symbolTableAlloc)
+ {
+ uint32 newAlloc = poffInfo->symbolTableAlloc + SYMBOL_TABLE_INCREMENT;
+ ubyte *tmp;
+
+ /* Reallocate the file name buffer */
+
+ tmp = (ubyte*)realloc(poffInfo->symbolTable, newAlloc);
+ if (!tmp)
+ {
+ fatal(eNOMEMORY);
+ }
+
+ /* And set the new size */
+
+ poffInfo->symbolTableAlloc = newAlloc;
+ poffInfo->symbolTable = tmp;
+ }
+
+ /* Save the new symbol information in the symbol table data */
+
+ index = poffInfo->symbolTableSection.sh_size;
+ psym = (poffSymbol_t*)&poffInfo->symbolTable[index];
+
+ psym->st_type = symbol->type;
+ psym->st_align = symbol->align;
+ psym->st_flags = symbol->flags;
+ psym->st_pad = 0;
+ psym->st_name = st_name;
+ psym->st_value = symbol->value;
+ psym->st_size = symbol->size;
+
+ /* Set the new size of the file name table */
+
+ poffInfo->symbolTableSection.sh_size += poffInfo->symbolTableSection.sh_entsize;
+ return index / poffInfo->symbolTableSection.sh_entsize;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfxprog.c b/misc/pascal/libpoff/pfxprog.c
new file mode 100644
index 000000000..3c3783647
--- /dev/null
+++ b/misc/pascal/libpoff/pfxprog.c
@@ -0,0 +1,95 @@
+/**********************************************************************
+ * pfxprog.c
+ * Extract program data from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+uint32 poffExtractProgramData(poffHandle_t handle, ubyte **progData)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint32 size;
+
+ /* Give the program data to the caller */
+
+ *progData = poffInfo->progSectionData;
+ size = poffInfo->progSection.sh_size;
+
+ /* Indicate the no program data is owned by the container */
+
+ poffInfo->progSection.sh_size = 0;
+ poffInfo->progSectionData = NULL;
+ poffInfo->progSectionAlloc = 0;
+ poffInfo->progSectionIndex = 0;
+
+ return size;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfxrodata.c b/misc/pascal/libpoff/pfxrodata.c
new file mode 100644
index 000000000..a5141b491
--- /dev/null
+++ b/misc/pascal/libpoff/pfxrodata.c
@@ -0,0 +1,94 @@
+/**********************************************************************
+ * pfxrodata.c
+ * Extract program read-only data from a POFF file
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "keywords.h" /* Standard types */
+#include "pedefs.h" /* error code definitions */
+
+#include "perr.h" /* error() */
+#include "pofflib.h" /* POFF library interface */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+/***********************************************************************/
+
+uint32 poffExtractRoData(poffHandle_t handle, ubyte **roData)
+{
+ poffInfo_t *poffInfo = (poffInfo_t*)handle;
+ uint32 size;
+
+ /* Give the program data to the caller */
+
+ *roData = poffInfo->roDataSectionData;
+ size = poffInfo->roDataSection.sh_size;
+
+ /* Indicate the no program data is owned by the container */
+
+ poffInfo->roDataSection.sh_size = 0;
+ poffInfo->roDataSectionData = NULL;
+ poffInfo->roDataSectionAlloc = 0;
+
+ return size;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pofferr.c b/misc/pascal/libpoff/pofferr.c
new file mode 100644
index 000000000..fb4258304
--- /dev/null
+++ b/misc/pascal/libpoff/pofferr.c
@@ -0,0 +1,93 @@
+/**********************************************************************
+ * pofferr.c
+ * Simple error handlers
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "keywords.h"
+
+#include "perr.h"
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Function Prototypes
+ **********************************************************************/
+
+void errmsg(char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ (void)vfprintf(stderr, fmt, ap);
+ va_end(ap);
+}
+
+/***********************************************************************/
+
+void warn(uint16 errcode)
+{
+ /* Write error record to the error and list files */
+
+ fprintf(stderr, "WARNING: %d\n", errcode);
+} /* end warn */
+
+/***********************************************************************/
+
+void error(uint16 errcode)
+{
+ fatal(errcode);
+} /* end error */
+
+/***********************************************************************/
+
+void fatal(uint16 errcode)
+{
+ fprintf(stderr, "Fatal Error %d -- Aborting\n", errcode);
+ exit(errcode);
+} /* end fatal */
+
+/***********************************************************************/