summaryrefslogtreecommitdiff
path: root/misc/pascal/include
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-01-04 22:52:02 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-01-04 22:52:02 +0000
commiteca8fc5427fae36404c8f3772f8ed4f2f36100ea (patch)
tree15ba7e23c47bc4d4b4fdc59d730c3e0eb7b03fa6 /misc/pascal/include
parent2d2c6392898b29ae89d41a779ef712fb901900ac (diff)
downloadnuttx-eca8fc5427fae36404c8f3772f8ed4f2f36100ea.tar.gz
nuttx-eca8fc5427fae36404c8f3772f8ed4f2f36100ea.tar.bz2
nuttx-eca8fc5427fae36404c8f3772f8ed4f2f36100ea.zip
Pascal
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@485 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'misc/pascal/include')
-rw-r--r--misc/pascal/include/keywords.h94
-rw-r--r--misc/pascal/include/pmach.h82
-rw-r--r--misc/pascal/include/poff.h428
-rw-r--r--misc/pascal/include/pofflib.h316
4 files changed, 920 insertions, 0 deletions
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 <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *************************************************************/
+
+#ifndef __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 <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ***************************************************************************/
+
+#ifndef __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 <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ***************************************************************************/
+
+#ifndef __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 */