From eca8fc5427fae36404c8f3772f8ed4f2f36100ea Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 4 Jan 2008 22:52:02 +0000 Subject: [PATCH] Pascal git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@485 42af7a65-404d-4744-a932-0658087f49c3 --- misc/pascal/Makefile | 115 ++ misc/pascal/include/keywords.h | 94 ++ misc/pascal/include/pmach.h | 82 + misc/pascal/include/poff.h | 428 +++++ misc/pascal/include/pofflib.h | 316 ++++ misc/pascal/insn16/include/pdbg.h | 52 + misc/pascal/insn16/include/pexec.h | 138 ++ misc/pascal/insn16/include/pinsn16.h | 408 +++++ misc/pascal/insn16/prun/Make.defs | 38 + misc/pascal/insn16/prun/Makefile | 87 + misc/pascal/insn16/prun/pdbg.c | 751 +++++++++ misc/pascal/insn16/prun/pexec.c | 2239 ++++++++++++++++++++++++++ misc/pascal/insn16/prun/pload.c | 175 ++ misc/pascal/insn16/prun/prun.c | 257 +++ misc/pascal/insn32/include/pinsn32.h | 426 +++++ misc/pascal/libpoff/Make.defs | 49 + misc/pascal/libpoff/Makefile | 47 + misc/pascal/libpoff/pfdbgcontainer.c | 105 ++ misc/pascal/libpoff/pfdbgdiscard.c | 94 ++ misc/pascal/libpoff/pfdbginfo.c | 157 ++ misc/pascal/libpoff/pfdhdr.c | 182 +++ misc/pascal/libpoff/pfdreloc.c | 107 ++ misc/pascal/libpoff/pfdsymbol.c | 116 ++ misc/pascal/libpoff/pfhandle.c | 195 +++ misc/pascal/libpoff/pfiprog.c | 92 ++ misc/pascal/libpoff/pfirodata.c | 102 ++ misc/pascal/libpoff/pflabel.c | 284 ++++ misc/pascal/libpoff/pflineno.c | 333 ++++ misc/pascal/libpoff/pfprivate.h | 172 ++ misc/pascal/libpoff/pfproghandle.c | 127 ++ misc/pascal/libpoff/pfrdbgfunc.c | 130 ++ misc/pascal/libpoff/pfread.c | 318 ++++ misc/pascal/libpoff/pfrelease.c | 94 ++ misc/pascal/libpoff/pfrfname.c | 116 ++ misc/pascal/libpoff/pfrhdr.c | 117 ++ misc/pascal/libpoff/pfrlineno.c | 127 ++ misc/pascal/libpoff/pfrprog.c | 91 ++ misc/pascal/libpoff/pfrrawlineno.c | 110 ++ misc/pascal/libpoff/pfrrawreloc.c | 107 ++ misc/pascal/libpoff/pfrseek.c | 115 ++ misc/pascal/libpoff/pfrstring.c | 90 ++ misc/pascal/libpoff/pfrsymbol.c | 107 ++ misc/pascal/libpoff/pfsymhandle.c | 127 ++ misc/pascal/libpoff/pftprog.c | 224 +++ misc/pascal/libpoff/pftsymbol.c | 188 +++ misc/pascal/libpoff/pfwdbgfunc.c | 173 ++ misc/pascal/libpoff/pfwfname.c | 145 ++ misc/pascal/libpoff/pfwhdr.c | 115 ++ misc/pascal/libpoff/pfwlineno.c | 164 ++ misc/pascal/libpoff/pfwprog.c | 127 ++ misc/pascal/libpoff/pfwreloc.c | 161 ++ misc/pascal/libpoff/pfwrite.c | 477 ++++++ misc/pascal/libpoff/pfwrodata.c | 192 +++ misc/pascal/libpoff/pfwstring.c | 217 +++ misc/pascal/libpoff/pfwsymbol.c | 151 ++ misc/pascal/libpoff/pfxprog.c | 95 ++ misc/pascal/libpoff/pfxrodata.c | 94 ++ misc/pascal/libpoff/pofferr.c | 93 ++ misc/pascal/nuttx/INSTALL.sh | 143 ++ misc/pascal/nuttx/Makefile | 89 + misc/pascal/nuttx/README.txt | 31 + misc/pascal/nuttx/keywords.h | 64 + 62 files changed, 12360 insertions(+) create mode 100644 misc/pascal/Makefile create mode 100644 misc/pascal/include/keywords.h create mode 100644 misc/pascal/include/pmach.h create mode 100644 misc/pascal/include/poff.h create mode 100644 misc/pascal/include/pofflib.h create mode 100644 misc/pascal/insn16/include/pdbg.h create mode 100644 misc/pascal/insn16/include/pexec.h create mode 100644 misc/pascal/insn16/include/pinsn16.h create mode 100644 misc/pascal/insn16/prun/Make.defs create mode 100644 misc/pascal/insn16/prun/Makefile create mode 100644 misc/pascal/insn16/prun/pdbg.c create mode 100644 misc/pascal/insn16/prun/pexec.c create mode 100644 misc/pascal/insn16/prun/pload.c create mode 100644 misc/pascal/insn16/prun/prun.c create mode 100644 misc/pascal/insn32/include/pinsn32.h create mode 100644 misc/pascal/libpoff/Make.defs create mode 100644 misc/pascal/libpoff/Makefile create mode 100644 misc/pascal/libpoff/pfdbgcontainer.c create mode 100644 misc/pascal/libpoff/pfdbgdiscard.c create mode 100644 misc/pascal/libpoff/pfdbginfo.c create mode 100644 misc/pascal/libpoff/pfdhdr.c create mode 100644 misc/pascal/libpoff/pfdreloc.c create mode 100644 misc/pascal/libpoff/pfdsymbol.c create mode 100644 misc/pascal/libpoff/pfhandle.c create mode 100644 misc/pascal/libpoff/pfiprog.c create mode 100644 misc/pascal/libpoff/pfirodata.c create mode 100644 misc/pascal/libpoff/pflabel.c create mode 100644 misc/pascal/libpoff/pflineno.c create mode 100644 misc/pascal/libpoff/pfprivate.h create mode 100644 misc/pascal/libpoff/pfproghandle.c create mode 100644 misc/pascal/libpoff/pfrdbgfunc.c create mode 100644 misc/pascal/libpoff/pfread.c create mode 100644 misc/pascal/libpoff/pfrelease.c create mode 100644 misc/pascal/libpoff/pfrfname.c create mode 100644 misc/pascal/libpoff/pfrhdr.c create mode 100644 misc/pascal/libpoff/pfrlineno.c create mode 100644 misc/pascal/libpoff/pfrprog.c create mode 100644 misc/pascal/libpoff/pfrrawlineno.c create mode 100644 misc/pascal/libpoff/pfrrawreloc.c create mode 100644 misc/pascal/libpoff/pfrseek.c create mode 100644 misc/pascal/libpoff/pfrstring.c create mode 100644 misc/pascal/libpoff/pfrsymbol.c create mode 100644 misc/pascal/libpoff/pfsymhandle.c create mode 100644 misc/pascal/libpoff/pftprog.c create mode 100644 misc/pascal/libpoff/pftsymbol.c create mode 100644 misc/pascal/libpoff/pfwdbgfunc.c create mode 100644 misc/pascal/libpoff/pfwfname.c create mode 100644 misc/pascal/libpoff/pfwhdr.c create mode 100644 misc/pascal/libpoff/pfwlineno.c create mode 100644 misc/pascal/libpoff/pfwprog.c create mode 100644 misc/pascal/libpoff/pfwreloc.c create mode 100644 misc/pascal/libpoff/pfwrite.c create mode 100644 misc/pascal/libpoff/pfwrodata.c create mode 100644 misc/pascal/libpoff/pfwstring.c create mode 100644 misc/pascal/libpoff/pfwsymbol.c create mode 100644 misc/pascal/libpoff/pfxprog.c create mode 100644 misc/pascal/libpoff/pfxrodata.c create mode 100644 misc/pascal/libpoff/pofferr.c create mode 100755 misc/pascal/nuttx/INSTALL.sh create mode 100644 misc/pascal/nuttx/Makefile create mode 100644 misc/pascal/nuttx/README.txt create mode 100644 misc/pascal/nuttx/keywords.h diff --git a/misc/pascal/Makefile b/misc/pascal/Makefile new file mode 100644 index 000000000..b8af29415 --- /dev/null +++ b/misc/pascal/Makefile @@ -0,0 +1,115 @@ +# ---------------------------------------------------------------------- +# Makefile +# ---------------------------------------------------------------------- + +# ---------------------------------------------------------------------- +# Directories + +PASCAL = ${shell pwd} + +include $(PASCAL)/Make.config +include $(PASCAL)/Make.defs + +INCDIR = $(PASCAL)/include +LIBDIR = $(PASCAL)/lib +BINDIR-$(CONFIG_INSN16) = $(PASCAL)/bin16 +BINDIR-$(CONFIG_INSN32) = $(PASCAL)/bin32 +LIBPOFFDIR = $(PASCAL)/libpoff +LIBPASDIR = $(PASCAL)/libpas +PASDIR = $(PASCAL)/pascal +PLINKDIR = $(PASCAL)/plink +TESTDIR = $(PASCAL)/tests +INSN-$(CONFIG_INSN16) = $(PASCAL)/insn16 +INSN-$(CONFIG_INSN32) = $(PASCAL)/insn32 +LIBINSNDIR = $(INSN-y)/libinsn + +# ---------------------------------------------------------------------- +# Objects and targets + +LIBS = $(LIBDIR)/libpoff.a $(LIBDIR)/libpas.a \ + $(LIBDIR)/libinsn.a + +all: pascal popt regm plink plist prun +.PHONY: all config.h libpoff.a libpas.a libinsn.a pascal popt regm plink plist prun clean deep-clean + +$(INCDIR)/config.h: Make.config + @$(MAKE) -f Make.config.h + +config.h: $(INCDIR)/config.h + +$(LIBDIR): + mkdir $(LIBDIR) + +$(LIBDIR)/libpoff.a: $(LIBDIR) config.h + @$(MAKE) -C $(LIBPOFFDIR) libpoff.a + +libpoff.a: $(LIBDIR)/libpoff.a + +$(LIBDIR)/libpas.a: $(LIBDIR) config.h + @$(MAKE) -C $(LIBPASDIR) libpas.a + +libpas.a: $(LIBDIR)/libpas.a + +$(LIBDIR)/libinsn.a: $(LIBDIR) config.h + @$(MAKE) -C $(LIBINSNDIR) libinsn.a + +libinsn.a: $(LIBDIR)/libinsn.a + +$(BINDIR-y): + mkdir $(BINDIR-y) + +$(BINDIR-y)/pascal: $(BINDIR-y) config.h $(LIBS) + @$(MAKE) -C $(PASDIR) + +pascal: $(BINDIR-y)/pascal + +$(BINDIR-y)/popt: $(BINDIR-y) config.h $(LIBS) + @$(MAKE) -C $(INSN-y) popt + +popt: $(BINDIR-y)/popt + +$(BINDIR-y)/regm: $(BINDIR-y) config.h $(LIBS) +ifeq ($(CONFIG_REGM),y) + @$(MAKE) -C $(INSN-y) regm +endif + +regm: $(BINDIR-y)/regm + +$(BINDIR-y)/plink: $(BINDIR-y) config.h $(LIBS) + @$(MAKE) -C $(PLINKDIR) + +plink: $(BINDIR-y)/plink + +$(BINDIR-y)/prun: $(BINDIR-y) config.h $(LIBS) + @$(MAKE) -C $(INSN-y) prun + +prun: $(BINDIR-y)/prun + +$(BINDIR-y)/plist: $(BINDIR-y) config.h $(LIBS) + @$(MAKE) -C $(INSN-y) plist + +plist: $(BINDIR-y)/plist + +clean: + $(RM) -f core *~ + $(RM) -rf $(LIBDIR) + $(RM) -rf bin16 bin32 + $(MAKE) -f Make.config.h clean + $(MAKE) -C $(LIBPOFFDIR) clean + $(MAKE) -C $(LIBPASDIR) clean + $(MAKE) -C $(PASDIR) clean + $(MAKE) -C $(PLINKDIR) clean + $(MAKE) -C $(INSN-y) clean + find . -name \*~ -exec rm -f {} \; + find tests -name "*.err" -exec rm -f {} \; + find tests -name "*.lst" -exec rm -f {} \; + find tests -name "*.pex" -exec rm -f {} \; + find tests -name "*.o1" -exec rm -f {} \; + find tests -name "*.o" -exec rm -f {} \; + +deep-clean: clean + rm -f .config include/config.h Make.config + $(RM) bin16/* + $(RM) bin32/* + +# ---------------------------------------------------------------------- diff --git a/misc/pascal/include/keywords.h b/misc/pascal/include/keywords.h new file mode 100644 index 000000000..af87a832f --- /dev/null +++ b/misc/pascal/include/keywords.h @@ -0,0 +1,94 @@ +/************************************************************* + * keywords.h + * This file defines the pascal compilation environment + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __KEYWORDS_H +#define __KEYWORDS_H + +/************************************************************* + * Included Files + *************************************************************/ + +#include "config.h" + +/************************************************************* + * Definitions + *************************************************************/ + +#define TRUE 1 +#define FALSE 0 + +#ifndef CONFIG_DEBUG +# define CONFIG_DEBUG 0 +#endif + +#if CONFIG_DEBUG +# define DEBUG(stream, format, arg...) fprintf(stream, format, ##arg) +#else +# define DEBUG(x...) +#endif + +#ifndef CONFIG_TRACE +# define CONFIG_TRACE 0 +#endif + +#if CONFIG_TRACE +# define TRACE(stream, format, arg...) fprintf(stream, format, ##arg) +#else +# define TRACE(x...) +#endif + +#define FAR + +#define dbg(...) fprintf(stderr, __VA_ARGS__) +#define vdbg(...) DEBUG(__VA_ARGS__) + +/************************************************************* + * Type Definitions + *************************************************************/ + +typedef unsigned char ubyte; /* 8-bit integers */ +typedef signed char sbyte; +typedef unsigned short uint16; /* 16-bit integers */ +typedef signed short sint16; +typedef unsigned long uint32; /* 32-bit integers */ +typedef signed long sint32; +typedef float float32; /* floating point types */ +typedef double float64; +typedef unsigned char boolean; /* boolean type */ + +#endif /* __KEYWORDS_H */ + + + diff --git a/misc/pascal/include/pmach.h b/misc/pascal/include/pmach.h new file mode 100644 index 000000000..c7bc42e3a --- /dev/null +++ b/misc/pascal/include/pmach.h @@ -0,0 +1,82 @@ +/********************************************************************** + * File: pmach.h + * Description: Definitions associated with the simulated P-Machine + * Author: Gregory Nutt + * Modified: + **********************************************************************/ + +#ifndef __PMACH_H +#define __PMACH_H + +/********************************************************************** + * Definitions + **********************************************************************/ + +#define MIN_PROGRAM_COUNTER 0 + +/********************************************************************** + * Global Type Definitions + **********************************************************************/ + +typedef uint16 uStackType; /* Stack values are 16-bits in length */ +typedef sint16 sStackType; +typedef uint16 addrType; /* Addresses are 16-bits in length */ +typedef uint16 levelType; /* Limits to MAXUINT16 levels */ +typedef uint16 labelType; /* Limits to MAXUINT16 labels */ + +#define BPERI 2 +#define ITOBSTACK(i) ((i) << 1) +#define BTOISTACK(i) ((i) >> 1) +#define ROUNDBTOI(i) (((i) + 1) >> 1) +#define STACKALIGN(i) (((i) + 1) & ~1) + +union stack_u +{ + uStackType *i; + ubyte *b; +}; +typedef union stack_u stackType; + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/* This is the emulated P-Machine stack (D-Space) */ + +extern stackType stack; + +/* This is the emulated P-Machine instruction space */ + +extern ubyte *iSpace; + +/* These are the emulated P-Machine registers: + * + * baseReg: Base Register of the current stack frame. Holds the address + * of the base of the stack frame of the current block. + * topOfStringStack: The current top of the stack used to manage string + * storage + * topOfStack: The Pascal stack pointer + * programCounter: Holds the current p-code location + */ + +extern addrType baseReg; +extern addrType topOfStringStack; +extern addrType topOfStack; +extern addrType programCounter; + +/* Configuration variables + * + * readOnlyData: Stack address of read-only data + * bottomOfStack: Initial Value of the stack pointer + * sizeOfStack: Total allocated size of the Pascal stack + * maxProgramCounter: Address of last valid P-Code + * entryPoint: This is the address where execution begins. + */ + +extern addrType readOnlyData; +extern addrType bottomOfStack; +extern addrType sizeOfStack; +extern addrType maxProgramCounter; +extern uint32 entryPoint; + +#endif /* __PMACH_H */ diff --git a/misc/pascal/include/poff.h b/misc/pascal/include/poff.h new file mode 100644 index 000000000..e446a87b7 --- /dev/null +++ b/misc/pascal/include/poff.h @@ -0,0 +1,428 @@ +/*************************************************************************** + * poff.h + * Definitions for the PCode Object File Format (POFF) + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __POFF_H +#define __POFF_H + +/*************************************************************************** + * Compilation Switches + ***************************************************************************/ + +/*************************************************************************** + * Included Files + ***************************************************************************/ + +#include "keywords.h" +#include "config.h" + +/*************************************************************************** + * Definitions + ***************************************************************************/ + +/* Definitions for the fh_ident field of the poffHdr_t */ + +#define FHI_MAG0 0 /* fh_ident[] indices */ +#define FHI_MAG1 1 +#define FHI_MAG2 2 +#define FHI_MAG3 3 +#define FHI_NIDENT 4 + +#define FHI_POFF_MAG0 'P' +#define FHI_POFF_MAG1 'O' +#define FHI_POFF_MAG2 'F' +#define FHI_POFF_MAG3 'F' +#define FHI_POFF_MAG "POFF" + +/* Definitions for fh_version */ + +#define FHV_NONE 0 +#define FHV_CURRENT 1 + +/* Definitions for the fh_type */ + +#define FHT_NONE 0 /* Shouldn't happen */ +#define FHT_EXEC 1 /* Pascal program executable */ +#define FHT_SHLIB 2 /* Pascal shared library */ +#define FHT_PROGRAM 3 /* Pascal program object */ +#define FHT_UNIT 4 /* Pascal unit object */ +#define FHT_NTYPES 5 + +/* Definitions for fh_arch */ + +#define FHAW_INSN16 0 /* Data width is 16 bits */ +#define FHAW_INSN32 1 /* Data width is 32 bits */ + +#define FHAC_PCODE 0 /* Stack oriented P-Code machine class */ +#define FHAC_REGM 1 /* Generalized register machine class */ + +#define MK_FH_ARCH(c,w) (((c)<<4)|(w)) +#define GET_FH_CLASS(fha) ((fha) >> 4) +#define GET_FH_WIDTH(fha) ((fha) & 0x0f) + +#define FHA_PCODE_INSN16 MK_FH_ARCH(FHAC_PCODE,FHAW_INSN16) +#define FHA_PCODE_INSN32 MK_FH_ARCH(FHAC_PCODE,FHAW_INSN32) +#define FHA_REGM_INSN16 MK_FH_ARCH(FHAC_REGM,FHAW_INSN16) +#define FHA_REGM_INSN32 MK_FH_ARCH(FHAC_REGM,FHAW_INSN32) + +#ifdef CONFIG_INSN16 +# define FHA_PCODE FHA_PCODE_INSN16 +# define FHA_REGM FHA_REGM_INSN16 +#endif +#ifdef CONFIG_INSN32 +# define FHA_PCODE FHA_PCODE_INSN32 +# define FHA_REGM FHA_REGM_INSN16 +#endif + +/* Definitions for sh_type */ + +#define SHT_NULL 0 /* Shouldn't happen */ +#define SHT_PROGDATA 1 /* Program data */ +#define SHT_SYMTAB 2 /* Symbol table */ +#define SHT_STRTAB 3 /* String table */ +#define SHT_REL 4 /* Relocation data */ +#define SHT_FILETAB 5 /* File table */ +#define SHT_LINENO 6 /* Line number data */ +#define SHT_DEBUG 7 /* Procedure/Function info */ +#define SHT_NTYPES 8 + +/* Definitions for sh_flags */ + +#define SHF_WRITE 0x01 /* Section is write-able */ +#define SHF_ALLOC 0x02 /* Memory must be allocated for setion */ +#define SHF_EXEC 0x04 /* Section contains program data */ + +/* Values for st_type */ + +#define STT_NONE 0 /* Should not occur */ +#define STT_DATA 1 /* Stack data section symbol */ +#define STT_RODATA 2 /* Read only data section symbol */ +#define STT_PROC 3 /* Procedure entry point */ +#define STT_FUNC 4 /* Function entry point */ +#define STT_NTYPES 5 + +/* Values for st_align. Any power of two numeric value can be + * used, but the following are defined for convenience. + */ + +#define STA_NONE 0 /* Should not occur */ +#define STA_8BIT 1 /* 8-bit byte alignment */ +#define STA_16BIT 2 /* 16-bit half word alignment */ +#define STA_32BIT 4 /* 32-bit word alignment */ +#define STA_64BIT 8 /* 32-bit double word alignment */ + +/* Values for st_flags */ + +#define STF_NONE 0x00 +#define STF_UNDEFINED 0x01 /* Symbol is undefined (imported) */ + +/* P-Code relocation types (see RLI_type) */ + +#define RLT_NONE 0 /* Should not occur */ +#define RLT_PCAL 1 /* PCAL to external proc/func */ +#define RLT_LDST 2 /* LA or LAX to external stack loc */ +#define RLT_NTYPES 3 + +/* The following are used with relocation table rl_info field */ + +#define RLI_SYM(x) ((x) >> 8) /* Symbol index */ +#define RLI_TYPE(x) ((x) & 0xff) /* Rloc type */ +#define RLI_MAKE(s,t) (((uint32)(s) << 8) | ((t) & 0xff)) + +/*************************************************************************** + * Public Types + ***************************************************************************/ + +/* POFF file header */ + +struct poffFileHeader_s +{ + /* fh_ident holds the four characters 'P', 'O', 'F', 'F' + * See the FHI_ definitions above. + */ + + ubyte fh_ident[FHI_NIDENT]; + + /* fh_version holds the version of the POFF file format. This should + * always be FHV_CURRENT. + */ + + ubyte fh_version; + + /* fh_type holds the type of binary carry by the POFF file. + * See the FHT_ definitions above. + */ + + ubyte fh_type; + + /* fh_arch holds the mach architecture identifier. See the FHA_ + * definitions above. + */ + + ubyte fh_arch; + + /* fh_shsize is the size a section header. This should be + * sizeof(poffSectionHeader_t) + */ + + uint16 fh_shsize; + + /* fh_num is the number of section headers in section header + * list. The total size of the section header block is then + * fh_shsize * fh_shnum. + */ + + uint16 fh_shnum; + + /* fh_name is an offset into the string table section data. + * It refers to a name associated with fh_type that determines + * the specific instances of the type. + */ + + uint32 fh_name; + + /* For fhi_type = {FHI_EXEC or FHI_PROGRAM}, fh_entry holds the + * entry point into the program. For FHI_PROGRAM, this entry point + * is a instruction space label. For FHI_EXEC, this entry point + * is an instruction space address offset (from address zero). + */ + + uint32 fh_entry; + + /* fh_shoff is the file offset to the beginning of the table of file + * headers. fh_shoff will most likely be sizeof(poffFileHeader_t). + */ + + uint32 fh_shoff; +}; +typedef struct poffFileHeader_s poffFileHeader_t; + +/* POFF section header */ + +struct poffSectionHeader_s +{ + /* sh_type is the type of section described by this header. + * See the SHT_ definitions above. + */ + + ubyte sh_type; + + /* These flags describe the characteristics of the section. See the + * SHF_ definitions above. + */ + + ubyte sh_flags; + + /* If the section holds a table of fixed sized entries, sh_entsize + * gives the size of one entry. The number of entries can then be + * obtained by dividing sh_size by sh_entsize. + */ + + uint16 sh_entsize; + + /* sh_name is an offset into the string table section data. + * It refers to a name associated with section. + */ + + uint32 sh_name; + + /* If the section is loaded into memory (SHF_ALLOC), then this + * address holds the address at which the data must be loaded + * (if applicable). + */ + + uint32 sh_addr; + + /* sh_offset is the offset from the beginning of the file to + * beginning of data associated with this section. + */ + + uint32 sh_offset; + + /* sh_size provides the total size of the section data in bytes. + * If the section holds a table of fixed sized entries, then + * sh_size be equal to sh_entsize times the number of entries. + */ + + uint32 sh_size; +}; +typedef struct poffSectionHeader_s poffSectionHeader_t; + +/* Structures which may appear as arrays in sections */ + +/* Relocation data section array entry structure */ + +struct poffRelocation_s + { + /* This value includes the symbol table index plus the + * relocation type. See the RLI_* macros above. + */ + + uint32 rl_info; + + /* This is the section data offset to the instruction/data + * to be relocated. The effected section is implicit in the + * relocation type. + */ + + uint32 rl_offset; /* Offset to pcode */ +}; +typedef struct poffRelocation_s poffRelocation_t; + +/* Symbol section array entry structure */ + +struct poffSymbol_s +{ + /* st_type is the type of symbol described by this entry. + * See the STT_ definitions above. + */ + + ubyte st_type; + + /* For data section symbols, the following provides the required + * data space alignment for the symbol memory representation. For + * procedures and functions, this value is ignored. See the STT_ + * definitions above. + */ + + ubyte st_align; + + /* These flags describe the characteristics of the symbol. See the + * STF_ definitions above. + */ + + ubyte st_flags; + ubyte st_pad; + + /* st_name is an offset into the string table section data. + * It refers to a name associated with symbol. + */ + + uint32 st_name; + + /* st_value is the value associated with symbol. For defined data + * section symbols, this is the offset into the initialized data + * section data; for defined procedures and functions, this the + * offset into program section data. For undefined symbols, this + * valid can be used as as addend. + */ + + uint32 st_value; + + /* For data section symbols, this is the size of the initialized + * data region associated with the symbol. + */ + + uint32 st_size; +}; +typedef struct poffSymbol_s poffSymbol_t; + +/* The file table section just consists of a list of offsets + * into the string table. The file table index is used elsewhere + * (such as in the line number array) to refer to a specific + * file. + */ + +typedef uint32 poffFileTab_t; + +/* Line number section array entry structure. Line numbers are + * associated with executable program data sections. + */ + +struct poffLineNumber_s +{ + /* This is the source file line number */ + + uint16 ln_lineno; + + /* This is an index (not a byte offset) to an entry in the file + * section table. This can be used to identify the name of the + * file for which the line number applies. + */ + + uint16 ln_fileno; + + /* This is an offset to the beginning of the instruction in the + * program data section. At present, this is limited to a single + * program data section. + */ + + uint32 ln_poffset; +}; +typedef struct poffLineNumber_s poffLineNumber_t; + +/* The debug info section consists of a list of poffDebugFuncInfo_t + * entries, each following a sublist of poffDebugArgInfo_t entries. + */ + +/* poffDebugFuncInfo_t provides description of function input + * parameters and return values. + */ + +struct poffDebugFuncInfo_s +{ + /* This is the address or label of the function/procedure entry + * point. + */ + + uint32 df_value; + + /* This is the size of the value returned by the function in + * bytes (zero for procedures). + */ + + uint32 df_size; + + /* This is the number of parameters accepted by the function/ + * procedure. + */ + + uint32 df_nparms; +}; +typedef struct poffDebugFuncInfo_s poffDebugFuncInfo_t; + +/* poffDebugArgInfo_t provides description of one function input + * parameter. + */ + +struct poffDebugArgInfo_s +{ + /* This is the size, in bytes, of one input paramters */ + + uint32 da_size; +}; +typedef struct poffDebugArgInfo_s poffDebugArgInfo_t; + +#endif /* __POFF_H */ diff --git a/misc/pascal/include/pofflib.h b/misc/pascal/include/pofflib.h new file mode 100644 index 000000000..ee68bfa92 --- /dev/null +++ b/misc/pascal/include/pofflib.h @@ -0,0 +1,316 @@ +/*************************************************************************** + * pofflib.h + * Interfaces to the POFF library + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __POFFLIB_H +#define __POFFLIB_H + +/*************************************************************************** + * Compilation Switches + ***************************************************************************/ + +/*************************************************************************** + * Included Files + ***************************************************************************/ + +#include "keywords.h" +#include "poff.h" + +/*************************************************************************** + * Definitions + ***************************************************************************/ + +/*************************************************************************** + * Public Types + ***************************************************************************/ + +/* The internal form of the POFF data structures are hidden from the caller + * in these "handles" + */ + +typedef void *poffHandle_t; +typedef void *poffProgHandle_t; +typedef void *poffSymHandle_t; + +/* This is a externally visible form of a symbol table entry that is + * not entangled in the POFF internal string table logic. + */ + +struct poffLibSymbol_s +{ + /* type is the type of symbol described by this entry. + * See the STT_ definitions in poff.h. + */ + + ubyte type; + + /* For data section symbols, the following provides the required + * data space alignment for the symbol memory representation. For + * procedures and functions, this value is ignored. See the STT_ + * definitions in poff.h + */ + + ubyte align; + + /* These flags describe the characteristics of the symbol. See the + * STF_ definitions above. + */ + + ubyte flags; + + /* name is a reference to the symbol name in the string table + * section data. + */ + + const char *name; + + /* value is the value associated with symbol. For defined data + * section symbols, this is the offset into the initialized data + * section data; for defined procedures and functions, this the + * offset into program section data. For undefined symbols, this + * valid can be used as as addend. + */ + + uint32 value; + + /* For data section symbols, this is the size of the initialized + * data region associated with the symbol. + */ + + uint32 size; +}; +typedef struct poffLibSymbol_s poffLibSymbol_t; + +/* The externally visible form of a line number structure. Line numbers + * are associated with executable program data sections. + */ + +struct poffLibLineNumber_s +{ + /* This is the source file line number */ + + uint32 lineno; + + /* This is the full filename of the file containing the line number. */ + + const char *filename; + + /* This is an offset to the beginning code in the program data section + * associated with this line number. + */ + + uint32 offset; +}; +typedef struct poffLibLineNumber_s poffLibLineNumber_t; + +/* The externally visible form of a debug function info structure. + */ + +struct poffLibDebugFuncInfo_s +{ + /* For use outside of libpoff so that the allocated debug + * information can be retained in a list. + */ + + struct poffLibDebugFuncInfo_s *next; + + /* This is the address or label of the function/procedure entry + * point. + */ + + uint32 value; + + /* This is the size of the value returned by the function in + * bytes (zero for procedures). + */ + + uint32 retsize; + + /* This is the number of parameters accepted by the function/ + * procedure. + */ + + uint32 nparms; + + /* This is the beginning of a table of input parameter sizes + * the actually allocate size will be nparms entries. + */ + + uint32 argsize[1]; +}; +typedef struct poffLibDebugFuncInfo_s poffLibDebugFuncInfo_t; + +#define SIZEOFDEBUFINFO(n) (sizeof(poffLibDebugFuncInfo_t) + ((n)-1)*sizeof(uint32)) + +/*************************************************************************** + * Public Variables + ***************************************************************************/ + +/*************************************************************************** + * Public Function Prototypes + ***************************************************************************/ + +/* Functions to create/destroy a handle to POFF file data */ + +extern poffHandle_t poffCreateHandle(void); +extern void poffDestroyHandle(poffHandle_t handle); +extern void poffResetAccess(poffHandle_t handle); + +/* Functions to manage writing a POFF file */ + +extern void poffSetFileType(poffHandle_t handle, ubyte fh_type, + uint16 nfiles, const char *name); +extern void poffSetArchitecture(poffHandle_t handle, ubyte fh_arch); +extern void poffSetEntryPoint(poffHandle_t handle, uint32 entryPoint); +extern sint32 poffFindString(poffHandle_t handle, const char *string); +extern uint32 poffAddString(poffHandle_t handle, const char *string); +extern uint32 poffAddFileName(poffHandle_t handle, const char *name); +extern void poffAddProgByte(poffHandle_t handle, ubyte progByte); +#if 0 /* not used */ +extern uint32 poffAddRoDataByte(poffHandle_t handle, ubyte dataByte); +#endif +extern uint32 poffAddRoDataString(poffHandle_t handle, + const char *string); +extern uint32 poffAddSymbol(poffHandle_t handle, + poffLibSymbol_t *symbol); +extern uint32 poffAddLineNumber(poffHandle_t handle, + uint16 lineNumber, uint16 fileNumber, + uint32 progSectionDataOffset); +extern uint32 poffAddDebugFuncInfo(poffHandle_t handle, + poffLibDebugFuncInfo_t *pContainer); +extern uint32 poffAddRelocation(poffHandle_t handle, + ubyte relocType, uint32 symIndex, + uint32 sectionDataOffset); +extern void poffWriteFile(poffHandle_t handle, FILE *poffFile); + +/* Functions to manage reading a POFF file */ + +extern uint16 poffReadFile(poffHandle_t handle, FILE *poffFile); +extern ubyte poffGetFileType(poffHandle_t handle); +extern ubyte poffGetArchitecture(poffHandle_t handle); +extern uint32 poffGetEntryPoint(poffHandle_t handle); +extern const char *poffGetFileHdrName(poffHandle_t handle); +extern uint32 poffGetRoDataSize(poffHandle_t handle); +extern sint32 poffGetFileName(poffHandle_t handle, const char **fname); +extern int poffGetProgByte(poffHandle_t handle); +extern sint32 poffGetSymbol(poffHandle_t handle, + poffLibSymbol_t *symbol); +extern const char *poffGetString(poffHandle_t handle, uint32 index); +extern sint32 poffGetLineNumber(poffHandle_t handle, + poffLibLineNumber_t *lineno); +extern sint32 poffGetRawLineNumber(poffHandle_t handle, + poffLineNumber_t *lineno); +extern sint32 poffGetRawRelocation(poffHandle_t handle, + poffRelocation_t *reloc); +extern poffLibDebugFuncInfo_t *poffGetDebugFuncInfo(poffHandle_t handle); +extern poffLibDebugFuncInfo_t *poffCreateDebugInfoContainer(uint32 nparms); +extern void poffReleaseDebugFuncContainer(poffLibDebugFuncInfo_t *pDebugFuncInfo); +extern void poffDiscardDebugFuncInfo(poffHandle_t handle); +extern sint32 poffProgTell(poffHandle_t handle); +extern int poffProgSeek(poffHandle_t handle, uint32 offset); +extern uint32 poffGetProgSize(poffHandle_t handle); +extern void poffReleaseProgData(poffHandle_t handle); + +/* Functions used to manage modifications to a POFF file using a + * temporary container for the new program data. + */ + +extern poffProgHandle_t poffCreateProgHandle(void); +extern void poffDestroyProgHandle(poffProgHandle_t handle); +extern void poffResetProgHandle(poffProgHandle_t handle); +extern uint16 poffAddTmpProgByte(poffProgHandle_t handle, + ubyte progByte); +extern uint16 poffWriteTmpProgBytes(ubyte *buffer, uint32 nbyte, + poffProgHandle_t handle); +extern void poffReplaceProgData(poffHandle_t handle, + poffProgHandle_t progHandle); + +/* Functions used to manage modifications to a POFF file using a + * temporary container for the new symbol data. + */ + +extern poffSymHandle_t poffCreateSymHandle(void); +extern void poffDestroySymHandle(poffSymHandle_t handle); +extern void poffResetSymHandle(poffSymHandle_t handle); +extern uint32 poffAddTmpSymbol(poffHandle_t handle, poffSymHandle_t symHandle, + poffLibSymbol_t *symbol); +extern void poffReplaceSymbolTable(poffHandle_t handle, + poffSymHandle_t symHandle); + +/* Functions used to extract/insert whole data sections from/into a POFF + * file container + */ + +extern uint32 poffExtractProgramData(poffHandle_t handle, + ubyte **progData); +extern void poffInsertProgramData(poffHandle_t handle, + ubyte *progData, uint32 progSize); +extern uint32 poffExtractRoData(poffHandle_t handle, + ubyte **roData); +extern void poffAppendRoData(poffHandle_t handle, + ubyte *roData, uint32 roDataSize); + +/* Functions to manage printing of the POFF file content */ + +extern void poffDumpFileHeader(poffHandle_t handle, FILE *outFile); +extern void poffDumpSectionHeaders(poffHandle_t handle, FILE *outFile); +extern void poffDumpSymbolTable(poffHandle_t handle, FILE *outFile); +extern void poffDumpRelocTable(poffHandle_t handle, FILE *outFile); + +/* Helper functions to manage resolution of labels in POFF files. These + * just store and retrieve information by label number. + */ + +extern void poffAddToDefinedLabelTable(uint32 label, uint32 pc); +extern void poffAddToUndefinedLabelTable(uint32 label, + uint32 symIndex); +extern int poffGetSymIndexForUndefinedLabel(uint32 label); +extern int poffGetPcForDefinedLabel(uint32 label); +extern void poffReleaseLabelReferences(void); + +/* Helper functions for line numbers */ + +extern void poffReadLineNumberTable(poffHandle_t handle); +extern poffLibLineNumber_t *poffFindLineNumber(uint32 offset); +extern void poffReleaseLineNumberTable(void); + +/* Helper functions for debug information */ + +extern void poffReadDebugFuncInfoTable(poffHandle_t handle); +extern poffLibDebugFuncInfo_t *poffFindDebugFuncInfo(uint32 offset); +extern void poffReplaceDebugFuncInfo(poffHandle_t handle); +extern void poffReleaseDebugFuncInfoTable(void); + +#endif /* __POFFLIB_H */ diff --git a/misc/pascal/insn16/include/pdbg.h b/misc/pascal/insn16/include/pdbg.h new file mode 100644 index 000000000..1a0e148d2 --- /dev/null +++ b/misc/pascal/insn16/include/pdbg.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * pdbg.h + * External Declarations associated with the P-Code debugger + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __PDBG_H +#define __PDBG_H + +/*************************************************************************** + * Included Files + ***************************************************************************/ + +#include "pexec.h" + +/*************************************************************************** + * Global Function Prototypes + ***************************************************************************/ + +extern void dbg_run(struct pexec_s *st); + +#endif /* __PDBG_H */ diff --git a/misc/pascal/insn16/include/pexec.h b/misc/pascal/insn16/include/pexec.h new file mode 100644 index 000000000..de35589d9 --- /dev/null +++ b/misc/pascal/insn16/include/pexec.h @@ -0,0 +1,138 @@ +/**************************************************************************** + * pexec.h + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __PEXEC_H +#define __PEXEC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Type Definitions + ****************************************************************************/ + +/* This structure describes the parameters needed to initialize the p-code + * interpreter. + */ + +struct pexec_attr_s +{ + /* Instruction space (I-Space) */ + + FAR ubyte *ispace; /* Allocated I-Space containing p-code data */ + addrType entry; /* Entry point */ + addrType maxpc; /* Last valid p-code address */ + + /* Read-only data block */ + + FAR ubyte *rodata; /* Address of read-only data block */ + addrType rosize; /* Size of read-only data block */ + + /* Allocate for variable storage */ + + addrType varsize; /* Variable storage size */ + addrType strsize; /* String storage size */ +}; + +/* This structure defines the current state of the p-code interpreter */ + +struct pexec_s +{ + /* This is the emulated P-Machine stack (D-Space) */ + + stackType dstack; + + /* This is the emulated P-Machine instruction space (I-Space) */ + + FAR ubyte *ispace; + + /* Address of last valid P-Code */ + + addrType maxpc; + + /* These are the emulated P-Machine registers: + * + * spb: Base of the stack + * sp: The Pascal stack pointer + * csp: The current top of the stack used to manage string + * storage + * fp: Base Register of the current stack frame. Holds the address + * of the base of the stack frame of the current block. + * fop: Pointer to section containing read-only data + * pc: Holds the current p-code location + */ + + addrType spb; /* Pascal stack base */ + addrType sp; /* Pascal stack pointer */ + addrType csp; /* Character stack pointer */ + addrType fp; /* Base of the current frame */ + addrType rop; /* Read-only data pointer */ + addrType pc; /* Program counter */ + + /* Info needed to perform a simulated reset */ + + addrType strsize; /* String stack size */ + addrType rosize; /* Read-only stack size */ + addrType entry; /* Entry point */ + addrType stacksize; /* (debug only) */ +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +EXTERN FAR struct pexec_s *pload(const char *filename, addrType varsize, addrType strsize); +EXTERN FAR struct pexec_s *pexec_init(struct pexec_attr_s *attr); +EXTERN int pexec(FAR struct pexec_s *st); +EXTERN void pexec_reset(struct pexec_s *st); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __PEXEC_H */ diff --git a/misc/pascal/insn16/include/pinsn16.h b/misc/pascal/insn16/include/pinsn16.h new file mode 100644 index 000000000..a966f7aa3 --- /dev/null +++ b/misc/pascal/insn16/include/pinsn16.h @@ -0,0 +1,408 @@ +/**************************************************************************** + * pinsn16.h + * 16-bit P-code operation code definitions + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __PINSN16_H +#define __PINSN16_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* Op-code bit definitions */ + +#define o16 (0x80) +#define o8 (0x40) + +/* Opcode Encoding Summary: + * + * NO ARGS arg8 ONLY arg16 ONLY BOTH + * 00xx xxxx 01xx xxxx 10xx xxxx 11xx xxxx + * xx00 0000 NOP --- --- --- + * xx00 0001 NEG --- --- --- + * xx00 0010 ABS --- --- --- + * xx00 0011 INC --- --- --- + * xx00 0100 DEC --- --- --- + * xx00 0101 NOT --- --- --- + * xx00 0110 ADD --- --- --- + * xx00 0111 SUB --- --- --- + * xx00 1000 MUL --- --- PCAL l,ilbl + * xx00 1001 DIV --- --- --- + * xx00 1010 MOD --- --- --- + * xx00 1011 SLL --- --- --- + * xx00 1100 SRL --- --- --- + * xx00 1101 SRA --- --- --- + * xx00 1110 OR --- --- --- + * xx00 1111 AND --- --- --- + * + * xx01 0000 EQUZ --- JEQUZ ilbl --- + * xx01 0001 NEQZ --- JNEQZ ilbl --- + * xx01 0010 LTZ --- JLTZ ilbl --- + * xx01 0011 GTEZ --- JGTEZ ilbl --- + * xx01 0100 GTZ --- JGTZ ilbl --- + * xx01 0101 LTEZ --- JLTEZ ilbl --- + * xx01 0110 --- --- JMP ilbl --- + * xx01 0111 --- --- --- --- + * xx01 1000 EQU --- JEQU ilbl --- + * xx01 1001 NEQ --- JNEQ ilbl --- + * xx01 1010 LT --- JLT ilbl --- + * xx01 1011 GTE --- JGTE ilbl --- + * xx01 1100 GT --- JGT ilbl --- + * xx01 1101 LTE --- JLTE ilbl --- + * xx01 1110 --- --- --- --- + * xx01 1111 BIT --- --- --- + * + * xx10 0000 LDI --- LD uoffs LDS lvl,offs + * xx10 0001 LDIH --- LDH uoffs LDSH lvl,offs + * xx10 0010 LDIB --- LDB uoffs LDSB lvl,offs + * xx10 0011 LDIM --- LDM uoffs LDSM lvl,offs + * xx10 0100 STI --- ST uoffs STS lvl,offs + * xx10 0101 STIH --- STH uoffs STSH lvl,offs + * xx10 0110 STIB --- STB uoffs STSB lvl,offs + * xx10 0111 STIM --- STM uoffs STSM lvl,offs + * xx10 1000 DUP --- LDX uoffs LDSX lvl,offs + * xx10 1001 DUPH --- LDXH uoffs LDSXH lvl,offs + * xx10 1010 PUSHS --- LDXB uoffs LDSXB lvl,offs + * xx10 1011 POPS --- LDXM uoffs LDSXM lvl,offs + * xx10 1100 --- --- STX uoffs STSX lvl,offs + * xx10 1101 --- --- STXH uoffs STSXH lvl,offs + * xx10 1110 --- --- STXB uoffs STSXB lvl,offs + * xx10 1111 RET --- STXM uoffs STSXM lvl,offs + * + * xx11 0000 --- FLOAT fop LA uoffs LAS lvl,offs + * xx11 0001 --- --- LAC dlbl --- + * xx11 0010 --- --- --- --- + * xx11 0011 --- --- --- --- + * xx11 0100 --- PUSHB n PUSH nn --- + * xx11 0101 --- --- INDS nn --- + * xx11 0110 --- --- --- --- + * xx11 0111 --- --- --- --- + * xx11 1000 --- --- LAX uoffs LASX lvl,offs + * xx11 1001 --- --- LIB lop SYSIO fn,sop + * xx11 1010 --- --- --- --- + * xx11 1011 --- --- --- --- + * xx11 1100 --- --- --- --- + * xx11 1101 --- --- --- --- + * xx11 1110 --- --- --- --- + * xx11 1111 END --- *LABEL ilbl *LINE fn,lineno + * + * KEY: + * n = 8-bit value (unsigned) + * lvl = 8-bit static nesting level offset (unsigned) + * vt = 8-bit type code (unsigned) + * nn = 16-bit value (signed) + * fop = 8-bit floating point operation + * sop = 16-bit sysio operation + * lop = 16-bit library call identifier + * fn = 8-bit file number + * ilbl = instruction space label + * dlbl = stack data label + * offs = 16-bit frame offset (signed) + * uoffs = 16-bit base offset (unsigned) + * c = string follows psuedo-operation + * * = Indicates pseudo-operations (these are removed + * after final fixup of the object file). + */ + +/** OPCODES WITH NO ARGUMENTS ***********************************************/ + +/* Program control (No stack arguments) */ + +#define oNOP (0x00) + +/* Arithmetic & logical & and integer conversions (One 16-bit stack argument) */ + +#define oNEG (0x01) +#define oABS (0x02) +#define oINC (0x03) +#define oDEC (0x04) +#define oNOT (0x05) + +/* Arithmetic & logical (Two 16-bit stack arguments) */ + +#define oADD (0x06) +#define oSUB (0x07) +#define oMUL (0x08) +#define oDIV (0x09) +#define oMOD (0x0a) +#define oSLL (0x0b) +#define oSRL (0x0c) +#define oSRA (0x0d) +#define oOR (0x0e) +#define oAND (0x0f) + +/* Comparisons (One 16-bit stack argument) */ + +#define oEQUZ (0x10) +#define oNEQZ (0x11) +#define oLTZ (0x12) +#define oGTEZ (0x13) +#define oGTZ (0x14) +#define oLTEZ (0x15) + +/* 0x16-0x17 -- unassigned */ + +/* Comparisons (Two 16-bit stack arguments) */ + +#define oEQU (0x18) +#define oNEQ (0x19) +#define oLT (0x1a) +#define oGTE (0x1b) +#define oGT (0x1c) +#define oLTE (0x1d) + +/* 0x1e -- unassigned */ + +#define oBIT (0x1f) + +/* Load Immediate */ + +#define oLDI (0x20) /* (One 16-bit stack argument) */ +#define oLDIH (0x21) /* (One 16-bit stack argument) */ +#define oLDIB (0x22) /* (One 16-bit stack argument) */ +#define oLDIM (0x23) /* (Two 16-bit stack arguments) */ + +/* Store Immediate */ + +#define oSTI (0x24) /* (One 32-bit and one 16-bit stack arguments) */ +#define oSTIH (0x25) /* (Two 16-bit stack arguments) */ +#define oSTIB (0x26) /* (Two 16-bit stack arguments) */ +#define oSTIM (0x27) /* (Two + n 16-bit stack arguments) */ + +/* Data stack */ + +#define oDUP (0x28) /* (One 32-bit stack argument */ +#define oDUPH (0x29) /* (One 16-bit stack argument) */ + +/* 0x2a - 0x2b -- unassigned */ + +#define oPUSHS (0x2a) /* No arguments */ +#define oPOPS (0x2b) /* (One 16-bit stack argument) */ + +/* 0x2c - 0x2e -- unassigned */ + +/* Program control (No stack arguments) + * Behavior: + * Pop return address + * Pop saved base register (BR) + * Discard saved base address + * Set program counter (PC) to return address + */ + +#define oRET (0x2f) + +/* 0x30 - 0x3e -- unassigned */ + +/* System Functions (No stack arguments) */ + +#define oEND (0x3f) + +/** OPCODES WITH SINGLE BYTE ARGUMENT (arg8) ********************************/ + +/* (o8|0x00)-(o8|0x2f) -- unassigned */ + +/* Floating point operations: arg8 = FP op-code */ + +#define oFLOAT (o8|0x30) + +/* (o8|0x31)-(o8|0x33) -- unassigned */ + +/* Data stack: arg8 = 8 bit unsigned data (no stack arguments) */ + +#define oPUSHB (o8|0x34) + +/* (o8|0x35)-(o8|0x3f) -- unassigned */ + +/** OPCODES WITH SINGLE 16-BIT ARGUMENT (arg16) *****************************/ + +/* (o16|0x00)-(o16|0x0f) -- unassigned */ + +/* Program control: arg16 = unsigned label (One 16-bit stack argument) */ + +#define oJEQUZ (o16|0x10) +#define oJNEQZ (o16|0x11) +#define oJLTZ (o16|0x12) +#define oJGTEZ (o16|0x13) +#define oJGTZ (o16|0x14) +#define oJLTEZ (o16|0x15) + +/* Program control: arg16 = unsigned label (no stack arguments) */ + +#define oJMP (o16|0x16) + +/* (o16|0x17) -- unassigned */ + +/* Program control: arg16 = unsigned label (One 16-bit stack argument) */ + +#define oJEQU (o16|0x18) +#define oJNEQ (o16|0x19) +#define oJLT (o16|0x1a) +#define oJGTE (o16|0x1b) +#define oJGT (o16|0x1c) +#define oJLTE (o16|0x1d) + +/* (o16|0x1e)-(o16|0x1f) -- unassigned */ + +/* Load: arg16 = unsigned base offset */ + +#define oLD (o16|0x20) /* (no stack arguments) */ +#define oLDH (o16|0x21) /* (no stack arguments) */ +#define oLDB (o16|0x22) /* (no stack arguments) */ +#define oLDM (o16|0x23) /* (One 16-bit stack argument) */ + +/* Store: arg16 = unsigned base offset */ + +#define oST (o16|0x24) /* (One 32-bit stack argument) */ +#define oSTH (o16|0x25) /* (One 16-bit stack argument) */ +#define oSTB (o16|0x26) /* (One 16-bit stack argument) */ +#define oSTM (o16|0x27) /* (One+n 16-bit stack arguments) */ + +/* Load Indexed: arg16 = unsigned base offset */ + +#define oLDX (o16|0x28) /* (One 16-bit stack argument) */ +#define oLDXH (o16|0x29) /* (One 16-bit stack argument) */ +#define oLDXB (o16|0x2a) /* (One 16-bit stack argument) */ +#define oLDXM (o16|0x2b) /* (Two 16-bit stack arguments) */ + +/* Store Indexed: arg16 = unsigned base offset */ + +#define oSTX (o16|0x2c) /* (One 32-bit + one 16-bit stack arguments) */ +#define oSTXH (o16|0x2d) /* (Two 16-bit stack arguments) */ +#define oSTXB (o16|0x2e) /* (Two 16-bit stack arguments) */ +#define oSTXM (o16|0x2f) /* (Two+n 16-bit stack arguments) */ + +/* Load address relative to stack base: arg16 = unsigned offset */ + +#define oLA (o16|0x30) + +/* Load absolute stack address: arg16 = RODATA offset (No stack arguments) */ + +#define oLAC (o16|0x31) + +/* (o16|0x32)-(o16|0x33) -- unassigned */ + +/* Data stack: arg16 = 16 bit signed data (no stack arguments) */ + +#define oPUSH (o16|0x34) +#define oINDS (o16|0x35) + +/* (o16|0x34)-(o16|0x37) -- unassigned */ + +/* Load address relative to stack base: arg16 = unsigned offset, TOS=index */ + +#define oLAX (o16|0x38) + +/* System functions: arg16 = 16-bit library call identifier */ + +#define oLIB (o16|0x39) + +/* (o16|0x3a)-(o16|0x3e) -- unassigned */ + +/* Program control: arg16 = unsigned label (no stack arguments) */ + +#define oLABEL (o16|0x3f) + +/** OPCODES WITH 24-BITS OF ARGUMENET (arg8 + arg16) ************************/ + +/* (o16|o8|0x00)-(o8|o16|0x07) -- unassigned */ + +/* Program Control: arg8 = level; arg16 = unsigned label + * (No stack arguments) + * Behavior: + * Push base address of level + * Push base register (BR) value + * Set new base register value (BR) as top of stack + * Push return address + * Set program counter (PC) for address associated with label + */ + +#define oPCAL (o16|o8|0x08) + +/* (o16|o8|0x09)-(o8|o16|0x1f) -- unassigned */ + +/* Load: arg8 = level; arg16 = signed frame offset */ + +#define oLDS (o16|o8|0x20) /* (no stack arguments) */ +#define oLDSH (o16|o8|0x21) /* (no stack arguments) */ +#define oLDSB (o16|o8|0x22) /* (no stack arguments) */ +#define oLDSM (o16|o8|0x23) /* (One 16-bit stack argument) */ + +/* Store: arg8 = level; arg16 = signed frame offset */ + +#define oSTS (o16|o8|0x24) /* (One 32-bit stack argument) */ +#define oSTSH (o16|o8|0x25) /* (One 16-bit stack argument) */ +#define oSTSB (o16|o8|0x26) /* (One 16-bit stack argument) */ +#define oSTSM (o16|o8|0x27) /* (One+n 16-bit stack arguments) */ + +/* Load Indexed: arg8 = level; arg16 = signed frame offset */ + +#define oLDSX (o16|o8|0x28) /* (One 16-bit stack argument) */ +#define oLDSXH (o16|o8|0x29) /* (One 16-bit stack argument) */ +#define oLDSXB (o16|o8|0x2a) /* (One 16-bit stack argument) */ +#define oLDSXM (o16|o8|0x2b) /* (Two 16-bit stack arguments) */ + +/* Store Indexed: arg8 = level; arg16 = signed frame offset */ + +#define oSTSX (o16|o8|0x2c) /* (One 32-bit + one 16-bit stack arguments) */ +#define oSTSXH (o16|o8|0x2d) /* (Two 16-bit stack arguments) */ +#define oSTSXB (o16|o8|0x2e) /* (Two 16-bit stack arguments) */ +#define oSTSXM (o16|o8|0x2f) /* (Two+n 16-bit stack arguments) */ + +/* FOR LAS/LASX arg8 = level; arg16 = signed frame offset + * (no stack arguments) + */ + +#define oLAS (o16|o8|0x30) +#define oLASX (o16|o8|0x38) + +/* System calls: + * For SYSIO: arg8 = file number; arg16 = sub-function code + */ + +#define oSYSIO (o16|o8|0x39) + +/* (o16|o8|0x3a)-(o8|o16|0x3e) -- unassigned */ + +/* Psuedo-operations: + * For LINE: arg8 = file number; arg16 = line number + */ + +#define oLINE (o16|o8|0x3f) + +#endif /* __PINSN16_H */ diff --git a/misc/pascal/insn16/prun/Make.defs b/misc/pascal/insn16/prun/Make.defs new file mode 100644 index 000000000..234e5e139 --- /dev/null +++ b/misc/pascal/insn16/prun/Make.defs @@ -0,0 +1,38 @@ +############################################################################ +# insn16/prun/Make.defs +# NuttX runtime makefile fragment +# +# Copyright (C) 2008 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +INSN_ASRCS = +INSN_CSRCS = pload.c pexec.c diff --git a/misc/pascal/insn16/prun/Makefile b/misc/pascal/insn16/prun/Makefile new file mode 100644 index 000000000..e4a9dd05e --- /dev/null +++ b/misc/pascal/insn16/prun/Makefile @@ -0,0 +1,87 @@ +############################################################################ +# insn16/prun/Makefile +# Host system makefile +# +# Copyright (C) 2008 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ +# +# Directories +# +PRUNDIR = ${shell pwd} +INSNDIR = $(PRUNDIR)/.. +PASCAL = $(PRUNDIR)/../.. + +include $(PASCAL)/Make.config +include $(PASCAL)/Make.defs + +INCDIR = $(PASCAL)/include +LIBDIR = $(PASCAL)/lib +BINDIR = $(PASCAL)/bin16 + +# +# Tools +# +EXTRA_INCLUDES = -I$(INSNDIR)/include +INCLUDES += $(EXTRA_INCLUDES) +CFLAGS += $(EXTRA_INCLUDES) + +# +# Objects and targets +# +RUNSRCS = prun.c pdbg.c pload.c pexec.c +RUNOBJS = $(RUNSRCS:.c=.o) + +OBJS = $(RUNOBJS) + +all: prun +.PHONY: all prun clean + +$(OBJS): %.o: %.c + @$(CC) -c $(CFLAGS) $< -o $@ + +check_libs: + @if [ ! -f $(LIBDIR)/libpoff.a ] ; then \ + echo "$(LIBDIR)/libpoff.a does not exist" ; \ + exit 1 ; \ + fi + @if [ ! -f $(LIBDIR)/libpas.a ] ; then \ + echo "$(LIBDIR)/libpas.a does not exist" ; \ + exit 1 ; \ + fi + +$(BINDIR)/prun: check_libs $(RUNOBJS) + @$(CC) -o $@ $(LDFLAGS) $(RUNOBJS) -lpas -linsn -lm -lpoff + +prun: $(BINDIR)/prun + +clean: + $(RM) prun *.o core *~ diff --git a/misc/pascal/insn16/prun/pdbg.c b/misc/pascal/insn16/prun/pdbg.c new file mode 100644 index 000000000..54ebefa39 --- /dev/null +++ b/misc/pascal/insn16/prun/pdbg.c @@ -0,0 +1,751 @@ +/********************************************************************** + * pdbg.c + * P-Code Debugger + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include +#include + +#include "keywords.h" +#include "pdefs.h" +#include "podefs.h" +#include "pinsn16.h" +#include "pxdefs.h" +#include "pedefs.h" +#include "pmach.h" + +#include "paslib.h" +#include "pinsn.h" +#include "pexec.h" +#include "pdbg.h" + +/********************************************************************** + * Definitions + **********************************************************************/ + +#define TRACE_ARRAY_SIZE 16 +#define MAX_BREAK_POINTS 8 +#define DISPLAY_STACK_SIZE 16 +#define DISPLAY_INST_SIZE 16 + +/********************************************************************** + * Private Type Definitions + **********************************************************************/ + +enum commandEnum +{ + eCMD_NONE = 0, + eCMD_RESET, + eCMD_RUN, + eCMD_STEP, + eCMD_NEXT, + eCMD_GO, + eCMD_BS, + eCMD_BC, + eCMD_DP, + eCMD_DT, + eCMD_DS, + eCMD_DI, + eCMD_DB, + eCMD_HELP, + eCMD_QUIT +}; + +typedef struct +{ + addrType PC; + addrType SP; + uStackType TOS; +} traceType; + +/********************************************************************** + * Private Constant Data + **********************************************************************/ + +/********************************************************************** + * Private Data + **********************************************************************/ + +static enum commandEnum lastCmd = eCMD_NONE; +static uint32 lastValue; + +/********************************************************************** + * Private Function Prototypes + **********************************************************************/ + +static void pdbg_showcommands(void); +static void pdbg_execcommand(struct pexec_s *st, enum commandEnum cmd, uint32 value); +static sint32 pdbg_readdecimal(char *ptr); +static sint32 pdbg_readhex(char *ptr, sint32 defaultValue); +static void pdbg_programstatus(struct pexec_s *st); +static addrType pdbg_printpcode(struct pexec_s *st, addrType PC, sint16 nItems); +static addrType pdbg_printstack(struct pexec_s *st, addrType SP, sint16 nItems); +static void pdbg_printregisters(struct pexec_s *st); +static void pdbg_printtracearray(struct pexec_s *st); +static void pdbg_addbreakpoint(addrType PC); +static void pdbg_deletebreakpoint(sint16 bpNumber); +static void pdbg_printbreakpoints(struct pexec_s *st); +static void pdbg_checkbreakpoint(struct pexec_s *st); +static void pdbg_initdebugger(void); +static void pdbg_debugpcode(struct pexec_s *st); + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/* Debugging variables */ + +static traceType traceArray[TRACE_ARRAY_SIZE]; + /* Holds execution histor */ +static uint16 traceIndex; + /* This is the index into the circular traceArray */ +static uint16 numTracePoints; + /* This is the number of valid enties in traceArray */ +static addrType breakPoint[MAX_BREAK_POINTS]; + /* Contains address associated with all active */ + /* break points. */ +static addrType untilPoint; + /* The 'untilPoint' is a temporary breakpoint */ +static uint16 numBreakPoints; + /* Number of items in breakPoints[] */ +static addrType displayLoc; + /* P-code display location display */ +static boolean stopExecution; + /* TRUE means to stop program execution */ + +/* ? */ +static int K; + +/* I/O variables */ + +static char inLine[LINE_SIZE+1]; + /* Command line buffer */ + +/********************************************************************** + * Public Functions + **********************************************************************/ + +void dbg_run(struct pexec_s *st) +{ + addrType PC; + int i; + + pdbg_showcommands(); + pdbg_initdebugger(); + pdbg_programstatus(st); + + while (TRUE) + { + printf("CMD: "); + (void) fgets(inLine, LINE_SIZE, stdin); + switch (toupper(inLine[0])) + { + case 'R' : + switch (toupper(inLine[1])) { + case 'E' : /* Reset */ + pdbg_execcommand(st, eCMD_RESET, 0); + break; + case 'U' : /* Run */ + pdbg_execcommand(st, eCMD_RUN, 0); + break; + default : + printf("Unrecognized Command\n"); + pdbg_execcommand(st, eCMD_HELP, 0); + break; + } /* end switch */ + break; + case 'S' : /* Single Step (into) */ + pdbg_execcommand(st, eCMD_STEP, 0); + break; + case 'N' : /* Single Step (over) */ + pdbg_execcommand(st, eCMD_NEXT, 0); + break; + case 'G' : /* Go */ + pdbg_execcommand(st, eCMD_GO, 0); + break; + case 'B' : + switch (toupper(inLine[1])) { + case 'S' : /* Set Breakpoint */ + PC = pdbg_readhex(&inLine[2], st->pc); + pdbg_execcommand(st, eCMD_BS, PC); + break; + case 'C' : /* Clear Breakpoint */ + i = pdbg_readdecimal(&inLine[2]); + pdbg_execcommand(st, eCMD_BC, i); + break; + default : + printf("Unrecognized Command\n"); + pdbg_execcommand(st, eCMD_HELP, 0); + break; + } /* end switch */ + break; + case 'D' : + switch (toupper(inLine[1])) { + case 'P' : /* Display Program Status */ + pdbg_execcommand(st, eCMD_DP, 0); + break; + case 'T' : /* Display Program Trace */ + pdbg_execcommand(st, eCMD_DT, 0); + break; + case 'S' : /* Display Stack */ + PC = pdbg_readhex(&inLine[2], st->sp); + pdbg_execcommand(st, eCMD_DS, PC); + break; + case 'I' : /* Display Instructions */ + PC = pdbg_readhex(&inLine[2], st->pc); + pdbg_execcommand(st, eCMD_DI, PC); + break; + case 'B' : /* Display Breakpoints */ + pdbg_execcommand(st, eCMD_DB, PC); + break; + default : + printf("Unrecognized Command\n"); + pdbg_execcommand(st, eCMD_HELP, 0); + break; + } /* end switch */ + break; + case 'Q' : /* Quit */ + pdbg_execcommand(st, eCMD_QUIT, PC); + break; + case 'H' : /* Help */ + case '?' : + pdbg_execcommand(st, eCMD_HELP, 0); + break; + case '\0' : /* Repeat last command */ + case '\n' : /* Repeat last command */ + pdbg_execcommand(st, lastCmd, lastValue); + break; + default : + printf("Unrecognized Command\n"); + pdbg_execcommand(st, eCMD_HELP, 0); + break; + } /* end switch */ + } /* end while */ + +} /* end pdbg_debugpcodeProgram */ + +/********************************************************************** + * Private Functions + **********************************************************************/ +/* Show command characters */ + +static void pdbg_showcommands(void) +{ + printf("Commands:\n"); + printf(" RE[set] - Reset\n"); + printf(" RU[n] - Run\n"); + printf(" S[tep] - Single Step (Into)\n"); + printf(" N[ext] - Single Step (Over)\n"); + printf(" G[o] - Go\n"); + printf(" BS xxxx - Set Breakpoint\n"); + printf(" BC n - Clear Breakpoint\n"); + printf(" DP - Display Program Status\n"); + printf(" DT - Display Program Trace\n"); + printf(" DS [xxxx] - Display Stack\n"); + printf(" DI [xxxx] - Display Instructions\n"); + printf(" DB - Display Breakpoints\n"); + printf(" H or ? - Shows this list\n"); + printf(" Q[uit] - Quit\n"); + +} /* end pdbg_showcommands */ + +/***********************************************************************/ +static void pdbg_execcommand(struct pexec_s *st, enum commandEnum cmd, uint32 value) +{ + /* Save the command to resuse if the user enters nothing */ + + lastCmd = cmd; + lastValue = value; + + switch (cmd) + { + case eCMD_NONE: /* Do nothing */ + break; + case eCMD_RESET: /* Reset */ + pexec_reset(st); + pdbg_initdebugger(); + pdbg_programstatus(st); + lastCmd = eCMD_NONE; + break; + case eCMD_RUN: /* Run */ + pexec_reset(st); + pdbg_initdebugger(); + pdbg_debugpcode(st); + pdbg_programstatus(st); + break; + case eCMD_STEP: /* Single Step (into)*/ + stopExecution = TRUE; + pdbg_debugpcode(st); + pdbg_programstatus(st); + break; + case eCMD_NEXT: /* Single Step (over) */ + if (st->ispace[st->pc] == oPCAL) + { + stopExecution = FALSE; + untilPoint = st->pc + 4; + } + else + { + stopExecution = TRUE; + } + pdbg_debugpcode(st); + untilPoint = 0; + pdbg_programstatus(st); + break; + case eCMD_GO: /* Go */ + stopExecution = FALSE; + pdbg_debugpcode(st); + pdbg_programstatus(st); + break; + case eCMD_BS: /* Set Breakpoint */ + if (numBreakPoints >= MAX_BREAK_POINTS) + { + printf("Too many breakpoints\n"); + lastCmd = eCMD_NONE; + } + else if (value >= st->maxpc) + { + printf("Invalid address for breakpoint\n"); + lastCmd = eCMD_NONE; + } + else + { + pdbg_addbreakpoint(value); + pdbg_printbreakpoints(st); + } /* end else */ + break; + case eCMD_BC: /* Clear Breakpoint */ + if ((value >= 1) && (value <= numBreakPoints)) + { + pdbg_deletebreakpoint(value); + } + else + { + printf("Invalid breakpoint number\n"); + lastCmd = eCMD_NONE; + } + pdbg_printbreakpoints(st); + break; + case eCMD_DP: /* Display Program Status */ + pdbg_programstatus(st); + break; + case eCMD_DT: /* Display Program Trace */ + pdbg_printtracearray(st); + break; + case eCMD_DS: /* Display Stack */ + if (value > st->sp) + { + printf("Invalid stack address\n"); + lastCmd = eCMD_NONE; + } + else + { + lastValue = pdbg_printstack(st, value, DISPLAY_STACK_SIZE); + } /* end else */ + break; + case eCMD_DI: /* Display Instructions */ + if (value >= st->maxpc) + { + printf("Invalid instruction address\n"); + lastCmd = eCMD_NONE; + } + else + { + lastValue = pdbg_printpcode(st, value, DISPLAY_INST_SIZE); + } /* end else */ + break; + case eCMD_DB: /* Display Breakpoints */ + pdbg_printbreakpoints(st); + break; + case eCMD_QUIT: /* Quit */ + printf("Goodbye\n"); + exit(0); + break; + case eCMD_HELP: /* Help */ + default: /* Internal error */ + pdbg_showcommands(); + lastCmd = eCMD_NONE; + break; + } /* end switch */ + +} /* end pdbg_execcommand */ + +/***********************************************************************/ +/* Read a decimal value from the input string */ + +static sint32 pdbg_readdecimal(char *ptr) +{ + sint32 decimal = 0; + + while (!isspace(*ptr)) ptr++; + while (isspace(*ptr)) ptr++; + for (; ((*ptr >= '0') && (*ptr <= '9')); ptr++) + decimal = 10*decimal + (sint32)*ptr - (sint32)'0'; + + return decimal; + +} /* end pdbg_readdecimal */ +/***********************************************************************/ +/* Read a hexadecimal value from the input string */ + +static sint32 pdbg_readhex(char *ptr, sint32 defaultValue) +{ + char c; + sint32 hex = 0; + boolean found = FALSE; + + while (!isspace(*ptr)) ptr++; + while (isspace(*ptr)) ptr++; + while (TRUE) { + + c = toupper(*ptr); + if ((c >= '0') && (c <= '9')) { + hex = ((hex << 4) | ((sint32)c - (sint32)'0')); + found = TRUE; + } /* end if */ + else if ((c >= 'A') && (c <= 'F')) { + hex = ((hex << 4) | ((sint32)c - (sint32)'A' + 10)); + found = TRUE; + } /* end else if */ + else { + if (found) + return hex; + else + return defaultValue; + } /* end else */ + ptr++; + + } /* end while */ + +} /* end pdbg_readhex */ + +/***********************************************************************/ +/* Print the disassembled P-Code at PC */ + +static void pdbg_programstatus(struct pexec_s *st) +{ + (void)pdbg_printpcode(st, st->pc, 1); + (void)pdbg_printstack(st, st->sp, 2); + pdbg_printregisters(st); + +} /* end pdbg_programstatus */ + +/***********************************************************************/ +/* Print the disassembled P-Code at PC */ + +static addrType pdbg_printpcode(struct pexec_s *st, addrType PC, sint16 nItems) +{ + OPTYPE op; + addrType pCodeSize; + ubyte *address; + + for (; ((PC < st->maxpc) && (nItems > 0)); nItems--) + { + address = &st->ispace[PC]; + + op.op = *address++; + op.arg1 = 0; + op.arg2 = 0; + pCodeSize = 1; + printf("PC:%04x %02x", PC, op.op); + + if ((op.op & o8) != 0) + { + op.arg1 = *address++; + printf("%02x", op.arg1); + pCodeSize++; + } /* end if */ + else + printf(".."); + + if ((op.op & o16) != 0) + { + op.arg2 = ((*address++) << 8); + op.arg2 |= *address++; + printf("%04x", op.arg2); + pCodeSize += 2; + } /* end if */ + else + printf("...."); + + /* The disassemble it to stdout */ + + printf(" "); + insn_DisassemblePCode(stdout, &op); + + /* Get the address of the next P-Code */ + + PC += pCodeSize; + + } /* end for */ + + return PC; + +} /* end pdbg_printpcode */ + +/***********************************************************************/ +/* Print the stack value at SP */ + +static addrType pdbg_printstack(struct pexec_s *st, addrType SP, sint16 nItems) +{ + sint32 iSP; + + if ((st->sp < st->stacksize) && (SP <= st->sp)) + { + iSP = BTOISTACK(SP); + printf("SP:%04x %04x\n", SP, st->dstack.i[iSP]); + + for (iSP--, SP -= BPERI, nItems--; + ((iSP >= 0) && (nItems > 0)); + iSP--, SP -= BPERI, nItems--) + printf(" %04x %04x\n", SP, st->dstack.i[iSP] & 0xffff); + } /* end if */ + else + { + printf("SP:%04x BAD\n", SP); + } /* end else */ + + return SP; +} /* end pdbg_printstack */ + +/***********************************************************************/ +/* Print the base register */ + +static void pdbg_printregisters(struct pexec_s *st) +{ + if (st->fp <= st->sp) + printf("FP:%04x ", st->fp); + + printf("CSP:%04x\n", st->csp); + +} /* end pdbg_printregisters */ + +/***********************************************************************/ +/* Print the traceArray */ + +static void pdbg_printtracearray(struct pexec_s *st) +{ + int nPrinted; + int index; + + index = traceIndex + TRACE_ARRAY_SIZE - numTracePoints; + if (index >= TRACE_ARRAY_SIZE) + index -= TRACE_ARRAY_SIZE; + + for (nPrinted = 0; nPrinted < numTracePoints; nPrinted++) { + + printf("SP:%04x %04x ", + traceArray[ index ].SP, traceArray[ index ].TOS); + + /* Print the instruction executed at this traced address */ + (void)pdbg_printpcode(st, traceArray[ index ].PC, 1); + + /* Index to the next trace entry */ + if (++index >= TRACE_ARRAY_SIZE) + index = 0; + + } /* end for */ + +} /* end pdbg_printtracearray */ + +/***********************************************************************/ +/* Add a breakpoint to the breakpoint array */ + +static void pdbg_addbreakpoint(addrType PC) +{ + int i; + + /* Is there room for another breakpoint? */ + + if (numBreakPoints < MAX_BREAK_POINTS) + { + /* Yes..Check if the breakpoint already exists */ + + for (i = 0; i < numBreakPoints; i++) + { + if (breakPoint[i] == PC) + { + /* It is already set. Return without doing anything */ + + return; + } + } + + /* The breakpoint is not already set -- set it */ + + breakPoint[numBreakPoints++] = PC; + } /* end if */ + +} /* end pdbg_addbreakpoint */ + +/***********************************************************************/ +/* Remove a breakpoint from the breakpoint array */ + +static void pdbg_deletebreakpoint(sint16 bpNumber) +{ + if ((bpNumber >= 1) && (bpNumber <= numBreakPoints)) { + + for (; (bpNumber < numBreakPoints); bpNumber++) + breakPoint[bpNumber-1] = breakPoint[bpNumber]; + + numBreakPoints--; + + } /* end if */ + +} /* end pdbg_deletebreakpoint */ + +/***********************************************************************/ +/* Print the breakpoint array */ + +static void pdbg_printbreakpoints(struct pexec_s *st) +{ + int i; + printf("BP:# Address P-Code\n"); + for (i = 0; i < numBreakPoints; i++) + { + printf("BP:%d ", (i+1)); + (void)pdbg_printpcode(st, breakPoint[i], 1); + } /* end for */ + +} /* end pdbg_printbreakpoints */ + +/***********************************************************************/ +/* Check if a breakpoint is set at the current value of program counter. + * If so, print the instruction and stop execution. */ + +static void pdbg_checkbreakpoint(struct pexec_s *st) +{ + uint16 bpIndex; + + /* Check for a user breakpoint */ + + for (bpIndex = 0; + ((bpIndex < numBreakPoints) && (!stopExecution)); + bpIndex++) + { + if (breakPoint[bpIndex] == st->pc) + { + printf("Breakpoint #%d -- Execution Stopped\n", (bpIndex+1)); + stopExecution = TRUE; + return; + } /* end if */ + } /* end for */ + +} /* end pdbg_checkbreakpoint */ + +/***********************************************************************/ +/* Initialize Debugger variables */ + +static void pdbg_initdebugger(void) +{ + stopExecution = FALSE; + displayLoc = 0; + K = 0; + traceIndex = 0; + numTracePoints = 0; +} + +/***********************************************************************/ +/* This function executes the P-Code program until a stopping condition + * is encountered. */ + +static void pdbg_debugpcode(struct pexec_s *st) +{ + uint16 errno; + + do { + /* Trace the next instruction execution */ + + traceArray[traceIndex].PC = st->pc; + traceArray[traceIndex].SP = st->sp; + if (st->sp < st->stacksize) + traceArray[traceIndex].TOS = st->dstack.i[BTOISTACK(st->sp)]; + else + traceArray[traceIndex].TOS = 0; + + if (++traceIndex >= TRACE_ARRAY_SIZE) + traceIndex = 0; + if (numTracePoints < TRACE_ARRAY_SIZE) + numTracePoints++; + + /* Execute the instruction */ + + errno = pexec(st); + + /* Check for exceptional stopping conditions */ + + if (errno != eNOERROR) + { + if (errno == eEXIT) + printf("Normal Termination\n"); + else + printf("Runtime error 0x%02x -- Execution Stopped\n", errno); + stopExecution = TRUE; + } /* end if */ + + /* Check for normal stopping conditions */ + + if (!stopExecution) + { + /* Check for attempt to execute code outside of legal range */ + + if (st->pc >= st->maxpc) + stopExecution = TRUE; + + /* Check for a temporary breakpoint */ + + else if ((untilPoint > 0) && (untilPoint == st->pc)) + stopExecution = TRUE; + + /* Check if there is a breakpoint at the next instruction */ + + else if (numBreakPoints > 0) + pdbg_checkbreakpoint(st); + } + + } while (!stopExecution); + +} /* end pdbg_debugpcode */ + +/***********************************************************************/ diff --git a/misc/pascal/insn16/prun/pexec.c b/misc/pascal/insn16/prun/pexec.c new file mode 100644 index 000000000..d2caca850 --- /dev/null +++ b/misc/pascal/insn16/prun/pexec.c @@ -0,0 +1,2239 @@ +/**************************************************************************** + * pexec.c + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include +#include +#include + +#include "keywords.h" +#include "pdefs.h" +#include "pinsn16.h" +#include "pfdefs.h" +#include "pxdefs.h" +#include "pedefs.h" +#include "pmach.h" + +#include "paslib.h" +#include "pexec.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#define PTRUE ((uStackType)-1) +#define PFALSE ((uStackType) 0) + +/**************************************************************************** + * Macros + ****************************************************************************/ + +/* Remove the value from the top of the stack */ + +#define POP(st, dest) \ + do { \ + dest = (st)->dstack.i[BTOISTACK((st)->sp)]; \ + (st)->sp -= BPERI; \ + } while (0) + +/* Add the value to top of the stack */ + +#define PUSH(st, src) \ + do { \ + (st)->sp += BPERI; \ + (st)->dstack.i[BTOISTACK((st)->sp)] = src; \ + } while (0) + +/* Return an rvalue for the (word) offset from the top of the stack */ + +#define TOS(st, off) \ + (st)->dstack.i[BTOISTACK((st)->sp)-(off)] + +/* Save the src (word) at the dest (word) stack position */ + +#define PUTSTACK(st, src, dest) \ + do { \ + (st)->dstack.i[BTOISTACK(dest)] = src; \ + } while (0) + +/* Return an rvalue for the (word) from the absolute stack position */ + +#define GETSTACK(st, src) \ + (st)->dstack.i[BTOISTACK(src)] + +/* Store a byte to an absolute (byte) stack position */ + +#define PUTBSTACK(st, src,dest) \ + do { \ + (st)->dstack.b[dest] = dest; \ + } while (0) + +/* Return an rvalue for the absolute (byte) stack position */ + +#define GETBSTACK(st, src) \ + (st)->dstack.b[src] + +/* Return the address for an absolute (byte) stack position. */ + +#define ATSTACK(st, src) \ + &(st)->dstack.b[src] + +/* Discard n words from the top of the stack */ + +#define DISCARD(st, n) \ + do { \ + (st)->sp -= BPERI*(n); \ + } while (0) + +/* Release a C string */ + +#define free_cstring(a) \ + free(a) + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +union fparg_u +{ + float64 f; + uint16 hw[4]; +}; + +typedef union fparg_u fparg_t; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static uint16 pexec_sysio(struct pexec_s *st, ubyte fileNumber, uint16 subFunction); +static uint16 pexec_libcall(struct pexec_s *st, ubyte fileNumber, uint16 subFunction); +static uint16 pexec_execfp(struct pexec_s *st, ubyte fpOpCode); +static void pexec_getfparguments(struct pexec_s *st, ubyte fpOpCode, fparg_t *arg1, fparg_t *arg2); +static uStackType pexec_readinteger(ubyte *ioPtr); +static void pexec_readreal(uint16 *dest, ubyte *ioPtr); +static uStackType pexec_getbaseaddress(struct pexec_s *st, levelType levelOffset); +static ubyte *pexec_mkcstring(ubyte *buffer, int buflen); + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +static const ubyte nullString[] = ""; + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +static ubyte ioline[LINE_SIZE+1]; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* This function process a system I/O operation */ + +static uint16 pexec_sysio(struct pexec_s *st, ubyte fileNumber, uint16 subFunction) +{ + uStackType uParm1; + fparg_t fp; + + ubyte *ptr; + + switch (subFunction) + { + case xEOF : +/* FINISH ME -- > */ + break; + case xEOLN : +/* FINISH ME -- > */ + break; + case xRESET : +/* FINISH ME -- > */ + break; + case xREWRITE : +/* FINISH ME -- > */ + break; + + case xREADLN : +/* FINISH ME -- > */ + break; + case xREAD_BINARY : +/* FINISH ME -- > */ + break; + + /* xREAD_INT: + * STACK INPUTS: TOS(st, 0) = address to store integer */ + case xREAD_INT : + (void)fgets((char*)ioline, LINE_SIZE, stdin); + PUTSTACK(st, pexec_readinteger(ioline),TOS(st, 0)); + break; + + /* xREAD_CHAR: + * STACK INPUTS: TOS(st, 0) = address to store integer */ + + case xREAD_CHAR: + (void)fgets((char*)ioline, LINE_SIZE, stdin); + PUTBSTACK(st, ioline[0],TOS(st, 0)); + break; + + /* XREAD_STRING: + + * STACK INPUTS: + * TOS = Number of bytes to read + * TOS-1 = Address to store byte(s) */ + case xREAD_STRING : + (void)fgets((char*)ATSTACK(st, TOS(st, 1)), TOS(st, 0), stdin); + break; + + /* xREAD_REAL: + * STACK INPUTS: TOS = address to store REAL */ + + case xREAD_REAL : + (void)fgets((char*)ioline, LINE_SIZE, stdin); + pexec_readreal((uint16*)ATSTACK(st, TOS(st, 0)), ioline); + break; + + case xWRITELN : + putchar('\n'); + break; + case xWRITE_PAGE : + putchar('\f'); + break; + case xWRITE_BINARY : +/* FINISH ME -- > */ + break; + + /* xWRITE_INT: + * STACK INPUTS: TOS = integer value to write. */ + + case xWRITE_INT : + printf("%ld", signExtend16(TOS(st, 0))); + break; + + /* xWRITE_CHAR: + * STACK INPUTS: TOS = char value to write. */ + + case xWRITE_CHAR : + putchar(TOS(st, 0)); + break; + + /* xWRITE_STRING: + * STACK INPUTS: + * TOS = Number of bytes to write + * TOS-1 = Address of src data */ + + case xWRITE_STRING : + uParm1 = TOS(st, 0); + for (ptr = (ubyte*)ATSTACK(st, TOS(st, 1)); uParm1; uParm1--, ptr++) + putchar(*ptr); + break; + + /* xWRITE_REAL: + * STACK INPUTS: TOS = value of float64 */ + + case xWRITE_REAL : + fp.hw[0] = TOS(st, 3); + fp.hw[1] = TOS(st, 2); + fp.hw[2] = TOS(st, 1); + fp.hw[3] = TOS(st, 0);; + printf("%f", fp.f); + break; + + default : + return eBADSYSIOFUNC; + + } /* end switch */ + + return eNOERROR; + +} /* end pexec_sysio */ + +/* This function process a system I/O operation */ + +static uint16 pexec_libcall(struct pexec_s *st, ubyte fileNumber, uint16 subFunction) +{ + uStackType uParm1; + uStackType uParm2; + addrType addr1; + addrType addr2; + uint16 *tmp; + uint16 *ref; + ubyte *src; + ubyte *dest; + ubyte *name; + int len; + int value; + + switch (subFunction) + { + /* Get the value of an environment string + * + * ON INPUT: + * TOS(st, 0) = Number of bytes in environment identifier string + * TOS(st, 1) = Address environment identifier string + * ON RETURN (above replaced with): + * TOS(st, 0) = MS 16-bits of 32-bit C string pointer + * TOS(st, 1) = LS 16-bits of 32-bit C string pointer + */ + + case lbGETENV : + len = TOS(st, 0); /* Number of bytes in string */ + src = (ubyte*)&GETSTACK(st, TOS(st, 1)); /* Pointer to string */ + + /* Make a C string out of the pascal string */ + + name = pexec_mkcstring(src, len); + if (name == NULL) + { + return eNOMEMORY; + } + + /* Make the C-library call and free the string copy */ + + src = (ubyte*)getenv((char*)name); + free_cstring(name); + + /* Save the returned pointer in the stack */ + + TOS(st, 0) = (uStackType)((uint32)src >> 16); + TOS(st, 1) = (uStackType)((uint32)src & 0x0000ffff); + break; + + /* Copy pascal string to a pascal string + * + * ON INPUT: + * TOS(st, 0) = address of dest string hdr + * TOS(st, 1) = length of source string + * TOS(st, 2) = pointer to source string + * ON RETURN (input consumed): + */ + + case lbSTR2STR : + /* "Pop" in the input parameters from the stack */ + + POP(st, addr1); /* addr of dest string header */ + POP(st, uParm1); /* length of source data */ + POP(st, addr2); /* addr of source string data */ + + /* Do nothing if the source and destinations are the same + * string. This happens normally on cases like: + * string name; + * char c; + * name := name + c; + */ + + if (addr1 != addr2) + { + /* The source and destination strings are different. + * Make sure that the string length will fit into the destination. + */ + + if (uParm1 >= sSTRING_MAX_SIZE) + { + /* Clip to the maximum size */ + + uParm1 = sSTRING_MAX_SIZE; + len = sSTRING_MAX_SIZE; + } + else + { + /* We have space */ + + len = (int)uParm1; + } + + /* Get proper string pointers */ + + dest = ATSTACK(st, addr1); + src = ATSTACK(st, addr2); + + /* Transfer the (16-bit) string length (must be aligned!) */ + + tmp = (uint16*)dest; + *tmp++ = uParm1; + dest = (ubyte*)tmp; + + /* Then transfer the string contents */ + + memcpy(dest, src, len); + } + break; + + /* Copy C string to a pascal string + * + * ON INPUT: + * TOS(st, 0) = address of dest hdr + * TOS(st, 1) = MS 16-bits of 32-bit C string pointer + * TOS(st, 2) = LS 16-bits of 32-bit C string pointer + * ON RETURN (input consumed): + */ + case lbCSTR2STR : + /* "Pop" in the input parameters from the stack */ + + POP(st, addr1); /* addr of dest string header */ + POP(st, uParm1); /* MS 16-bits of 32-bit C string pointer */ + POP(st, uParm2); /* LS 16-bits of 32-bit C string pointer */ + + /* Get proper string pointers */ + + dest = ATSTACK(st, addr1); + src = (ubyte*)((unsigned long)uParm1 << 16 | (unsigned long)uParm2); + + /* Handle null src pointer */ + + if (src == NULL) + { + *dest = 0; + } + else + { + /* Get the length of the string */ + + uParm1 = strlen((char*)src); + + /* Make sure that the string length will fit into the + * destination. */ + + if (uParm1 >= sSTRING_MAX_SIZE) + { + /* Clip to the maximum size */ + + uParm1 = sSTRING_MAX_SIZE; + len = sSTRING_MAX_SIZE; + } + else + { + /* We have space */ + + len = (int)uParm1; + } + + /* Transfer the (16-bit) string length (must be aligned!) */ + + tmp = (uint16*)dest; + *tmp++ = uParm1; + dest = (ubyte*)tmp; + + /* Then transfer the string contents */ + + memcpy(dest, src, len); + } + break; + + /* Copy pascal string to a pascal string reference + * procedure str2rstr(src : string; var dest : rstring) + * ON INPUT: + * TOS(st, 0)=address of dest string reference + * TOS(st, 1)=length of source string + * TOS(st, 2)=pointer to source string + * ON RETURN: actual parameters released. + */ + + case lbSTR2RSTR : + /* "Pop" in the input parameters from the stack */ + + POP(st, addr1); /* addr of dest string reference */ + POP(st, uParm1); /* length of source data */ + POP(st, addr2); /* addr of source string data */ + + /* Make sure that the string length will fit into the destination. */ + + if (uParm1 >= sSTRING_MAX_SIZE) + { + return eSTRSTKOVERFLOW; + } + + /* Get a pointer to the destination reference */ + + ref = (uint16*)ATSTACK(st, addr1); + + /* Get proper string pointers */ + + dest = ATSTACK(st, ref[0] - 2); + src = ATSTACK(st, addr2); + + /* Transfer the (16-bit) string length (must be aligned!) */ + + tmp = (uint16*)dest; + *tmp++ = uParm1; + dest = (ubyte*)tmp; + + /* Then transfer the string contents and save the new size */ + + memcpy(dest, src, uParm1); + ref[1] = uParm1; + break; + + /* Copy C string to a pascal string reference + * procedure cstr2str(src : cstring; var dest : string) + * ON INPUT: + * TOS(st, 0)=address of dest string reference + * TOS(st, 0)=MS 16-bits of 32-bit C source string pointer + * TOS(st, 1)=LS 16-bits of 32-bit C source string pointer + * ON RETURN: actual parameters released + */ + + case lbCSTR2RSTR : + /* "Pop" in the input parameters from the stack */ + + POP(st, addr1); /* addr of dest string reference */ + POP(st, uParm1); /* MS 16-bits of 32-bit C string pointer */ + POP(st, uParm2); /* LS 16-bits of 32-bit C string pointer */ + + /* Get a pointer to the destination reference */ + + ref = (uint16*)ATSTACK(st, addr1); + + /* Get proper string pointers */ + + dest = ATSTACK(st, ref[0] - 2); + src = (ubyte*)((unsigned long)uParm1 << 16 | (unsigned long)uParm2); + + /* Handle null src pointer */ + + if (src == NULL) + { + *dest = 0; + } + else + { + /* Get the length of the string */ + + uParm1 = strlen((char*)src); + + /* Make sure that the string length will fit into the + * destination. */ + + if (uParm1 >= sSTRING_MAX_SIZE) + { + return eSTRSTKOVERFLOW; + } + + /* Transfer the (16-bit) string length (must be aligned!) */ + + tmp = (uint16*)dest; + *tmp++ = uParm1; + dest = (ubyte*)tmp; + + /* Then transfer the string contents */ + + memcpy(dest, src, len); + ref[1] = uParm1; + } + break; + + /* Convert a string to a numeric value + * procedure val(const s : string; var v; var code : word); + * + * Description: + * val() converts the value represented in the string S to a numerical + * value, and stores this value in the variable V, which can be of type + * Longint, Real and Byte. If the conversion isn't succesfull, then the + * parameter Code contains the index of the character in S which + * prevented the conversion. The string S is allowed to contain spaces + * in the beginning. + * + * The string S can contain a number in decimal, hexadecimal, binary or + * octal format, as described in the language reference. + * + * Errors: + * If the conversion doesn¡Çt succeed, the value of Code indicates the + * position where the conversion went wrong. + * + * ON INPUT + * TOS(st, 0)=address of code + * TOS(st, 1)=address of value + * TOS(st, 2)=length of source string + * TOS(st, 3)=pointer to source string + * ON RETURN: actual parameters released + */ + + case lbVAL : + /* Get the string information */ + + len = TOS(st, 2); /* Number of bytes in string */ + src = (ubyte*)&GETSTACK(st, TOS(st, 3)); /* Pointer to string */ + + /* Make a C string out of the pascal string */ + + name = pexec_mkcstring(src, len); + if (name == NULL) + { + return eNOMEMORY; + } + + /* Convert the string to an integer */ + + value = atoi((char*)name); + if ((value < MININT) || (value > MAXINT)) + { + return eINTEGEROVERFLOW; + } + PUTSTACK(st, TOS(st, 0), 0); + PUTSTACK(st, TOS(st, 1), value); + DISCARD(st, 4); + break; + + /* Create an empty string + * function mkstk : string; + * ON INPUT + * ON RETURN + * TOS(st, 0)=length of new string + * TOS(st, 1)=pointer to new string + */ + + case lbMKSTK : + /* Allocate space on the string stack for the new string + * FIXME: This logic does not handle strings with other than the + * default size! + */ + + addr1 = ((st->csp + 1) & ~1); + st->csp += sSTRING_SIZE; /* Allocate max size */ + + /* Save the length at the beginning of the copy */ + + tmp = (uint16*)&GETSTACK(st, addr1); /* Pointer to new string */ + *tmp++ = 0; /* Save current size */ + + /* Update the stack content */ + + PUSH(st, addr1 + sSTRING_HDR_SIZE); /* Pointer to new string */ + PUSH(st, 0); /* Current size */ + break; + + /* Replace a string with a duplicate string residing in allocated + * string stack. + * function mkstkstr(name : string) : string; + * ON INPUT + * TOS(st, 0)=length of original string + * TOS(st, 1)=pointer to original string data + * ON RETURN + * TOS(st, 0)=length of new string (unchanged) + * TOS(st, 1)=pointer to new string data + */ + + case lbMKSTKSTR : + /* Get the parameters from the stack (leaving the string reference + * in place. + */ + + uParm1 = TOS(st, 0); /* Original string size */ + addr1 = TOS(st, 1); /* Original string data pointer */ + + /* Check if there is space on the string stack for the new string + * FIXME: This logic does not handle strings with other than the + * default size! + */ + + if (st->csp + sSTRING_SIZE >= st->spb) + { + return eSTRSTKOVERFLOW; + } + + /* Allocate space on the string stack for the new string */ + + addr2 = ((st->csp + 1) & ~1); + st->csp += sSTRING_SIZE; /* Allocate max size */ + + /* Save the length at the beginning of the copy */ + + tmp = (uint16*)&GETSTACK(st, addr2); /* Pointer to new string */ + *tmp++ = uParm1; /* Save current size */ + dest = (ubyte*)tmp; /* Pointer to string data */ + + /* Copy the string into the string stack */ + + src = (ubyte*)&GETSTACK(st, addr1); /* Pointer to original string */ + memcpy(dest, src, uParm1); + + /* Update the stack content */ + + TOS(st, 1) = addr2 + sSTRING_HDR_SIZE; + break; + + /* Replace a character with a string residing in allocated string stack. + * function mkstkc(c : char) : string; + * ON INPUT + * TOS(st, 0)=Character value + * ON RETURN + * TOS(st, 0)=length of new string + * TOS(st, 1)=pointer to new string + */ + + case lbMKSTKC : + /* Check if there is space on the string stack for the new string + * FIXME: This logic does not handle strings with other than the + * default size! + */ + + if (st->csp + sSTRING_SIZE >= st->spb) + { + return eSTRSTKOVERFLOW; + } + + /* Allocate space on the string stack for the new string */ + + addr2 = ((st->csp + 1) & ~1); + st->csp += sSTRING_SIZE; /* Allocate max size */ + + /* Save the length at the beginning of the copy */ + + tmp = (uint16*)&GETSTACK(st, addr2); /* Pointer to new string */ + *tmp++ = 1; /* Save initial size */ + dest = (ubyte*)tmp; /* Pointer to string data */ + + /* Copy the character into the string stack */ + + *dest++ = TOS(st, 0); /* Save character as string */ + + /* Update the stack content */ + + TOS(st, 0) = addr2 + sSTRING_HDR_SIZE; /* String address */ + PUSH(st, 1); /* String length */ + break; + + /* Concatenate a string to the end of a string. + * function strcat(name : string, c : char) : string; + * + * ON INPUT + * TOS(st, 0)=length of string1 + * TOS(st, 1)=pointer to string1 data + * TOS(st, 2)=length of string2 + * TOS(st, 3)=pointer to string2 data + * ON OUTPUT + * TOS(st, 1)=new length of string2 + * TOS(st, 2)=pointer to string2 + */ + + case lbSTRCAT : + /* Get the parameters from the stack (leaving the string reference + * in place. + */ + + POP(st, uParm1); /* string1 size */ + POP(st, addr1); /* string1 data stack addr */ + uParm2 = TOS(st, 0); /* string2 size */ + + /* Check for string overflow. FIXME: This logic does not handle + * strings with other than the default size! + */ + + if (uParm1 + uParm2 > sSTRING_MAX_SIZE) + return eSTRSTKOVERFLOW; + else + { + /* Get a pointer to string1 data */ + + src = ATSTACK(st, addr1); + + /* Get a pointer to string2 header, set new size then, get + * a pointer to string2 data. + */ + + tmp = ((uint16*)&GETSTACK(st, TOS(st, 1))) - 1; + *tmp++ = uParm1 + uParm2; + dest = (ubyte*)tmp; + + memcpy(&dest[uParm2], src, uParm1); /* cat strings */ + TOS(st, 0) = uParm1 + uParm2; /* Save new size */ + } + break; + + /* Concatenate a character to the end of a string. + * function strcatc(name : string, c : char) : string; + * + * ON INPUT + * TOS(st, 0)=character to concatenate + * TOS(st, 1)=length of string + * TOS(st, 2)=pointer to string + * ON OUTPUT + * TOS(st, 1)=new length of string + * TOS(st, 2)=pointer to string + */ + + case lbSTRCATC : + /* Get the parameters from the stack (leaving the string reference + * in place. + */ + + POP(st, uParm1); /* Character to concatenate */ + uParm2 = TOS(st, 0); /* Current length of string */ + + /* Check for string overflow. FIXME: This logic does not handle + * strings with other than the default size! + */ + + if (uParm2 >= sSTRING_MAX_SIZE) + return eSTRSTKOVERFLOW; + else + { + /* Get a pointer to string header, set size new size then, get + * a pointer to string data. + */ + + tmp = ((uint16*)&GETSTACK(st, TOS(st, 1))) - 1; + *tmp++ = uParm2 + 1; + dest = (ubyte*)tmp; + + /* Add the new charcter */ + + dest[uParm2] = (ubyte)uParm1; + + /* Save the new string size */ + + TOS(st, 0) = uParm2 + 1; + } + break; + + /* Compare two pascal strings + * function strcmp(name1 : string, name2 : string) : integer; + * ON INPUT + * TOS(st, 1)=length of string2 + * TOS(st, 2)=address of string2 data + * TOS(st, 3)=length of string1 + * TOS(st, 4)=address of string1 data + * ON OUTPUT + * TOS(st, 0)=(-1=less than, 0=equal, 1=greater than} + */ + + case lbSTRCMP : + { + int result; + + /* Get the parameters from the stack (leaving space for the + * return value); + */ + + POP(st, uParm2); /* length of string2 */ + POP(st, addr2); /* address of string2 data */ + POP(st, uParm1); /* length of string1 */ + addr1 = TOS(st, 0); /* address of string1 data */ + + /* Get full address */ + + dest = ATSTACK(st, addr1); + src = ATSTACK(st, addr2); + + /* If name1 is shorter than name2, then we can only return + * -1 (less than) or +1 greater than. If the substrings + * of length of name1 are equal, then we return less than. + */ + + if (uParm1 < uParm2) + { + result = memcmp(dest, src, uParm1); + if (result == 0) result = -1; + } + + /* If name1 is longer than name2, then we can only return + * -1 (less than) or +1 greater than. If the substrings + * of length of name2 are equal, then we return greater than. + */ + + else if (uParm1 > uParm2) + { + result = memcmp(dest, src, uParm2); + if (result == 0) result = 1; + } + + /* The strings are of equal length. Return the result of + * the comparison. + */ + + else + { + result = memcmp(dest, src, uParm1); + } + TOS(st, 0) = result; + } + break; + + default : + return eBADSYSLIBCALL; + + } /* end switch */ + + return eNOERROR; + +} /* end pexec_libcall */ + +/* This function process a system I/O operation */ + +static uint16 pexec_execfp(struct pexec_s *st, ubyte fpOpCode) +{ + sint16 intValue; + fparg_t arg1; + fparg_t arg2; + fparg_t result; + + switch (fpOpCode & fpMASK) + { + /* Floating Pointer Conversions (On stack argument: FP or Integer) */ + + case fpFLOAT : + POP(st, intValue); + result.f = (float64)intValue; + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + + case fpTRUNC : + case fpROUND : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + intValue = (sint16)arg1.f; + PUSH(st, intValue); + break; + + /* Floating Point arithmetic instructions (Two FP stack arguments) */ + + case fpADD : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + result.f = arg1.f + arg2.f; + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpSUB : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + result.f = arg1.f - arg2.f; + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpMUL : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + result.f = arg1.f * arg2.f; + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpDIV : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + result.f = arg1.f / arg2.f; + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpMOD : + return eBADFPOPCODE; +#if 0 /* Not yet */ + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + result.f = arg1.f % arg2.f; + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; +#endif + + /* Floating Point Comparisons (Two FP stack arguments) */ + + case fpEQU : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + intValue = PFALSE; + if (arg1.f == arg2.f) + intValue = PTRUE; + PUSH(st, intValue); + break; + case fpNEQ : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + intValue = PFALSE; + if (arg1.f != arg2.f) + intValue = PTRUE; + PUSH(st, intValue); + break; + case fpLT : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + intValue = PFALSE; + if (arg1.f < arg2.f) + intValue = PTRUE; + PUSH(st, intValue); + break; + case fpGTE : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + intValue = PFALSE; + if (arg1.f >= arg2.f) + intValue = PTRUE; + PUSH(st, intValue); + break; + case fpGT : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + intValue = PFALSE; + if (arg1.f > arg2.f) + intValue = PTRUE; + PUSH(st, intValue); + break; + case fpLTE : + pexec_getfparguments(st, fpOpCode, &arg1, &arg2); + intValue = PFALSE; + if (arg1.f <= arg2.f) + intValue = PTRUE; + PUSH(st, intValue); + break; + + /* Floating Point arithmetic instructions (One FP stack arguments) */ + + case fpNEG : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = -arg1.f; + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpABS : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = fabs(arg1.f); + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpSQR : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = arg1.f * arg1.f; + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpSQRT : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = sqrt(arg1.f); + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpSIN : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = sin(arg1.f); + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpCOS : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = cos(arg1.f); + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpATAN : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = atan(arg1.f); + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpLN : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = log(arg1.f); + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + case fpEXP : + pexec_getfparguments(st, fpOpCode, &arg1, NULL); + result.f = exp(arg1.f); + PUSH(st, result.hw[0]); + PUSH(st, result.hw[1]); + PUSH(st, result.hw[2]); + PUSH(st, result.hw[3]); + break; + + default : + return eBADFPOPCODE; + + } /* end switch */ + return eNOERROR; + +} /* end pexec_execfp */ + +/* This function retrieves the floating point arguments and performs + * integer to REAL conversions as necessary */ +static void pexec_getfparguments(struct pexec_s *st, ubyte fpOpCode, fparg_t *arg1, fparg_t *arg2) +{ + sint16 intArg; + + /* Extract arg2 from the stack */ + + if (arg2) + { + /* Convert an integer argument to type REAL */ + + if ((fpOpCode & fpARG2) != 0) + { + POP(st, intArg); + arg2->f = (float64)intArg; + } /* end if */ + else + { + POP(st, arg2->hw[3]); + POP(st, arg2->hw[2]); + POP(st, arg2->hw[1]); + POP(st, arg2->hw[0]); + } /* end else */ + } /* end if */ + + /* Extract arg1 from the stack */ + + if (arg1) + { + /* Convert an integer argument to type REAL */ + + if ((fpOpCode & fpARG1) != 0) + { + POP(st, intArg); + arg1->f = (float64)intArg; + } /* end if */ + else + { + POP(st, arg1->hw[3]); + POP(st, arg1->hw[2]); + POP(st, arg1->hw[1]); + POP(st, arg1->hw[0]); + } /* end else */ + } /* end if */ + +} /* end pexec_getfparguments */ + +/* This function parses a decimal integer from ioPtr */ + +static uStackType pexec_readinteger(ubyte *ioPtr) +{ + sStackType value = 0; + + while (isspace(*ioPtr)) ioPtr++; + while ((*ioPtr >= '0') && (*ioPtr <= '9')) + { + value = 10*value + + (sStackType)(*ioPtr) + - (sStackType)'0'; + ioPtr++; + } /* end while */ + + return (uStackType)value; + +} /* end pexec_readinteger */ + +/* This function parses a decimal integer from ioPtr */ + +static void pexec_readreal(uint16 *dest, ubyte *inPtr) +{ + sint32 intPart; + fparg_t result; + float64 fraction; + ubyte unaryOperator; + + intPart = 0; + unaryOperator = '+'; + + /* Check for a leading unary - */ + + if ((*inPtr == '-') || (*inPtr == '+')) + unaryOperator = *inPtr++; + + /* Get the integer part of the real */ + + while ((*inPtr >= '0') && (*inPtr <= '9')) + intPart = 10*intPart + ((sint32)*inPtr++) - ((sint32)'0'); + + result.f = ((float64)intPart); + + /* Check for the a fractional part */ + + if (*inPtr == '.') + { + inPtr++; + fraction = 0.1; + while ((*inPtr >= '0') && (*inPtr <= '9')) + { + result.f += fraction * (float64)(((sint32)*inPtr++) - ((sint32)'0')); + fraction /= 10.0; + } /* end while */ + } /* end if */ + + /* Correct the sign of the result */ + + if (unaryOperator == '-') + result.f = -result.f; + + /* Return the value into the P-Machine stack */ + + *dest++ = result.hw[0]; + *dest++ = result.hw[1]; + *dest++ = result.hw[2]; + *dest = result.hw[3]; + +} /* end pexec_readreal */ + +/* This function binds the base address corresponding to a given + * level offset. */ + +static uStackType pexec_getbaseaddress(struct pexec_s *st, levelType levelOffset) +{ + /* Start with the base register of the current frame */ + + uStackType baseAddress = st->fp; + + /* Search backware "levelOffset" frames until the correct frame is + * found + */ + + while (levelOffset > 0) + { + baseAddress = st->dstack.i[BTOISTACK(baseAddress)]; + levelOffset--; + } /* end while */ + + /* Offset that value by two words (one for the st->fp and one for the + * return value + */ + + return baseAddress + 2*BPERI; + +} /* end pexec_getbaseaddress */ + +static ubyte *pexec_mkcstring(ubyte *buffer, int buflen) +{ + ubyte *string; + string = malloc(buflen + 1); + if (string != NULL) + { + memcpy(string, buffer, buflen); + string[buflen] = '\0'; + } + return string; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +FAR struct pexec_s *pexec_init(struct pexec_attr_s *attr) +{ + struct pexec_s *st; + addrType stacksize; + addrType adjusted_rosize; + + /* Allocate the p-machine state stucture */ + + st = (struct pexec_s *)malloc(sizeof(struct pexec_s)); + if (!st) + { + return NULL; + } + + /* Set up I-Space */ + + st->ispace = attr->ispace; + st->maxpc = attr->maxpc; + + /* Align size of read-only data to 16-bit boundary. */ + + adjusted_rosize = (attr->rosize + 1) & ~1; + + /* Allocate the pascal stack. Organization is string stack, then + * constant data, then "normal" pascal stack. + */ + + stacksize = attr->varsize + adjusted_rosize + attr->strsize; + st->dstack.b = (ubyte*)malloc(stacksize); + if (!st->dstack.b) + { + free(st); + return NULL; + } + + /* Copy the rodata into the stack */ + + if (attr->rodata && attr->rosize) + { + memcpy(&st->dstack.b[attr->strsize], attr->rodata, attr->rosize); + } + + /* Set up info needed to perform a simulated reset */ + + st->strsize = attr->strsize; + st->rosize = adjusted_rosize; + st->entry = attr->entry; + st->stacksize = stacksize; + + /* Then perform a simulated reset */ + + pexec_reset(st); + return st; +} + +int pexec(FAR struct pexec_s *st) +{ + ubyte opCode; + ubyte arg8; + uint16 arg16; + ubyte opCodeSize; + sStackType sParm1; + sStackType sParm2; + uStackType uParm1; + uStackType uParm2; + uStackType uParm3; + + /* Make sure that the program counter is within range */ + + if (st->pc >= st->maxpc) + return eBADPC; + + else + { + /* Get the instruction to execute */ + + opCode = st->ispace[st->pc]; + arg8 = 0; + arg16 = 0; + opCodeSize = 1; + if ((opCode & o8) != 0) + { + arg8 = st->ispace[st->pc + opCodeSize]; + opCodeSize++; + } /* end if */ + if ((opCode & o16) != 0) + { + arg16 = ((st->ispace[st->pc + opCodeSize]) << 8); + arg16 |= st->ispace[st->pc + opCodeSize + 1]; + opCodeSize += 2; + } /* end if */ + + switch (opCode) + { + +/**--------------------------------------------------------------------- + OPCODES WITH NO ARGUMENTS + ---------------------------------------------------------------------**/ + /* Arithmetic & logical & and integer conversions (One stack argument) */ + case oNEG : + TOS(st, 0) = (uStackType)(-(sStackType)TOS(st, 0)); + st->pc += opCodeSize; + break; + case oABS : + if (signExtend16(TOS(st, 0)) < 0) + TOS(st, 0) = (uStackType)(-signExtend16(TOS(st, 0))); + st->pc += opCodeSize; + break; + case oINC : + TOS(st, 0)++; + st->pc += opCodeSize; + break; + case oDEC : + TOS(st, 0)--; + st->pc += opCodeSize; + break; + case oNOT : + TOS(st, 0) = ~TOS(st, 0); + st->pc += opCodeSize; + break; + + /* Arithmetic & logical (Two stack arguments) */ + + case oADD : + POP(st, sParm1); + TOS(st, 0) = (uStackType)(((sStackType)TOS(st, 0)) + sParm1); + st->pc += opCodeSize; + break; + case oSUB : + POP(st, sParm1); + TOS(st, 0) = (uStackType)(((sStackType)TOS(st, 0)) - sParm1); + st->pc += opCodeSize; + break; + case oMUL : + POP(st, sParm1); + TOS(st, 0) = (uStackType)(((sStackType)TOS(st, 0)) * sParm1); + st->pc += opCodeSize; + break; + case oDIV : + POP(st, sParm1); + TOS(st, 0) = (uStackType)(((sStackType)TOS(st, 0)) / sParm1); + st->pc += opCodeSize; + break; + case oMOD : + POP(st, sParm1); + TOS(st, 0) = (uStackType)(((sStackType)TOS(st, 0)) % sParm1); + st->pc += opCodeSize; + break; + case oSLL : + POP(st, sParm1); + TOS(st, 0) = (uStackType)(((sStackType)TOS(st, 0)) << sParm1); + st->pc += opCodeSize; + break; + case oSRL : + POP(st, sParm1); + TOS(st, 0) = (TOS(st, 0) >> sParm1); + st->pc += opCodeSize; + break; + case oSRA : + POP(st, sParm1); + TOS(st, 0) = (uStackType)(((sStackType)TOS(st, 0)) >> sParm1); + st->pc += opCodeSize; + break; + case oOR : + POP(st, uParm1); + TOS(st, 0) = (TOS(st, 0) | uParm1); + st->pc += opCodeSize; + break; + case oAND : + POP(st, uParm1); + TOS(st, 0) = (TOS(st, 0) & uParm1); + st->pc += opCodeSize; + break; + case oBIT : + POP(st, uParm1); + uParm2 = TOS(st, 0); + if ((uParm1 & (1 << uParm2)) != 0) + TOS(st, 0) = PTRUE; + else + TOS(st, 0) = PFALSE; + st->pc += opCodeSize; + break; + + /* Comparisons (One stack argument) */ + + case oEQUZ : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 == 0) + uParm1 = PTRUE; + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oNEQZ : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 != 0) + uParm1 = PTRUE; + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oLTZ : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 < 0) + uParm1 = PTRUE; + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oGTEZ : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 >= 0) + uParm1 = PTRUE; + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oGTZ : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 > 0) + uParm1 = PTRUE; + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oLTEZ : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 <= 0) + uParm1 = PTRUE; + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + + /* Comparisons (Two stack arguments) */ + + case oEQU : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 == (sStackType)TOS(st, 0)) + uParm1 = PTRUE; + TOS(st, 0) = uParm1; + st->pc += opCodeSize; + break; + case oNEQ : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 != (sStackType)TOS(st, 0)) + uParm1 = PTRUE; + TOS(st, 0) = uParm1; + st->pc += opCodeSize; + break; + case oLT : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 < (sStackType)TOS(st, 0)) + uParm1 = PTRUE; + TOS(st, 0) = uParm1; + st->pc += opCodeSize; + break; + case oGTE : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 >= (sStackType)TOS(st, 0)) + uParm1 = PTRUE; + TOS(st, 0) = uParm1; + st->pc += opCodeSize; + break; + case oGT : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 > (sStackType)TOS(st, 0)) + uParm1 = PTRUE; + TOS(st, 0) = uParm1; + st->pc += opCodeSize; + break; + case oLTE : + POP(st, sParm1); + uParm1 = PFALSE; + if (sParm1 <= (sStackType)TOS(st, 0)) + uParm1 = PTRUE; + TOS(st, 0) = uParm1; + st->pc += opCodeSize; + break; + + /* Load (One stack argument) */ + + case oLDI : + POP(st, uParm1); /* Address */ + PUSH(st, GETSTACK(st, uParm1)); + PUSH(st, GETSTACK(st, uParm1 + BPERI)); + st->pc += opCodeSize; + break; + case oLDIH : + TOS(st, 0) = GETSTACK(st, TOS(st, 0)); + st->pc += opCodeSize; + break; + case oLDIB : + TOS(st, 0) = GETBSTACK(st, TOS(st, 0)); + st->pc += opCodeSize; + break; + case oLDIM : + /* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); /* Size */ + POP(st, uParm2); /* Stack offset */ + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUSH(st, GETSTACK(st, uParm2)); + uParm2 += BPERI; + uParm1 -= BPERI; + } /* end if */ + else + { + PUSH(st, GETBSTACK(st, uParm2)); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + st->pc += opCodeSize; + break; + case oDUP : + uParm1 = TOS(st, 0); + uParm2 = TOS(st, 1); + PUSH(st, uParm2); + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oDUPH : + uParm1 = TOS(st, 0); + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oPUSHS : + PUSH(st, st->csp); + st->pc += opCodeSize; + break; + case oPOPS : + POP(st, st->csp); + st->pc += opCodeSize; + break; + + /* Store (Two stack arguments) */ + + case oSTIH : + POP(st, uParm1); + POP(st, uParm2); + PUTSTACK(st, uParm1,uParm2); + st->pc += opCodeSize; + break; + case oSTIB : + POP(st, uParm1); + POP(st, uParm2); + PUTBSTACK(st, uParm1, uParm2); + st->pc += opCodeSize; + break; + case oSTIM : + /* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); /* Size in bytes */ + uParm3 = uParm1; /* Save for stack discard */ + sParm1 = ROUNDBTOI(uParm1); /* Size in words */ + uParm2 = TOS(st, sParm1); /* Stack offset */ + sParm1--; + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUTSTACK(st, TOS(st, sParm1), uParm2); + uParm2 += BPERI; + uParm1 -= BPERI; + sParm1--; + } /* end if */ + else + { + PUTBSTACK(st, TOS(st, sParm1), uParm2); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + + /* Discard the stored data + the stack offset */ + + DISCARD(st, (ROUNDBTOI(uParm3) + 1)); + st->pc += opCodeSize; + break; + + /* Program control (No stack arguments) */ + + case oNOP : + st->pc += opCodeSize; + break; + case oRET : + POP(st, st->pc); + POP(st, st->fp); + DISCARD(st, 1); + break; + + /* System Functions (No stack arguments) */ + + case oEND : + return eEXIT; + +/**--------------------------------------------------------------------- + OPCODES WITH SINGLE BYTE ARGUMENT (arg8) + ---------------------------------------------------------------------**/ + /* Data stack: arg8 = 8 bit unsigned data (no stack arguments) */ + + case oPUSHB : + PUSH(st, arg8); + st->pc += opCodeSize; + break; + + /* Floating Point: arg8 = FP op-code (varying number of stack arguments) */ + case oFLOAT : + st->pc += opCodeSize; + return pexec_execfp(st, arg8); + +/**--------------------------------------------------------------------- + OPCODES WITH SINGLE 16-BIT ARGUMENT (arg16) + ---------------------------------------------------------------------**/ + /* Program control: arg16 = unsigned label (no stack arguments) */ + + case oJMP : + st->pc = (addrType)arg16; + break; + + /* Program control: arg16 = unsigned label (One stack argument) */ + + case oJEQUZ : + POP(st, sParm1); + if (sParm1 == 0) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJNEQZ : + POP(st, sParm1); + if (sParm1 != 0) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJLTZ : + POP(st, sParm1); + if (sParm1 < 0) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJGTEZ : + POP(st, sParm1); + if (sParm1 >= 0) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJGTZ : + POP(st, sParm1); + if (sParm1 > 0) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJLTEZ : + POP(st, sParm1); + if (sParm1 <= 0) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + + /* Program control: arg16 = unsigned label (Two stack arguments) */ + + case oJEQU : + POP(st, sParm1); + POP(st, sParm2); + if (sParm2 == sParm1) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJNEQ : + POP(st, sParm1); + POP(st, sParm2); + if (sParm2 != sParm1) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJLT : + POP(st, sParm1); + POP(st, sParm2); + if (sParm2 < sParm1) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJGTE : + POP(st, sParm1); + POP(st, sParm2); + if (sParm2 >= sParm1) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJGT : + POP(st, sParm1); + POP(st, sParm2); + if (sParm2 > sParm1) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + case oJLTE : + POP(st, sParm1); + POP(st, sParm2); + if (sParm2 <= sParm1) + st->pc = (addrType)arg16; + else + st->pc += opCodeSize; + break; + + /* Load: arg16 = usigned offset (no stack arguments) */ + + case oLD : + uParm1 = st->spb + arg16; + PUSH(st, GETSTACK(st, uParm1)); + PUSH(st, GETSTACK(st, uParm1 + BPERI)); + st->pc += opCodeSize; + break; + case oLDH : + uParm1 = st->spb + arg16; + PUSH(st, GETSTACK(st, uParm1)); + st->pc += opCodeSize; + break; + case oLDB : + uParm1 = st->spb + arg16; + PUSH(st, GETBSTACK(st, uParm1)); + st->pc += opCodeSize; + break; + case oLDM : + /* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); + uParm2 = st->spb + arg16; + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUSH(st, GETSTACK(st, uParm2)); + uParm2 += BPERI; + uParm1 -= BPERI; + } /* end if */ + else + { + PUSH(st, GETBSTACK(st, uParm2)); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + st->pc += opCodeSize; + break; + + /* Load & store: arg16 = unsigned base offset (One stack argument) */ + + case oST : + uParm1 = st->spb + arg16; + POP(st, uParm2); + PUTSTACK(st, uParm2, uParm1 + BPERI); + POP(st, uParm2); + PUTSTACK(st, uParm2, uParm1); + st->pc += opCodeSize; + break; + case oSTH : + uParm1 = st->spb + arg16; + POP(st, uParm2); + PUTSTACK(st, uParm2, uParm1); + st->pc += opCodeSize; + break; + case oSTB : + uParm1 = st->spb + arg16; + POP(st, uParm2); + PUTBSTACK(st, uParm2, uParm1); + st->pc += opCodeSize; + break; + case oSTM : + /* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); /* Size */ + uParm3 = uParm1; /* Save for stack discard */ + uParm2 = st->spb + arg16; + sParm1 = ROUNDBTOI(uParm1) - 1; + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUTSTACK(st, TOS(st, sParm1), uParm2); + uParm2 += BPERI; + uParm1 -= BPERI; + sParm1--; + } /* end if */ + else + { + PUTBSTACK(st, TOS(st, sParm1), uParm2); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + + /* Discard the stored data */ + + DISCARD(st, ROUNDBTOI(uParm3)); + st->pc += opCodeSize; + break; + case oLDX : + uParm1 = st->spb + arg16 + TOS(st, 0); + TOS(st, 0) = GETSTACK(st, uParm1); + PUSH(st, GETSTACK(st, uParm1 + BPERI)); + st->pc += opCodeSize; + break; + case oLDXH : + uParm1 = st->spb + arg16 + TOS(st, 0); + TOS(st, 0) = GETSTACK(st, uParm1); + st->pc += opCodeSize; + break; + case oLDXB : + uParm1 = st->spb + arg16 + TOS(st, 0); + TOS(st, 0) = GETBSTACK(st, uParm1); + st->pc += opCodeSize; + break; + case oLDXM : + /* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); + POP(st, uParm2); + uParm2 += st->spb + arg16; + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUSH(st, GETSTACK(st, uParm2)); + uParm2 += BPERI; + uParm1 -= BPERI; + } /* end if */ + else + { + PUSH(st, GETBSTACK(st, uParm2)); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + st->pc += opCodeSize; + break; + + /* Store: arg16 = unsigned base offset (Two stack arguments) */ + + case oSTXH : + POP(st, uParm1); + POP(st, uParm2); + uParm2 += st->spb + arg16; + PUTSTACK(st, uParm1,uParm2); + st->pc += opCodeSize; + break; + case oSTXB : + POP(st, uParm1); + POP(st, uParm2); + uParm2 += st->spb + arg16; + PUTBSTACK(st, uParm1, uParm2); + st->pc += opCodeSize; + break; + case oSTXM : +/* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); /* Size */ + uParm3 = uParm1; /* Save for stack discard */ + sParm1 = ROUNDBTOI(uParm1); /* Size in 16-bit words */ + uParm2 = TOS(st, sParm1); /* index */ + sParm1--; + uParm2 += st->spb + arg16; + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUTSTACK(st, TOS(st, sParm1), uParm2); + uParm2 += BPERI; + uParm1 -= BPERI; + sParm1--; + } /* end if */ + else + { + PUTBSTACK(st, TOS(st, sParm1), uParm2); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + + /* Discard the stored data + the index */ + + DISCARD(st, (ROUNDBTOI(uParm3) + 1)); + st->pc += opCodeSize; + break; + + case oLA : + uParm1 = st->spb + arg16; + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oLAX : + TOS(st, 0) = st->spb + arg16 + TOS(st, 0); + st->pc += opCodeSize; + break; + + /* Data stack: arg16 = 16 bit signed data (no stack arguments) */ + + case oPUSH : + PUSH(st, arg16); + st->pc += opCodeSize; + break; + case oINDS : + st->sp += signExtend16(arg16); + st->pc += opCodeSize; + break; + + /* System Functions: + * For LIB: arg16 = sub-function code + */ + + case oLIB : + st->pc += opCodeSize; + return pexec_libcall(st, arg8, arg16); + + /* Program control: arg16 = unsigned label (no stack arguments) */ + + case oLAC : + uParm1 = arg16 + st->rop; + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + + case oLABEL : + return eILLEGALOPCODE; + +/**--------------------------------------------------------------------- + OPCODES WITH BYTE ARGUMENT (arg8) AND 16-BIT ARGUMENT (arg16) + ---------------------------------------------------------------------**/ + /* Load: arg8 = level; arg16 = signed frame offset (no stack arguments) */ + case oLDS : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + PUSH(st, GETSTACK(st, uParm1)); + PUSH(st, GETSTACK(st, uParm1 + BPERI)); + st->pc += opCodeSize; + break; + case oLDSH : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + PUSH(st, GETSTACK(st, uParm1)); + st->pc += opCodeSize; + break; + case oLDSB : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + PUSH(st, GETBSTACK(st, uParm1)); + st->pc += opCodeSize; + break; + case oLDSM : + /* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); + uParm2 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUSH(st, GETSTACK(st, uParm2)); + uParm2 += BPERI; + uParm1 -= BPERI; + } /* end if */ + else + { + PUSH(st, GETBSTACK(st, uParm2)); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + st->pc += opCodeSize; + break; + + /* Load & store: arg8 = level; arg16 = signed frame offset (One stack argument) */ + + case oSTSH : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + POP(st, uParm2); + PUTSTACK(st, uParm2, uParm1); + st->pc += opCodeSize; + break; + case oSTSB : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + POP(st, uParm2); + PUTBSTACK(st, uParm2, uParm1); + st->pc += opCodeSize; + break; + case oSTSM : + /* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); /* Size */ + uParm3 = uParm1; /* Save for stack discard */ + uParm2 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + sParm1 = ROUNDBTOI(uParm1) - 1; + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUTSTACK(st, TOS(st, sParm1), uParm2); + uParm2 += BPERI; + uParm1 -= BPERI; + sParm1--; + } /* end if */ + else + { + PUTBSTACK(st, TOS(st, sParm1), uParm2); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + + /* Discard the stored data */ + + DISCARD(st, ROUNDBTOI(uParm3)); + st->pc += opCodeSize; + break; + case oLDSX : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16) + TOS(st, 0); + TOS(st, 0) = GETSTACK(st, uParm1); + PUSH(st, GETSTACK(st, uParm1 + BPERI)); + st->pc += opCodeSize; + break; + case oLDSXH : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16) + TOS(st, 0); + TOS(st, 0) = GETSTACK(st, uParm1); + st->pc += opCodeSize; + break; + case oLDSXB : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16) + TOS(st, 0); + TOS(st, 0) = GETBSTACK(st, uParm1); + st->pc += opCodeSize; + break; + case oLDSXM : + /* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); + POP(st, uParm2); + uParm2 += pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUSH(st, GETSTACK(st, uParm2)); + uParm2 += BPERI; + uParm1 -= BPERI; + } /* end if */ + else + { + PUSH(st, GETBSTACK(st, uParm2)); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + st->pc += opCodeSize; + break; + + /* Store: arg8 = level; arg16 = signed frame offset (Two stack arguments) */ + + case oSTSXH : + POP(st, uParm1); + POP(st, uParm2); + uParm2 += pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + PUTSTACK(st, uParm1,uParm2); + st->pc += opCodeSize; + break; + case oSTSXB : + POP(st, uParm1); + POP(st, uParm2); + uParm2 += pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + PUTBSTACK(st, uParm1, uParm2); + st->pc += opCodeSize; + break; + case oSTSXM : +/* FIX ME --> Need to handle the unaligned case */ + POP(st, uParm1); /* Size */ + uParm3 = uParm1; /* Save for stack discard */ + sParm1 = ROUNDBTOI(uParm1); /* Size in 16-bit words */ + uParm2 = TOS(st, sParm1); /* index */ + sParm1--; + uParm2 += pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + while (uParm1 > 0) + { + if (uParm1 >= BPERI) + { + PUTSTACK(st, TOS(st, sParm1), uParm2); + uParm2 += BPERI; + uParm1 -= BPERI; + sParm1--; + } /* end if */ + else + { + PUTBSTACK(st, TOS(st, sParm1), uParm2); + uParm2++; + uParm1--; + } /* end else */ + } /* end while */ + + /* Discard the stored data + the index */ + + DISCARD(st, (ROUNDBTOI(uParm3) + 1)); + st->pc += opCodeSize; + break; + + case oLAS : + uParm1 = pexec_getbaseaddress(st, arg8) + signExtend16(arg16); + PUSH(st, uParm1); + st->pc += opCodeSize; + break; + case oLASX : + TOS(st, 0) = pexec_getbaseaddress(st, arg8) + signExtend16(arg16) + TOS(st, 0); + st->pc += opCodeSize; + break; + + /* Program Control: arg8 = level; arg16 = unsigned label (No + * stack arguments) + */ + + case oPCAL : + PUSH(st, pexec_getbaseaddress(st, arg8)); + PUSH(st, st->fp); + uParm1 = st->sp; + PUSH(st, st->pc + opCodeSize); + st->fp = uParm1; + st->pc = (addrType)arg16; + break; + + /* System Functions: + * For SYSIO: arg8 = file number; arg16 = sub-function code + */ + + case oSYSIO : + st->pc += opCodeSize; + return pexec_sysio(st, arg8, arg16); + + /* Psuedo-operations: (No stack arguments) + * For LINE: arg8 = file number; arg16 = line number + */ + + case oLINE : + default : + return eILLEGALOPCODE; + + } /* end switch */ + } /* end else */ + + return eNOERROR; +} + +void pexec_reset(struct pexec_s *st) +{ + int dndx; + + /* Setup the bottom of the "normal" pascal stack */ + + st->rop = st->strsize; + st->spb = st->strsize + st->rosize; + + /* Initialize the emulated P-Machine registers */ + + st->csp = 0; + st->sp = st->spb + 2*BPERI; + st->fp = st->spb + BPERI; + st->pc = st->entry; + + /* Initialize the P-Machine stack */ + + dndx = BTOISTACK(st->spb); + st->dstack.i[dndx] = 0; + st->dstack.i[dndx+1] = 0; + st->dstack.i[dndx+2] = -1; +} diff --git a/misc/pascal/insn16/prun/pload.c b/misc/pascal/insn16/prun/pload.c new file mode 100644 index 000000000..e71026256 --- /dev/null +++ b/misc/pascal/insn16/prun/pload.c @@ -0,0 +1,175 @@ +/**************************************************************************** + * pload.c + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +#include "keywords.h" +#include "pmach.h" +#include "pedefs.h" +#include "pofflib.h" +#include "perr.h" +#include "pexec.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +FAR struct pexec_s *pload(const char *filename, addrType varsize, addrType strsize) +{ + struct pexec_attr_s attr; + struct pexec_s *st; + poffHandle_t phandle; + FILE *exe; + uint16 err; + ubyte ftype; + ubyte farch; + + /* Create a handle to contain the executable data */ + + phandle = poffCreateHandle(); + if (phandle == NULL) fatal(eNOMEMORY); + + /* Open the executable file */ + + if (!(exe = fopen(filename, "rb"))) + { + dbg("ERROR: Error opening '%s': %d\n", filename, errno); + goto errout_with_handle; + } + + /* Load the POFF file into memory */ + + err = poffReadFile(phandle, exe); + if (err != eNOERROR) + { + dbg("ERROR: Could not read %s: %d\n", filename, err); + goto errout_with_file; + } + + /* Verify that the file is a pascal executable */ + + ftype = poffGetFileType(phandle); + if (ftype != FHT_EXEC) + { + dbg("ERROR: File is not a pascal executable: %d\n", ftype); + goto errout_with_file; + } + + farch = poffGetArchitecture(phandle); + if (farch != FHA_PCODE_INSN16) + { + dbg("ERROR: File is not 16-bit pcode: %d\n", farch); + goto errout_with_file; + } + + /* Initialize the attribute structure */ + + attr.varsize = varsize; + attr.strsize = strsize; + + /* Extract the program entry point from the pascal executable */ + + attr.entry = poffGetEntryPoint(phandle); + + /* Close the POFF file */ + + (void)fclose(exe); + + /* Extract the program data from the POFF image */ + + attr.maxpc = poffExtractProgramData(phandle, &attr.ispace); + + /* Extract the read-only data from the POFF image */ + + attr.rosize = poffExtractRoData(phandle, &attr.rodata); + + /* Destroy the POFF image */ + + poffDestroyHandle(phandle); + + /* Initialize the p-code interpreter */ + + st = pexec_init(&attr); + if (!st && attr.ispace) + { + /* Initialization failed, discard the allocated I-Space */ + + free(st->ispace); + } + + /* Discard the allocated RO data in any event */ + + if (attr.rodata) + { + free(attr.rodata); + } + return st; + + errout_with_file: + (void)fclose(exe); + + errout_with_handle: + poffDestroyHandle(phandle); + return NULL; +} diff --git a/misc/pascal/insn16/prun/prun.c b/misc/pascal/insn16/prun/prun.c new file mode 100644 index 000000000..cc7c91111 --- /dev/null +++ b/misc/pascal/insn16/prun/prun.c @@ -0,0 +1,257 @@ +/**************************************************************************** + * prun.c + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include +#include +#include +#include + +#include "keywords.h" +#include "pdefs.h" +#include "pinsn16.h" +#include "pxdefs.h" +#include "pedefs.h" +#include "pmach.h" + +#include "paslib.h" +#include "perr.h" +#include "pexec.h" +#include "pdbg.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#define MIN_STACK_SIZE 1024 +#define DEFAULT_STACK_SIZE 4096 +#define DEFAULT_STKSTR_SIZE 0 + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +static const struct option long_options[] = +{ + {"stack", 1, NULL, 's'}, + {"string", 1, NULL, 't'}, + {"debug", 0, NULL, 'd'}, + {"help", 0, NULL, 'h'}, + {NULL, 0, NULL, 0} +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const char *poffFileName; +static sint32 varStackSize = DEFAULT_STACK_SIZE; +static sint32 stringStackSize = DEFAULT_STKSTR_SIZE; +static int debug = 0; + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void showUsage(const char *progname) +{ + fprintf(stderr, "Usage:\n"); + fprintf(stderr, " %s [options] \n", + progname); + fprintf(stderr, "options:\n"); + fprintf(stderr, " -s \n"); + fprintf(stderr, " --stack \n"); + fprintf(stderr, " Memory in bytes to allocate for the pascal program\n"); + fprintf(stderr, " stack in bytes (minimum is %d; default is %d bytes)\n", + MIN_STACK_SIZE, DEFAULT_STACK_SIZE); + fprintf(stderr, " -t \n"); + fprintf(stderr, " --string \n"); + fprintf(stderr, " Memory in bytes to allocate for the pascal program\n"); + fprintf(stderr, " string storage in bytes (default is %d bytes)\n", + DEFAULT_STKSTR_SIZE); + fprintf(stderr, " -d\n"); + fprintf(stderr, " --debug\n"); + fprintf(stderr, " Enable PCode program debugger\n"); + fprintf(stderr, " -h\n"); + fprintf(stderr, " --help\n"); + fprintf(stderr, " Shows this message\n"); + exit(1); +} + +static void parse_args(int argc, char **argv) +{ + int option_index; + int size; + int c; + + /* Check for existence of filename argument */ + + if (argc < 2) + { + fprintf(stderr, "ERROR: Filename required\n"); + showUsage(argv[0]); + } /* end if */ + + /* Parse the command line options */ + + do + { + c = getopt_long (argc, argv, "t:s:dh", + long_options, &option_index); + if (c != -1) + { + switch (c) + { + case 's' : + size = atoi(optarg); + if (size < MIN_STACK_SIZE) + { + fprintf(stderr, "ERROR: Invalid stack size\n"); + showUsage(argv[0]); + } + varStackSize = (size + 3) & ~3; + break; + + case 't' : + size = atoi(optarg); + if (size < 0) + { + fprintf(stderr, "ERROR: Invalid string storage size\n"); + showUsage(argv[0]); + } + stringStackSize = ((size + 3) & ~3); + break; + + case 'd' : + debug++; + break; + + case 'h' : + showUsage(argv[0]); + break; + + default: + /* Shouldn't happen */ + + fprintf(stderr, "ERROR: Unrecognized option\n"); + showUsage(argv[0]); + } + } + } + while (c != -1); + + if (optind != argc-1) + { + fprintf(stderr, "ERROR: Only one filename permitted on command line\n"); + showUsage(argv[0]); + } + + /* Get the name of the p-code file(s) from the last argument(s) */ + + poffFileName = argv[argc-1]; +} + +/* This function executes the P-Code program until a stopping condition + * is encountered. */ + +static void run(struct pexec_s *st) +{ + uint16 errcode; + + for (;;) + { + /* Execute the instruction; Check for exceptional conditions */ + + errcode = pexec(st); + if (errcode != eNOERROR) break; + } + + if (errcode != eEXIT) + { + printf("Runtime error 0x%02x -- Execution Stopped\n", errcode); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char *argv[], char *envp[]) +{ + struct pexec_s *st; + char fileName[FNAME_SIZE+1]; /* Object file name */ + + /* Parse the command line arguments */ + + parse_args(argc, argv); + + /* Load the POFF files specified on the command line */ + /* Use .o or command line extension, if supplied */ + + (void)extension(poffFileName, "o", fileName, 0); + + /* Load the POFF file */ + + st = pload(fileName, varStackSize, stringStackSize); + if (!st) + { + fprintf(stderr, "ERROR: Could not load %s\n", fileName); + exit(1); + } /* end if */ + printf("%s Loaded\n", fileName); + + /* And start program execution in the specified mode */ + + if (debug) + dbg_run(st); + else + run(st); + + return 0; + +} /* end main */ diff --git a/misc/pascal/insn32/include/pinsn32.h b/misc/pascal/insn32/include/pinsn32.h new file mode 100644 index 000000000..e92202402 --- /dev/null +++ b/misc/pascal/insn32/include/pinsn32.h @@ -0,0 +1,426 @@ +/**************************************************************************** + * pinsn32.h + * 32-bit P-code operation code definitions + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __PINSN32_H +#define __PINSN32_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* 32-bit op-code bit definitions + * + * Machine model: + * + * SPB 32-bit Pascal stack base address + * SP 32-bit Pascal stack pointer + * LSP 32-bit Level stack pointer + * CSB 32-bit Character stack base address + * CSP 32-bit Character stack pointer + * DS 32-bit Data size register (for multiple reg transfers) + * PC 32-bit Program Counter + * CC Condition code register + * --- Volatile general purpose registers + * --- Static general purpose registers + * + * Condition codes: Z(ero), N(egative) + * + * +=====+=====+ + * | Z | N | + * +=====+=====+=====+ + * | EQ | 1 | - | + * | NEQ | 0 | - | + * | LT | - | 1 | + * | GTE | - | 0 | + * | GT | 0 | 0 | + * | LTE | 1 | 1 | + * +=====+=====+=====+ + * + * Opcode Encoding Summary: + * + * 0rxx xxxx 1rxxx xxxx + * xr00 0000 NOP LD uoffs4 + * xr00 0001 NEG LDH uoffs3 + * xr00 0010 ABS LDB uoffs + * xr00 0011 INC LDM uoffs4 + * xr00 0100 DEC ST uoffs4 + * xr00 0101 NOT STH uoffs2 + * xr00 0110 ADD STB uoffs + * xr00 0111 SUB STM uoffs4 + * xr00 1000 MUL LDX uoffs4 + * xr00 1001 DIV LDXH uoffs2 + * xr00 1010 MOD LDXB uoffs + * xr00 1011 SLL LDXM uoffs4 + * xr00 1100 SRL STX uoffs4 + * xr00 1101 SRA STXH uoffs2 + * xr00 1110 OR STXB uoffs + * xr00 1111 AND STXM uoffs + * + * xr01 0000 EQUZ JEQUZ ilbl + * xr01 0001 NEQZ JNEQZ ilbl + * xr01 0010 LTZ JLTZ ilbl + * xr01 0011 GTEZ JGTEZ ilbl + * xr01 0100 GTZ JGTZ ilbl + * xr01 0101 LTEZ JLTEZ ilbl + * xr01 0110 --- JMP ilbl + * xr01 0111 --- PUSH nn + * xr01 1000 EQU JEQU ilbl + * xr01 1001 NEQ JNEQ ilbl + * xr01 1010 LT JLT ilbl + * xr01 1011 GTE JGTE ilbl + * xr01 1100 GT JGT ilbl + * xr01 1101 LTE JLTE ilbl + * xr01 1110 --- --- + * xr01 1111 BIT INDS nn + * + * xr10 0000 LDI LDS offs4 + * xr10 0001 LDIH LDSH offs3 + * xr10 0010 LDIB LDSB offs + * xr10 0011 LDIM LDSM offs4 + * xr10 0100 STI STS offs4 + * xr10 0101 STIH STSH offs2 + * xr10 0110 STIB STSB offs + * xr10 0111 STIM STSM offs4 + * xr10 1000 DUP LDSX offs4 + * xr10 1001 --- LDSXH offs2 + * xr10 1010 PUSHS LDSXB offs + * xr10 1011 POPS LDSXM offs4 + * xr10 1100 --- STSX offs4 + * xr10 1101 --- STSXH offs2 + * xr10 1110 --- STSXB offs + * xr10 1111 RET STSXM offs + * + * xr11 0000 --- LA uoffs + * xr11 0001 --- LAS offs + * xr11 0010 --- LAC dlbl + * xr11 0011 --- --- + * xr11 0100 --- LAX uoffs + * xr11 0101 --- LASX offs + * xr11 0110 --- SLSP level + * xr11 0111 --- SDC uu + * xr11 1000 --- --- + * xr11 1001 --- PCAL ilbl + * xr11 1010 --- SYSIO fn,sop + * xr11 1011 --- LIB lop + * xr11 1100 --- FLOAT fop + * xr11 1101 --- *LABEL ilbl + * xr11 1110 --- *INCLUDE fn + * xr11 1111 END *LINE lineno + * + * KEY: + * r = Reserved bit (must be zero) + * fn = 8-bit file number + * lvl = 8-bit static nexting level + * sop = 17-bit sysio operation + * lineno = 17-bit line number + * nn = 32-bit constant value (signed) + * uu = 32-bit constant value (unsigned) + * fop = 32-bit floating point operation + * lop = 32-bit library call identifier + * ilbl = 32-bit Instruction space label number + * dlbl = 32-stack data label + * offs4 = 32-bit word offset with respect to LSP (signed) + * offs2 = 32-bit halfword offset with respect to LSP (signed) + * offs = 32-bit byte offset with respect to LSP (signed) + * uoffs4 = 32-bit word offset with respect to SPB (unsigned) + * uoffs2 = 32-bit halfword offset with respect to SPB (unsigned) + * uoffs = 32-bit byte offset with respect to SPB (unsigned) + * c = string follows psuedo-operation + * * = Indicates pseudo-operations (these are removed + * after final fixup of the object file). + */ + +#define o32 (0x80) + +#define GETOP(o) ((o)->op) +#define PUTOP(o,v) do { (o)->op = (v); } while (0) + +#define GETARG(o) ((o)->arg) +#define PUTARG(o,a) do { (o)->arg = (a); } while (0) + +#define ARGONES 0xffffffff + +/* The opcode binary is stored in big endian order (so that the opcode + * always comes first). The following definitions simplify ordering + * of byte accesses. + */ + +#ifdef CONFIG_ENDIAN_BIG +# define opB1 0 +# define opB2 1 +# define opB3 2 +# define opB4 3 +#else +# define opB1 3 +# define opB2 2 +# define opB3 1 +# define opB4 0 +#endif + +/** 1-BYTE OPCODES WITH NO ARGUMENTS (other than stack arguments) ***********/ + +/* Program control (No stack arguments) */ + +#define oNOP (0x00) + +/* Arithmetic & logical & and integer conversions (One 32-bit stack + * argument) + */ + +#define oNEG (0x01) +#define oABS (0x02) +#define oINC (0x03) +#define oDEC (0x04) +#define oNOT (0x05) +#define oADD (0x06) +#define oSUB (0x07) +#define oMUL (0x08) +#define oDIV (0x09) +#define oMOD (0x0a) +#define oSLL (0x0b) +#define oSRL (0x0c) +#define oSRA (0x0d) +#define oOR (0x0e) +#define oAND (0x0f) + +/* Comparisons (One 32-bit stack argument) */ + +#define oEQUZ (0x10) +#define oNEQZ (0x11) +#define oLTZ (0x12) +#define oGTEZ (0x13) +#define oGTZ (0x14) +#define oLTEZ (0x15) + +/* Comparisons (Two 32-bit stack arguments) */ + +#define oEQU (0x18) +#define oNEQ (0x19) +#define oLT (0x1a) +#define oGTE (0x1b) +#define oGT (0x1c) +#define oLTE (0x1d) +#define oBIT (0x1f) + +/* Load Immediate */ + +#define oLDI (0x20) /* (One 32-bit stack argument) */ +#define oLDIH (0x21) /* (One 32-bit stack argument) */ +#define oLDIB (0x22) /* (One 32-bit stack argument) */ +#define oLDIM (0x23) /* (Two 32-bit stack argument) */ + +/* Store Immediate */ + +#define oSTI (0x24) /* (Two 32-bit stack argument) */ +#define oSTIH (0x25) /* (Two 32-bit stack argument) */ +#define oSTIB (0x26) /* (Two 32-bit stack argument) */ +#define oSTIM (0x27) /* (Two+n 32-bit stack argument) */ + +/* Data stack */ + +#define oDUP (0x28) /* (One 32-bit stack argument) */ +#define oDUPH (0x29) /* (One 32-bit stack argument) */ +#define oPUSHS (0x2a) /* No stack arguments */ +#define oPOPS (0x2b) /* (One 32-bit stack argument) */ + +/* Program control (No stack arguments) + * Behavior: + * Pop return address + * Pop saved base register (BR) + * Discard saved base address + * Set program counter (PC) to return address + */ + +#define oRET (0x2f) + +/* System Functions (No stack arguments) */ + +#define oEND (0x3f) + +/** 4-BYTE OPCODES INCLUDING ONE 32-BIT ARGUMENT ****************************/ + +/* Load: arg = unsigned base offset */ + +#define oLD (o32|0x00) /* No stack arguments */ +#define oLDH (o32|0x01) /* No stack arguments */ +#define oLDB (o32|0x02) /* No stack arguments */ +#define oLDM (o32|0x03) /* One 32-bit stack argument */ + +/* Store: arg = unsigned base offset */ + +#define oST (o32|0x04) /* One 32-bit stack argument */ +#define oSTH (o32|0x05) /* One 32-bit stack argument */ +#define oSTB (o32|0x06) /* One 32-bit stack argument */ +#define oSTM (o32|0x07) /* One+n 32-bit stack argument */ + +/* Load Indexed: arg = unsigned base offset */ + +#define oLDX (o32|0x08) /* One 32-bit stack argument */ +#define oLDXH (o32|0x09) /* One 32-bit stack argument */ +#define oLDXB (o32|0x0a) /* One 32-bit stack argument */ +#define oLDXM (o32|0x0b) /* Two 32-bit stack argument */ + +/* Store Indexed: arg = unsigned base offset */ + +#define oSTX (o32|0x0c) /* Two 32-bit stack argument */ +#define oSTXH (o32|0x0d) /* Two 32-bit stack argument */ +#define oSTXB (o32|0x0e) /* Two 32-bit stack argument */ +#define oSTXM (o32|0x0f) /* Two+n 32-bit stack argument */ + +/* Program control: arg = unsigned label (One 32-bit stack argument) */ + +#define oJEQUZ (o32|0x10) +#define oJNEQZ (o32|0x11) +#define oJLTZ (o32|0x12) +#define oJGTEZ (o32|0x13) +#define oJGTZ (o32|0x14) +#define oJLTEZ (o32|0x15) + +/* Program control: arg = unsigned label (no stack arguments) */ + +#define oJMP (o32|0x16) + +/* Data stack: arg = 32 bit signed data (no stack arguments) */ + +#define oPUSH (o32|0x17) + +/* Program control: arg = unsigned label (One 32-bit stack argument) */ + +#define oJEQU (o32|0x18) +#define oJNEQ (o32|0x19) +#define oJLT (o32|0x1a) +#define oJGTE (o32|0x1b) +#define oJGT (o32|0x1c) +#define oJLTE (o32|0x1d) + +/* Data stack: arg = 32 bit signed data (no stack arguments) */ + +#define oINDS (o32|0x1f) + +/* Load: Uses LSP; arg = signed frame offset */ + +#define oLDS (o32|0x20) /* No stack arguments */ +#define oLDSH (o32|0x21) /* No stack arguments */ +#define oLDSB (o32|0x22) /* No stack arguments */ +#define oLDSM (o32|0x23) /* One 32-bit stack argument */ + +/* Store: Uses LSP; arg = signed frame offset */ + +#define oSTS (o32|0x24) /* One 32-bit stack argument */ +#define oSTSH (o32|0x25) /* One 32-bit stack argument */ +#define oSTSB (o32|0x26) /* One 32-bit stack argument */ +#define oSTSM (o32|0x27) /* One+n 32-bit stack argument */ + +/* Load Indexed: Uses LSP; arg = signed frame offset */ + +#define oLDSX (o32|0x28) /* One 32-bit stack argument */ +#define oLDSXH (o32|0x29) /* One 32-bit stack argument */ +#define oLDSXB (o32|0x2a) /* One 32-bit stack argument */ +#define oLDSXM (o32|0x2b) /* Two 32-bit stack argument */ + +/* Store Indexed: Uses LSP; arg = signed frame offset */ + +#define oSTSX (o32|0x2c) /* Two 32-bit stack argument */ +#define oSTSXH (o32|0x2d) /* Two 32-bit stack argument */ +#define oSTSXB (o32|0x2e) /* Two 32-bit stack argument */ +#define oSTSXM (o32|0x2f) /* Two+n 32-bit stack argument */ + +/* Load address relative to stack base: arg = unsigned offset */ + +#define oLA (o32|0x30) + +/* Load address: Uses SLP, arg = signed frame offset */ + +#define oLAS (o32|0x31) /* No stack arguments */ + +/* Load absolute stack address: arg = RODATA offset (No stack arguments) */ + +#define oLAC (o32|0x32) + +/* Load address relative to stack base: arg = unsigned offset, TOS=index */ + +#define oLAX (o32|0x34) + +/* Load address indexed: Uses SLP, arg = signed frame offset */ + +#define oLASX (o32|0x35) /* No stack arguments */ + +/* Set LSP: arg = new level that evaluates to LSP value */ + +#define oSLSP (o32|0x36) + +/* Set DS: arg = new byte count in DS register */ + +#define oSDC (o32|0x37) + +/* Program Control: Uses LSP; arg = unsigned label + * (No stack arguments) + * Behavior: + * Push base address of level + * Push base register (BR) value + * Set new base register value (BR) as top of stack + * Push return address + * Set program counter (PC) for address associated with label + */ + +#define oPCAL (o32|0x39) + +/* System calls: arg = file number | sub-function code */ + +#define oSYSIO (o32|0x3a) + +/* System functions: arg = 32-bit library call identifier */ + +#define oLIB (o32|0x3b) + +/* Floating point operations: arg = FP op-code */ + +#define oFLOAT (o32|0x3c) + +/* Program control: arg = unsigned label (no stack arguments) */ + +#define oLABEL (o32|0x3d) + +/* Psuedo-operations: arg = file number OR line number */ + +#define oINCLUDE (o32|0x3e) +#define oLINE (o32|0x3f) + +#endif /* __PINSN32_H */ 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 +# +# 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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include + +#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 + * + * 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 +#include + +#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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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(§ionHeader, 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 + * + * 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 +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 ""; + } +} + +/***********************************************************************/ 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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include +#include + +#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 + * + * 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 +#include +#include + +#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 */ + +/***********************************************************************/ diff --git a/misc/pascal/nuttx/INSTALL.sh b/misc/pascal/nuttx/INSTALL.sh new file mode 100755 index 000000000..71509827f --- /dev/null +++ b/misc/pascal/nuttx/INSTALL.sh @@ -0,0 +1,143 @@ +############################################################################ +# nuttx/INSTALL.sh +# Install the pascaldirl runtime into the NuttX source tree +# +# Copyright (C) 2008 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Parse command arguments + +wd=`pwd` + +modeldir=insn16 +unset nuttxdir +while [ ! -z "$1" ]; do + case "$1" in + -d ) + set -x + ;; + -16 ) + modeldir=insn16 + ;; + -32 ) + modeldir=insn32 + ;; + -h ) + echo "USAGE: $0 [-16|-32] " + exit 0 + ;; + *) + nuttxdir=$1 + ;; + esac + shift +done + +echo "Installing model $modeldir to $nuttxdir" + +# Verify that required parameters were provided + +if [ -z "${nuttxdir}" ]; then + echo "USAGE: $0 [-16|-32] " + exit 1 +fi + +# Find the directory we were executed from and that things look sane + +myname=`basename $0` + +if [ -x ${wd}/${myname} ] ; then + pascaldir=`dirname ${wd}` +else + if [ -x ${wd}/nuttx/${myname} ] ; then + pascaldir=${wd} + else + echo "You must cd into the pascal directory to execute this script." + exit 1 + fi +fi + +if [ ! -d ${pascaldir}/${modeldir} ]; then + echo "Subdirectory ${modeldir} does not exist" + exit 1 +fi + +if [ ! -d ${nuttxdir} ]; then + echo "NuttX directory ${nuttxdir} does not exist" + exit 1 +fi + +if [ -d ${nuttxdir}/pcode ]; then + echo "${nuttxdir}/pcode already exists. Remove it and try again." + exit 1 +fi + +# Looks good enough. Create NuttX directories + +mkdir ${nuttxdir}/pcode || \ + { echo "mkdir ${nuttxdir}/pcode failed" ; exit 1 ; } + +mkdir ${nuttxdir}/pcode/include || \ + { echo "mkdir ${nuttxdir}/pcode/include failed" ; exit 1 ; } + +mkdir ${nuttxdir}/pcode/insn || \ + { echo "mkdir ${nuttxdir}/pcode/insn failed" ; exit 1 ; } + +# Copy runtime files + +cp -a ${pascaldir}/include/poff.h ${nuttxdir}/pcode/include/. || \ + { echo "Failed to copy ${pascaldir}/include/poff.h" ; exit 1; } + +cp -a ${pascaldir}/include/pofflib.h ${nuttxdir}/pcode/include/. || \ + { echo "Failed to copy ${pascaldir}/include/poff.h" ; exit 1; } + +cp -a ${pascaldir}/nuttx/Makefile ${nuttxdir}/pcode/. || \ + { echo "Failed to copy ${pascaldir}/nuttx/Makefile" ; exit 1; } + +cp -a ${pascaldir}/nuttx/keywords.h ${nuttxdir}/pcode/include/. || \ + { echo "Failed to copy ${pascaldir}/nuttx/keywords.h" ; exit 1; } + +cp -a ${pascaldir}/libpoff ${nuttxdir}/pcode/. || \ + { echo "Failed to copy ${pascaldir}/libpoff" ; exit 1; } + +rm -f ${nuttxdir}/pcode/libpoff/Makefile || \ + { echo "Failed to remove ${nuttxdir}/pcode/libpoff/Makefile" ; exit 1; } + +cp -a ${pascaldir}/${modeldir}/include ${nuttxdir}/pcode/insn/. || \ + { echo "Failed to copy ${pascaldir}/${modeldir}/include" ; exit 1; } + +cp -a ${pascaldir}/${modeldir}/prun ${nuttxdir}/pcode/insn/. || \ + { echo "Failed to copy ${pascaldir}/${modeldir}/prun" ; exit 1; } + +rm -f ${nuttxdir}/pcode/insn/Makefile || \ + { echo "Failed to remove ${nuttxdir}/pcode/insn/Makefile" ; exit 1; } + diff --git a/misc/pascal/nuttx/Makefile b/misc/pascal/nuttx/Makefile new file mode 100644 index 000000000..055e719c6 --- /dev/null +++ b/misc/pascal/nuttx/Makefile @@ -0,0 +1,89 @@ +############################################################################ +# pcode/Makefile +# +# Copyright (C) 2008 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +-include $(TOPDIR)/Make.defs + +MKDEP = $(TOPDIR)/tools/mkdeps.sh +CFLAGS += -Iinclude -Iinsn/include + +ifeq ($(CONFIG_NET),y) +include insn/Make.defs +include libpoff/Make.defs +endif + +ASRCS = $(INSN_ASRCS) $(POFF_ASRCS) +AOBJS = $(ASRCS:.S=$(OBJEXT)) + +CSRCS = $(INSN_CSRCS) $(POFF_CSRCS) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +BIN = libpcode$(LIBEXT) + +VPATH = insn:libpoff + +all: $(BIN) + +$(AOBJS): %$(OBJEXT): %.S + $(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@ + +$(COBJS): %$(OBJEXT): %.c + $(CC) -c $(CFLAGS) $< -o $@ + +$(BIN): $(OBJS) + ( for obj in $(OBJS) ; do \ + $(AR) $@ $${obj} || \ + { echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \ + done ; ) + +.depend: Makefile $(SRCS) +ifeq ($(CONFIG_NET),y) + $(MKDEP) --dep-path . --dep-path insn --dep-path liboff $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep +else + $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep +endif + touch $@ + +depend: .depend + +clean: + rm -f $(BIN) *.o *.rel *.asm *.lst *.sym *.adb *~ + +distclean: clean + rm -f Make.dep .depend + +-include Make.dep diff --git a/misc/pascal/nuttx/README.txt b/misc/pascal/nuttx/README.txt new file mode 100644 index 000000000..ca18eb830 --- /dev/null +++ b/misc/pascal/nuttx/README.txt @@ -0,0 +1,31 @@ +README.txt +^^^^^^^^^^ + +This directory contains miscellaneous files needed to install +pascal runtime logic into the NuttX source tree. After +installation, the NuttX source tree contain the following files + +pcode +|-- Makefile +|-- include +| `-- Common header files +|-- libboff +| `-- Pascal object format (POFF) library +`--insn + |-- include + | `-- model-specific header files + `-- prun + `-- model-specific source files + +This directory contains: + +INSTALL.sh -- The script that performs the operation. Usage: + + ./INSTALL.sh [-16|-32] + +Makefile -- The NuttX makefile for the runtime logic + +keywords.h -- A version that adjusts build context for the NuttX + environment. + + diff --git a/misc/pascal/nuttx/keywords.h b/misc/pascal/nuttx/keywords.h new file mode 100644 index 000000000..e8ad91461 --- /dev/null +++ b/misc/pascal/nuttx/keywords.h @@ -0,0 +1,64 @@ +/************************************************************* + * keywords.h + * This file defines the pascal compilation environment + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __KEYWORDS_H +#define __KEYWORDS_H + +/************************************************************* + * Included Files + *************************************************************/ + +#include +#include +#include + +/************************************************************* + * Definitions + *************************************************************/ + +#ifndef CONFIG_DEBUG +# define CONFIG_DEBUG 0 +#endif + +#define DEBUG(stream, format, arg...) dbg(format, ##arg) + +#ifndef CONFIG_TRACE +# define CONFIG_TRACE 0 +#endif + +#define TRACE(stream, format, arg...) dbg(format, ##arg) +#define errno *get_errno_ptr() + +#endif /* __KEYWORDS_H */