Resync new repository with old repo r5166

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-09-17 18:18:44 +00:00
commit 57623d42eb
5691 changed files with 1361853 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
/*************************************************************
* keywords.h
* This file defines the pascal compilation environment
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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"
/*************************************************************
*Pre-processor Definitions
*************************************************************/
#ifndef NULL
# define NULL ((void*)0)
#endif
#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__)
#endif /* __KEYWORDS_H */
+90
View File
@@ -0,0 +1,90 @@
/***************************************************************************
* include/paslib.h
* External Declarations associated with paslib
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 __PASLIB_H
#define __PASLIB_H
/***************************************************************************
* Included Files
***************************************************************************/
#include "keywords.h"
#include "stdint.h"
#include "stdbool.h"
#include "pdefs.h"
#include "pofflib.h"
/***************************************************************************
* Global Function Prototypes
***************************************************************************/
/* POFF file is always big-endian */
#ifdef CONFIG_ENDIAN_BIG
# undef CONFIG_POFF_SWAPNEEDED
# define poff16(val) (val)
# define poff32(val) (val)
#else
# define CONFIG_POFF_SWAPNEEDED 1
# define poff16(val) poffSwap16(val)
# define poff32(val) poffSwap32(val)
#endif
/***************************************************************************
* Global Function Prototypes
***************************************************************************/
/* File name extension helper */
extern bool extension(const char *inName, const char *ext, char *outName,
bool force_default);
/* Math helpers */
extern int32_t signExtend16(uint16_t arg16);
extern int32_t signExtend25(uint32_t arg25);
/* Endian-ness helpers */
extern uint16_t poffSwap16(uint16_t val);
extern uint32_t poffSwap32(uint32_t val);
/***************************************************************************
* Global Variables
***************************************************************************/
#endif /* __PASLIB_H */
+115
View File
@@ -0,0 +1,115 @@
/***********************************************************************
* include/pdefs.h
* Common definitions
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 __PDEFS_H
#define __PDEFS_H
/***********************************************************************
* Included Files
***********************************************************************/
#include <stdint.h>
#include <stdio.h> /* for FILE */
#include "config.h"
/***********************************************************************
* Pre-processor Definitions
***********************************************************************/
/* Common Sizing Parameters */
#define FNAME_SIZE 40 /* Max size file name */
#define LINE_SIZE 256 /* Max size of input line buffer */
/* Target P-Machine Data Storage Sizes */
#ifdef CONFIG_INSN16
# define sINT_SIZE 2
# define MAXINT 32767
# define MININT -32768
# define BITS_IN_INTEGER 16
# define MAXUINT 0xffff
# define MINUINT 0
#endif
#ifdef CONFIG_INSN32
# define sINT_SIZE 4
# define MAXINT 2147483647
# define MININT -2147483648
# define BITS_IN_INTEGER 32
# define MAXUINT 0xffffffff
# define MINUINT 0
#endif
#define sCHAR_SIZE 1
#define sBOOLEAN_SIZE sINT_SIZE
#define sREAL_SIZE 8
#define sPTR_SIZE sINT_SIZE
#define sRETURN_SIZE (3*sPTR_SIZE)
#define sSTRING_HDR_SIZE 2
#define sSTRING_SIZE 256 /* size(2) + string(255) */
#define sSTRING_MAX_SIZE (sSTRING_SIZE - 2) /* string storage size(254) */
#define sRSTRING_SIZE (sPTR_SIZE + sINT_SIZE) /* ptr + size */
#define sCSTRING_SIZE (sizeof(void*)) /* absolute C pointer */
#define MAXCHAR 255
#define MINCHAR 0
/***********************************************************************
* Public Structure/Types
***********************************************************************/
/* Representation of one P-Code */
#ifdef CONFIG_INSN16
typedef struct P
{
uint8_t op;
uint8_t arg1;
uint16_t arg2;
} OPTYPE;
#endif
#ifdef CONFIG_INSN32
typedef struct P
{
uint8_t op;
uint32_t arg;
} OPTYPE;
#endif
#endif /* __PDEFS_H */
+280
View File
@@ -0,0 +1,280 @@
/***********************************************************************
* pedefs.h
* Definitions of error codes
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 __PEDEFS_H
#define __PEDEFS_H
/***********************************************************************
* Included Files
***********************************************************************/
#include <stdint.h>
/***********************************************************************
* Pre-processor Definitions
***********************************************************************/
/***********************************************************************
* COMPILATION TIME ERRORS
* eASSIGN Expected ':='
* eBEGIN Expected 'BEGIN'
* eCOLON Expected ':'
* eCOMMA Expected ','
* eCOUNT Error count exceeded (FATAL)
* eDO Expected 'DO'
* eDUPFILE Attempt to re-define file
* eDUPSYM Attempt to declare duplicate symbol
* eEND Expected 'END'
* eEQ Expected '='
* eEXPONENT Error in exponent of real constant
* eFILE Expected file identifier declared in PROGRAM
* eHUH Internal error (FATAL)
* eIDENT Expected identifier
* eIMPLEMENTATION Expected implementation section in unit file
* eINCLUDE Include file OPEN error (FATAL)
* eINTCONST Expected integer constant
* eINTERFACE Expected interface section in unit file
* eINTOVF Integer overflow (or underflow)
* eINTVAR Integer variable name expected
* eINVALIDFUNC Unrecognized built-in function
* eINVALIDPROC Unrecognized built-in procedure
* eINVARG Invalid procedure/function argument type
* eINVCONST Invalid constant in declaration
* eINVSIGNEDCONST Invalid constant after sign
* eINVFACTOR Invalid factor
* eINVFILE Invalid file identifier (as declared in PROGRAM)
* eINVLABEL Invalid label
* eINVPTR Invalid pointer type
* eINVTYPE Invalid type identifier
* eINVVARPARM Invalid/unsupported VAR parameter type
* eLBRACKET Expected '['
* eLPAREN Expected '('
* eMULTLABEL Attempt to multiply define label
* eNOSQUOTE EOL encounter in a string, probable missing "'"
* eNOTYET Not implemented yet
* eNPARMS Number of parameters in function or procedure
* call does not match number in declaration
* eOF Expected 'OF'
* eOVF Internal table overflow (FATAL)
* ePERIOD Expected '.'
* ePOFFCONFUSION Internal logic error in POFF file generation
* ePOFFWRITEERROR Error writing to POFF file
* ePROGRAM Expected 'PROGRAM'
* ePTRADR Expected pointer address (probably got value) form
* ePTRVAL Expected pointer value form, got value form
* eRBRACKET Expected ']'
* eRPAREN Expected ')'
* eRPARENorCOMMA Expected ')' or ','
* eSEEKFAIL Seek to file position failed
* eSEMICOLON Expected ';'
* eSTRING Expected a string
* eTHEN Expected 'THEN'
* eTOorDOWNTO Expected 'TO' or 'DOWNTO' in for statement
* eTRUNC String truncated
* eUNDECLABEL Attempt to define an undeclared label.
* eUNDEFILE Undefined file buffer
* eUNDEFLABEL A declared label was not defined.
* eUNDEFSYM Undefined symbol
* eUNTIL Expected 'UNTIL'
* eEXPRTYPE Illegal expression type for this operation
* eTERMTYPE Illegal term type for this operation
* eFACTORTYPE Illegal factor type for this operation
* eREADPARM Illegal parameter in READ statement
* eWRITEPARM Illegal parameter in WRITE statement
* eARRAYTYPE Illegal type for ARRAY OF
* ePOINTERTYPE Illegal pointer type
* eVARPARMTYPE Illegal VAR parameter type
* eSUBRANGE Expected ".."
* eSUBRANGETYPE Illegal subrange type
* eSET Expected valid/consistent type for SET OF
* sSETRANGE Value out of range for SET OF
* eSCALARTYPE Illegal scalar type
* eBADSHORTINT Short integer is out of range
* eSYMTABINTERNAL Internal error in symbol table
* eRECORDDECLARE Error in RECORD declaration
* eRECORDOBJECT Expected a field of RECORD
* eRECORDVAR Expected a RECORD variable in WITH
* eUNIT Expected UNIT at beginning of unit file
* eUNITNAME File does not contain the expected UNIT
* eARGIGNORED An argument was provided, but ignored
*
* LINK TIME ERRORS
* eUNDEFINEDSYMBOL A necessary symbol was not defined
* eMULTIDEFSYMBOL A symbol was defined multiple times
*
* ERRORS WHICH MAY OCCUR AT EITHER COMPILATION, LINK OR RUNTIME
* eNOMEMORY Memory allocation failed
* ePOFFREADERROR Error reading a POFF file
* ePOFFBADFORMAT The file format does not like valid POFF
* eRCVDSIGNAL Received SIGSEGV (or other) signal.
*
* RUN TIME ERRORS
* eBADPC Program Counter is out-of-range
* eBADSP Stack reference is out-of-range
* eSTRSTKOVERFLOW String stack overflow
* eILLEGALOPCODE Non-executable instruction found
* eEXIT oEND P-Code encountered
* eBADSYSIOFUNC Illegal SYSIO sub-function
* eBADSYSLIBCALL Illegal runtime library call
* eBADFPOPCODE Illegal FLOAT POINT op-code
* eFAILEDLIBCALL Runtime library call returned failure
* eINTEGEROVERFLOW Integer overflow
**********************************************************************/
/* This is the error code that indicates that no error has occurred */
#define eNOERROR ((uint16_t) 0x00)
/* This is the maximum number of errors that will be reported before
* compilation is terminated.
*/
#define MAX_ERRORS 100
/* COMPILATION TIME ERRORS */
#define eASSIGN ((uint16_t) 0x01)
#define eBEGIN ((uint16_t) 0x02)
#define eCOLON ((uint16_t) 0x03)
#define eCOMMA ((uint16_t) 0x04)
#define eCOUNT ((uint16_t) 0x05)
#define eDO ((uint16_t) 0x06)
#define eDUPFILE ((uint16_t) 0x07)
#define eDUPSYM ((uint16_t) 0x08)
#define eEND ((uint16_t) 0x09)
#define eEQ ((uint16_t) 0x0a)
#define eEXPONENT ((uint16_t) 0x0b)
#define eFILE ((uint16_t) 0x0c)
#define eHUH ((uint16_t) 0x0d)
#define eIDENT ((uint16_t) 0x0e)
#define eIMPLEMENTATION ((uint16_t) 0x0f)
#define eINCLUDE ((uint16_t) 0x10)
#define eINTCONST ((uint16_t) 0x11)
#define eINTERFACE ((uint16_t) 0x12)
#define eINTOVF ((uint16_t) 0x13)
#define eINTVAR ((uint16_t) 0x14)
#define eINVALIDFUNC ((uint16_t) 0x15)
#define eINVALIDPROC ((uint16_t) 0x16)
#define eINVARG ((uint16_t) 0x17)
#define eINVCONST ((uint16_t) 0x18)
#define eINVSIGNEDCONST ((uint16_t) 0x19)
#define eINVFACTOR ((uint16_t) 0x1a)
#define eINVFILE ((uint16_t) 0x1b)
#define eINVLABEL ((uint16_t) 0x1c)
#define eINVPTR ((uint16_t) 0x1d)
#define eINVTYPE ((uint16_t) 0x1e)
#define eINVVARPARM ((uint16_t) 0x1f)
#define eLBRACKET ((uint16_t) 0x20)
#define eLPAREN ((uint16_t) 0x21)
#define eMULTLABEL ((uint16_t) 0x22)
#define eNOSQUOTE ((uint16_t) 0x23)
#define eNOTYET ((uint16_t) 0x24)
#define eNPARMS ((uint16_t) 0x25)
#define eOF ((uint16_t) 0x26)
#define eOVF ((uint16_t) 0x27)
#define ePERIOD ((uint16_t) 0x28)
#define ePOFFCONFUSION ((uint16_t) 0x29)
#define ePOFFWRITEERROR ((uint16_t) 0x2a)
#define ePROGRAM ((uint16_t) 0x2b)
#define ePTRADR ((uint16_t) 0x2c)
#define ePTRVAL ((uint16_t) 0x2d)
#define eRBRACKET ((uint16_t) 0x2e)
#define eRPAREN ((uint16_t) 0x2f)
#define eRPARENorCOMMA ((uint16_t) 0x30)
#define eSEEKFAIL ((uint16_t) 0x31)
#define eSEMICOLON ((uint16_t) 0x32)
#define eSTRING ((uint16_t) 0x33)
#define eTHEN ((uint16_t) 0x34)
#define eTOorDOWNTO ((uint16_t) 0x35)
#define eTRUNC ((uint16_t) 0x36)
#define eUNDECLABEL ((uint16_t) 0x37)
#define eUNDEFILE ((uint16_t) 0x38)
#define eUNDEFLABEL ((uint16_t) 0x39)
#define eUNDEFSYM ((uint16_t) 0x3a)
#define eUNTIL ((uint16_t) 0x3b)
#define eEXPRTYPE ((uint16_t) 0x3c)
#define eTERMTYPE ((uint16_t) 0x3d)
#define eFACTORTYPE ((uint16_t) 0x3e)
#define eREADPARM ((uint16_t) 0x3f)
#define eWRITEPARM ((uint16_t) 0x40)
#define eARRAYTYPE ((uint16_t) 0x41)
#define ePOINTERTYPE ((uint16_t) 0x42)
#define eVARPARMTYPE ((uint16_t) 0x43)
#define eSUBRANGE ((uint16_t) 0x44)
#define eSUBRANGETYPE ((uint16_t) 0x45)
#define eSET ((uint16_t) 0x46)
#define eSETRANGE ((uint16_t) 0x47)
#define eSCALARTYPE ((uint16_t) 0x48)
#define eBADSHORTINT ((uint16_t) 0x49)
#define eSYMTABINTERNAL ((uint16_t) 0x4a)
#define eRECORDDECLARE ((uint16_t) 0x4b)
#define eRECORDOBJECT ((uint16_t) 0x4c)
#define eRECORDVAR ((uint16_t) 0x4d)
#define eUNIT ((uint16_t) 0x4e)
#define eUNITNAME ((uint16_t) 0x4f)
#define eARGIGNORED ((uint16_t) 0x50)
/* LINK TIME ERRORS */
#define eUNDEFINEDSYMBOL ((uint16_t) 0x60)
#define eMULTIDEFSYMBOL ((uint16_t) 0x61)
/* ERRORS WHICH MAY OCCUR AT EITHER COMPILATION OR RUNTIME */
#define eNOMEMORY ((uint16_t) 0x70)
#define ePOFFREADERROR ((uint16_t) 0x71)
#define ePOFFBADFORMAT ((uint16_t) 0x72)
#define eRCVDSIGNAL ((uint16_t) 0x73)
/* RUN TIME ERRORS */
#define eBADPC ((uint16_t) 0x80)
#define eBADSP ((uint16_t) 0x81)
#define eSTRSTKOVERFLOW ((uint16_t) 0x82)
#define eILLEGALOPCODE ((uint16_t) 0x83)
#define eEXIT ((uint16_t) 0x84)
#define eBADSYSIOFUNC ((uint16_t) 0x85)
#define eBADSYSLIBCALL ((uint16_t) 0x86)
#define eBADFPOPCODE ((uint16_t) 0x87)
#define eINTEGEROVERFLOW ((uint16_t) 0x89)
#define eFAILEDLIBCALL ((uint16_t) 0x90)
#endif /* __PEDEFS_H */
+56
View File
@@ -0,0 +1,56 @@
/**********************************************************************
* perr.h
* External Declarations associated with perr.c
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 __PERR_H
#define __PERR_H
/***********************************************************************
* Included Files
***********************************************************************/
#include <stdint.h>
/***********************************************************************
* Public Function Prototypes
***********************************************************************/
extern void errmsg(char *fmt, ...);
extern void warn(uint16_t errcode);
extern void error(uint16_t errcode);
extern void fatal(uint16_t errcode);
#endif /* __PERR_H */
+93
View File
@@ -0,0 +1,93 @@
/***********************************************************************
* pfdefs.h
* Floating point operation codes
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 __PFDEFS_H
#define __PFDEFS_H
/***********************************************************************
* FLOATING POINT SUB-OPCODES
***********************************************************************/
/* This bit may be set in the opcode to indicate that the arguments
* is(are) type integer and require(s) conversion. */
#define fpARG1 (0x40)
#define fpARG2 (0x80)
#define fpMASK (0x3f)
#define fpSHIFT 6
/* The "INVALID" floating point operation */
#define fpINVLD (0x00)
/* Floating Pointer Conversions (On 16-bit stack argument: FP or Integer) */
#define fpFLOAT (0x01)
#define fpTRUNC (0x02)
#define fpROUND (0x03)
/* Floating Point arithmetic instructions (Two FP 16-bit stack arguments) */
#define fpADD (0x04)
#define fpSUB (0x05)
#define fpMUL (0x06)
#define fpDIV (0x07)
#define fpMOD (0x08)
/* Floating Point Comparisons (Two FP 16-bit stack arguments) */
#define fpEQU (0x0a)
#define fpNEQ (0x0b)
#define fpLT (0x0c)
#define fpGTE (0x0d)
#define fpGT (0x0e)
#define fpLTE (0x0f)
/* Floating Point arithmetic instructions (One FP 16-bit stack arguments) */
#define fpNEG (0x10)
#define fpABS (0x11)
#define fpSQR (0x12)
#define fpSQRT (0x13)
#define fpSIN (0x14)
#define fpCOS (0x15)
#define fpATAN (0x16)
#define fpLN (0x17)
#define fpEXP (0x18)
#define MAX_FOP (0x19) /* Number of floating point operations */
#endif /* __PFDEFS_H */
+82
View File
@@ -0,0 +1,82 @@
/***************************************************************************
* pinsn.h
* External Declarations associated libinsn.a
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 __PINSN_H
#define __PINSN_H
/***************************************************************************
* Included Files
***************************************************************************/
#include <stdint.h>
/***************************************************************************
* Global Function Prototypes
***************************************************************************/
/* Opcode generators */
extern void insn_GenerateSimple(enum pcode_e opcode);
extern void insn_GenerateDataOperation(enum pcode_e opcode, int32_t data);
extern void insn_GenerateDataSize(uint32_t dwDataSize);
extern void insn_GenerateFpOperation(uint8_t fpOpcode);
extern void insn_GenerateIoOperation(uint16_t ioOpcode, uint16_t fileNumber);
extern void insn_BuiltInFunctionCall(uint16_t libOpcode);
extern void insn_GenerateLevelReference(enum pcode_e opcode, uint16_t level,
int32_t offset);
extern void insn_GenerateProcedureCall(uint16_t level, int32_t offset);
extern void insn_GenerateLineNumber(uint16_t includeNumber, uint32_t lineNumber);
extern void insn_SetStackLevel(uint32_t level);
/* Opcode relocation */
extern int insn_Relocate(OPTYPE *op, uint32_t pcOffset, uint32_t roOffset);
extern void insn_FixupProcedureCall(uint8_t *progData, uint32_t symValue);
/* POFF-wrapped INSNS access helpers */
extern uint32_t insn_GetOpCode(poffHandle_t handle, OPTYPE *ptr);
extern void insn_ResetOpCodeRead(poffHandle_t handle);
extern void insn_AddOpCode(poffHandle_t handle, OPTYPE *ptr);
extern void insn_ResetOpCodeWrite(poffHandle_t handle);
extern void insn_AddTmpOpCode(poffProgHandle_t progHandle, OPTYPE *ptr);
extern void insn_ResetTmpOpCodeWrite(poffProgHandle_t progHandle);
/* INSN-specific disassembler */
extern void insn_DisassemblePCode(FILE* lfile, OPTYPE *pop);
#endif /* __PINSN_H */
+204
View File
@@ -0,0 +1,204 @@
/***********************************************************************
* podefs.h
* Logical P-code operation code definitions
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 __PODEFS_H
#define __PODEFS_H
/* These definitions represent logical operations as needed by the
* the compiler. The specific INSN generation layer must interpret
* these requests as is appropriate to the supported INSNS.
*/
enum pcode_e
{
/**-------------------------------------------------------------------
* OPCODES WITH NO ARGUMENTS
**-------------------------------------------------------------------**/
/* Program control (No stack arguments) */
opNOP = 0,
/* Arithmetic & logical & and integer conversions (One stack argument) */
opNEG, opABS, opINC, opDEC, opNOT,
/* Arithmetic & logical (Two stack arguments) */
opADD, opSUB, opMUL, opDIV, opMOD, opSLL, opSRL, opSRA, opOR, opAND,
/* Comparisons (One stack argument) */
opEQUZ, opNEQZ, opLTZ, opGTEZ, opGTZ, opLTEZ,
/* Comparisons (Two stack arguments) */
opEQU, opNEQ, opLT, opGTE, opGT, opLTE,
opBIT,
/* Load Immediate */
opLDI, opLDIB, opLDIM,
/* Store Immediate */
opSTI, opSTIB, opSTIM,
/* Data stack */
opDUP, opPUSHS, opPOPS,
/* 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
*/
opRET,
/* System Functions (No stack arguments) */
opEND,
/**-------------------------------------------------------------------
** OPCODES WITH ONE ARGUMENT
**-------------------------------------------------------------------**/
/* Floating point operations: arg = FP op-code */
opFLOAT,
/* Program control: arg = unsigned label (One stack argument) */
opJEQUZ, opJNEQZ,
/* Program control: arg = unsigned label (no stack arguments) */
opJMP,
/* Program control: arg = unsigned label (One stack argument) */
opJEQU, opJNEQ, opJLT, opJGTE, opJGT, opJLTE,
/* Load: arg = unsigned base offset */
opLD, opLDH, opLDB, opLDM,
/* Store: arg = unsigned base offset */
opST, opSTB, opSTM,
/* Load Indexed: arg = unsigned base offset */
opLDX, opLDXB, opLDXM,
/* Store Indexed: arg16 = unsigned base offset */
opSTX, opSTXB, opSTXM,
/* Load address relative to stack base: arg = unsigned offset */
opLA,
/* Load absolute stack address: arg = RODATA offset (No stack arguments) */
opLAC,
/* Data stack: arg = 16 bit signed data (no stack arguments) */
opPUSH, opINDS,
/* Load address relative to stack base: arg1 = unsigned offset, TOS=index */
opLAX,
/* System functions: arg = 16-bit library call identifier */
opLIB,
/* Program control: arg = unsigned label (no stack arguments) */
opLABEL,
/**-------------------------------------------------------------------
** OPCODES WITH TWO ARGUMENTS
**-------------------------------------------------------------------**/
/* Program Control: arg1 = level; arg2 = unsigned label */
opPCAL,
/* Load: arg1 = level; arg2 = signed frame offset */
opLDS, opLDSH, opLDSB, opLDSM,
/* Store: arg1 = level; arg2 = signed frame offset */
opSTS, opSTSB, opSTSM,
/* Load Indexed: arg1 = level; arg2 = signed frame offset */
opLDSX, opLDSXB, opLDSXM,
/* Store Indexed: arg1 = level; arg2 = signed frame offset */
opSTSX, opSTSXB, opSTSXM,
/* FOR LAS/LASX arg1 = level; arg2 = signed frame offset
* (no stack arguments)
*/
opLAS, opLASX,
/* System calls:
* For SYSIO: arg1 = file number; arg2 = sub-function code
*/
opSYSIO,
/* Pseudo-operations:
* For LINE: arg1 = file number; arg2 = line number
*/
opLINE,
NUM_OPCODES
};
#endif /* __PODEFS_H */
+429
View File
@@ -0,0 +1,429 @@
/***************************************************************************
* poff.h
* Definitions for the PCode Object File Format (POFF)
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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
/***************************************************************************
* Included Files
***************************************************************************/
#include <stdint.h>
#include "keywords.h"
#include "config.h"
/***************************************************************************
* Pre-processor 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_t)(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.
*/
uint8_t fh_ident[FHI_NIDENT];
/* fh_version holds the version of the POFF file format. This should
* always be FHV_CURRENT.
*/
uint8_t fh_version;
/* fh_type holds the type of binary carry by the POFF file.
* See the FHT_ definitions above.
*/
uint8_t fh_type;
/* fh_arch holds the mach architecture identifier. See the FHA_
* definitions above.
*/
uint8_t fh_arch;
/* Pad so that the next field is aligned */
uint8_t fh_padding;
/* fh_shsize is the size a section header. This should be
* sizeof(poffSectionHeader_t)
*/
uint16_t 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_t 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_t 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_t 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_t 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.
*/
uint8_t sh_type;
/* These flags describe the characteristics of the section. See the
* SHF_ definitions above.
*/
uint8_t 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_t sh_entsize;
/* sh_name is an offset into the string table section data.
* It refers to a name associated with section.
*/
uint32_t 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_t sh_addr;
/* sh_offset is the offset from the beginning of the file to
* beginning of data associated with this section.
*/
uint32_t 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_t 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_t 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_t 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.
*/
uint8_t 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.
*/
uint8_t st_align;
/* These flags describe the characteristics of the symbol. See the
* STF_ definitions above.
*/
uint8_t st_flags;
uint8_t st_pad;
/* st_name is an offset into the string table section data.
* It refers to a name associated with symbol.
*/
uint32_t 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_t st_value;
/* For data section symbols, this is the size of the initialized
* data region associated with the symbol.
*/
uint32_t 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_t 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_t 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_t 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_t 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_t df_value;
/* This is the size of the value returned by the function in
* bytes (zero for procedures).
*/
uint32_t df_size;
/* This is the number of parameters accepted by the function/
* procedure.
*/
uint32_t 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 paramter */
uint32_t da_size;
};
typedef struct poffDebugArgInfo_s poffDebugArgInfo_t;
#endif /* __POFF_H */
+313
View File
@@ -0,0 +1,313 @@
/***************************************************************************
* pofflib.h
* Interfaces to the POFF library
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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
/***************************************************************************
* Included Files
***************************************************************************/
#include <stdint.h>
#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.
*/
uint8_t 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
*/
uint8_t align;
/* These flags describe the characteristics of the symbol. See the
* STF_ definitions above.
*/
uint8_t 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_t value;
/* For data section symbols, this is the size of the initialized
* data region associated with the symbol.
*/
uint32_t 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_t 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_t 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_t value;
/* This is the size of the value returned by the function in
* bytes (zero for procedures).
*/
uint32_t retsize;
/* This is the number of parameters accepted by the function/
* procedure.
*/
uint32_t nparms;
/* This is the beginning of a table of input parameter sizes
* the actually allocate size will be nparms entries.
*/
uint32_t argsize[1];
};
typedef struct poffLibDebugFuncInfo_s poffLibDebugFuncInfo_t;
#define SIZEOFDEBUFINFO(n) (sizeof(poffLibDebugFuncInfo_t) + ((n)-1)*sizeof(uint32_t))
/***************************************************************************
* 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, uint8_t fh_type,
uint16_t nfiles, const char *name);
extern void poffSetArchitecture(poffHandle_t handle, uint8_t fh_arch);
extern void poffSetEntryPoint(poffHandle_t handle, uint32_t entryPoint);
extern int32_t poffFindString(poffHandle_t handle, const char *string);
extern uint32_t poffAddString(poffHandle_t handle, const char *string);
extern uint32_t poffAddFileName(poffHandle_t handle, const char *name);
extern void poffAddProgByte(poffHandle_t handle, uint8_t progByte);
#if 0 /* not used */
extern uint32_t poffAddRoDataByte(poffHandle_t handle, uint8_t dataByte);
#endif
extern uint32_t poffAddRoDataString(poffHandle_t handle,
const char *string);
extern uint32_t poffAddSymbol(poffHandle_t handle,
poffLibSymbol_t *symbol);
extern uint32_t poffAddLineNumber(poffHandle_t handle,
uint16_t lineNumber, uint16_t fileNumber,
uint32_t progSectionDataOffset);
extern uint32_t poffAddDebugFuncInfo(poffHandle_t handle,
poffLibDebugFuncInfo_t *pContainer);
extern uint32_t poffAddRelocation(poffHandle_t handle,
uint8_t relocType, uint32_t symIndex,
uint32_t sectionDataOffset);
extern void poffWriteFile(poffHandle_t handle, FILE *poffFile);
/* Functions to manage reading a POFF file */
extern uint16_t poffReadFile(poffHandle_t handle, FILE *poffFile);
extern uint8_t poffGetFileType(poffHandle_t handle);
extern uint8_t poffGetArchitecture(poffHandle_t handle);
extern uint32_t poffGetEntryPoint(poffHandle_t handle);
extern const char *poffGetFileHdrName(poffHandle_t handle);
extern uint32_t poffGetRoDataSize(poffHandle_t handle);
extern int32_t poffGetFileName(poffHandle_t handle, const char **fname);
extern int poffGetProgByte(poffHandle_t handle);
extern int32_t poffGetSymbol(poffHandle_t handle,
poffLibSymbol_t *symbol);
extern const char *poffGetString(poffHandle_t handle, uint32_t index);
extern int32_t poffGetLineNumber(poffHandle_t handle,
poffLibLineNumber_t *lineno);
extern int32_t poffGetRawLineNumber(poffHandle_t handle,
poffLineNumber_t *lineno);
extern int32_t poffGetRawRelocation(poffHandle_t handle,
poffRelocation_t *reloc);
extern poffLibDebugFuncInfo_t *poffGetDebugFuncInfo(poffHandle_t handle);
extern poffLibDebugFuncInfo_t *poffCreateDebugInfoContainer(uint32_t nparms);
extern void poffReleaseDebugFuncContainer(poffLibDebugFuncInfo_t *pDebugFuncInfo);
extern void poffDiscardDebugFuncInfo(poffHandle_t handle);
extern int32_t poffProgTell(poffHandle_t handle);
extern int poffProgSeek(poffHandle_t handle, uint32_t offset);
extern uint32_t 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_t poffAddTmpProgByte(poffProgHandle_t handle,
uint8_t progByte);
extern uint16_t poffWriteTmpProgBytes(uint8_t *buffer, uint32_t 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_t 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_t poffExtractProgramData(poffHandle_t handle,
uint8_t **progData);
extern void poffInsertProgramData(poffHandle_t handle,
uint8_t *progData, uint32_t progSize);
extern uint32_t poffExtractRoData(poffHandle_t handle,
uint8_t **roData);
extern void poffAppendRoData(poffHandle_t handle,
uint8_t *roData, uint32_t 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_t label, uint32_t pc);
extern void poffAddToUndefinedLabelTable(uint32_t label,
uint32_t symIndex);
extern int poffGetSymIndexForUndefinedLabel(uint32_t label);
extern int poffGetPcForDefinedLabel(uint32_t label);
extern void poffReleaseLabelReferences(void);
/* Helper functions for line numbers */
extern void poffReadLineNumberTable(poffHandle_t handle);
extern poffLibLineNumber_t *poffFindLineNumber(uint32_t offset);
extern void poffReleaseLineNumberTable(void);
/* Helper functions for debug information */
extern void poffReadDebugFuncInfoTable(poffHandle_t handle);
extern poffLibDebugFuncInfo_t *poffFindDebugFuncInfo(uint32_t offset);
extern void poffReplaceDebugFuncInfo(poffHandle_t handle);
extern void poffReleaseDebugFuncInfoTable(void);
#endif /* __POFFLIB_H */
+232
View File
@@ -0,0 +1,232 @@
/***********************************************************************
* pxdefs.h
* Definitions of the arguments of the oSYSIO opcode
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 __PXDEFS_H
#define __PXDEFS_H
/***********************************************************************/
/* Codes for system IO calls associated with standard Pascal procedure
* and function calls. These must be confined to the range 0x0000
* through 0xffff.
*/
#define xEOF (0x0001)
#define xEOLN (0x0002)
#define xRESET (0x0003)
#define xREWRITE (0x0004)
#define xREADLN (0x0010)
#define xREAD_PAGE (0x0011)
#define xREAD_BINARY (0x0012)
#define xREAD_INT (0x0013)
#define xREAD_CHAR (0x0014)
#define xREAD_STRING (0x0015)
#define xREAD_REAL (0x0016)
#define xWRITELN (0x0020)
#define xWRITE_PAGE (0x0021)
#define xWRITE_BINARY (0x0022)
#define xWRITE_INT (0x0023)
#define xWRITE_CHAR (0x0024)
#define xWRITE_STRING (0x0025)
#define xWRITE_REAL (0x0026)
#define MAX_XOP (0x0027)
/***********************************************************************/
/* Codes for runtime library interfaces. These must be confined to the
* range 0x0000 through 0xffff.
*/
/* Get an environment string.
* function getent(name : string) : cstring;
* ON INPUT:
* TOS(0)=length of string
* TOS(1)=pointer to string
* ON RETURN: actual parameters released
* TOS(0,1)=32-bit absolute address of string
*/
#define lbGETENV (0x0000)
/* Copy pascal string to a pascal string
* procedure str2str(src : string; var dest : string)
* ON INPUT:
* TOS(0)=address of dest string
* TOS(1)=length of source string
* TOS(2)=pointer to source string
* ON RETURN: actual parameters released.
*/
#define lbSTR2STR (0x0001)
/* Copy C string to a pascal string
* procedure cstr2str(src : cstring; var dest : string)
* ON INPUT:
* TOS(0)=address of dest string
* TOS(1,2)=32-bit absolute address of C string
* ON RETURN: actual parameters released
*/
#define lbCSTR2STR (0x0002)
/* Copy pascal string to a pascal string reference
* procedure str2rstr(src : string; var dest : rstring)
* ON INPUT:
* TOS(0)=address of dest string reference
* TOS(1)=length of source string
* TOS(2)=pointer to source string
* ON RETURN: actual parameters released.
*/
#define lbSTR2RSTR (0x0003)
/* Copy C string to a pascal string reference
* procedure cstr2str(src : cstring; var dest : string)
* ON INPUT:
* TOS(0)=address of dest string reference
* TOS(0)=MS 16-bits of 32-bit C source string pointer
* TOS(1)=LS 16-bits of 32-bit C source string pointer
* ON RETURN: actual parameters released
*/
#define lbCSTR2RSTR (0x0004)
/* 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(0)=address of Code
* TOS(1)=address of v
* TOS(2)=length of source string
* TOS(3)=pointer to source string
* ON RETURN: actual parameters released
*/
#define lbVAL (0x0005)
/* Create an empty string
* function mkstk : string;
* ON INPUT
* ON RETURN
* TOS(0)=length of new string
* TOS(1)=pointer to new string
*/
#define lbMKSTK (0x0006)
/* Replace a string with a duplicate string residing in allocated
* string stack.
* function mkstkstr(name : string) : string;
* ON INPUT
* TOS(0)=length of original string
* TOS(1)=pointer to original string
* ON RETURN
* TOS(0)=length of new string
* TOS(1)=pointer to new string
*/
#define lbMKSTKSTR (0x0007)
/* Replace a character with a string residing in allocated string stack.
* function mkstkc(c : char) : string;
* ON INPUT
* TOS(0)=Character value
* ON RETURN
* TOS(0)=length of new string
* TOS(1)=pointer to new string
*/
#define lbMKSTKC (0x0008)
/* Concatenate a string to the end of a string.
* function strcat(name : string, c : char) : string;
* ON INPUT
* TOS(0)=length of string
* TOS(1)=pointer to string
* TOS(2)=length of string
* TOS(3)=pointer to string
* ON OUTPUT
* TOS(1)=new length of string
* TOS(2)=pointer to string
*/
#define lbSTRCAT (0x0009)
/* Concatenate a character to the end of a string.
* function strcatc(name : string, c : char) : string;
* ON INPUT
* TOS(0)=character to concatenate
* TOS(1)=length of string
* TOS(2)=pointer to string
* ON OUTPUT
* TOS(1)=new length of string
* TOS(2)=pointer to string
*/
#define lbSTRCATC (0x000a)
/* Compare two pascal strings
* function strcmp(name1 : string, name2 : string) : integer;
* ON INPUT
* TOS(1)=length of string2
* TOS(2)=address of string2 data
* TOS(3)=length of string1
* TOS(4)=address of string1 data
* ON OUTPUT
* TOS(0)=(-1=less than, 0=equal, 1=greater than}
*/
#define lbSTRCMP (0x000b)
#define MAX_LBOP (0x000c)
#endif /* __PXDEFS_H */