summaryrefslogtreecommitdiff
path: root/misc/pascal
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-02-06 15:24:18 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-02-06 15:24:18 +0000
commitbb5ede8152f14cc757ff4ee6f44ff3128c3ff144 (patch)
treedb2726eb2b79bde890812a8227dae075f8ca2a3b /misc/pascal
parenta26dad80f4d004a4a0f6effedc803b3902389b39 (diff)
downloadnuttx-bb5ede8152f14cc757ff4ee6f44ff3128c3ff144.tar.gz
nuttx-bb5ede8152f14cc757ff4ee6f44ff3128c3ff144.tar.bz2
nuttx-bb5ede8152f14cc757ff4ee6f44ff3128c3ff144.zip
Standardize to big-endian binary
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@637 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'misc/pascal')
-rw-r--r--misc/pascal/ChangeLog1
-rw-r--r--misc/pascal/include/paslib.h23
-rw-r--r--misc/pascal/include/poff.h2
-rw-r--r--misc/pascal/insn16/popt/Makefile2
-rw-r--r--misc/pascal/insn16/prun/Makefile2
-rw-r--r--misc/pascal/insn32/popt/Makefile2
-rw-r--r--misc/pascal/insn32/regm/Makefile2
-rw-r--r--misc/pascal/libpas/Make.defs2
-rw-r--r--misc/pascal/libpas/Makefile2
-rw-r--r--misc/pascal/libpas/pswap.c59
-rw-r--r--misc/pascal/libpoff/Make.defs2
-rw-r--r--misc/pascal/libpoff/Makefile2
-rw-r--r--misc/pascal/libpoff/pfprivate.h16
-rw-r--r--misc/pascal/libpoff/pfread.c38
-rw-r--r--misc/pascal/libpoff/pfswap.c250
-rw-r--r--misc/pascal/libpoff/pfwrite.c115
-rwxr-xr-xmisc/pascal/nuttx/INSTALL.sh4
-rw-r--r--misc/pascal/pascal/Makefile2
-rw-r--r--misc/pascal/plink/Makefile2
19 files changed, 488 insertions, 40 deletions
diff --git a/misc/pascal/ChangeLog b/misc/pascal/ChangeLog
index 1d321788a..e1544d345 100644
--- a/misc/pascal/ChangeLog
+++ b/misc/pascal/ChangeLog
@@ -11,4 +11,5 @@ pascal-0.1.2 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* Add logic to build and link with the ZDS-II toolchain
use with the z16f.
* Make sure that POFF header structures are aligned
+ * Standardized POFF file format to big-endian
diff --git a/misc/pascal/include/paslib.h b/misc/pascal/include/paslib.h
index 6137cc68e..c99eca81e 100644
--- a/misc/pascal/include/paslib.h
+++ b/misc/pascal/include/paslib.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * paslib.h
+ * include/paslib.h
* External Declarations associated with paslib
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
@@ -49,6 +49,22 @@
* Global Function Prototypes
***************************************************************************/
+/* POFF file is always big-endian */
+
+#ifdef CONFIG_BIG_ENDIAN
+# undef CONFIG_POFF_SWAPNEEDED
+# define poff16(val) (val)
+# define poff32(val) (val)
+#else
+# define CONFIG_POFF_SWAPNEEDED 1
+# define poff16(val) poffSwap16(val)
+# define poff32(val) poffSwap32(val)
+#endif
+
+/***************************************************************************
+ * Global Function Prototypes
+ ***************************************************************************/
+
/* File name extension helper */
extern boolean extension(const char *inName, const char *ext, char *outName,
@@ -59,6 +75,11 @@ extern boolean extension(const char *inName, const char *ext, char *outName,
extern sint32 signExtend16(uint16 arg16);
extern sint32 signExtend25(uint32 arg25);
+/* Endian-ness helpers */
+
+extern uint16 poffSwap16(uint16 val);
+extern uint32 poffSwap32(uint32 val);
+
/***************************************************************************
* Global Variables
***************************************************************************/
diff --git a/misc/pascal/include/poff.h b/misc/pascal/include/poff.h
index 5f8e360cf..244384873 100644
--- a/misc/pascal/include/poff.h
+++ b/misc/pascal/include/poff.h
@@ -423,7 +423,7 @@ typedef struct poffDebugFuncInfo_s poffDebugFuncInfo_t;
struct poffDebugArgInfo_s
{
- /* This is the size, in bytes, of one input paramters */
+ /* This is the size, in bytes, of one input paramter */
uint32 da_size;
};
diff --git a/misc/pascal/insn16/popt/Makefile b/misc/pascal/insn16/popt/Makefile
index 155ea6281..606ebe2c2 100644
--- a/misc/pascal/insn16/popt/Makefile
+++ b/misc/pascal/insn16/popt/Makefile
@@ -84,7 +84,7 @@ check_libs:
fi
$(BINDIR)/popt: check_libs $(POPTOBJS)
- $(CC) -o $@ $(LDFLAGS) $(POPTOBJS) -lpas -lpoff -linsn
+ $(CC) -o $@ $(LDFLAGS) $(POPTOBJS) -lpoff -linsn -lpas
popt: $(BINDIR)/popt
diff --git a/misc/pascal/insn16/prun/Makefile b/misc/pascal/insn16/prun/Makefile
index e4a9dd05e..f660b4a2a 100644
--- a/misc/pascal/insn16/prun/Makefile
+++ b/misc/pascal/insn16/prun/Makefile
@@ -79,7 +79,7 @@ check_libs:
fi
$(BINDIR)/prun: check_libs $(RUNOBJS)
- @$(CC) -o $@ $(LDFLAGS) $(RUNOBJS) -lpas -linsn -lm -lpoff
+ @$(CC) -o $@ $(LDFLAGS) $(RUNOBJS) -linsn -lpoff -lpas -lm
prun: $(BINDIR)/prun
diff --git a/misc/pascal/insn32/popt/Makefile b/misc/pascal/insn32/popt/Makefile
index 5670a6a3d..6073ff165 100644
--- a/misc/pascal/insn32/popt/Makefile
+++ b/misc/pascal/insn32/popt/Makefile
@@ -83,7 +83,7 @@ check_libs:
fi
$(BINDIR)/popt: check_libs $(POPTOBJS)
- $(CC) -o $@ $(LDFLAGS) $(POPTOBJS) -lpas -linsn -lpoff
+ $(CC) -o $@ $(LDFLAGS) $(POPTOBJS) -linsn -lpoff -lpas
popt: $(BINDIR)/popt
diff --git a/misc/pascal/insn32/regm/Makefile b/misc/pascal/insn32/regm/Makefile
index 3b06fc88f..2fa4a3424 100644
--- a/misc/pascal/insn32/regm/Makefile
+++ b/misc/pascal/insn32/regm/Makefile
@@ -84,7 +84,7 @@ check_libs:
fi
$(BINDIR)/regm: check_libs $(REGMOBJS)
- $(CC) -o $@ $(LDFLAGS) $(REGMOBJS) -lpas -linsn -lpoff
+ $(CC) -o $@ $(LDFLAGS) $(REGMOBJS) -linsn -lpoff -lpas
regm: $(BINDIR)/regm
diff --git a/misc/pascal/libpas/Make.defs b/misc/pascal/libpas/Make.defs
index 9dca4a720..558f6b507 100644
--- a/misc/pascal/libpas/Make.defs
+++ b/misc/pascal/libpas/Make.defs
@@ -35,4 +35,4 @@
############################################################################
PAS_ASRCS =
-PAS_CSRCS = psignextend16.c
+PAS_CSRCS = psignextend16.c pswap.c
diff --git a/misc/pascal/libpas/Makefile b/misc/pascal/libpas/Makefile
index 047a47a13..b686daa89 100644
--- a/misc/pascal/libpas/Makefile
+++ b/misc/pascal/libpas/Makefile
@@ -47,7 +47,7 @@ LIBDIR = $(PASCAL)/lib
#
# Objects and targets
#
-LIBPASSRCS = pextension.c psignextend16.c
+LIBPASSRCS = pextension.c psignextend16.c pswap.c
LIBPASOBJS = $(LIBPASSRCS:.c=.o)
OBJS = $(LIBPASOBJS)
diff --git a/misc/pascal/libpas/pswap.c b/misc/pascal/libpas/pswap.c
new file mode 100644
index 000000000..0bf4a31f8
--- /dev/null
+++ b/misc/pascal/libpas/pswap.c
@@ -0,0 +1,59 @@
+/**********************************************************************
+ * libpas/pswap.c
+ * Byte swapping to handling endian-ness conversions
+ *
+ * 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 <string.h>
+
+#include "keywords.h"
+#include "pdefs.h"
+#include "paslib.h"
+
+/***********************************************************************/
+
+uint16 poffSwap16(uint16 val)
+{
+ return val >> 8 | val << 8;
+}
+
+uint32 poffSwap32(uint32 val)
+{
+ return val >> 24 | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | val << 24;
+}
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/Make.defs b/misc/pascal/libpoff/Make.defs
index 8ffcd4d62..67852b705 100644
--- a/misc/pascal/libpoff/Make.defs
+++ b/misc/pascal/libpoff/Make.defs
@@ -45,4 +45,4 @@ POFF_CSRCS = pfhandle.c pfproghandle.c pftprog.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
+ pflineno.c pfdbginfo.c pfswap.c
diff --git a/misc/pascal/libpoff/Makefile b/misc/pascal/libpoff/Makefile
index ece3ccb16..ebbf1e2ac 100644
--- a/misc/pascal/libpoff/Makefile
+++ b/misc/pascal/libpoff/Makefile
@@ -26,7 +26,7 @@ LIBPOFFSRCS = pfhandle.c pfproghandle.c pftprog.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
+ pflineno.c pfdbginfo.c pfswap.c
LIBPOFFOBJS = $(LIBPOFFSRCS:.c=.o)
all: libpoff.a
diff --git a/misc/pascal/libpoff/pfprivate.h b/misc/pascal/libpoff/pfprivate.h
index 3bcdf89dc..ed5e239e6 100644
--- a/misc/pascal/libpoff/pfprivate.h
+++ b/misc/pascal/libpoff/pfprivate.h
@@ -48,6 +48,7 @@
#include "keywords.h"
#include "poff.h"
+#include "paslib.h" /* Endian-ness support */
/***************************************************************************
* Definitions
@@ -86,6 +87,11 @@
#define HAVE_LINE_NUMBER (poffInfo->lineNumberSection.sh_size > 0)
#define HAVE_DEBUG_SECTION (poffInfo->debugFuncSection.sh_size > 0)
+#ifndef CONFIG_POFF_SWAPNEEDED
+# define poffSwapFileHeader(p)
+# define poffSwapSectionHeader(p)
+#endif
+
/***************************************************************************
* Public Types
***************************************************************************/
@@ -169,4 +175,14 @@ typedef struct poffSymInfo_s poffSymInfo_t;
* Public Function Prototypes
***************************************************************************/
+#ifdef CONFIG_POFF_SWAPNEEDED
+extern void poffSwapFileHeader(poffFileHeader_t *pFileHeader);
+extern void poffSwapSectionHeader(poffSectionHeader_t *pSectionHeader);
+extern void poffSwapSymbolTableData(poffInfo_t *poffInfo);
+extern void poffSwapRelocationData(poffInfo_t *poffInfo);
+extern void poffSwapFileTableData(poffInfo_t *poffInfo);
+extern void poffSwapLineNumberData(poffInfo_t *poffInfo);
+extern void poffSwapDebugData(poffInfo_t *poffInfo);
+#endif
+
#endif /* __PFPRIVATE_H */
diff --git a/misc/pascal/libpoff/pfread.c b/misc/pascal/libpoff/pfread.c
index 016aebceb..1bcc1618a 100644
--- a/misc/pascal/libpoff/pfread.c
+++ b/misc/pascal/libpoff/pfread.c
@@ -101,6 +101,10 @@ static uint16 poffReadFileHeader(poffHandle_t handle, FILE *poffFile)
return ePOFFREADERROR;
}
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapFileHeader(&poffInfo->fileHeader);
+
/* Verify that this is a valid POFF header */
if ((poffInfo->fileHeader.fh_ident[FHI_MAG0] != FHI_POFF_MAG0) ||
@@ -145,6 +149,10 @@ static uint16 poffReadSectionHeaders(poffHandle_t handle, FILE *poffFile)
return ePOFFREADERROR;
}
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapSectionHeader(&sectionHeader);
+
/* Copy the section header to the correct location */
switch (sectionHeader.sh_type)
@@ -251,6 +259,12 @@ static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile)
retval = poffReadSectionData(&poffInfo->symbolTableSection,
(ubyte**)&poffInfo->symbolTable,
poffFile);
+#ifdef CONFIG_POFF_SWAPNEEDED
+ if (retval == eNOERROR)
+ {
+ poffSwapSymbolTableData(poffInfo);
+ }
+#endif
}
if ((retval == eNOERROR) && (HAVE_STRING_TABLE))
@@ -265,6 +279,12 @@ static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile)
retval = poffReadSectionData(&poffInfo->relocSection,
(ubyte**)&poffInfo->relocTable,
poffFile);
+#ifdef CONFIG_POFF_SWAPNEEDED
+ if (retval == eNOERROR)
+ {
+ poffSwapRelocationData(poffInfo);
+ }
+#endif
}
if ((retval == eNOERROR) && (HAVE_FILE_TABLE))
@@ -272,6 +292,12 @@ static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile)
retval = poffReadSectionData(&poffInfo->fileNameTableSection,
(ubyte**)&poffInfo->fileNameTable,
poffFile);
+#ifdef CONFIG_POFF_SWAPNEEDED
+ if (retval == eNOERROR)
+ {
+ poffSwapFileTableData(poffInfo);
+ }
+#endif
}
if ((retval == eNOERROR) && (HAVE_LINE_NUMBER))
@@ -279,6 +305,12 @@ static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile)
retval = poffReadSectionData(&poffInfo->lineNumberSection,
(ubyte**)&poffInfo->lineNumberTable,
poffFile);
+#ifdef CONFIG_POFF_SWAPNEEDED
+ if (retval == eNOERROR)
+ {
+ poffSwapLineNumberData(poffInfo);
+ }
+#endif
}
if ((retval == eNOERROR) && (HAVE_DEBUG_SECTION))
@@ -286,6 +318,12 @@ static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile)
retval = poffReadSectionData(&poffInfo->debugFuncSection,
(ubyte**)&poffInfo->debugFuncTable,
poffFile);
+#ifdef CONFIG_POFF_SWAPNEEDED
+ if (retval == eNOERROR)
+ {
+ poffSwapDebugData(poffInfo);
+ }
+#endif
}
return retval;
diff --git a/misc/pascal/libpoff/pfswap.c b/misc/pascal/libpoff/pfswap.c
new file mode 100644
index 000000000..bb99190bc
--- /dev/null
+++ b/misc/pascal/libpoff/pfswap.c
@@ -0,0 +1,250 @@
+/**********************************************************************
+ * libpoff/pfswap.c
+ * Handle POFF Endian-ness
+ *
+ * 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 "keywords.h" /* Standard types */
+#include "paslib.h" /* Common library */
+#include "pfprivate.h" /* POFF private definitions */
+
+/**********************************************************************
+ * Definitions
+ **********************************************************************/
+
+/**********************************************************************
+ * Global Variables
+ **********************************************************************/
+
+/**********************************************************************
+ * Private Variables
+ **********************************************************************/
+
+/***********************************************************************
+ * Private Function Prototypes
+ ***********************************************************************/
+
+/***********************************************************************
+ * Private Functions
+ ***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+static inline void poffSwapRelocationEntry(poffRelocation_t *prel)
+{
+ prel->rl_info = poff32(prel->rl_info);
+ prel->rl_offset = poff32(prel->rl_offset);
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+static inline void poffSwapSymbolTableEntry(poffSymbol_t *psym)
+{
+ psym->st_name = poff32(psym->st_name);
+ psym->st_value = poff32(psym->st_value);
+ psym->st_size = poff32(psym->st_size);
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+static inline void poffSwapFileTabEntry(poffFileTab_t *pfile)
+{
+ *pfile = poff32((uint32)*pfile);
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+static inline void poffSwaplineno(poffLineNumber_t *plineno)
+{
+ plineno->ln_lineno = poff16(plineno->ln_lineno);
+ plineno->ln_fileno = poff16(plineno->ln_fileno);
+ plineno->ln_poffset = poff32(plineno->ln_poffset);
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+static inline void poffDebugFuncEntry(poffDebugFuncInfo_t *pdbg)
+{
+ pdbg->df_value = poff32(pdbg->df_value);
+ pdbg->df_size = poff32(pdbg->df_size);
+ pdbg->df_nparms = poff32(pdbg->df_nparms);
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+static inline void poffDebugArgEntry(poffDebugArgInfo_t *parg)
+{
+ parg->da_size = poff32(parg->da_size);
+}
+#endif
+
+/***********************************************************************
+ * Public Functions
+ ***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+void poffSwapFileHeader(poffFileHeader_t *pFileHeader)
+{
+ pFileHeader->fh_shsize = poff16(pFileHeader->fh_shsize);
+ pFileHeader->fh_shnum = poff16(pFileHeader->fh_shnum);
+ pFileHeader->fh_name = poff32(pFileHeader->fh_name);
+ pFileHeader->fh_entry = poff32(pFileHeader->fh_entry);
+ pFileHeader->fh_shoff = poff32(pFileHeader->fh_shoff);
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+void poffSwapSectionHeader(poffSectionHeader_t *pSectionHeader)
+{
+ pSectionHeader->sh_entsize = poff16(pSectionHeader->sh_entsize);
+ pSectionHeader->sh_name = poff32(pSectionHeader->sh_name);
+ pSectionHeader->sh_addr = poff32(pSectionHeader->sh_addr);
+ pSectionHeader->sh_offset = poff32(pSectionHeader->sh_offset);
+ pSectionHeader->sh_size = poff32(pSectionHeader->sh_size);
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+void poffSwapSymbolTableData(poffInfo_t *poffInfo)
+{
+ poffSymbol_t *psym;
+ uint32 index;
+
+ for (index = 0;
+ index < poffInfo->symbolTableSection.sh_size;
+ index += poffInfo->symbolTableSection.sh_entsize)
+ {
+ psym = (poffSymbol_t*)&poffInfo->symbolTable[index];
+ poffSwapSymbolTableEntry(psym);
+ }
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+void poffSwapRelocationData(poffInfo_t *poffInfo)
+{
+ poffRelocation_t *prel;
+ uint32 index;
+
+ for (index = 0;
+ index < poffInfo->relocSection.sh_size;
+ index += poffInfo->relocSection.sh_entsize)
+ {
+ prel = (poffRelocation_t*)&poffInfo->relocTable[index];
+ poffSwapRelocationEntry(prel);
+ }
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+void poffSwapFileTableData(poffInfo_t *poffInfo)
+{
+ poffFileTab_t *pfile;
+ uint32 index;
+
+ for (index = 0;
+ index < poffInfo->relocSection.sh_size;
+ index += poffInfo->relocSection.sh_entsize)
+ {
+ pfile = (poffFileTab_t*)&poffInfo->relocTable[index];
+ poffSwapFileTabEntry(pfile);
+ }
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+void poffSwapLineNumberData(poffInfo_t *poffInfo)
+{
+ poffLineNumber_t *plineno;
+ uint32 index;
+
+ for (index = 0;
+ index < poffInfo->relocSection.sh_size;
+ index += poffInfo->relocSection.sh_entsize)
+ {
+ plineno = (poffLineNumber_t*)&poffInfo->relocTable[index];
+ poffSwaplineno(plineno);
+ }
+}
+#endif
+
+/***********************************************************************/
+
+#ifdef CONFIG_POFF_SWAPNEEDED
+void poffSwapDebugData(poffInfo_t *poffInfo)
+{
+ poffDebugFuncInfo_t *pdbg;
+ poffDebugArgInfo_t *parg;
+ uint32 i;
+ int j;
+
+ for (i = 0; i + sizeof(poffDebugFuncInfo_t) < poffInfo->relocSection.sh_size;)
+ {
+ pdbg = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[i];
+ poffDebugFuncEntry(pdbg);
+
+ i += sizeof(poffDebugFuncInfo_t);
+ for (j = 0; j < pdbg->df_nparms; j++)
+ {
+ parg = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[i];
+ poffDebugArgEntry(parg);
+ i += sizeof(poffDebugArgInfo_t);
+ }
+ }
+}
+#endif
+
+/***********************************************************************/
diff --git a/misc/pascal/libpoff/pfwrite.c b/misc/pascal/libpoff/pfwrite.c
index 75eac9497..c655dba71 100644
--- a/misc/pascal/libpoff/pfwrite.c
+++ b/misc/pascal/libpoff/pfwrite.c
@@ -1,5 +1,5 @@
/**********************************************************************
- * pfwrite.c
+ * libpoff/pfwrite.c
* Write a POFF file
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
@@ -116,6 +116,10 @@ static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile)
poffInfo->fileHeader.fh_shnum = poffCountSections(handle);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapFileHeader(&poffInfo->fileHeader);
+
/* Write the POFF file header */
entriesWritten = fwrite(&poffInfo->fileHeader, sizeof(poffFileHeader_t),
@@ -125,6 +129,30 @@ static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile)
errmsg("Failed to write POFF header: %s\n", strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore fields to host order */
+
+ poffSwapFileHeader(&poffInfo->fileHeader);
+}
+
+/***********************************************************************/
+
+static size_t poffWriteSectionHeader(poffSectionHeader_t *pheader, FILE *poffFile)
+{
+ size_t entriesWritten;
+
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapSectionHeader(pheader);
+
+ /* Write the POFF section header */
+
+ entriesWritten = fwrite(pheader, sizeof(poffSectionHeader_t), 1, poffFile);
+
+ /* Restore fields to host order */
+
+ poffSwapSectionHeader(pheader);
+ return entriesWritten;
}
/***********************************************************************/
@@ -153,9 +181,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
/* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->progSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->progSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write program section header: %s\n",
@@ -176,9 +202,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
/* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->roDataSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->roDataSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write data section header: %s\n",
@@ -199,9 +223,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
/* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->symbolTableSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->symbolTableSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write symbol table section header: %s\n",
@@ -222,9 +244,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
/* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->relocSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->relocSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write relocation section header: %s\n",
@@ -245,9 +265,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
/* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->fileNameTableSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->fileNameTableSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write file table section header: %s\n",
@@ -268,9 +286,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
/* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->lineNumberSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->lineNumberSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write line number section header: %s\n",
@@ -291,9 +307,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
/* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->debugFuncSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->debugFuncSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write debug section header: %s\n",
@@ -314,9 +328,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
/* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->stringTableSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->stringTableSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write string table section header: %s\n",
@@ -370,6 +382,12 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
{
if (!poffInfo->symbolTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapSymbolTableData(poffInfo);
+
+ /* Write the symbol table entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->symbolTable, sizeof(ubyte),
poffInfo->symbolTableSection.sh_size, poffFile);
if (entriesWritten != poffInfo->symbolTableSection.sh_size)
@@ -378,6 +396,11 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host data order */
+
+ poffSwapSymbolTableData(poffInfo);
+
}
/* Write the relocation table section data (if we have one) */
@@ -386,6 +409,12 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
{
if (!poffInfo->relocTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapRelocationData(poffInfo);
+
+ /* Write the relocation table entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->relocTable, sizeof(ubyte),
poffInfo->relocSection.sh_size, poffFile);
if (entriesWritten != poffInfo->relocSection.sh_size)
@@ -394,6 +423,10 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host data order */
+
+ poffSwapRelocationData(poffInfo);
}
/* Write the file table section data (if we have one) */
@@ -402,6 +435,12 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
{
if (!poffInfo->fileNameTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapFileTableData(poffInfo);
+
+ /* Write the file table entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->fileNameTable, sizeof(ubyte),
poffInfo->fileNameTableSection.sh_size,
poffFile);
@@ -411,6 +450,10 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host data order */
+
+ poffSwapFileTableData(poffInfo);
}
/* Write the line number section data (if we have one) */
@@ -419,6 +462,12 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
{
if (!poffInfo->lineNumberTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapLineNumberData(poffInfo);
+
+ /* Write the line number table entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->lineNumberTable, sizeof(ubyte),
poffInfo->lineNumberSection.sh_size,
poffFile);
@@ -428,14 +477,24 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host order */
+
+ poffSwapLineNumberData(poffInfo);
}
- /* Write the line number section data (if we have one) */
+ /* Write the debug section data (if we have one) */
if (HAVE_DEBUG_SECTION)
{
if (!poffInfo->debugFuncTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapDebugData(poffInfo);
+
+ /* Write the debug entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->debugFuncTable, sizeof(ubyte),
poffInfo->debugFuncSection.sh_size,
poffFile);
@@ -445,6 +504,10 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host order */
+
+ poffSwapDebugData(poffInfo);
}
/* Write the string table section data LAST (because we may have
diff --git a/misc/pascal/nuttx/INSTALL.sh b/misc/pascal/nuttx/INSTALL.sh
index c2f374e57..ad9802d9f 100755
--- a/misc/pascal/nuttx/INSTALL.sh
+++ b/misc/pascal/nuttx/INSTALL.sh
@@ -153,8 +153,8 @@ cp -a ${pascaldir}/libpoff/*.c ${pascaldir}/libpoff/*.h \
${pascaldir}/libpoff/Make.defs ${nuttxdir}/pcode/libpoff/. || \
{ echo "Failed to copy ${pascaldir}/libpoff" ; exit 1; }
-cp -a ${pascaldir}/libpas/psignextend16.c ${pascaldir}/libpas/Make.defs \
- ${nuttxdir}/pcode/libpas/. || \
+cp -a ${pascaldir}/libpas/psignextend16.c ${pascaldir}/libpas/pswap.c \
+ ${pascaldir}/libpas/Make.defs ${nuttxdir}/pcode/libpas/. || \
{ echo "Failed to copy ${pascaldir}/libpas" ; exit 1; }
cp -a ${pascaldir}/${modeldir}/include/pexec.h ${pascaldir}/${modeldir}/include/pinsn16.h \
diff --git a/misc/pascal/pascal/Makefile b/misc/pascal/pascal/Makefile
index 6029fb245..9171700fd 100644
--- a/misc/pascal/pascal/Makefile
+++ b/misc/pascal/pascal/Makefile
@@ -77,7 +77,7 @@ check_libs:
fi
$(BINDIR-y)/pascal: check_libs $(PASOBJS)
- $(CC) -o $@ $(LDFLAGS) $(PASOBJS) -linsn -lpas -lpoff -lm
+ $(CC) -o $@ $(LDFLAGS) $(PASOBJS) -linsn -lpoff -lpas -lm
pascal: $(BINDIR-y)/pascal
diff --git a/misc/pascal/plink/Makefile b/misc/pascal/plink/Makefile
index 9b76aa6a0..7a5d188f5 100644
--- a/misc/pascal/plink/Makefile
+++ b/misc/pascal/plink/Makefile
@@ -75,7 +75,7 @@ check_libs:
fi
$(BINDIR-y)/plink: check_libs $(PLINKOBJS)
- $(CC) -o $@ $(LDFLAGS) $(PLINKOBJS) -lpas -linsn -lpoff
+ $(CC) -o $@ $(LDFLAGS) $(PLINKOBJS) -linsn -lpoff -lpas
plink: $(BINDIR-y)/plink