diff options
35 files changed, 5420 insertions, 5382 deletions
diff --git a/misc/pascal/libpoff/pfdbgcontainer.c b/misc/pascal/libpoff/pfdbgcontainer.c index 15057745b3..d5eb03c271 100644 --- a/misc/pascal/libpoff/pfdbgcontainer.c +++ b/misc/pascal/libpoff/pfdbgcontainer.c @@ -1,105 +1,106 @@ -/**********************************************************************
- * pfrdbgcontainer.c
- * Create/destroy debug info container.
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-poffLibDebugFuncInfo_t *poffCreateDebugInfoContainer(uint32 nparms)
-{
- poffLibDebugFuncInfo_t *pDebugFuncInfo;
- int wAllocSize = SIZEOFDEBUFINFO(nparms);
-
- pDebugFuncInfo = (poffLibDebugFuncInfo_t*)malloc(wAllocSize);
- if (!pDebugFuncInfo)
- {
- fatal(eNOMEMORY);
- return NULL;
- }
-
- memset(pDebugFuncInfo, 0, wAllocSize);
- return pDebugFuncInfo;
-}
-
-/***********************************************************************/
-
-void poffReleaseDebugFuncContainer(poffLibDebugFuncInfo_t *pDebugFuncInfo)
-{
- if (pDebugFuncInfo)
- {
- free(pDebugFuncInfo);
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrdbgcontainer.c + * Create/destroy debug info container. + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ + +poffLibDebugFuncInfo_t *poffCreateDebugInfoContainer(uint32_t nparms) +{ + poffLibDebugFuncInfo_t *pDebugFuncInfo; + int wAllocSize = SIZEOFDEBUFINFO(nparms); + + pDebugFuncInfo = (poffLibDebugFuncInfo_t*)malloc(wAllocSize); + if (!pDebugFuncInfo) + { + fatal(eNOMEMORY); + return NULL; + } + + memset(pDebugFuncInfo, 0, wAllocSize); + return pDebugFuncInfo; +} + +/***********************************************************************/ + +void poffReleaseDebugFuncContainer(poffLibDebugFuncInfo_t *pDebugFuncInfo) +{ + if (pDebugFuncInfo) + { + free(pDebugFuncInfo); + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfdbginfo.c b/misc/pascal/libpoff/pfdbginfo.c index 3de279b914..5d2e889bc9 100644 --- a/misc/pascal/libpoff/pfdbginfo.c +++ b/misc/pascal/libpoff/pfdbginfo.c @@ -1,157 +1,158 @@ -/**********************************************************************
- * pdbginfo.c
- * Manage debug information
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-static poffLibDebugFuncInfo_t *g_pDebugInfoHead = NULL;
-static poffLibDebugFuncInfo_t *g_pDebugInfoTail = NULL;
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-void poffReadDebugFuncInfoTable(poffHandle_t handle)
-{
- poffLibDebugFuncInfo_t *pDebugInfo;
-
- /* Read all function debug information into a link list */
-
- while ((pDebugInfo = poffGetDebugFuncInfo(handle)) != NULL)
- {
- if (!g_pDebugInfoHead)
- {
- g_pDebugInfoHead = pDebugInfo;
- }
- else
- {
- g_pDebugInfoTail->next = pDebugInfo;
- }
- g_pDebugInfoTail = pDebugInfo;
- }
-}
-
-/***********************************************************************/
-
-poffLibDebugFuncInfo_t *poffFindDebugFuncInfo(uint32 offset)
-{
- poffLibDebugFuncInfo_t *pDebugInfo;
-
- /* Search the list for an entry with PC==offset */
-
- for (pDebugInfo = g_pDebugInfoHead; pDebugInfo;
- pDebugInfo = pDebugInfo->next)
- {
- if (pDebugInfo->value == offset)
- {
- return pDebugInfo;
- }
- }
- return NULL;
-}
-
-/***********************************************************************/
-
-void poffReplaceDebugFuncInfo(poffHandle_t handle)
-{
- poffLibDebugFuncInfo_t *pDebugInfo;
-
- /* Discard any existing debug info in the POFF object */
-
- poffDiscardDebugFuncInfo(handle);
-
- /* Then add all of the buffered debug info into the object */
-
- for (pDebugInfo = g_pDebugInfoHead; pDebugInfo;
- pDebugInfo = pDebugInfo->next)
- {
- (void)poffAddDebugFuncInfo(handle, pDebugInfo);
-
- }
-}
-
-/***********************************************************************/
-
-void poffReleaseDebugFuncInfoTable(void)
-{
- poffLibDebugFuncInfo_t *pDebugInfo;
- poffLibDebugFuncInfo_t *pNextDebugInfo;
-
- /* Release the bufferred debug information */
-
- pDebugInfo = g_pDebugInfoHead;
- while (pDebugInfo)
- {
- pNextDebugInfo = pDebugInfo->next;
- poffReleaseDebugFuncContainer(pDebugInfo);
- pDebugInfo = pNextDebugInfo;
- }
-
- g_pDebugInfoHead = NULL;
- g_pDebugInfoTail = NULL;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pdbginfo.c + * Manage debug information + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +static poffLibDebugFuncInfo_t *g_pDebugInfoHead = NULL; +static poffLibDebugFuncInfo_t *g_pDebugInfoTail = NULL; + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +void poffReadDebugFuncInfoTable(poffHandle_t handle) +{ + poffLibDebugFuncInfo_t *pDebugInfo; + + /* Read all function debug information into a link list */ + + while ((pDebugInfo = poffGetDebugFuncInfo(handle)) != NULL) + { + if (!g_pDebugInfoHead) + { + g_pDebugInfoHead = pDebugInfo; + } + else + { + g_pDebugInfoTail->next = pDebugInfo; + } + g_pDebugInfoTail = pDebugInfo; + } +} + +/***********************************************************************/ + +poffLibDebugFuncInfo_t *poffFindDebugFuncInfo(uint32_t offset) +{ + poffLibDebugFuncInfo_t *pDebugInfo; + + /* Search the list for an entry with PC==offset */ + + for (pDebugInfo = g_pDebugInfoHead; pDebugInfo; + pDebugInfo = pDebugInfo->next) + { + if (pDebugInfo->value == offset) + { + return pDebugInfo; + } + } + return NULL; +} + +/***********************************************************************/ + +void poffReplaceDebugFuncInfo(poffHandle_t handle) +{ + poffLibDebugFuncInfo_t *pDebugInfo; + + /* Discard any existing debug info in the POFF object */ + + poffDiscardDebugFuncInfo(handle); + + /* Then add all of the buffered debug info into the object */ + + for (pDebugInfo = g_pDebugInfoHead; pDebugInfo; + pDebugInfo = pDebugInfo->next) + { + (void)poffAddDebugFuncInfo(handle, pDebugInfo); + + } +} + +/***********************************************************************/ + +void poffReleaseDebugFuncInfoTable(void) +{ + poffLibDebugFuncInfo_t *pDebugInfo; + poffLibDebugFuncInfo_t *pNextDebugInfo; + + /* Release the bufferred debug information */ + + pDebugInfo = g_pDebugInfoHead; + while (pDebugInfo) + { + pNextDebugInfo = pDebugInfo->next; + poffReleaseDebugFuncContainer(pDebugInfo); + pDebugInfo = pNextDebugInfo; + } + + g_pDebugInfoHead = NULL; + g_pDebugInfoTail = NULL; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfdreloc.c b/misc/pascal/libpoff/pfdreloc.c index 732419fd48..e082bee35d 100644 --- a/misc/pascal/libpoff/pfdreloc.c +++ b/misc/pascal/libpoff/pfdreloc.c @@ -1,107 +1,108 @@ -/**********************************************************************
- * pfdreloc.c
- * Dump contents of a POFF file reloc table
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "keywords.h" /* Standard types */
-#include "pfprivate.h" /* POFF private definitions */
-#include "pofflib.h" /* Public interfaces */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Constant Data
- **********************************************************************/
-
-static const char *poffRelocationTypes[RLT_NTYPES] =
-{
- "NULL", /* Shouldn't happen */
- "PCAL", /* Procedure/Function call */
- "LDST", /* Load from stack base */
-};
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-void poffDumpRelocTable(poffHandle_t handle, FILE *outFile)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffRelocation_t *prel;
- uint32 index;
-
- fprintf(outFile, "\nPOFF Relocation Table:\n");
- fprintf(outFile, "RELO SYMBOL SECTION\n");
- fprintf(outFile, "TYPE TBL INDEX DATA OFFSET\n");
-
- for (index = 0;
- index < poffInfo->relocSection.sh_size;
- index += poffInfo->relocSection.sh_entsize)
- {
- prel = (poffRelocation_t*)&poffInfo->relocTable[index];
-
- fprintf(outFile, "%-6s 0x%08lx 0x%08lx\n",
- poffRelocationTypes[RLI_TYPE(prel->rl_info)],
- RLI_SYM(prel->rl_info),
- prel->rl_offset);
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfdreloc.c + * Dump contents of a POFF file reloc table + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "keywords.h" /* Standard types */ +#include "pfprivate.h" /* POFF private definitions */ +#include "pofflib.h" /* Public interfaces */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/********************************************************************** + * Private Constant Data + **********************************************************************/ + +static const char *poffRelocationTypes[RLT_NTYPES] = +{ + "NULL", /* Shouldn't happen */ + "PCAL", /* Procedure/Function call */ + "LDST", /* Load from stack base */ +}; + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +void poffDumpRelocTable(poffHandle_t handle, FILE *outFile) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffRelocation_t *prel; + uint32_t index; + + fprintf(outFile, "\nPOFF Relocation Table:\n"); + fprintf(outFile, "RELO SYMBOL SECTION\n"); + fprintf(outFile, "TYPE TBL INDEX DATA OFFSET\n"); + + for (index = 0; + index < poffInfo->relocSection.sh_size; + index += poffInfo->relocSection.sh_entsize) + { + prel = (poffRelocation_t*)&poffInfo->relocTable[index]; + + fprintf(outFile, "%-6s 0x%08lx 0x%08lx\n", + poffRelocationTypes[RLI_TYPE(prel->rl_info)], + RLI_SYM(prel->rl_info), + prel->rl_offset); + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfdsymbol.c b/misc/pascal/libpoff/pfdsymbol.c index aa7aa14741..384d5b362d 100644 --- a/misc/pascal/libpoff/pfdsymbol.c +++ b/misc/pascal/libpoff/pfdsymbol.c @@ -1,116 +1,117 @@ -/**********************************************************************
- * pfdsymbol.c
- * Dump contents of a POFF file symbol table
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "keywords.h" /* Standard types */
-#include "pfprivate.h" /* POFF private definitions */
-#include "pofflib.h" /* Public interfaces */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Constant Data
- **********************************************************************/
-
-static const char *poffSymTypes[STT_NTYPES] =
-{
- "NULL ", /* Shouldn't happen */
- "DATA ", /* Stack data */
- "RODATA", /* Read-only data */
- "PROC ", /* Symbol table */
- "FUNC " /* String table */
-};
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-void poffDumpSymbolTable(poffHandle_t handle, FILE *outFile)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffSymbol_t *psym;
- uint32 index;
-
- fprintf(outFile, "\nPOFF Symbol Table:\n");
- fprintf(outFile, "NAME "
- "TYPE "
- "FLAG "
- "ALGN "
- "VALUE "
- "SIZE\n");
-
- for (index = 0;
- index < poffInfo->symbolTableSection.sh_size;
- index += poffInfo->symbolTableSection.sh_entsize)
- {
- psym = (poffSymbol_t*)&poffInfo->symbolTable[index];
-
- fprintf(outFile, "%-20s %6s 0x%02x 0x%02x 0x%08lx 0x%08lx\n",
- poffGetString(poffInfo, psym->st_name),
- poffSymTypes[psym->st_type],
- psym->st_flags,
- psym->st_align,
- psym->st_value,
- psym->st_size);
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfdsymbol.c + * Dump contents of a POFF file symbol table + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "keywords.h" /* Standard types */ +#include "pfprivate.h" /* POFF private definitions */ +#include "pofflib.h" /* Public interfaces */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/********************************************************************** + * Private Constant Data + **********************************************************************/ + +static const char *poffSymTypes[STT_NTYPES] = +{ + "NULL ", /* Shouldn't happen */ + "DATA ", /* Stack data */ + "RODATA", /* Read-only data */ + "PROC ", /* Symbol table */ + "FUNC " /* String table */ +}; + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +void poffDumpSymbolTable(poffHandle_t handle, FILE *outFile) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffSymbol_t *psym; + uint32_t index; + + fprintf(outFile, "\nPOFF Symbol Table:\n"); + fprintf(outFile, "NAME " + "TYPE " + "FLAG " + "ALGN " + "VALUE " + "SIZE\n"); + + for (index = 0; + index < poffInfo->symbolTableSection.sh_size; + index += poffInfo->symbolTableSection.sh_entsize) + { + psym = (poffSymbol_t*)&poffInfo->symbolTable[index]; + + fprintf(outFile, "%-20s %6s 0x%02x 0x%02x 0x%08lx 0x%08lx\n", + poffGetString(poffInfo, psym->st_name), + poffSymTypes[psym->st_type], + psym->st_flags, + psym->st_align, + psym->st_value, + psym->st_size); + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfiprog.c b/misc/pascal/libpoff/pfiprog.c index 2d175db4b1..5cbf1b79ee 100644 --- a/misc/pascal/libpoff/pfiprog.c +++ b/misc/pascal/libpoff/pfiprog.c @@ -1,92 +1,93 @@ -/**********************************************************************
- * pfiprog.c
- * Insert program data int a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-void poffInsertProgramData(poffHandle_t handle,
- ubyte *progData, uint32 progSize)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
-
- /* If there is already program data in the container, discard it. */
-
- if (poffInfo->progSectionData) free(poffInfo->progSectionData);
-
- /* Then, insert the new program data */
-
- poffInfo->progSection.sh_size = progSize;
- poffInfo->progSectionData = progData;
- poffInfo->progSectionAlloc = progSize;
- poffInfo->progSectionIndex = 0;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfiprog.c + * Insert program data int a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ + +void poffInsertProgramData(poffHandle_t handle, + uint8_t *progData, uint32_t progSize) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + + /* If there is already program data in the container, discard it. */ + + if (poffInfo->progSectionData) free(poffInfo->progSectionData); + + /* Then, insert the new program data */ + + poffInfo->progSection.sh_size = progSize; + poffInfo->progSectionData = progData; + poffInfo->progSectionAlloc = progSize; + poffInfo->progSectionIndex = 0; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfirodata.c b/misc/pascal/libpoff/pfirodata.c index 2d4679ada2..35e65268f5 100644 --- a/misc/pascal/libpoff/pfirodata.c +++ b/misc/pascal/libpoff/pfirodata.c @@ -1,102 +1,103 @@ -/**********************************************************************
- * pfirodata.c
- * Append program read-only data to a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-void poffAppendRoData(poffHandle_t handle,
- ubyte *roData, uint32 roDataSize)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- ubyte *tmp;
- uint32 newSize;
-
- if ((roData) && (roDataSize))
- {
- /* Reallocate the read-only data */
-
- newSize = poffInfo->roDataSection.sh_size + roDataSize;
- tmp = (ubyte*)realloc(poffInfo->roDataSectionData, newSize);
- if (!tmp) fatal(eNOMEMORY);
-
- /* Add the new data to the new allocation */
-
- memcpy(&tmp[poffInfo->roDataSection.sh_size], roData, roDataSize);
-
- /* Add the new allocation to the read-only section */
-
- poffInfo->roDataSection.sh_size = newSize;
- poffInfo->roDataSectionData = tmp;
- poffInfo->roDataSectionAlloc = newSize;
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfirodata.c + * Append program read-only data to a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ + +void poffAppendRoData(poffHandle_t handle, + uint8_t *roData, uint32_t roDataSize) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint8_t *tmp; + uint32_t newSize; + + if ((roData) && (roDataSize)) + { + /* Reallocate the read-only data */ + + newSize = poffInfo->roDataSection.sh_size + roDataSize; + tmp = (uint8_t*)realloc(poffInfo->roDataSectionData, newSize); + if (!tmp) fatal(eNOMEMORY); + + /* Add the new data to the new allocation */ + + memcpy(&tmp[poffInfo->roDataSection.sh_size], roData, roDataSize); + + /* Add the new allocation to the read-only section */ + + poffInfo->roDataSection.sh_size = newSize; + poffInfo->roDataSectionData = tmp; + poffInfo->roDataSectionAlloc = newSize; + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pflabel.c b/misc/pascal/libpoff/pflabel.c index e322fbb5cf..073e73292a 100644 --- a/misc/pascal/libpoff/pflabel.c +++ b/misc/pascal/libpoff/pflabel.c @@ -2,7 +2,7 @@ * pflabel.c * Label resolution logic * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,7 @@ * Included Files **********************************************************************/ +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -64,15 +65,15 @@ struct optDefinedLabelRef_s { - uint32 label; - uint32 pc; + uint32_t label; + uint32_t pc; }; typedef struct optDefinedLabelRef_s optDefinedLabelRef_t; struct optUndefinedLabelRef_s { - uint32 label; - uint32 symIndex; + uint32_t label; + uint32_t symIndex; }; typedef struct optUndefinedLabelRef_s optUndefinedLabelRef_t; @@ -81,12 +82,12 @@ typedef struct optUndefinedLabelRef_s optUndefinedLabelRef_t; **********************************************************************/ static optDefinedLabelRef_t *definedLabelRefs = NULL; -static uint32 definedLabelRefAlloc = 0; -static uint32 nDefinedLabelRefs = 0; +static uint32_t definedLabelRefAlloc = 0; +static uint32_t nDefinedLabelRefs = 0; static optUndefinedLabelRef_t *undefinedLabelRefs = NULL; -static uint32 undefinedLabelRefAlloc = 0; -static uint32 nUndefinedLabelRefs = 0; +static uint32_t undefinedLabelRefAlloc = 0; +static uint32_t nUndefinedLabelRefs = 0; /********************************************************************** * Private Function Prototypes @@ -111,12 +112,12 @@ static void poffCheckDefinedLabelAlloc(void) /* No, allocate it now */ definedLabelRefs = (optDefinedLabelRef_t*) - malloc(INITIAL_DEFINED_ALLOCATION); + malloc(INITIAL_DEFINED_ALLOCATION); if (!definedLabelRefs) - { - fatal(eNOMEMORY); - } + { + fatal(eNOMEMORY); + } definedLabelRefAlloc = INITIAL_DEFINED_ALLOCATION; } } @@ -130,16 +131,16 @@ static void poffCheckDefinedLabelRealloc(void) if (((nDefinedLabelRefs + 1)*sizeof(optDefinedLabelRef_t)) > definedLabelRefAlloc) { - uint32 newAlloc = definedLabelRefAlloc + DEFINED_INCREMENT; + uint32_t newAlloc = definedLabelRefAlloc + DEFINED_INCREMENT; void *tmp; /* Reallocate the label reference tabel */ tmp = realloc(definedLabelRefs, newAlloc); if (!tmp) - { - fatal(eNOMEMORY); - } + { + fatal(eNOMEMORY); + } /* And set the new size */ @@ -159,12 +160,12 @@ static void poffCheckUndefinedLabelAlloc(void) /* No, allocate it now */ undefinedLabelRefs = (optUndefinedLabelRef_t*) - malloc(INITIAL_UNDEFINED_ALLOCATION); + malloc(INITIAL_UNDEFINED_ALLOCATION); if (!undefinedLabelRefs) - { - fatal(eNOMEMORY); - } + { + fatal(eNOMEMORY); + } undefinedLabelRefAlloc = INITIAL_UNDEFINED_ALLOCATION; } } @@ -178,16 +179,16 @@ static void poffCheckUndefinedLabelRealloc(void) if (((nUndefinedLabelRefs + 1)*sizeof(optUndefinedLabelRef_t)) > undefinedLabelRefAlloc) { - uint32 newAlloc = undefinedLabelRefAlloc + UNDEFINED_INCREMENT; + uint32_t newAlloc = undefinedLabelRefAlloc + UNDEFINED_INCREMENT; void *tmp; /* Reallocate the label reference tabel */ tmp = realloc(undefinedLabelRefs, newAlloc); if (!tmp) - { - fatal(eNOMEMORY); - } + { + fatal(eNOMEMORY); + } /* And set the new size */ @@ -204,7 +205,7 @@ static void poffCheckUndefinedLabelRealloc(void) /**********************************************************************/ -void poffAddToDefinedLabelTable(uint32 label, uint32 pc) +void poffAddToDefinedLabelTable(uint32_t label, uint32_t pc) { /* Make sure we have memory to do this. If not, we will crash */ @@ -220,7 +221,7 @@ void poffAddToDefinedLabelTable(uint32 label, uint32 pc) /**********************************************************************/ -void poffAddToUndefinedLabelTable(uint32 label, uint32 symIndex) +void poffAddToUndefinedLabelTable(uint32_t label, uint32_t symIndex) { /* Make sure we have memory to do this. If not, we will crash */ @@ -236,32 +237,32 @@ void poffAddToUndefinedLabelTable(uint32 label, uint32 symIndex) /**********************************************************************/ -int poffGetSymIndexForUndefinedLabel(uint32 label) +int poffGetSymIndexForUndefinedLabel(uint32_t label) { int i; for (i = 0; i < nUndefinedLabelRefs; i++) { if (undefinedLabelRefs[i].label == label) - { - return undefinedLabelRefs[i].symIndex; - } + { + return undefinedLabelRefs[i].symIndex; + } } return -1; } /**********************************************************************/ -int poffGetPcForDefinedLabel(uint32 label) +int poffGetPcForDefinedLabel(uint32_t label) { int i; for (i = 0; i < nDefinedLabelRefs; i++) { if (definedLabelRefs[i].label == label) - { - return definedLabelRefs[i].pc; - } + { + return definedLabelRefs[i].pc; + } } return -1; } diff --git a/misc/pascal/libpoff/pflineno.c b/misc/pascal/libpoff/pflineno.c index 95d17723b2..ed257d52d6 100644 --- a/misc/pascal/libpoff/pflineno.c +++ b/misc/pascal/libpoff/pflineno.c @@ -1,335 +1,336 @@ -/**********************************************************************
- * pflineno.c
- * Manage line number information
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-
-poffLibLineNumber_t
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-#define INITIAL_LINENUMBER_TABLE_SIZE 2048*sizeof(poffLibLineNumber_t)
-#define LINENUMBER_TABLE_INCREMENT 512*sizeof(poffLibLineNumber_t)
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-static poffLibLineNumber_t *lineNumberTable;
-static uint32 nLineNumbers;
-static uint32 lineNumberTableAlloc;
-static uint32 prevLineNumberIndex;
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-static inline void poffCheckLineNumberAllocation(void)
-{
- /* Check if we have allocated a line number buffer yet */
-
- if (!lineNumberTable)
- {
- /* No, allocate it now */
-
- lineNumberTable = (poffLibLineNumber_t*)
- malloc(INITIAL_LINENUMBER_TABLE_SIZE);
-
- if (!lineNumberTable)
- {
- fatal(eNOMEMORY);
- }
-
- lineNumberTableAlloc = INITIAL_LINENUMBER_TABLE_SIZE;
- nLineNumbers = 0;
- }
-}
-
-/***********************************************************************/
-
-static inline void poffCheckLineNumberReallocation(void)
-{
- if ((nLineNumbers +1) * sizeof(poffLibLineNumber_t) > lineNumberTableAlloc)
- {
- uint32 newAlloc = lineNumberTableAlloc + LINENUMBER_TABLE_INCREMENT;
- void *tmp;
-
- /* Reallocate the line number buffer */
-
- tmp = realloc(lineNumberTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- lineNumberTableAlloc = newAlloc;
- lineNumberTable = (poffLibLineNumber_t*)tmp;
- }
-}
-
-/***********************************************************************/
-/* Add a line number to the line number table. */
-
-static void poffAddLineNumberToTable(poffLibLineNumber_t *lineno)
-{
- /* Verify that the line number table has been allocated */
-
- poffCheckLineNumberAllocation();
-
- /* Verify that the line number table is large enough to hold
- * information about another line.
- */
-
- poffCheckLineNumberReallocation();
-
- /* Save the line number information in the line number table */
-
- memcpy(&lineNumberTable[nLineNumbers], lineno, sizeof(poffLibLineNumber_t));
- nLineNumbers++;
-}
-
-/***********************************************************************/
-/* Discard any unused memory */
-
-static void poffDiscardUnusedAllocation(void)
-{
- uint32 newAlloc = nLineNumbers * sizeof(poffLibLineNumber_t);
- void *tmp;
-
- /* Was a line number table allocated? And, if so, are there unused
- * entries?
- */
-
- if ((lineNumberTable) && (nLineNumbers < lineNumberTableAlloc))
- {
- /* Reallocate the line number buffer */
-
- tmp = realloc(lineNumberTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- lineNumberTableAlloc = newAlloc;
- lineNumberTable = (poffLibLineNumber_t*)tmp;
- }
-}
-
-/***********************************************************************/
-/* "The comparison function must return an integer less than, equal to,
- * or greater than zero if the first argument is considered to be
- * respectively less than, equal to, or greater than the second. If two
- * members compare as equal, their order in the sorted array is undefined."
- */
-
-static int poffCompareLineNumbers(const void *pv1, const void *pv2)
-{
- register poffLibLineNumber_t *ln1 = (poffLibLineNumber_t*)pv1;
- register poffLibLineNumber_t *ln2 = (poffLibLineNumber_t*)pv2;
-
- if (ln1->offset < ln2->offset) return -1;
- else if (ln1->offset > ln2->offset) return 1;
- else return 0;
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-void poffReadLineNumberTable(poffHandle_t handle)
-{
- poffLibLineNumber_t lineno;
- sint32 offset;
-
- /* Initialize global variables */
-
- prevLineNumberIndex = 0;
-
- /* Create a table of line number information */
-
- do
- {
- offset = poffGetLineNumber(handle, &lineno);
- if (offset >= 0)
- {
- poffAddLineNumberToTable(&lineno);
- }
- }
- while (offset >= 0);
-
- /* Discard any memory that is not being used */
-
- poffDiscardUnusedAllocation();
-
- /* Sort the table by offset */
-
- qsort(lineNumberTable, nLineNumbers,
- sizeof(poffLibLineNumber_t), poffCompareLineNumbers);
-}
-
-/***********************************************************************/
-
-poffLibLineNumber_t *poffFindLineNumber(uint32 offset)
-{
- uint32 firstLineNumberIndex;
- uint32 lastLineNumberIndex;
- uint32 lineNumberIndex;
-
- /* Was a line number table allocated? */
-
- if (!lineNumberTable) return NULL;
-
- /* We used the last returned line number entry as a hint to speed
- * up the next search. We don't know how the line numbers will
- * be searched but most likely, they will be searched ina a sequence
- * of ascending offsets. In that case, a dumb linear search
- * would be better than what we are trying to do here. we are
- * trying to support fast random access.
- */
-
- if (lineNumberTable[prevLineNumberIndex].offset <= offset)
- {
- firstLineNumberIndex = prevLineNumberIndex;
- lastLineNumberIndex = nLineNumbers - 1;
- }
- else
- {
- firstLineNumberIndex = 0;
- lastLineNumberIndex = prevLineNumberIndex;
- }
-
- /* Search until firstLineNumberIndex and firstLineNumberIndex+1
- * contain the searched for offset. Exact matches may or may
- * not occur.
- */
-
- lineNumberIndex = firstLineNumberIndex;
- while (firstLineNumberIndex != lastLineNumberIndex)
- {
- /* Look at the midpoint index. This will be biased toward
- * the lower index due to truncation. This means that
- * can always be assured that as long as firstLineNumberIndex !=
- * lastLineNumberIndex, then lineNumberIndex+1 is valid. We
- * exploit this fact below.
- */
-
- lineNumberIndex = (firstLineNumberIndex + lastLineNumberIndex) >> 1;
-
- /* If the offset at the midpoint is greater than the sought
- * for offset, then we can safely set the upper search index
- * to the midpoint.
- */
-
- if (lineNumberTable[lineNumberIndex].offset > offset)
- lastLineNumberIndex = lineNumberIndex;
-
- /* If we have an exact match, we break out of the loop now */
-
- else if (lineNumberTable[lineNumberIndex].offset == offset)
- break;
-
- /* If the next entry is an offset greater then the one we
- * are searching for, then we can break out of the loop now.
- * We know that lineNumberIndex+1 is a valid index (see above).
- */
-
- else if (lineNumberTable[lineNumberIndex + 1].offset > offset)
- break;
-
- /* Otherwise, we safely do the following */
-
- else
- firstLineNumberIndex = lineNumberIndex + 1;
- }
-
- /* Check that we terminated the loop with a valid line number
- * match. This should only fail if all of the line numbers in the
- * table have offsets greater than the one in the table. If we
- * could not find a match, return NULL.
- */
-
- if (lineNumberTable[lineNumberIndex].offset > offset)
- {
- prevLineNumberIndex = 0;
- return NULL;
- }
- else
- {
- prevLineNumberIndex = lineNumberIndex;
- return &lineNumberTable[lineNumberIndex];
- }
-}
-
-/***********************************************************************/
-
-void poffReleaseLineNumberTable(void)
-{
- if (lineNumberTable)
- free(lineNumberTable);
-
- lineNumberTable = NULL;
- nLineNumbers = 0;
- lineNumberTableAlloc = 0;
- prevLineNumberIndex = 0;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pflineno.c + * Manage line number information + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ + +poffLibLineNumber_t + +/********************************************************************** + * Definitions + **********************************************************************/ + +#define INITIAL_LINENUMBER_TABLE_SIZE 2048*sizeof(poffLibLineNumber_t) +#define LINENUMBER_TABLE_INCREMENT 512*sizeof(poffLibLineNumber_t) + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +static poffLibLineNumber_t *lineNumberTable; +static uint32_t nLineNumbers; +static uint32_t lineNumberTableAlloc; +static uint32_t prevLineNumberIndex; + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +static inline void poffCheckLineNumberAllocation(void) +{ + /* Check if we have allocated a line number buffer yet */ + + if (!lineNumberTable) + { + /* No, allocate it now */ + + lineNumberTable = (poffLibLineNumber_t*) + malloc(INITIAL_LINENUMBER_TABLE_SIZE); + + if (!lineNumberTable) + { + fatal(eNOMEMORY); + } + + lineNumberTableAlloc = INITIAL_LINENUMBER_TABLE_SIZE; + nLineNumbers = 0; + } +} + +/***********************************************************************/ + +static inline void poffCheckLineNumberReallocation(void) +{ + if ((nLineNumbers +1) * sizeof(poffLibLineNumber_t) > lineNumberTableAlloc) + { + uint32_t newAlloc = lineNumberTableAlloc + LINENUMBER_TABLE_INCREMENT; + void *tmp; + + /* Reallocate the line number buffer */ + + tmp = realloc(lineNumberTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + lineNumberTableAlloc = newAlloc; + lineNumberTable = (poffLibLineNumber_t*)tmp; + } +} + +/***********************************************************************/ +/* Add a line number to the line number table. */ + +static void poffAddLineNumberToTable(poffLibLineNumber_t *lineno) +{ + /* Verify that the line number table has been allocated */ + + poffCheckLineNumberAllocation(); + + /* Verify that the line number table is large enough to hold + * information about another line. + */ + + poffCheckLineNumberReallocation(); + + /* Save the line number information in the line number table */ + + memcpy(&lineNumberTable[nLineNumbers], lineno, sizeof(poffLibLineNumber_t)); + nLineNumbers++; +} + +/***********************************************************************/ +/* Discard any unused memory */ + +static void poffDiscardUnusedAllocation(void) +{ + uint32_t newAlloc = nLineNumbers * sizeof(poffLibLineNumber_t); + void *tmp; + + /* Was a line number table allocated? And, if so, are there unused + * entries? + */ + + if ((lineNumberTable) && (nLineNumbers < lineNumberTableAlloc)) + { + /* Reallocate the line number buffer */ + + tmp = realloc(lineNumberTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + lineNumberTableAlloc = newAlloc; + lineNumberTable = (poffLibLineNumber_t*)tmp; + } +} + +/***********************************************************************/ +/* "The comparison function must return an integer less than, equal to, + * or greater than zero if the first argument is considered to be + * respectively less than, equal to, or greater than the second. If two + * members compare as equal, their order in the sorted array is undefined." + */ + +static int poffCompareLineNumbers(const void *pv1, const void *pv2) +{ + register poffLibLineNumber_t *ln1 = (poffLibLineNumber_t*)pv1; + register poffLibLineNumber_t *ln2 = (poffLibLineNumber_t*)pv2; + + if (ln1->offset < ln2->offset) return -1; + else if (ln1->offset > ln2->offset) return 1; + else return 0; +} + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +void poffReadLineNumberTable(poffHandle_t handle) +{ + poffLibLineNumber_t lineno; + int32_t offset; + + /* Initialize global variables */ + + prevLineNumberIndex = 0; + + /* Create a table of line number information */ + + do + { + offset = poffGetLineNumber(handle, &lineno); + if (offset >= 0) + { + poffAddLineNumberToTable(&lineno); + } + } + while (offset >= 0); + + /* Discard any memory that is not being used */ + + poffDiscardUnusedAllocation(); + + /* Sort the table by offset */ + + qsort(lineNumberTable, nLineNumbers, + sizeof(poffLibLineNumber_t), poffCompareLineNumbers); +} + +/***********************************************************************/ + +poffLibLineNumber_t *poffFindLineNumber(uint32_t offset) +{ + uint32_t firstLineNumberIndex; + uint32_t lastLineNumberIndex; + uint32_t lineNumberIndex; + + /* Was a line number table allocated? */ + + if (!lineNumberTable) return NULL; + + /* We used the last returned line number entry as a hint to speed + * up the next search. We don't know how the line numbers will + * be searched but most likely, they will be searched ina a sequence + * of ascending offsets. In that case, a dumb linear search + * would be better than what we are trying to do here. we are + * trying to support fast random access. + */ + + if (lineNumberTable[prevLineNumberIndex].offset <= offset) + { + firstLineNumberIndex = prevLineNumberIndex; + lastLineNumberIndex = nLineNumbers - 1; + } + else + { + firstLineNumberIndex = 0; + lastLineNumberIndex = prevLineNumberIndex; + } + + /* Search until firstLineNumberIndex and firstLineNumberIndex+1 + * contain the searched for offset. Exact matches may or may + * not occur. + */ + + lineNumberIndex = firstLineNumberIndex; + while (firstLineNumberIndex != lastLineNumberIndex) + { + /* Look at the midpoint index. This will be biased toward + * the lower index due to truncation. This means that + * can always be assured that as long as firstLineNumberIndex != + * lastLineNumberIndex, then lineNumberIndex+1 is valid. We + * exploit this fact below. + */ + + lineNumberIndex = (firstLineNumberIndex + lastLineNumberIndex) >> 1; + + /* If the offset at the midpoint is greater than the sought + * for offset, then we can safely set the upper search index + * to the midpoint. + */ + + if (lineNumberTable[lineNumberIndex].offset > offset) + lastLineNumberIndex = lineNumberIndex; + + /* If we have an exact match, we break out of the loop now */ + + else if (lineNumberTable[lineNumberIndex].offset == offset) + break; + + /* If the next entry is an offset greater then the one we + * are searching for, then we can break out of the loop now. + * We know that lineNumberIndex+1 is a valid index (see above). + */ + + else if (lineNumberTable[lineNumberIndex + 1].offset > offset) + break; + + /* Otherwise, we safely do the following */ + + else + firstLineNumberIndex = lineNumberIndex + 1; + } + + /* Check that we terminated the loop with a valid line number + * match. This should only fail if all of the line numbers in the + * table have offsets greater than the one in the table. If we + * could not find a match, return NULL. + */ + + if (lineNumberTable[lineNumberIndex].offset > offset) + { + prevLineNumberIndex = 0; + return NULL; + } + else + { + prevLineNumberIndex = lineNumberIndex; + return &lineNumberTable[lineNumberIndex]; + } +} + +/***********************************************************************/ + +void poffReleaseLineNumberTable(void) +{ + if (lineNumberTable) + free(lineNumberTable); + + lineNumberTable = NULL; + nLineNumbers = 0; + lineNumberTableAlloc = 0; + prevLineNumberIndex = 0; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfprivate.h b/misc/pascal/libpoff/pfprivate.h index 0cf152c5c3..afcd3da9d8 100644 --- a/misc/pascal/libpoff/pfprivate.h +++ b/misc/pascal/libpoff/pfprivate.h @@ -3,7 +3,7 @@ * Contains command, internal, private definitions used by * the POFF library. These were not intended for exportation. * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,7 @@ * Included Files ***************************************************************************/ +#include <stdint.h> #include "keywords.h" #include "poff.h" #include "paslib.h" /* Endian-ness support */ @@ -120,55 +121,55 @@ struct poffInfo_s /* In-memory section data */ - ubyte *progSectionData; - ubyte *roDataSectionData; - ubyte *symbolTable; + uint8_t *progSectionData; + uint8_t *roDataSectionData; + uint8_t *symbolTable; char *stringTable; - ubyte *relocTable; + uint8_t *relocTable; poffFileTab_t *fileNameTable; - ubyte *lineNumberTable; - ubyte *debugFuncTable; + uint8_t *lineNumberTable; + uint8_t *debugFuncTable; /* Current allocation sizes. Used only on writing to determine if * in-memory has been allocated and how much memory has been allocated * in case the buffer needs to be re-allocated. */ - uint32 progSectionAlloc; - uint32 roDataSectionAlloc; - uint32 symbolTableAlloc; - uint32 stringTableAlloc; - uint32 relocAlloc; - uint32 fileNameTableAlloc; - uint32 lineNumberTableAlloc; - uint32 debugFuncTableAlloc; + uint32_t progSectionAlloc; + uint32_t roDataSectionAlloc; + uint32_t symbolTableAlloc; + uint32_t stringTableAlloc; + uint32_t relocAlloc; + uint32_t fileNameTableAlloc; + uint32_t lineNumberTableAlloc; + uint32_t debugFuncTableAlloc; /* Current buffer indices. These are used on reading data sequentially * from the in-memory section data. */ - uint32 progSectionIndex; - uint32 symbolIndex; - uint32 relocIndex; - uint32 fileNameIndex; - uint32 lineNumberIndex; - uint32 debugFuncIndex; + uint32_t progSectionIndex; + uint32_t symbolIndex; + uint32_t relocIndex; + uint32_t fileNameIndex; + uint32_t lineNumberIndex; + uint32_t debugFuncIndex; }; typedef struct poffInfo_s poffInfo_t; struct poffProgInfo_s { - uint32 progSectionSize; - uint32 progSectionAlloc; - ubyte *progSectionData; + uint32_t progSectionSize; + uint32_t progSectionAlloc; + uint8_t *progSectionData; }; typedef struct poffProgInfo_s poffProgInfo_t; struct poffSymInfo_s { - uint32 symbolTableSize; - uint32 symbolTableAlloc; - ubyte *symbolTable; + uint32_t symbolTableSize; + uint32_t symbolTableAlloc; + uint8_t *symbolTable; }; typedef struct poffSymInfo_s poffSymInfo_t; diff --git a/misc/pascal/libpoff/pfrdbgfunc.c b/misc/pascal/libpoff/pfrdbgfunc.c index da944de980..052bd735cc 100644 --- a/misc/pascal/libpoff/pfrdbgfunc.c +++ b/misc/pascal/libpoff/pfrdbgfunc.c @@ -1,130 +1,131 @@ -/**********************************************************************
- * pfrdbgfunc.c
- * Read debug function information from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-poffLibDebugFuncInfo_t *poffGetDebugFuncInfo(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffDebugFuncInfo_t *pDebugInfo;
- poffDebugArgInfo_t *pArgInfo;
- poffLibDebugFuncInfo_t *pRet;
- uint32 debugFuncIndex;
- int i;
-
- /* Check if there is another debug entgry in the table to be had */
-
- debugFuncIndex = poffInfo->debugFuncIndex;
-
- if (debugFuncIndex + sizeof(poffDebugFuncInfo_t) >=
- poffInfo->debugFuncSection.sh_size)
- {
- /* Return NULL to signal the end of the list */
-
- return NULL;
- }
-
- /* Get a reference to the debug function entry */
-
- pDebugInfo = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[debugFuncIndex];
-
- /* Allocate a container */
-
- pRet = poffCreateDebugInfoContainer(pDebugInfo->df_nparms);
-
- /* Return the debug function information */
-
- pRet->value = pDebugInfo->df_value;
- pRet->retsize = pDebugInfo->df_size;
- pRet->nparms = pDebugInfo->df_nparms;
-
- /* Return the size of each parameter */
-
- debugFuncIndex += sizeof(poffDebugFuncInfo_t);
- for (i = 0; i < pRet->nparms; i++)
- {
- pArgInfo = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[debugFuncIndex];
- pRet->argsize[i] = pArgInfo->da_size;
- debugFuncIndex += sizeof(poffDebugArgInfo_t);
- }
-
- /* Set up for the next read */
-
- poffInfo->debugFuncIndex = debugFuncIndex;
- return pRet;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrdbgfunc.c + * Read debug function information from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ + +poffLibDebugFuncInfo_t *poffGetDebugFuncInfo(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffDebugFuncInfo_t *pDebugInfo; + poffDebugArgInfo_t *pArgInfo; + poffLibDebugFuncInfo_t *pRet; + uint32_t debugFuncIndex; + int i; + + /* Check if there is another debug entgry in the table to be had */ + + debugFuncIndex = poffInfo->debugFuncIndex; + + if (debugFuncIndex + sizeof(poffDebugFuncInfo_t) >= + poffInfo->debugFuncSection.sh_size) + { + /* Return NULL to signal the end of the list */ + + return NULL; + } + + /* Get a reference to the debug function entry */ + + pDebugInfo = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[debugFuncIndex]; + + /* Allocate a container */ + + pRet = poffCreateDebugInfoContainer(pDebugInfo->df_nparms); + + /* Return the debug function information */ + + pRet->value = pDebugInfo->df_value; + pRet->retsize = pDebugInfo->df_size; + pRet->nparms = pDebugInfo->df_nparms; + + /* Return the size of each parameter */ + + debugFuncIndex += sizeof(poffDebugFuncInfo_t); + for (i = 0; i < pRet->nparms; i++) + { + pArgInfo = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[debugFuncIndex]; + pRet->argsize[i] = pArgInfo->da_size; + debugFuncIndex += sizeof(poffDebugArgInfo_t); + } + + /* Set up for the next read */ + + poffInfo->debugFuncIndex = debugFuncIndex; + return pRet; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfread.c b/misc/pascal/libpoff/pfread.c index e28236e431..1c03cd2743 100644 --- a/misc/pascal/libpoff/pfread.c +++ b/misc/pascal/libpoff/pfread.c @@ -1,359 +1,361 @@ -/**********************************************************************
- * pfread.c
- * POFF library global variables
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* Pascal error definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-static uint16 poffReadFileHeader(poffHandle_t handle, FILE *poffFile);
-static uint16 poffReadSectionHeaders(poffHandle_t handle, FILE *poffFile);
-static uint16 poffReadSectionData(poffSectionHeader_t *shdr,
- ubyte **sdata, FILE *poffFile);
-static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile);
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Read and verify the POFF file header */
-
-static uint16 poffReadFileHeader(poffHandle_t handle, FILE *poffFile)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- size_t entriesRead;
-
- /* Seek to the beginning of the file */
-
- if (fseek(poffFile, 0, SEEK_SET) != 0)
- {
- return ePOFFREADERROR;
- }
-
- /* Read the POFF file header */
-
- entriesRead = fread(&poffInfo->fileHeader, sizeof(poffFileHeader_t),
- 1, poffFile);
- if (entriesRead != 1)
- {
- return ePOFFREADERROR;
- }
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapFileHeader(&poffInfo->fileHeader);
-
- /* Verify that this is a valid POFF header */
-
- if ((poffInfo->fileHeader.fh_ident[FHI_MAG0] != FHI_POFF_MAG0) ||
- (poffInfo->fileHeader.fh_ident[FHI_MAG1] != FHI_POFF_MAG1) ||
- (poffInfo->fileHeader.fh_ident[FHI_MAG2] != FHI_POFF_MAG2) ||
- (poffInfo->fileHeader.fh_ident[FHI_MAG3] != FHI_POFF_MAG3) ||
- (poffInfo->fileHeader.fh_version != FHV_CURRENT))
- {
- return ePOFFBADFORMAT;
- }
- return eNOERROR;
-}
-
-/***********************************************************************/
-/* Read and verify all of the POFF section headers */
-
-static uint16 poffReadSectionHeaders(poffHandle_t handle, FILE *poffFile)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffSectionHeader_t sectionHeader;
- poffSectionHeader_t *dest;
- long offset;
- size_t entriesRead;
- int i;
-
- offset = poffInfo->fileHeader.fh_shoff;
-
- for (i = 0; i < poffInfo->fileHeader.fh_shnum; i++)
- {
- /* Seek to the beginning of the next section header */
-
- if (fseek(poffFile, offset, SEEK_SET) != 0)
- {
- return ePOFFREADERROR;
- }
-
- /* Read the section header */
-
- entriesRead = fread(§ionHeader, sizeof(poffSectionHeader_t),
- 1, poffFile);
- if (entriesRead != 1)
- {
- return ePOFFREADERROR;
- }
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapSectionHeader(§ionHeader);
-
- /* Copy the section header to the correct location */
-
- switch (sectionHeader.sh_type)
- {
- case SHT_PROGDATA : /* Program data */
- if ((sectionHeader.sh_flags & SHF_EXEC) != 0)
- dest = &poffInfo->progSection;
- else
- dest = &poffInfo->roDataSection;
- break;
-
- case SHT_SYMTAB : /* Symbol table */
- dest = &poffInfo->symbolTableSection;
- break;
-
- case SHT_STRTAB : /* String table */
- dest = &poffInfo->stringTableSection;
- break;
-
- case SHT_REL : /* Relocation data */
- dest = &poffInfo->relocSection;
- break;
-
- case SHT_FILETAB : /* File table */
- dest = &poffInfo->fileNameTableSection;
- break;
-
- case SHT_LINENO : /* Line number data */
- dest = &poffInfo->lineNumberSection;
- break;
-
- case SHT_DEBUG : /* Debug function info data */
- dest = &poffInfo->debugFuncSection;
- break;
-
- default:
- return ePOFFREADERROR;
- }
- memcpy(dest, §ionHeader, sizeof(poffSectionHeader_t));
-
- /* Get the offset to the next section */
-
- offset += poffInfo->fileHeader.fh_shsize;
- }
- return eNOERROR;
-}
-
-/***********************************************************************/
-/* Read and buffer all of the POFF section data */
-
-static uint16 poffReadSectionData(poffSectionHeader_t *shdr,
- ubyte **sdata, FILE *poffFile)
-{
- size_t entriesRead;
-
- /* Seek to the beginning of the section data */
-
- if (fseek(poffFile, shdr->sh_offset, SEEK_SET) != 0)
- {
- return ePOFFREADERROR;
- }
-
- /* Allocate memory to hold the section data */
-
- *sdata = (ubyte*)malloc(shdr->sh_size);
- if (*sdata == NULL)
- {
- return eNOMEMORY;
- }
-
- /* Read the section data */
-
- entriesRead = fread(*sdata, 1, shdr->sh_size, poffFile);
- if (entriesRead != shdr->sh_size)
- {
- return ePOFFREADERROR;
- }
- return eNOERROR;
-}
-
-/***********************************************************************/
-/* Read and buffer all of the POFF section data */
-
-static uint16 poffReadAllSectionData(poffHandle_t handle, FILE *poffFile)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint16 retval = eNOERROR;
-
- if (HAVE_PROGRAM_SECTION)
- {
- retval = poffReadSectionData(&poffInfo->progSection,
- (ubyte**)&poffInfo->progSectionData,
- poffFile);
- }
-
- if ((retval == eNOERROR) && (HAVE_RODATA_SECTION))
- {
- retval = poffReadSectionData(&poffInfo->roDataSection,
- (ubyte**)&poffInfo->roDataSectionData,
- poffFile);
- }
-
- if ((retval == eNOERROR) && (HAVE_SYMBOL_TABLE))
- {
- retval = poffReadSectionData(&poffInfo->symbolTableSection,
- (ubyte**)&poffInfo->symbolTable,
- poffFile);
-#ifdef CONFIG_POFF_SWAPNEEDED
- if (retval == eNOERROR)
- {
- poffSwapSymbolTableData(poffInfo);
- }
-#endif
- }
-
- if ((retval == eNOERROR) && (HAVE_STRING_TABLE))
- {
- retval = poffReadSectionData(&poffInfo->stringTableSection,
- (ubyte**)&poffInfo->stringTable,
- poffFile);
- }
-
- if ((retval == eNOERROR) && (HAVE_RELOC_SECTION))
- {
- retval = poffReadSectionData(&poffInfo->relocSection,
- (ubyte**)&poffInfo->relocTable,
- poffFile);
-#ifdef CONFIG_POFF_SWAPNEEDED
- if (retval == eNOERROR)
- {
- poffSwapRelocationData(poffInfo);
- }
-#endif
- }
-
- if ((retval == eNOERROR) && (HAVE_FILE_TABLE))
- {
- retval = poffReadSectionData(&poffInfo->fileNameTableSection,
- (ubyte**)&poffInfo->fileNameTable,
- poffFile);
-#ifdef CONFIG_POFF_SWAPNEEDED
- if (retval == eNOERROR)
- {
- poffSwapFileTableData(poffInfo);
- }
-#endif
- }
-
- if ((retval == eNOERROR) && (HAVE_LINE_NUMBER))
- {
- retval = poffReadSectionData(&poffInfo->lineNumberSection,
- (ubyte**)&poffInfo->lineNumberTable,
- poffFile);
-#ifdef CONFIG_POFF_SWAPNEEDED
- if (retval == eNOERROR)
- {
- poffSwapLineNumberData(poffInfo);
- }
-#endif
- }
-
- if ((retval == eNOERROR) && (HAVE_DEBUG_SECTION))
- {
- retval = poffReadSectionData(&poffInfo->debugFuncSection,
- (ubyte**)&poffInfo->debugFuncTable,
- poffFile);
-#ifdef CONFIG_POFF_SWAPNEEDED
- if (retval == eNOERROR)
- {
- poffSwapDebugData(poffInfo);
- }
-#endif
- }
-
- return retval;
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Set all global data structures to a known state */
-
-uint16 poffReadFile(poffHandle_t handle, FILE *poffFile)
-{
- uint16 retVal;
-
- /* Read the POFF header file */
-
- retVal = poffReadFileHeader(handle, poffFile);
- if (retVal == eNOERROR)
- {
- retVal = poffReadSectionHeaders(handle, poffFile);
- if (retVal == eNOERROR)
- {
- retVal = poffReadAllSectionData(handle, poffFile);
- }
- }
- return retVal;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfread.c + * POFF library global variables + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <sys/types.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* Pascal error definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +static uint16_t poffReadFileHeader(poffHandle_t handle, FILE *poffFile); +static uint16_t poffReadSectionHeaders(poffHandle_t handle, FILE *poffFile); +static uint16_t poffReadSectionData(poffSectionHeader_t *shdr, + uint8_t **sdata, FILE *poffFile); +static uint16_t poffReadAllSectionData(poffHandle_t handle, FILE *poffFile); + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Read and verify the POFF file header */ + +static uint16_t poffReadFileHeader(poffHandle_t handle, FILE *poffFile) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + size_t entriesRead; + + /* Seek to the beginning of the file */ + + if (fseek(poffFile, 0, SEEK_SET) != 0) + { + return ePOFFREADERROR; + } + + /* Read the POFF file header */ + + entriesRead = fread(&poffInfo->fileHeader, sizeof(poffFileHeader_t), + 1, poffFile); + if (entriesRead != 1) + { + return ePOFFREADERROR; + } + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapFileHeader(&poffInfo->fileHeader); + + /* Verify that this is a valid POFF header */ + + if ((poffInfo->fileHeader.fh_ident[FHI_MAG0] != FHI_POFF_MAG0) || + (poffInfo->fileHeader.fh_ident[FHI_MAG1] != FHI_POFF_MAG1) || + (poffInfo->fileHeader.fh_ident[FHI_MAG2] != FHI_POFF_MAG2) || + (poffInfo->fileHeader.fh_ident[FHI_MAG3] != FHI_POFF_MAG3) || + (poffInfo->fileHeader.fh_version != FHV_CURRENT)) + { + return ePOFFBADFORMAT; + } + return eNOERROR; +} + +/***********************************************************************/ +/* Read and verify all of the POFF section headers */ + +static uint16_t poffReadSectionHeaders(poffHandle_t handle, FILE *poffFile) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffSectionHeader_t sectionHeader; + poffSectionHeader_t *dest; + long offset; + size_t entriesRead; + int i; + + offset = poffInfo->fileHeader.fh_shoff; + + for (i = 0; i < poffInfo->fileHeader.fh_shnum; i++) + { + /* Seek to the beginning of the next section header */ + + if (fseek(poffFile, offset, SEEK_SET) != 0) + { + return ePOFFREADERROR; + } + + /* Read the section header */ + + entriesRead = fread(§ionHeader, sizeof(poffSectionHeader_t), + 1, poffFile); + if (entriesRead != 1) + { + return ePOFFREADERROR; + } + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapSectionHeader(§ionHeader); + + /* Copy the section header to the correct location */ + + switch (sectionHeader.sh_type) + { + case SHT_PROGDATA : /* Program data */ + if ((sectionHeader.sh_flags & SHF_EXEC) != 0) + dest = &poffInfo->progSection; + else + dest = &poffInfo->roDataSection; + break; + + case SHT_SYMTAB : /* Symbol table */ + dest = &poffInfo->symbolTableSection; + break; + + case SHT_STRTAB : /* String table */ + dest = &poffInfo->stringTableSection; + break; + + case SHT_REL : /* Relocation data */ + dest = &poffInfo->relocSection; + break; + + case SHT_FILETAB : /* File table */ + dest = &poffInfo->fileNameTableSection; + break; + + case SHT_LINENO : /* Line number data */ + dest = &poffInfo->lineNumberSection; + break; + + case SHT_DEBUG : /* Debug function info data */ + dest = &poffInfo->debugFuncSection; + break; + + default: + return ePOFFREADERROR; + } + memcpy(dest, §ionHeader, sizeof(poffSectionHeader_t)); + + /* Get the offset to the next section */ + + offset += poffInfo->fileHeader.fh_shsize; + } + return eNOERROR; +} + +/***********************************************************************/ +/* Read and buffer all of the POFF section data */ + +static uint16_t poffReadSectionData(poffSectionHeader_t *shdr, + uint8_t **sdata, FILE *poffFile) +{ + size_t entriesRead; + + /* Seek to the beginning of the section data */ + + if (fseek(poffFile, shdr->sh_offset, SEEK_SET) != 0) + { + return ePOFFREADERROR; + } + + /* Allocate memory to hold the section data */ + + *sdata = (uint8_t*)malloc(shdr->sh_size); + if (*sdata == NULL) + { + return eNOMEMORY; + } + + /* Read the section data */ + + entriesRead = fread(*sdata, 1, shdr->sh_size, poffFile); + if (entriesRead != shdr->sh_size) + { + return ePOFFREADERROR; + } + return eNOERROR; +} + +/***********************************************************************/ +/* Read and buffer all of the POFF section data */ + +static uint16_t poffReadAllSectionData(poffHandle_t handle, FILE *poffFile) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint16_t retval = eNOERROR; + + if (HAVE_PROGRAM_SECTION) + { + retval = poffReadSectionData(&poffInfo->progSection, + (uint8_t**)&poffInfo->progSectionData, + poffFile); + } + + if ((retval == eNOERROR) && (HAVE_RODATA_SECTION)) + { + retval = poffReadSectionData(&poffInfo->roDataSection, + (uint8_t**)&poffInfo->roDataSectionData, + poffFile); + } + + if ((retval == eNOERROR) && (HAVE_SYMBOL_TABLE)) + { + retval = poffReadSectionData(&poffInfo->symbolTableSection, + (uint8_t**)&poffInfo->symbolTable, + poffFile); +#ifdef CONFIG_POFF_SWAPNEEDED + if (retval == eNOERROR) + { + poffSwapSymbolTableData(poffInfo); + } +#endif + } + + if ((retval == eNOERROR) && (HAVE_STRING_TABLE)) + { + retval = poffReadSectionData(&poffInfo->stringTableSection, + (uint8_t**)&poffInfo->stringTable, + poffFile); + } + + if ((retval == eNOERROR) && (HAVE_RELOC_SECTION)) + { + retval = poffReadSectionData(&poffInfo->relocSection, + (uint8_t**)&poffInfo->relocTable, + poffFile); +#ifdef CONFIG_POFF_SWAPNEEDED + if (retval == eNOERROR) + { + poffSwapRelocationData(poffInfo); + } +#endif + } + + if ((retval == eNOERROR) && (HAVE_FILE_TABLE)) + { + retval = poffReadSectionData(&poffInfo->fileNameTableSection, + (uint8_t**)&poffInfo->fileNameTable, + poffFile); +#ifdef CONFIG_POFF_SWAPNEEDED + if (retval == eNOERROR) + { + poffSwapFileTableData(poffInfo); + } +#endif + } + + if ((retval == eNOERROR) && (HAVE_LINE_NUMBER)) + { + retval = poffReadSectionData(&poffInfo->lineNumberSection, + (uint8_t**)&poffInfo->lineNumberTable, + poffFile); +#ifdef CONFIG_POFF_SWAPNEEDED + if (retval == eNOERROR) + { + poffSwapLineNumberData(poffInfo); + } +#endif + } + + if ((retval == eNOERROR) && (HAVE_DEBUG_SECTION)) + { + retval = poffReadSectionData(&poffInfo->debugFuncSection, + (uint8_t**)&poffInfo->debugFuncTable, + poffFile); +#ifdef CONFIG_POFF_SWAPNEEDED + if (retval == eNOERROR) + { + poffSwapDebugData(poffInfo); + } +#endif + } + + return retval; +} + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Set all global data structures to a known state */ + +uint16_t poffReadFile(poffHandle_t handle, FILE *poffFile) +{ + uint16_t retVal; + + /* Read the POFF header file */ + + retVal = poffReadFileHeader(handle, poffFile); + if (retVal == eNOERROR) + { + retVal = poffReadSectionHeaders(handle, poffFile); + if (retVal == eNOERROR) + { + retVal = poffReadAllSectionData(handle, poffFile); + } + } + return retVal; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfrfname.c b/misc/pascal/libpoff/pfrfname.c index 70a7883168..68fc2fb4c3 100644 --- a/misc/pascal/libpoff/pfrfname.c +++ b/misc/pascal/libpoff/pfrfname.c @@ -1,116 +1,117 @@ -/**********************************************************************
- * pfrfname.c
- * Read file name data from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-sint32 poffGetFileName(poffHandle_t handle, const char **fname)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint32 stringTableIndex;
- uint32 fileNameIndex;
-
- /* First, check if there is another file name in the table to be had.
- * This check is a little sloppy in that it assumes the the size in
- * in the header is an even multiple of file name table entries
- */
-
- fileNameIndex = poffInfo->fileNameIndex;
- if (fileNameIndex * sizeof(poffFileTab_t) >=
- poffInfo->fileNameTableSection.sh_size)
- {
- /* Return -1 to signal the end of the list */
-
- *fname = NULL;
- return -1;
- }
- else
- {
- /* Get the string table index from the file name table */
-
- stringTableIndex = (uint32)poffInfo->fileNameTable[fileNameIndex];
-
- /* Return the file name */
-
- *fname = poffGetString(handle, stringTableIndex);
-
- /* Set up for the next read */
-
- poffInfo->fileNameIndex++;
- return fileNameIndex;
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrfname.c + * Read file name data from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ + +int32_t poffGetFileName(poffHandle_t handle, const char **fname) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint32_t stringTableIndex; + uint32_t fileNameIndex; + + /* First, check if there is another file name in the table to be had. + * This check is a little sloppy in that it assumes the the size in + * in the header is an even multiple of file name table entries + */ + + fileNameIndex = poffInfo->fileNameIndex; + if (fileNameIndex * sizeof(poffFileTab_t) >= + poffInfo->fileNameTableSection.sh_size) + { + /* Return -1 to signal the end of the list */ + + *fname = NULL; + return -1; + } + else + { + /* Get the string table index from the file name table */ + + stringTableIndex = (uint32_t)poffInfo->fileNameTable[fileNameIndex]; + + /* Return the file name */ + + *fname = poffGetString(handle, stringTableIndex); + + /* Set up for the next read */ + + poffInfo->fileNameIndex++; + return fileNameIndex; + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfrhdr.c b/misc/pascal/libpoff/pfrhdr.c index ca153c83ee..8415c31fbb 100644 --- a/misc/pascal/libpoff/pfrhdr.c +++ b/misc/pascal/libpoff/pfrhdr.c @@ -1,117 +1,118 @@ -/**********************************************************************
- * pfrhdr.c
- * Read info from a POFF file header
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Get the type of the file from the POFF file header */
-
-ubyte poffGetFileType(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- return poffInfo->fileHeader.fh_type;
-}
-
-/***********************************************************************/
-/* Get the machine architecture from the POFF file header */
-
-ubyte poffGetArchitecture(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- return poffInfo->fileHeader.fh_arch;
-}
-
-/***********************************************************************/
-/* Get the program entry point */
-
-uint32 poffGetEntryPoint(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- return poffInfo->fileHeader.fh_entry;
-}
-
-/***********************************************************************/
-/* Return the name associated with the file in the file header */
-
-const char *poffGetFileHdrName(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- return poffGetString(handle, poffInfo->fileHeader.fh_name);
-}
-
-/***********************************************************************/
-
-uint32 poffGetRoDataSize(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- return poffInfo->roDataSection.sh_size;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrhdr.c + * Read info from a POFF file header + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Get the type of the file from the POFF file header */ + +uint8_t poffGetFileType(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + return poffInfo->fileHeader.fh_type; +} + +/***********************************************************************/ +/* Get the machine architecture from the POFF file header */ + +uint8_t poffGetArchitecture(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + return poffInfo->fileHeader.fh_arch; +} + +/***********************************************************************/ +/* Get the program entry point */ + +uint32_t poffGetEntryPoint(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + return poffInfo->fileHeader.fh_entry; +} + +/***********************************************************************/ +/* Return the name associated with the file in the file header */ + +const char *poffGetFileHdrName(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + return poffGetString(handle, poffInfo->fileHeader.fh_name); +} + +/***********************************************************************/ + +uint32_t poffGetRoDataSize(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + return poffInfo->roDataSection.sh_size; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfrlineno.c b/misc/pascal/libpoff/pfrlineno.c index d1ec2a5f2f..f7d76a973a 100644 --- a/misc/pascal/libpoff/pfrlineno.c +++ b/misc/pascal/libpoff/pfrlineno.c @@ -1,127 +1,128 @@ -/**********************************************************************
- * pfrlineno.c
- * Read line number data from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-sint32 poffGetLineNumber(poffHandle_t handle, poffLibLineNumber_t *lineno)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffLineNumber_t *pln;
- uint32 stringTableIndex;
- uint32 lineNumberIndex;
-
- /* First, check if there is another line number in the table to be had.
- * This check is a little sloppy in that it assumes the the size in
- * in the header is an even multiple of line number table entries
- */
-
- lineNumberIndex = poffInfo->lineNumberIndex;
- if (lineNumberIndex >= poffInfo->lineNumberSection.sh_size)
- {
- /* Return -1 to signal the end of the list */
-
- memset(lineno, 0, sizeof(poffLibLineNumber_t));
- return -1;
- }
- else
- {
- /* Get a reference to the line number record */
-
- pln = (poffLineNumber_t*)&poffInfo->lineNumberTable[lineNumberIndex];
-
- /* Get the filename table index */
-
- if (pln->ln_fileno * sizeof(poffFileTab_t) >
- poffInfo->fileNameTableSection.sh_size)
- {
- fatal(ePOFFCONFUSION);
- }
- stringTableIndex = (uint32)poffInfo->fileNameTable[pln->ln_fileno];
-
- /* Return the line number information */
-
- lineno->lineno = pln->ln_lineno;
- lineno->offset = pln->ln_poffset;
- lineno->filename = poffGetString(handle, stringTableIndex);
-
- /* Set up for the next read */
-
- poffInfo->lineNumberIndex += poffInfo->lineNumberSection.sh_entsize;
- return lineNumberIndex;
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrlineno.c + * Read line number data from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ + +int32_t poffGetLineNumber(poffHandle_t handle, poffLibLineNumber_t *lineno) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffLineNumber_t *pln; + uint32_t stringTableIndex; + uint32_t lineNumberIndex; + + /* First, check if there is another line number in the table to be had. + * This check is a little sloppy in that it assumes the the size in + * in the header is an even multiple of line number table entries + */ + + lineNumberIndex = poffInfo->lineNumberIndex; + if (lineNumberIndex >= poffInfo->lineNumberSection.sh_size) + { + /* Return -1 to signal the end of the list */ + + memset(lineno, 0, sizeof(poffLibLineNumber_t)); + return -1; + } + else + { + /* Get a reference to the line number record */ + + pln = (poffLineNumber_t*)&poffInfo->lineNumberTable[lineNumberIndex]; + + /* Get the filename table index */ + + if (pln->ln_fileno * sizeof(poffFileTab_t) > + poffInfo->fileNameTableSection.sh_size) + { + fatal(ePOFFCONFUSION); + } + stringTableIndex = (uint32_t)poffInfo->fileNameTable[pln->ln_fileno]; + + /* Return the line number information */ + + lineno->lineno = pln->ln_lineno; + lineno->offset = pln->ln_poffset; + lineno->filename = poffGetString(handle, stringTableIndex); + + /* Set up for the next read */ + + poffInfo->lineNumberIndex += poffInfo->lineNumberSection.sh_entsize; + return lineNumberIndex; + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfrrawlineno.c b/misc/pascal/libpoff/pfrrawlineno.c index 6eb1371574..9855bc5931 100644 --- a/misc/pascal/libpoff/pfrrawlineno.c +++ b/misc/pascal/libpoff/pfrrawlineno.c @@ -1,110 +1,111 @@ -/**********************************************************************
- * pfrrawlineno.c
- * Read raw line number data from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-sint32 poffGetRawLineNumber(poffHandle_t handle, poffLineNumber_t *lineno)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint32 lineNumberIndex;
-
- /* First, check if there is another line number in the table to be had.
- * This check is a little sloppy in that it assumes the the size in
- * in the header is an even multiple of line number table entries
- */
-
- lineNumberIndex = poffInfo->lineNumberIndex;
- if (lineNumberIndex >= poffInfo->lineNumberSection.sh_size)
- {
- /* Return -1 to signal the end of the list */
-
- memset(lineno, 0, sizeof(poffLineNumber_t));
- return -1;
- }
- else
- {
- /* Copy the raw line number information to the user */
-
- memcpy(lineno, &poffInfo->lineNumberTable[lineNumberIndex], sizeof(poffLineNumber_t));
-
- /* Set up for the next read */
-
- poffInfo->lineNumberIndex += poffInfo->lineNumberSection.sh_entsize;
- return lineNumberIndex;
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrrawlineno.c + * Read raw line number data from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ + +int32_t poffGetRawLineNumber(poffHandle_t handle, poffLineNumber_t *lineno) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint32_t lineNumberIndex; + + /* First, check if there is another line number in the table to be had. + * This check is a little sloppy in that it assumes the the size in + * in the header is an even multiple of line number table entries + */ + + lineNumberIndex = poffInfo->lineNumberIndex; + if (lineNumberIndex >= poffInfo->lineNumberSection.sh_size) + { + /* Return -1 to signal the end of the list */ + + memset(lineno, 0, sizeof(poffLineNumber_t)); + return -1; + } + else + { + /* Copy the raw line number information to the user */ + + memcpy(lineno, &poffInfo->lineNumberTable[lineNumberIndex], sizeof(poffLineNumber_t)); + + /* Set up for the next read */ + + poffInfo->lineNumberIndex += poffInfo->lineNumberSection.sh_entsize; + return lineNumberIndex; + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfrrawreloc.c b/misc/pascal/libpoff/pfrrawreloc.c index 2a3e6d7d57..50e6e1bf87 100644 --- a/misc/pascal/libpoff/pfrrawreloc.c +++ b/misc/pascal/libpoff/pfrrawreloc.c @@ -1,107 +1,108 @@ -/**********************************************************************
- * pfrrawreloc.c
- * Read raw relocation data from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-sint32 poffGetRawRelocation(poffHandle_t handle, poffRelocation_t *lineno)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint32 relocIndex;
-
- /* First, check if there is another relocation in the table to be had. */
-
- relocIndex = poffInfo->relocIndex;
- if (relocIndex >= poffInfo->relocSection.sh_size)
- {
- /* Return -1 to signal the end of the list */
-
- memset(lineno, 0, sizeof(poffRelocation_t));
- return -1;
- }
- else
- {
- /* Copy the raw line number information to the user */
-
- memcpy(lineno, &poffInfo->relocTable[relocIndex], sizeof(poffRelocation_t));
-
- /* Set up for the next read */
-
- poffInfo->relocIndex += poffInfo->relocSection.sh_entsize;
- return relocIndex;
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrrawreloc.c + * Read raw relocation data from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ + +int32_t poffGetRawRelocation(poffHandle_t handle, poffRelocation_t *lineno) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint32_t relocIndex; + + /* First, check if there is another relocation in the table to be had. */ + + relocIndex = poffInfo->relocIndex; + if (relocIndex >= poffInfo->relocSection.sh_size) + { + /* Return -1 to signal the end of the list */ + + memset(lineno, 0, sizeof(poffRelocation_t)); + return -1; + } + else + { + /* Copy the raw line number information to the user */ + + memcpy(lineno, &poffInfo->relocTable[relocIndex], sizeof(poffRelocation_t)); + + /* Set up for the next read */ + + poffInfo->relocIndex += poffInfo->relocSection.sh_entsize; + return relocIndex; + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfrseek.c b/misc/pascal/libpoff/pfrseek.c index ea0b9c0aa9..e7c0577809 100644 --- a/misc/pascal/libpoff/pfrseek.c +++ b/misc/pascal/libpoff/pfrseek.c @@ -1,115 +1,116 @@ -/**********************************************************************
- * pfrseek.c
- * Seek to a position in buffered program data from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-sint32 poffProgTell(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- sint32 retval = -1;
-
- /* Check if there is more data that has not yet been read */
-
- if (poffInfo->progSectionData != NULL)
- {
- retval = poffInfo->progSectionIndex;
- }
- return retval;
-}
-
-/***********************************************************************/
-
-int poffProgSeek(poffHandle_t handle, uint32 offset)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- int retval = -1;
-
- /* Check if there is more data that has not yet been read */
-
- if ((offset < poffInfo->progSection.sh_size) &&
- (poffInfo->progSectionData != NULL))
- {
- poffInfo->progSectionIndex = offset;
- retval = offset;
- }
- return retval;
-}
-
-/***********************************************************************/
-
-uint32 poffGetProgSize(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- return poffInfo->progSection.sh_size;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrseek.c + * Seek to a position in buffered program data from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ + +int32_t poffProgTell(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + int32_t retval = -1; + + /* Check if there is more data that has not yet been read */ + + if (poffInfo->progSectionData != NULL) + { + retval = poffInfo->progSectionIndex; + } + return retval; +} + +/***********************************************************************/ + +int poffProgSeek(poffHandle_t handle, uint32_t offset) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + int retval = -1; + + /* Check if there is more data that has not yet been read */ + + if ((offset < poffInfo->progSection.sh_size) && + (poffInfo->progSectionData != NULL)) + { + poffInfo->progSectionIndex = offset; + retval = offset; + } + return retval; +} + +/***********************************************************************/ + +uint32_t poffGetProgSize(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + return poffInfo->progSection.sh_size; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfrstring.c b/misc/pascal/libpoff/pfrstring.c index 666da886ae..664620cbbc 100644 --- a/misc/pascal/libpoff/pfrstring.c +++ b/misc/pascal/libpoff/pfrstring.c @@ -1,90 +1,91 @@ -/**********************************************************************
- * pfrstring.c
- * Read a string from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-const char *poffGetString(poffHandle_t handle, uint32 index)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
-
- if ((index < poffInfo->stringTableSection.sh_size) &&
- (poffInfo->stringTable != NULL))
- {
- return &poffInfo->stringTable[index];
- }
- else
- {
- return "<NULL>";
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrstring.c + * Read a string from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ + +const char *poffGetString(poffHandle_t handle, uint32_t index) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + + if ((index < poffInfo->stringTableSection.sh_size) && + (poffInfo->stringTable != NULL)) + { + return &poffInfo->stringTable[index]; + } + else + { + return "<NULL>"; + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfrsymbol.c b/misc/pascal/libpoff/pfrsymbol.c index dc76e524da..fe41e43b00 100644 --- a/misc/pascal/libpoff/pfrsymbol.c +++ b/misc/pascal/libpoff/pfrsymbol.c @@ -1,107 +1,108 @@ -/**********************************************************************
- * pfrsymbol
- * Read symbols from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-sint32 poffGetSymbol(poffHandle_t handle, poffLibSymbol_t *symbol)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffSymbol_t *psym;
- uint32 index;
-
- /* First, check if there is another symbol in the table to be had.
- * This check is a little sloppy in that it assumes the the size in
- * in the section header is an even multiple of symbol table entries
- */
-
- index = poffInfo->symbolIndex;
- if (index >= poffInfo->symbolTableSection.sh_size)
- {
- memset(symbol, 0, sizeof(poffLibSymbol_t));
- return -1;
- }
- else
- {
- psym = (poffSymbol_t*)&poffInfo->symbolTable[index];
- symbol->type = psym->st_type;
- symbol->align = psym->st_align;
- symbol->flags = psym->st_flags;
- symbol->name = poffGetString(handle, psym->st_name);
- symbol->value = psym->st_value;
- symbol->size = psym->st_size;
-
- poffInfo->symbolIndex += poffInfo->symbolTableSection.sh_entsize;
- return index / poffInfo->symbolTableSection.sh_entsize;
- }
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfrsymbol + * Read symbols from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ + +int32_t poffGetSymbol(poffHandle_t handle, poffLibSymbol_t *symbol) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffSymbol_t *psym; + uint32_t index; + + /* First, check if there is another symbol in the table to be had. + * This check is a little sloppy in that it assumes the the size in + * in the section header is an even multiple of symbol table entries + */ + + index = poffInfo->symbolIndex; + if (index >= poffInfo->symbolTableSection.sh_size) + { + memset(symbol, 0, sizeof(poffLibSymbol_t)); + return -1; + } + else + { + psym = (poffSymbol_t*)&poffInfo->symbolTable[index]; + symbol->type = psym->st_type; + symbol->align = psym->st_align; + symbol->flags = psym->st_flags; + symbol->name = poffGetString(handle, psym->st_name); + symbol->value = psym->st_value; + symbol->size = psym->st_size; + + poffInfo->symbolIndex += poffInfo->symbolTableSection.sh_entsize; + return index / poffInfo->symbolTableSection.sh_entsize; + } +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfswap.c b/misc/pascal/libpoff/pfswap.c index bb99190bc0..9c30aad8f2 100644 --- a/misc/pascal/libpoff/pfswap.c +++ b/misc/pascal/libpoff/pfswap.c @@ -1,250 +1,252 @@ -/**********************************************************************
- * libpoff/pfswap.c
- * Handle POFF Endian-ness
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include "keywords.h" /* Standard types */
-#include "paslib.h" /* Common library */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-static inline void poffSwapRelocationEntry(poffRelocation_t *prel)
-{
- prel->rl_info = poff32(prel->rl_info);
- prel->rl_offset = poff32(prel->rl_offset);
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-static inline void poffSwapSymbolTableEntry(poffSymbol_t *psym)
-{
- psym->st_name = poff32(psym->st_name);
- psym->st_value = poff32(psym->st_value);
- psym->st_size = poff32(psym->st_size);
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-static inline void poffSwapFileTabEntry(poffFileTab_t *pfile)
-{
- *pfile = poff32((uint32)*pfile);
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-static inline void poffSwaplineno(poffLineNumber_t *plineno)
-{
- plineno->ln_lineno = poff16(plineno->ln_lineno);
- plineno->ln_fileno = poff16(plineno->ln_fileno);
- plineno->ln_poffset = poff32(plineno->ln_poffset);
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-static inline void poffDebugFuncEntry(poffDebugFuncInfo_t *pdbg)
-{
- pdbg->df_value = poff32(pdbg->df_value);
- pdbg->df_size = poff32(pdbg->df_size);
- pdbg->df_nparms = poff32(pdbg->df_nparms);
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-static inline void poffDebugArgEntry(poffDebugArgInfo_t *parg)
-{
- parg->da_size = poff32(parg->da_size);
-}
-#endif
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-void poffSwapFileHeader(poffFileHeader_t *pFileHeader)
-{
- pFileHeader->fh_shsize = poff16(pFileHeader->fh_shsize);
- pFileHeader->fh_shnum = poff16(pFileHeader->fh_shnum);
- pFileHeader->fh_name = poff32(pFileHeader->fh_name);
- pFileHeader->fh_entry = poff32(pFileHeader->fh_entry);
- pFileHeader->fh_shoff = poff32(pFileHeader->fh_shoff);
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-void poffSwapSectionHeader(poffSectionHeader_t *pSectionHeader)
-{
- pSectionHeader->sh_entsize = poff16(pSectionHeader->sh_entsize);
- pSectionHeader->sh_name = poff32(pSectionHeader->sh_name);
- pSectionHeader->sh_addr = poff32(pSectionHeader->sh_addr);
- pSectionHeader->sh_offset = poff32(pSectionHeader->sh_offset);
- pSectionHeader->sh_size = poff32(pSectionHeader->sh_size);
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-void poffSwapSymbolTableData(poffInfo_t *poffInfo)
-{
- poffSymbol_t *psym;
- uint32 index;
-
- for (index = 0;
- index < poffInfo->symbolTableSection.sh_size;
- index += poffInfo->symbolTableSection.sh_entsize)
- {
- psym = (poffSymbol_t*)&poffInfo->symbolTable[index];
- poffSwapSymbolTableEntry(psym);
- }
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-void poffSwapRelocationData(poffInfo_t *poffInfo)
-{
- poffRelocation_t *prel;
- uint32 index;
-
- for (index = 0;
- index < poffInfo->relocSection.sh_size;
- index += poffInfo->relocSection.sh_entsize)
- {
- prel = (poffRelocation_t*)&poffInfo->relocTable[index];
- poffSwapRelocationEntry(prel);
- }
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-void poffSwapFileTableData(poffInfo_t *poffInfo)
-{
- poffFileTab_t *pfile;
- uint32 index;
-
- for (index = 0;
- index < poffInfo->relocSection.sh_size;
- index += poffInfo->relocSection.sh_entsize)
- {
- pfile = (poffFileTab_t*)&poffInfo->relocTable[index];
- poffSwapFileTabEntry(pfile);
- }
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-void poffSwapLineNumberData(poffInfo_t *poffInfo)
-{
- poffLineNumber_t *plineno;
- uint32 index;
-
- for (index = 0;
- index < poffInfo->relocSection.sh_size;
- index += poffInfo->relocSection.sh_entsize)
- {
- plineno = (poffLineNumber_t*)&poffInfo->relocTable[index];
- poffSwaplineno(plineno);
- }
-}
-#endif
-
-/***********************************************************************/
-
-#ifdef CONFIG_POFF_SWAPNEEDED
-void poffSwapDebugData(poffInfo_t *poffInfo)
-{
- poffDebugFuncInfo_t *pdbg;
- poffDebugArgInfo_t *parg;
- uint32 i;
- int j;
-
- for (i = 0; i + sizeof(poffDebugFuncInfo_t) < poffInfo->relocSection.sh_size;)
- {
- pdbg = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[i];
- poffDebugFuncEntry(pdbg);
-
- i += sizeof(poffDebugFuncInfo_t);
- for (j = 0; j < pdbg->df_nparms; j++)
- {
- parg = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[i];
- poffDebugArgEntry(parg);
- i += sizeof(poffDebugArgInfo_t);
- }
- }
-}
-#endif
-
-/***********************************************************************/
+/********************************************************************** + * libpoff/pfswap.c + * Handle POFF Endian-ness + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> + +#include "keywords.h" /* Standard types */ +#include "paslib.h" /* Common library */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +static inline void poffSwapRelocationEntry(poffRelocation_t *prel) +{ + prel->rl_info = poff32(prel->rl_info); + prel->rl_offset = poff32(prel->rl_offset); +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +static inline void poffSwapSymbolTableEntry(poffSymbol_t *psym) +{ + psym->st_name = poff32(psym->st_name); + psym->st_value = poff32(psym->st_value); + psym->st_size = poff32(psym->st_size); +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +static inline void poffSwapFileTabEntry(poffFileTab_t *pfile) +{ + *pfile = poff32((uint32_t)*pfile); +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +static inline void poffSwaplineno(poffLineNumber_t *plineno) +{ + plineno->ln_lineno = poff16(plineno->ln_lineno); + plineno->ln_fileno = poff16(plineno->ln_fileno); + plineno->ln_poffset = poff32(plineno->ln_poffset); +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +static inline void poffDebugFuncEntry(poffDebugFuncInfo_t *pdbg) +{ + pdbg->df_value = poff32(pdbg->df_value); + pdbg->df_size = poff32(pdbg->df_size); + pdbg->df_nparms = poff32(pdbg->df_nparms); +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +static inline void poffDebugArgEntry(poffDebugArgInfo_t *parg) +{ + parg->da_size = poff32(parg->da_size); +} +#endif + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +void poffSwapFileHeader(poffFileHeader_t *pFileHeader) +{ + pFileHeader->fh_shsize = poff16(pFileHeader->fh_shsize); + pFileHeader->fh_shnum = poff16(pFileHeader->fh_shnum); + pFileHeader->fh_name = poff32(pFileHeader->fh_name); + pFileHeader->fh_entry = poff32(pFileHeader->fh_entry); + pFileHeader->fh_shoff = poff32(pFileHeader->fh_shoff); +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +void poffSwapSectionHeader(poffSectionHeader_t *pSectionHeader) +{ + pSectionHeader->sh_entsize = poff16(pSectionHeader->sh_entsize); + pSectionHeader->sh_name = poff32(pSectionHeader->sh_name); + pSectionHeader->sh_addr = poff32(pSectionHeader->sh_addr); + pSectionHeader->sh_offset = poff32(pSectionHeader->sh_offset); + pSectionHeader->sh_size = poff32(pSectionHeader->sh_size); +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +void poffSwapSymbolTableData(poffInfo_t *poffInfo) +{ + poffSymbol_t *psym; + uint32_t index; + + for (index = 0; + index < poffInfo->symbolTableSection.sh_size; + index += poffInfo->symbolTableSection.sh_entsize) + { + psym = (poffSymbol_t*)&poffInfo->symbolTable[index]; + poffSwapSymbolTableEntry(psym); + } +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +void poffSwapRelocationData(poffInfo_t *poffInfo) +{ + poffRelocation_t *prel; + uint32_t index; + + for (index = 0; + index < poffInfo->relocSection.sh_size; + index += poffInfo->relocSection.sh_entsize) + { + prel = (poffRelocation_t*)&poffInfo->relocTable[index]; + poffSwapRelocationEntry(prel); + } +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +void poffSwapFileTableData(poffInfo_t *poffInfo) +{ + poffFileTab_t *pfile; + uint32_t index; + + for (index = 0; + index < poffInfo->relocSection.sh_size; + index += poffInfo->relocSection.sh_entsize) + { + pfile = (poffFileTab_t*)&poffInfo->relocTable[index]; + poffSwapFileTabEntry(pfile); + } +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +void poffSwapLineNumberData(poffInfo_t *poffInfo) +{ + poffLineNumber_t *plineno; + uint32_t index; + + for (index = 0; + index < poffInfo->relocSection.sh_size; + index += poffInfo->relocSection.sh_entsize) + { + plineno = (poffLineNumber_t*)&poffInfo->relocTable[index]; + poffSwaplineno(plineno); + } +} +#endif + +/***********************************************************************/ + +#ifdef CONFIG_POFF_SWAPNEEDED +void poffSwapDebugData(poffInfo_t *poffInfo) +{ + poffDebugFuncInfo_t *pdbg; + poffDebugArgInfo_t *parg; + uint32_t i; + int j; + + for (i = 0; i + sizeof(poffDebugFuncInfo_t) < poffInfo->relocSection.sh_size;) + { + pdbg = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[i]; + poffDebugFuncEntry(pdbg); + + i += sizeof(poffDebugFuncInfo_t); + for (j = 0; j < pdbg->df_nparms; j++) + { + parg = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[i]; + poffDebugArgEntry(parg); + i += sizeof(poffDebugArgInfo_t); + } + } +} +#endif + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pftprog.c b/misc/pascal/libpoff/pftprog.c index 9c88921a11..3a7e71e210 100644 --- a/misc/pascal/libpoff/pftprog.c +++ b/misc/pascal/libpoff/pftprog.c @@ -1,224 +1,225 @@ -/**********************************************************************
- * pftprog.c
- * Program data manipulations on POFF temporary object
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* Pascal error codes */
-
-#include "pfprivate.h" /* POFF private definitions */
-#include "pofflib.h" /* Public interfaces */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-static uint16 poffCheckProgAlloc(poffProgInfo_t *poffProgInfo)
-{
- if (!poffProgInfo->progSectionData)
- {
- /* No, allocate it now */
-
- poffProgInfo->progSectionData = (ubyte*)malloc(INITIAL_PROG_SECTION_SIZE);
- if (!poffProgInfo->progSectionData)
- {
- return eNOMEMORY;
- }
-
- poffProgInfo->progSectionSize = 0;
- poffProgInfo->progSectionAlloc = INITIAL_PROG_SECTION_SIZE;
- }
- return eNOERROR;
-}
-
-static uint16 poffCheckProgRealloc(poffProgInfo_t *poffProgInfo, uint16 len)
-{
- /* Check if there is room for the new data */
-
- if (poffProgInfo->progSectionSize + len > poffProgInfo->progSectionAlloc)
- {
- uint32 newAlloc =
- poffProgInfo->progSectionAlloc + PROG_SECTION_INCREMENT;
- void *tmp;
-
- /* Make certain that this is big enough (it should be) */
-
- while (poffProgInfo->progSectionSize + len > newAlloc)
- {
- newAlloc += PROG_SECTION_INCREMENT;
- }
-
- /* Reallocate the program data section buffer */
-
- tmp = realloc(poffProgInfo->progSectionData, newAlloc);
- if (!tmp)
- {
- return eNOMEMORY;
- }
-
- /* And set the new size */
-
- poffProgInfo->progSectionAlloc = newAlloc;
- poffProgInfo->progSectionData = (ubyte*)tmp;
- }
- return eNOERROR;
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-uint16 poffAddTmpProgByte(poffProgHandle_t handle, ubyte progByte)
-{
- poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)handle;
- uint16 errCode;
-
- /* Check if we have allocated a program section buffer yet */
-
- errCode = poffCheckProgAlloc(poffProgInfo);
- if (errCode != eNOERROR)
- {
- return errCode;
- }
-
- /* Check if there is room for the new byte */
-
- errCode = poffCheckProgRealloc(poffProgInfo, 1);
- if (errCode != eNOERROR)
- {
- return errCode;
- }
-
- /* Copy program data byte into the program data buffer */
-
- poffProgInfo->progSectionData[poffProgInfo->progSectionSize] = progByte;
-
- /* Set the new size of the string table */
-
- poffProgInfo->progSectionSize++;
- return eNOERROR;
-}
-
-/***********************************************************************/
-
-uint16 poffWriteTmpProgBytes(ubyte *buffer, uint32 nbytes,
- poffProgHandle_t handle)
-
-{
- poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)handle;
- uint16 errCode;
-
- /* Check if we have allocated a program section buffer yet */
-
- errCode = poffCheckProgAlloc(poffProgInfo);
- if (errCode != eNOERROR)
- {
- return errCode;
- }
-
- /* Check if there is room for the new data */
-
- errCode = poffCheckProgRealloc(poffProgInfo, nbytes);
- if (errCode != eNOERROR)
- {
- return errCode;
- }
-
- /* Copy program data byte into the program data buffer */
-
- memcpy(&poffProgInfo->progSectionData[poffProgInfo->progSectionSize],
- buffer, nbytes);
-
- /* Set the new size of the string table */
-
- poffProgInfo->progSectionSize += nbytes;
- return eNOERROR;
-}
-
-/***********************************************************************/
-
-void poffReplaceProgData(poffHandle_t handle, poffProgHandle_t progHandle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)progHandle;
-
- /* Discard any existing program section data */
-
- if (poffInfo->progSectionData)
- {
- free(poffInfo->progSectionData);
- }
-
- /* Replace the program section data with the tmp data */
-
- poffInfo->progSectionData = poffProgInfo->progSectionData;
- poffInfo->progSection.sh_size = poffProgInfo->progSectionSize;
- poffInfo->progSectionAlloc = poffProgInfo->progSectionAlloc;
-
- /* Reset the read index */
-
- poffInfo->progSectionIndex = 0;
-
- /* Then nullify the tmp data */
-
- poffProgInfo->progSectionData = NULL;
- poffProgInfo->progSectionSize = 0;
- poffProgInfo->progSectionAlloc = 0;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pftprog.c + * Program data manipulations on POFF temporary object + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* Pascal error codes */ + +#include "pfprivate.h" /* POFF private definitions */ +#include "pofflib.h" /* Public interfaces */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +static uint16_t poffCheckProgAlloc(poffProgInfo_t *poffProgInfo) +{ + if (!poffProgInfo->progSectionData) + { + /* No, allocate it now */ + + poffProgInfo->progSectionData = (uint8_t*)malloc(INITIAL_PROG_SECTION_SIZE); + if (!poffProgInfo->progSectionData) + { + return eNOMEMORY; + } + + poffProgInfo->progSectionSize = 0; + poffProgInfo->progSectionAlloc = INITIAL_PROG_SECTION_SIZE; + } + return eNOERROR; +} + +static uint16_t poffCheckProgRealloc(poffProgInfo_t *poffProgInfo, uint16_t len) +{ + /* Check if there is room for the new data */ + + if (poffProgInfo->progSectionSize + len > poffProgInfo->progSectionAlloc) + { + uint32_t newAlloc = + poffProgInfo->progSectionAlloc + PROG_SECTION_INCREMENT; + void *tmp; + + /* Make certain that this is big enough (it should be) */ + + while (poffProgInfo->progSectionSize + len > newAlloc) + { + newAlloc += PROG_SECTION_INCREMENT; + } + + /* Reallocate the program data section buffer */ + + tmp = realloc(poffProgInfo->progSectionData, newAlloc); + if (!tmp) + { + return eNOMEMORY; + } + + /* And set the new size */ + + poffProgInfo->progSectionAlloc = newAlloc; + poffProgInfo->progSectionData = (uint8_t*)tmp; + } + return eNOERROR; +} + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +uint16_t poffAddTmpProgByte(poffProgHandle_t handle, uint8_t progByte) +{ + poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)handle; + uint16_t errCode; + + /* Check if we have allocated a program section buffer yet */ + + errCode = poffCheckProgAlloc(poffProgInfo); + if (errCode != eNOERROR) + { + return errCode; + } + + /* Check if there is room for the new byte */ + + errCode = poffCheckProgRealloc(poffProgInfo, 1); + if (errCode != eNOERROR) + { + return errCode; + } + + /* Copy program data byte into the program data buffer */ + + poffProgInfo->progSectionData[poffProgInfo->progSectionSize] = progByte; + + /* Set the new size of the string table */ + + poffProgInfo->progSectionSize++; + return eNOERROR; +} + +/***********************************************************************/ + +uint16_t poffWriteTmpProgBytes(uint8_t *buffer, uint32_t nbytes, + poffProgHandle_t handle) + +{ + poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)handle; + uint16_t errCode; + + /* Check if we have allocated a program section buffer yet */ + + errCode = poffCheckProgAlloc(poffProgInfo); + if (errCode != eNOERROR) + { + return errCode; + } + + /* Check if there is room for the new data */ + + errCode = poffCheckProgRealloc(poffProgInfo, nbytes); + if (errCode != eNOERROR) + { + return errCode; + } + + /* Copy program data byte into the program data buffer */ + + memcpy(&poffProgInfo->progSectionData[poffProgInfo->progSectionSize], + buffer, nbytes); + + /* Set the new size of the string table */ + + poffProgInfo->progSectionSize += nbytes; + return eNOERROR; +} + +/***********************************************************************/ + +void poffReplaceProgData(poffHandle_t handle, poffProgHandle_t progHandle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)progHandle; + + /* Discard any existing program section data */ + + if (poffInfo->progSectionData) + { + free(poffInfo->progSectionData); + } + + /* Replace the program section data with the tmp data */ + + poffInfo->progSectionData = poffProgInfo->progSectionData; + poffInfo->progSection.sh_size = poffProgInfo->progSectionSize; + poffInfo->progSectionAlloc = poffProgInfo->progSectionAlloc; + + /* Reset the read index */ + + poffInfo->progSectionIndex = 0; + + /* Then nullify the tmp data */ + + poffProgInfo->progSectionData = NULL; + poffProgInfo->progSectionSize = 0; + poffProgInfo->progSectionAlloc = 0; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pftsymbol.c b/misc/pascal/libpoff/pftsymbol.c index 32eb375dd4..d30de5fb94 100644 --- a/misc/pascal/libpoff/pftsymbol.c +++ b/misc/pascal/libpoff/pftsymbol.c @@ -1,188 +1,189 @@ -/**********************************************************************
- * pftsymbol.c
- * Write symbol information to a temporary container
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Add a symbol to the symbol table section data. Returns index value
- * associated with the symbol entry in the symbol table section data.
- */
-
-uint32 poffAddTmpSymbol(poffHandle_t handle, poffSymHandle_t symHandle,
- poffLibSymbol_t *symbol)
-{
- poffSymInfo_t *poffSymInfo = (poffSymInfo_t*)symHandle;
- poffSymbol_t *psym;
- uint32 st_name;
- uint32 index;
-
- /* Add the name to the string table. Note: We are probably re-writing
- * the string table and so the string probably already exists in the
- * string table. We are counting of the string table logic's abililty
- * avoid duplicated strings to keep from adding trash to the string
- * table.
- */
-
- st_name = poffAddString(handle, symbol->name);
-
- /* Check if we have allocated a symbol table buffer yet */
-
- if (!poffSymInfo->symbolTable)
- {
- /* No, allocate it now */
-
- poffSymInfo->symbolTable = (ubyte*)malloc(INITIAL_SYMBOL_TABLE_SIZE);
- if (!poffSymInfo->symbolTable)
- {
- fatal(eNOMEMORY);
- }
-
- poffSymInfo->symbolTableSize = 0;
- poffSymInfo->symbolTableAlloc = INITIAL_SYMBOL_TABLE_SIZE;
- }
-
- /* Check if there is room for a new symbol */
-
- if (poffSymInfo->symbolTableSize + sizeof(poffSymbol_t) >
- poffSymInfo->symbolTableAlloc)
- {
- uint32 newAlloc = poffSymInfo->symbolTableAlloc + SYMBOL_TABLE_INCREMENT;
- ubyte *tmp;
-
- /* Reallocate the file name buffer */
-
- tmp = (ubyte*)realloc(poffSymInfo->symbolTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- poffSymInfo->symbolTableAlloc = newAlloc;
- poffSymInfo->symbolTable = tmp;
- }
-
- /* Save the new symbol information in the symbol table data */
-
- index = poffSymInfo->symbolTableSize;
- psym = (poffSymbol_t*)&poffSymInfo->symbolTable[index];
-
- psym->st_type = symbol->type;
- psym->st_align = symbol->align;
- psym->st_flags = symbol->flags;
- psym->st_pad = 0;
- psym->st_name = st_name;
- psym->st_value = symbol->value;
- psym->st_size = symbol->size;
-
- /* Set the new size of the file name table */
-
- poffSymInfo->symbolTableSize += sizeof(poffSymbol_t);
- return index;
-}
-
-/***********************************************************************/
-
-void poffReplaceSymbolTable(poffHandle_t handle, poffSymHandle_t symHandle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffSymInfo_t *poffSymInfo = (poffSymInfo_t*)symHandle;
-
- /* Discard any existing symbol table */
-
- if (poffInfo->symbolTable)
- {
- free(poffInfo->symbolTable);
- }
-
- /* Replace the symram section data with the tmp data */
-
- poffInfo->symbolTable = poffSymInfo->symbolTable;
- poffInfo->symbolTableSection.sh_size = poffSymInfo->symbolTableSize;
- poffInfo->symbolTableSection.sh_entsize = sizeof(poffSymbol_t);
- poffInfo->symbolTableAlloc = poffSymInfo->symbolTableAlloc;
-
- /* Reset the read index */
-
- poffInfo->symbolIndex = 0;
-
- /* Then nullify the tmp data */
-
- poffSymInfo->symbolTable = NULL;
- poffSymInfo->symbolTableSize = 0;
- poffSymInfo->symbolTableAlloc = 0;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pftsymbol.c + * Write symbol information to a temporary container + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Add a symbol to the symbol table section data. Returns index value + * associated with the symbol entry in the symbol table section data. + */ + +uint32_t poffAddTmpSymbol(poffHandle_t handle, poffSymHandle_t symHandle, + poffLibSymbol_t *symbol) +{ + poffSymInfo_t *poffSymInfo = (poffSymInfo_t*)symHandle; + poffSymbol_t *psym; + uint32_t st_name; + uint32_t index; + + /* Add the name to the string table. Note: We are probably re-writing + * the string table and so the string probably already exists in the + * string table. We are counting of the string table logic's abililty + * avoid duplicated strings to keep from adding trash to the string + * table. + */ + + st_name = poffAddString(handle, symbol->name); + + /* Check if we have allocated a symbol table buffer yet */ + + if (!poffSymInfo->symbolTable) + { + /* No, allocate it now */ + + poffSymInfo->symbolTable = (uint8_t*)malloc(INITIAL_SYMBOL_TABLE_SIZE); + if (!poffSymInfo->symbolTable) + { + fatal(eNOMEMORY); + } + + poffSymInfo->symbolTableSize = 0; + poffSymInfo->symbolTableAlloc = INITIAL_SYMBOL_TABLE_SIZE; + } + + /* Check if there is room for a new symbol */ + + if (poffSymInfo->symbolTableSize + sizeof(poffSymbol_t) > + poffSymInfo->symbolTableAlloc) + { + uint32_t newAlloc = poffSymInfo->symbolTableAlloc + SYMBOL_TABLE_INCREMENT; + uint8_t *tmp; + + /* Reallocate the file name buffer */ + + tmp = (uint8_t*)realloc(poffSymInfo->symbolTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + poffSymInfo->symbolTableAlloc = newAlloc; + poffSymInfo->symbolTable = tmp; + } + + /* Save the new symbol information in the symbol table data */ + + index = poffSymInfo->symbolTableSize; + psym = (poffSymbol_t*)&poffSymInfo->symbolTable[index]; + + psym->st_type = symbol->type; + psym->st_align = symbol->align; + psym->st_flags = symbol->flags; + psym->st_pad = 0; + psym->st_name = st_name; + psym->st_value = symbol->value; + psym->st_size = symbol->size; + + /* Set the new size of the file name table */ + + poffSymInfo->symbolTableSize += sizeof(poffSymbol_t); + return index; +} + +/***********************************************************************/ + +void poffReplaceSymbolTable(poffHandle_t handle, poffSymHandle_t symHandle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffSymInfo_t *poffSymInfo = (poffSymInfo_t*)symHandle; + + /* Discard any existing symbol table */ + + if (poffInfo->symbolTable) + { + free(poffInfo->symbolTable); + } + + /* Replace the symram section data with the tmp data */ + + poffInfo->symbolTable = poffSymInfo->symbolTable; + poffInfo->symbolTableSection.sh_size = poffSymInfo->symbolTableSize; + poffInfo->symbolTableSection.sh_entsize = sizeof(poffSymbol_t); + poffInfo->symbolTableAlloc = poffSymInfo->symbolTableAlloc; + + /* Reset the read index */ + + poffInfo->symbolIndex = 0; + + /* Then nullify the tmp data */ + + poffSymInfo->symbolTable = NULL; + poffSymInfo->symbolTableSize = 0; + poffSymInfo->symbolTableAlloc = 0; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwdbgfunc.c b/misc/pascal/libpoff/pfwdbgfunc.c index 9f3b35d398..babec18e8d 100644 --- a/misc/pascal/libpoff/pfwdbgfunc.c +++ b/misc/pascal/libpoff/pfwdbgfunc.c @@ -1,173 +1,174 @@ -/**********************************************************************
- * pfwdbgfunc.c
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-static void poffCheckDebugFuncInfoAllocation(poffInfo_t *poffInfo)
-{
- /* Check if we have allocated a line number buffer yet */
-
- if (!poffInfo->debugFuncTable)
- {
- /* No, allocate it now */
-
- poffInfo->debugFuncTable = (ubyte*)
- malloc(INITIAL_DEBUGFUNC_TABLE_SIZE);
-
- if (!poffInfo->debugFuncTable)
- {
- fatal(eNOMEMORY);
- }
-
- poffInfo->debugFuncSection.sh_size = 0;
- poffInfo->debugFuncTableAlloc = INITIAL_DEBUGFUNC_TABLE_SIZE;
- }
-}
-
-/***********************************************************************/
-
-static void poffCheckDebugFuncInfoReallocation(poffInfo_t *poffInfo, uint32 nparms)
-{
- uint32 needed = sizeof(poffDebugFuncInfo_t) + nparms*sizeof(poffDebugArgInfo_t);
- if (poffInfo->debugFuncSection.sh_size + needed > poffInfo->debugFuncTableAlloc)
- {
- uint32 newAlloc =
- poffInfo->debugFuncTableAlloc +
- DEBUGFUNC_TABLE_INCREMENT;
-
- void *tmp;
-
- /* Reallocate the line number buffer */
-
- tmp = realloc(poffInfo->debugFuncTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- poffInfo->debugFuncTableAlloc = newAlloc;
- poffInfo->debugFuncTable = (ubyte*)tmp;
- }
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Add a debug inforamtion to the debug func table. Returns the index
- * associated with the line number entry in the line number table.
- */
-
-uint32 poffAddDebugFuncInfo(poffHandle_t handle,
- poffLibDebugFuncInfo_t *pContainer)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffDebugFuncInfo_t *pFuncInfo;
- poffDebugArgInfo_t *pArgInfo;
- uint32 funcInfoIndex;
- uint32 argInfoIndex;
- int i;
-
- /* Verify that the debug info table has been allocated */
-
- poffCheckDebugFuncInfoAllocation(poffInfo);
-
- /* Verify that the debug infotable is large enough to hold
- * information about function
- */
-
- poffCheckDebugFuncInfoReallocation(poffInfo, pContainer->nparms);
-
- /* Save the information in the debug func info table */
-
- funcInfoIndex = poffInfo->debugFuncSection.sh_size;
- pFuncInfo = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[funcInfoIndex];
-
- pFuncInfo->df_value = pContainer->value;
- pFuncInfo->df_size = pContainer->retsize;
- pFuncInfo->df_nparms = pContainer->nparms;
-
- argInfoIndex = funcInfoIndex + sizeof(poffDebugFuncInfo_t);
- for (i = 0; i < pContainer->nparms; i++)
- {
- pArgInfo = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[argInfoIndex];
- pArgInfo->da_size = pContainer->argsize[i];
- argInfoIndex += sizeof(poffDebugArgInfo_t);
- }
-
- /* Set the new size of the debug func info table */
-
- poffInfo->debugFuncSection.sh_size = argInfoIndex;
- return funcInfoIndex;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwdbgfunc.c + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +static void poffCheckDebugFuncInfoAllocation(poffInfo_t *poffInfo) +{ + /* Check if we have allocated a line number buffer yet */ + + if (!poffInfo->debugFuncTable) + { + /* No, allocate it now */ + + poffInfo->debugFuncTable = (uint8_t*) + malloc(INITIAL_DEBUGFUNC_TABLE_SIZE); + + if (!poffInfo->debugFuncTable) + { + fatal(eNOMEMORY); + } + + poffInfo->debugFuncSection.sh_size = 0; + poffInfo->debugFuncTableAlloc = INITIAL_DEBUGFUNC_TABLE_SIZE; + } +} + +/***********************************************************************/ + +static void poffCheckDebugFuncInfoReallocation(poffInfo_t *poffInfo, uint32_t nparms) +{ + uint32_t needed = sizeof(poffDebugFuncInfo_t) + nparms*sizeof(poffDebugArgInfo_t); + if (poffInfo->debugFuncSection.sh_size + needed > poffInfo->debugFuncTableAlloc) + { + uint32_t newAlloc = + poffInfo->debugFuncTableAlloc + + DEBUGFUNC_TABLE_INCREMENT; + + void *tmp; + + /* Reallocate the line number buffer */ + + tmp = realloc(poffInfo->debugFuncTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + poffInfo->debugFuncTableAlloc = newAlloc; + poffInfo->debugFuncTable = (uint8_t*)tmp; + } +} + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Add a debug inforamtion to the debug func table. Returns the index + * associated with the line number entry in the line number table. + */ + +uint32_t poffAddDebugFuncInfo(poffHandle_t handle, + poffLibDebugFuncInfo_t *pContainer) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffDebugFuncInfo_t *pFuncInfo; + poffDebugArgInfo_t *pArgInfo; + uint32_t funcInfoIndex; + uint32_t argInfoIndex; + int i; + + /* Verify that the debug info table has been allocated */ + + poffCheckDebugFuncInfoAllocation(poffInfo); + + /* Verify that the debug infotable is large enough to hold + * information about function + */ + + poffCheckDebugFuncInfoReallocation(poffInfo, pContainer->nparms); + + /* Save the information in the debug func info table */ + + funcInfoIndex = poffInfo->debugFuncSection.sh_size; + pFuncInfo = (poffDebugFuncInfo_t*)&poffInfo->debugFuncTable[funcInfoIndex]; + + pFuncInfo->df_value = pContainer->value; + pFuncInfo->df_size = pContainer->retsize; + pFuncInfo->df_nparms = pContainer->nparms; + + argInfoIndex = funcInfoIndex + sizeof(poffDebugFuncInfo_t); + for (i = 0; i < pContainer->nparms; i++) + { + pArgInfo = (poffDebugArgInfo_t*)&poffInfo->debugFuncTable[argInfoIndex]; + pArgInfo->da_size = pContainer->argsize[i]; + argInfoIndex += sizeof(poffDebugArgInfo_t); + } + + /* Set the new size of the debug func info table */ + + poffInfo->debugFuncSection.sh_size = argInfoIndex; + return funcInfoIndex; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwfname.c b/misc/pascal/libpoff/pfwfname.c index d5d051e7e3..dde752f5a2 100644 --- a/misc/pascal/libpoff/pfwfname.c +++ b/misc/pascal/libpoff/pfwfname.c @@ -1,145 +1,146 @@ -/**********************************************************************
- * pfwfname.c
- * Write filename data to a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Add a file name to the file table. Returns file number index value
- * and NOT the byte offset associated with the file name entry in the
- * file name section.
- */
-
-uint32 poffAddFileName(poffHandle_t handle, const char *name)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffFileTab_t ft;
- uint32 index;
-
- /* Add the name to the string table */
-
- ft = (poffFileTab_t)poffAddString(poffInfo, name);
-
- /* Add string table offset to the file table
- *
- * Check if we have allocated a filename table buffer yet
- */
-
- if (!poffInfo->fileNameTable)
- {
- /* No, allocate it now */
-
- poffInfo->fileNameTable = (poffFileTab_t*)malloc(INITIAL_FILENAME_TABLE_SIZE);
- if (!poffInfo->fileNameTable)
- {
- fatal(eNOMEMORY);
- }
-
- poffInfo->fileNameTableSection.sh_size = 0;
- poffInfo->fileNameTableAlloc = INITIAL_FILENAME_TABLE_SIZE;
- }
-
- /* Check if there is room for the new file name index */
-
- if (poffInfo->fileNameTableSection.sh_size + sizeof(poffFileTab_t)>
- poffInfo->fileNameTableAlloc)
- {
- uint32 newAlloc = poffInfo->fileNameTableAlloc + FILENAME_TABLE_INCREMENT;
- void *tmp;
-
- /* Reallocate the file name buffer */
-
- tmp = realloc(poffInfo->fileNameTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- poffInfo->fileNameTableAlloc = newAlloc;
- poffInfo->fileNameTable = (poffFileTab_t*)tmp;
- }
-
- /* Save the index in the file name table */
-
- index = poffInfo->fileNameTableSection.sh_size / sizeof(poffFileTab_t);
- poffInfo->fileNameTable[index] = ft;
-
- /* Set the new size of the file name table */
-
- poffInfo->fileNameTableSection.sh_size += sizeof(poffFileTab_t);
- return index;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwfname.c + * Write filename data to a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Add a file name to the file table. Returns file number index value + * and NOT the byte offset associated with the file name entry in the + * file name section. + */ + +uint32_t poffAddFileName(poffHandle_t handle, const char *name) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffFileTab_t ft; + uint32_t index; + + /* Add the name to the string table */ + + ft = (poffFileTab_t)poffAddString(poffInfo, name); + + /* Add string table offset to the file table + * + * Check if we have allocated a filename table buffer yet + */ + + if (!poffInfo->fileNameTable) + { + /* No, allocate it now */ + + poffInfo->fileNameTable = (poffFileTab_t*)malloc(INITIAL_FILENAME_TABLE_SIZE); + if (!poffInfo->fileNameTable) + { + fatal(eNOMEMORY); + } + + poffInfo->fileNameTableSection.sh_size = 0; + poffInfo->fileNameTableAlloc = INITIAL_FILENAME_TABLE_SIZE; + } + + /* Check if there is room for the new file name index */ + + if (poffInfo->fileNameTableSection.sh_size + sizeof(poffFileTab_t)> + poffInfo->fileNameTableAlloc) + { + uint32_t newAlloc = poffInfo->fileNameTableAlloc + FILENAME_TABLE_INCREMENT; + void *tmp; + + /* Reallocate the file name buffer */ + + tmp = realloc(poffInfo->fileNameTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + poffInfo->fileNameTableAlloc = newAlloc; + poffInfo->fileNameTable = (poffFileTab_t*)tmp; + } + + /* Save the index in the file name table */ + + index = poffInfo->fileNameTableSection.sh_size / sizeof(poffFileTab_t); + poffInfo->fileNameTable[index] = ft; + + /* Set the new size of the file name table */ + + poffInfo->fileNameTableSection.sh_size += sizeof(poffFileTab_t); + return index; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwhdr.c b/misc/pascal/libpoff/pfwhdr.c index 80f0401316..b8f9983b7a 100644 --- a/misc/pascal/libpoff/pfwhdr.c +++ b/misc/pascal/libpoff/pfwhdr.c @@ -1,115 +1,116 @@ -/**********************************************************************
- * pfwhdr.c
- * Write to POFF file file and section headers
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Add the type of the file to the POFF file header */
-
-void poffSetFileType(poffHandle_t handle, ubyte fh_type,
- uint16 nfiles, const char *name)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
-
- /* Save the type in the file header */
-
- poffInfo->fileHeader.fh_type = fh_type;
-
- /* Save the associated name in the string table */
-
- poffInfo->fileHeader.fh_name = poffAddString(poffInfo, name);
-}
-
-/***********************************************************************/
-/* Add the machine architecture to the POFF file header */
-
-void poffSetArchitecture(poffHandle_t handle, ubyte fh_arch)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
-
- /* Save the type in the file header */
-
- poffInfo->fileHeader.fh_arch = fh_arch;
-}
-
-/***********************************************************************/
-/* Set the program entry point */
-
-void poffSetEntryPoint(poffHandle_t handle, uint32 entryPoint)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffInfo->fileHeader.fh_entry = entryPoint;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwhdr.c + * Write to POFF file file and section headers + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Add the type of the file to the POFF file header */ + +void poffSetFileType(poffHandle_t handle, uint8_t fh_type, + uint16_t nfiles, const char *name) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + + /* Save the type in the file header */ + + poffInfo->fileHeader.fh_type = fh_type; + + /* Save the associated name in the string table */ + + poffInfo->fileHeader.fh_name = poffAddString(poffInfo, name); +} + +/***********************************************************************/ +/* Add the machine architecture to the POFF file header */ + +void poffSetArchitecture(poffHandle_t handle, uint8_t fh_arch) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + + /* Save the type in the file header */ + + poffInfo->fileHeader.fh_arch = fh_arch; +} + +/***********************************************************************/ +/* Set the program entry point */ + +void poffSetEntryPoint(poffHandle_t handle, uint32_t entryPoint) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffInfo->fileHeader.fh_entry = entryPoint; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwlineno.c b/misc/pascal/libpoff/pfwlineno.c index f7f4b99548..ca72bc1563 100644 --- a/misc/pascal/libpoff/pfwlineno.c +++ b/misc/pascal/libpoff/pfwlineno.c @@ -1,164 +1,165 @@ -/**********************************************************************
- * pfwlineno.c
- * Write line number data to a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-static void poffCheckLineNumberAllocation(poffInfo_t *poffInfo)
-{
- /* Check if we have allocated a line number buffer yet */
-
- if (!poffInfo->lineNumberTable)
- {
- /* No, allocate it now */
-
- poffInfo->lineNumberTable = (ubyte*)
- malloc(INITIAL_LINENUMBER_TABLE_SIZE);
-
- if (!poffInfo->lineNumberTable)
- {
- fatal(eNOMEMORY);
- }
-
- poffInfo->lineNumberSection.sh_size = 0;
- poffInfo->lineNumberTableAlloc = INITIAL_LINENUMBER_TABLE_SIZE;
- }
-}
-
-/***********************************************************************/
-
-static void poffCheckLineNumberReallocation(poffInfo_t *poffInfo)
-{
- if (poffInfo->lineNumberSection.sh_size + sizeof(poffLineNumber_t) >
- poffInfo->lineNumberTableAlloc)
- {
- uint32 newAlloc =
- poffInfo->lineNumberTableAlloc +
- LINENUMBER_TABLE_INCREMENT;
-
- void *tmp;
-
- /* Reallocate the line number buffer */
-
- tmp = realloc(poffInfo->lineNumberTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- poffInfo->lineNumberTableAlloc = newAlloc;
- poffInfo->lineNumberTable = (ubyte*)tmp;
- }
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Add a line number to the line number table. Returns index value
- * associated with the line number entry in the line number table.
- */
-
-uint32 poffAddLineNumber(poffHandle_t handle,
- uint16 lineNumber, uint16 fileNumber,
- uint32 progSectionDataOffset)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffLineNumber_t *pln;
- uint32 index;
-
- /* Verify that the line number table has been allocated */
-
- poffCheckLineNumberAllocation(poffInfo);
-
- /* Verify that the line number table is large enough to hold
- * information about another line.
- */
-
- poffCheckLineNumberReallocation(poffInfo);
-
- /* Save the line number information in the line number table */
-
- index = poffInfo->lineNumberSection.sh_size;
- pln = (poffLineNumber_t*)&poffInfo->lineNumberTable[index];
-
- pln->ln_lineno = lineNumber;
- pln->ln_fileno = fileNumber;
- pln->ln_poffset = progSectionDataOffset;
-
- /* Set the new size of the line number table */
-
- poffInfo->lineNumberSection.sh_size += sizeof(poffLineNumber_t);
- return index;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwlineno.c + * Write line number data to a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +static void poffCheckLineNumberAllocation(poffInfo_t *poffInfo) +{ + /* Check if we have allocated a line number buffer yet */ + + if (!poffInfo->lineNumberTable) + { + /* No, allocate it now */ + + poffInfo->lineNumberTable = (uint8_t*) + malloc(INITIAL_LINENUMBER_TABLE_SIZE); + + if (!poffInfo->lineNumberTable) + { + fatal(eNOMEMORY); + } + + poffInfo->lineNumberSection.sh_size = 0; + poffInfo->lineNumberTableAlloc = INITIAL_LINENUMBER_TABLE_SIZE; + } +} + +/***********************************************************************/ + +static void poffCheckLineNumberReallocation(poffInfo_t *poffInfo) +{ + if (poffInfo->lineNumberSection.sh_size + sizeof(poffLineNumber_t) > + poffInfo->lineNumberTableAlloc) + { + uint32_t newAlloc = + poffInfo->lineNumberTableAlloc + + LINENUMBER_TABLE_INCREMENT; + + void *tmp; + + /* Reallocate the line number buffer */ + + tmp = realloc(poffInfo->lineNumberTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + poffInfo->lineNumberTableAlloc = newAlloc; + poffInfo->lineNumberTable = (uint8_t*)tmp; + } +} + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Add a line number to the line number table. Returns index value + * associated with the line number entry in the line number table. + */ + +uint32_t poffAddLineNumber(poffHandle_t handle, + uint16_t lineNumber, uint16_t fileNumber, + uint32_t progSectionDataOffset) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffLineNumber_t *pln; + uint32_t index; + + /* Verify that the line number table has been allocated */ + + poffCheckLineNumberAllocation(poffInfo); + + /* Verify that the line number table is large enough to hold + * information about another line. + */ + + poffCheckLineNumberReallocation(poffInfo); + + /* Save the line number information in the line number table */ + + index = poffInfo->lineNumberSection.sh_size; + pln = (poffLineNumber_t*)&poffInfo->lineNumberTable[index]; + + pln->ln_lineno = lineNumber; + pln->ln_fileno = fileNumber; + pln->ln_poffset = progSectionDataOffset; + + /* Set the new size of the line number table */ + + poffInfo->lineNumberSection.sh_size += sizeof(poffLineNumber_t); + return index; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwprog.c b/misc/pascal/libpoff/pfwprog.c index b5dcbd1762..a9cb42e3a0 100644 --- a/misc/pascal/libpoff/pfwprog.c +++ b/misc/pascal/libpoff/pfwprog.c @@ -1,127 +1,128 @@ -/**********************************************************************
- * pfwprog.c
- * Write program data to a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-void poffAddProgByte(poffHandle_t handle, ubyte progByte)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
-
- /* Check if we have allocated a program section buffer yet */
-
- if (!poffInfo->progSectionData)
- {
- /* No, allocate it now */
-
- poffInfo->progSectionData = (ubyte*)malloc(INITIAL_PROG_SECTION_SIZE);
- if (!poffInfo->progSectionData)
- {
- fatal(eNOMEMORY);
- }
-
- poffInfo->progSection.sh_size = 0;
- poffInfo->progSectionAlloc = INITIAL_STRING_TABLE_SIZE;
- }
-
- /* Check if there is room for the new string */
-
- if (poffInfo->progSection.sh_size + 1 > poffInfo->progSectionAlloc)
- {
- uint32 newAlloc = poffInfo->progSectionAlloc + PROG_SECTION_INCREMENT;
- void *tmp;
-
- /* Reallocate the program data section buffer */
-
- tmp = realloc(poffInfo->progSectionData, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- poffInfo->progSectionAlloc = newAlloc;
- poffInfo->progSectionData = (ubyte*)tmp;
- }
-
- /* Copy program data byte into the program data buffer */
-
- poffInfo->progSectionData[poffInfo->progSection.sh_size] = progByte;
-
- /* Set the new size of the string table */
-
- poffInfo->progSection.sh_size++;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwprog.c + * Write program data to a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +void poffAddProgByte(poffHandle_t handle, uint8_t progByte) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + + /* Check if we have allocated a program section buffer yet */ + + if (!poffInfo->progSectionData) + { + /* No, allocate it now */ + + poffInfo->progSectionData = (uint8_t*)malloc(INITIAL_PROG_SECTION_SIZE); + if (!poffInfo->progSectionData) + { + fatal(eNOMEMORY); + } + + poffInfo->progSection.sh_size = 0; + poffInfo->progSectionAlloc = INITIAL_STRING_TABLE_SIZE; + } + + /* Check if there is room for the new string */ + + if (poffInfo->progSection.sh_size + 1 > poffInfo->progSectionAlloc) + { + uint32_t newAlloc = poffInfo->progSectionAlloc + PROG_SECTION_INCREMENT; + void *tmp; + + /* Reallocate the program data section buffer */ + + tmp = realloc(poffInfo->progSectionData, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + poffInfo->progSectionAlloc = newAlloc; + poffInfo->progSectionData = (uint8_t*)tmp; + } + + /* Copy program data byte into the program data buffer */ + + poffInfo->progSectionData[poffInfo->progSection.sh_size] = progByte; + + /* Set the new size of the string table */ + + poffInfo->progSection.sh_size++; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwreloc.c b/misc/pascal/libpoff/pfwreloc.c index 1b347ab37f..21abbb0cbd 100644 --- a/misc/pascal/libpoff/pfwreloc.c +++ b/misc/pascal/libpoff/pfwreloc.c @@ -1,161 +1,162 @@ -/**********************************************************************
- * pfwreloc.c
- * Write relocation data to a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-static void poffCheckRelocationAllocation(poffInfo_t *poffInfo)
-{
- /* Check if we have allocated a line number buffer yet */
-
- if (!poffInfo->relocTable)
- {
- /* No, allocate it now */
-
- poffInfo->relocTable = (ubyte*)malloc(INITIAL_RELOC_TABLE_SIZE);
- if (!poffInfo->relocTable)
- {
- fatal(eNOMEMORY);
- }
-
- poffInfo->relocSection.sh_size = 0;
- poffInfo->relocAlloc = INITIAL_RELOC_TABLE_SIZE;
- }
-}
-
-/***********************************************************************/
-
-static void poffCheckRelocationReallocation(poffInfo_t *poffInfo)
-{
- if (poffInfo->relocSection.sh_size + sizeof(poffRelocation_t) >
- poffInfo->relocAlloc)
- {
- uint32 newAlloc =
- poffInfo->relocAlloc +
- RELOC_TABLE_INCREMENT;
-
- void *tmp;
-
- /* Reallocate the line number buffer */
-
- tmp = realloc(poffInfo->relocTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- poffInfo->relocAlloc = newAlloc;
- poffInfo->relocTable = (ubyte*)tmp;
- }
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Add a relocation to the relocation table. Returns index value
- * associated with the relocation entry in the relocation table.
- */
-
-uint32 poffAddRelocation(poffHandle_t handle,
- ubyte relocType, uint32 symIndex,
- uint32 sectionDataOffset)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffRelocation_t *prl;
- uint32 index;
-
- /* Verify that the relocation table has been allocated */
-
- poffCheckRelocationAllocation(poffInfo);
-
- /* Verify that the relocation table is large enough to hold
- * information about another relocation.
- */
-
- poffCheckRelocationReallocation(poffInfo);
-
- /* Save the relocation information in the relocation table */
-
- index = poffInfo->relocSection.sh_size;
- prl = (poffRelocation_t*)&poffInfo->relocTable[index];
-
- prl->rl_info = RLI_MAKE(symIndex, relocType);
- prl->rl_offset = sectionDataOffset;
-
- /* Set the new size of the line number table */
-
- poffInfo->relocSection.sh_size += sizeof(poffRelocation_t);
- return index;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwreloc.c + * Write relocation data to a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +static void poffCheckRelocationAllocation(poffInfo_t *poffInfo) +{ + /* Check if we have allocated a line number buffer yet */ + + if (!poffInfo->relocTable) + { + /* No, allocate it now */ + + poffInfo->relocTable = (uint8_t*)malloc(INITIAL_RELOC_TABLE_SIZE); + if (!poffInfo->relocTable) + { + fatal(eNOMEMORY); + } + + poffInfo->relocSection.sh_size = 0; + poffInfo->relocAlloc = INITIAL_RELOC_TABLE_SIZE; + } +} + +/***********************************************************************/ + +static void poffCheckRelocationReallocation(poffInfo_t *poffInfo) +{ + if (poffInfo->relocSection.sh_size + sizeof(poffRelocation_t) > + poffInfo->relocAlloc) + { + uint32_t newAlloc = + poffInfo->relocAlloc + + RELOC_TABLE_INCREMENT; + + void *tmp; + + /* Reallocate the line number buffer */ + + tmp = realloc(poffInfo->relocTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + poffInfo->relocAlloc = newAlloc; + poffInfo->relocTable = (uint8_t*)tmp; + } +} + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Add a relocation to the relocation table. Returns index value + * associated with the relocation entry in the relocation table. + */ + +uint32_t poffAddRelocation(poffHandle_t handle, + uint8_t relocType, uint32_t symIndex, + uint32_t sectionDataOffset) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffRelocation_t *prl; + uint32_t index; + + /* Verify that the relocation table has been allocated */ + + poffCheckRelocationAllocation(poffInfo); + + /* Verify that the relocation table is large enough to hold + * information about another relocation. + */ + + poffCheckRelocationReallocation(poffInfo); + + /* Save the relocation information in the relocation table */ + + index = poffInfo->relocSection.sh_size; + prl = (poffRelocation_t*)&poffInfo->relocTable[index]; + + prl->rl_info = RLI_MAKE(symIndex, relocType); + prl->rl_offset = sectionDataOffset; + + /* Set the new size of the line number table */ + + poffInfo->relocSection.sh_size += sizeof(poffRelocation_t); + return index; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwrite.c b/misc/pascal/libpoff/pfwrite.c index 2ad8aaac5a..5debe7ec69 100644 --- a/misc/pascal/libpoff/pfwrite.c +++ b/misc/pascal/libpoff/pfwrite.c @@ -1,539 +1,541 @@ -/**********************************************************************
- * libpoff/pfwrite.c
- * Write a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-static uint16 poffCountSections(poffHandle_t handle);
-static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile);
-static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile);
-static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile);
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-static uint16 poffCountSections(poffHandle_t handle)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint16 nSections = 1; /* We always write the string table */
-
- /* Count each other section that has stored data */
-
- if (HAVE_PROGRAM_SECTION)
- nSections++;
-
- if (HAVE_RODATA_SECTION)
- nSections++;
-
- if (HAVE_SYMBOL_TABLE)
- nSections++;
-
- if (HAVE_RELOC_SECTION)
- nSections++;
-
- if (HAVE_FILE_TABLE)
- nSections++;
-
- if (HAVE_LINE_NUMBER)
- nSections++;
-
- if (HAVE_DEBUG_SECTION)
- nSections++;
-
- return nSections;
-}
-
-/***********************************************************************/
-
-static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- size_t entriesWritten;
-
- /* Get the number of section structures following the file header */
-
- poffInfo->fileHeader.fh_shnum = poffCountSections(handle);
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapFileHeader(&poffInfo->fileHeader);
-
- /* Write the POFF file header */
-
- entriesWritten = fwrite(&poffInfo->fileHeader, sizeof(poffFileHeader_t),
- 1, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write POFF header: %s\n", strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
-
- /* Restore fields to host order */
-
- poffSwapFileHeader(&poffInfo->fileHeader);
-}
-
-/***********************************************************************/
-
-static size_t poffWriteSectionHeader(poffSectionHeader_t *pheader, FILE *poffFile)
-{
- size_t entriesWritten;
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapSectionHeader(pheader);
-
- /* Write the POFF section header */
-
- entriesWritten = fwrite(pheader, sizeof(poffSectionHeader_t), 1, poffFile);
-
- /* Restore fields to host order */
-
- poffSwapSectionHeader(pheader);
- return entriesWritten;
-}
-
-/***********************************************************************/
-
-static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
-
- /* The data starts immediately after the file header and the array
- * of section headers.
- */
-
- uint32 dataOffset = poffInfo->fileHeader.fh_shoff +
- poffInfo->fileHeader.fh_shnum * poffInfo->fileHeader.fh_shsize;
- size_t entriesWritten;
-
- /* Write the program section header (if we have one) */
-
- if (HAVE_PROGRAM_SECTION)
- {
- /* Add the name of the section to the string table */
-
- poffInfo->progSection.sh_name = poffAddString(handle, ".text");
- poffInfo->progSection.sh_offset = dataOffset;
- dataOffset += poffInfo->progSection.sh_size;
-
- /* Then write the section header to the output file */
-
- entriesWritten = poffWriteSectionHeader(&poffInfo->progSection, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write program section header: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the initialized read-only data section header (if we have one) */
-
- if (HAVE_RODATA_SECTION)
- {
- /* Add the name of the section to the string table */
-
- poffInfo->roDataSection.sh_name = poffAddString(handle, ".rodata");
- poffInfo->roDataSection.sh_offset = dataOffset;
- dataOffset += poffInfo->roDataSection.sh_size;
-
- /* Then write the section header to the output file */
-
- entriesWritten = poffWriteSectionHeader(&poffInfo->roDataSection, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write data section header: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the symbol table section header (if we have one) */
-
- if (HAVE_SYMBOL_TABLE)
- {
- /* Add the name of the section to the string table */
-
- poffInfo->symbolTableSection.sh_name = poffAddString(handle, ".symtab");
- poffInfo->symbolTableSection.sh_offset = dataOffset;
- dataOffset += poffInfo->symbolTableSection.sh_size;
-
- /* Then write the section header to the output file */
-
- entriesWritten = poffWriteSectionHeader(&poffInfo->symbolTableSection, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write symbol table section header: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the relocation table section header (if we have one) */
-
- if (HAVE_RELOC_SECTION)
- {
- /* Add the name of the section to the string table */
-
- poffInfo->relocSection.sh_name = poffAddString(handle, ".rel");
- poffInfo->relocSection.sh_offset = dataOffset;
- dataOffset += poffInfo->relocSection.sh_size;
-
- /* Then write the section header to the output file */
-
- entriesWritten = poffWriteSectionHeader(&poffInfo->relocSection, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write relocation section header: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the file table section header (if we have one) */
-
- if (HAVE_FILE_TABLE)
- {
- /* Add the name of the section to the string table */
-
- poffInfo->fileNameTableSection.sh_name = poffAddString(handle, ".filetab");
- poffInfo->fileNameTableSection.sh_offset = dataOffset;
- dataOffset += poffInfo->fileNameTableSection.sh_size;
-
- /* Then write the section header to the output file */
-
- entriesWritten = poffWriteSectionHeader(&poffInfo->fileNameTableSection, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write file table section header: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the line number section header (if we have one) */
-
- if (HAVE_LINE_NUMBER)
- {
- /* Add the name of the section to the string table */
-
- poffInfo->lineNumberSection.sh_name = poffAddString(handle, ".lineno");
- poffInfo->lineNumberSection.sh_offset = dataOffset;
- dataOffset += poffInfo->lineNumberSection.sh_size;
-
- /* Then write the section header to the output file */
-
- entriesWritten = poffWriteSectionHeader(&poffInfo->lineNumberSection, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write line number section header: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the debug function info section header (if we have one) */
-
- if (HAVE_DEBUG_SECTION)
- {
- /* Add the name of the section to the string table */
-
- poffInfo->debugFuncSection.sh_name = poffAddString(handle, ".dbgfunc");
- poffInfo->debugFuncSection.sh_offset = dataOffset;
- dataOffset += poffInfo->debugFuncSection.sh_size;
-
- /* Then write the section header to the output file */
-
- entriesWritten = poffWriteSectionHeader(&poffInfo->debugFuncSection, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write debug section header: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the string table section header LAST (because we may have
- * added strings with the above logic.
- */
-
- /* Add the name of the section to the string table */
-
- poffInfo->stringTableSection.sh_name = poffAddString(handle, ".strtab");
- poffInfo->stringTableSection.sh_offset = dataOffset;
- dataOffset += poffInfo->stringTableSection.sh_size;
-
- /* Then write the section header to the output file */
-
- entriesWritten = poffWriteSectionHeader(&poffInfo->stringTableSection, poffFile);
- if (entriesWritten != 1)
- {
- errmsg("Failed to write string table section header: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
-}
-
-/***********************************************************************/
-
-static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- size_t entriesWritten;
-
- /* Write the program section data (if we have one) */
-
- if (HAVE_PROGRAM_SECTION)
- {
- if (!poffInfo->progSectionData) fatal(ePOFFCONFUSION);
-
- entriesWritten = fwrite(poffInfo->progSectionData, sizeof(ubyte),
- poffInfo->progSection.sh_size, poffFile);
- if (entriesWritten != poffInfo->progSection.sh_size)
- {
- errmsg("Failed to write program data: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the read-only data section data (if we have one) */
-
- if (HAVE_RODATA_SECTION)
- {
- if (!poffInfo->roDataSectionData) fatal(ePOFFCONFUSION);
-
- entriesWritten = fwrite(poffInfo->roDataSectionData, sizeof(ubyte),
- poffInfo->roDataSection.sh_size, poffFile);
- if (entriesWritten != poffInfo->roDataSection.sh_size)
- {
- errmsg("Failed to write initialized data: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
- }
-
- /* Write the symbol table section data (if we have one) */
-
- if (HAVE_SYMBOL_TABLE)
- {
- if (!poffInfo->symbolTable) fatal(ePOFFCONFUSION);
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapSymbolTableData(poffInfo);
-
- /* Write the symbol table entries in big-endian order */
-
- entriesWritten = fwrite(poffInfo->symbolTable, sizeof(ubyte),
- poffInfo->symbolTableSection.sh_size, poffFile);
- if (entriesWritten != poffInfo->symbolTableSection.sh_size)
- {
- errmsg("Failed to write symbol table data: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
-
- /* Restore host data order */
-
- poffSwapSymbolTableData(poffInfo);
- }
-
- /* Write the relocation table section data (if we have one) */
-
- if (HAVE_RELOC_SECTION)
- {
- if (!poffInfo->relocTable) fatal(ePOFFCONFUSION);
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapRelocationData(poffInfo);
-
- /* Write the relocation table entries in big-endian order */
-
- entriesWritten = fwrite(poffInfo->relocTable, sizeof(ubyte),
- poffInfo->relocSection.sh_size, poffFile);
- if (entriesWritten != poffInfo->relocSection.sh_size)
- {
- errmsg("Failed to write relocation data: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
-
- /* Restore host data order */
-
- poffSwapRelocationData(poffInfo);
- }
-
- /* Write the file table section data (if we have one) */
-
- if (HAVE_FILE_TABLE)
- {
- if (!poffInfo->fileNameTable) fatal(ePOFFCONFUSION);
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapFileTableData(poffInfo);
-
- /* Write the file table entries in big-endian order */
-
- entriesWritten = fwrite(poffInfo->fileNameTable, sizeof(ubyte),
- poffInfo->fileNameTableSection.sh_size,
- poffFile);
- if (entriesWritten != poffInfo->fileNameTableSection.sh_size)
- {
- errmsg("Failed to write filename table data: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
-
- /* Restore host data order */
-
- poffSwapFileTableData(poffInfo);
- }
-
- /* Write the line number section data (if we have one) */
-
- if (HAVE_LINE_NUMBER)
- {
- if (!poffInfo->lineNumberTable) fatal(ePOFFCONFUSION);
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapLineNumberData(poffInfo);
-
- /* Write the line number table entries in big-endian order */
-
- entriesWritten = fwrite(poffInfo->lineNumberTable, sizeof(ubyte),
- poffInfo->lineNumberSection.sh_size,
- poffFile);
- if (entriesWritten != poffInfo->lineNumberSection.sh_size)
- {
- errmsg("Failed to write line number table data: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
-
- /* Restore host order */
-
- poffSwapLineNumberData(poffInfo);
- }
-
- /* Write the debug section data (if we have one) */
-
- if (HAVE_DEBUG_SECTION)
- {
- if (!poffInfo->debugFuncTable) fatal(ePOFFCONFUSION);
-
- /* The POFF file is retained in big-endian order. Fixup fields as necessary */
-
- poffSwapDebugData(poffInfo);
-
- /* Write the debug entries in big-endian order */
-
- entriesWritten = fwrite(poffInfo->debugFuncTable, sizeof(ubyte),
- poffInfo->debugFuncSection.sh_size,
- poffFile);
- if (entriesWritten != poffInfo->debugFuncSection.sh_size)
- {
- errmsg("Failed to write debug table data: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
-
- /* Restore host order */
-
- poffSwapDebugData(poffInfo);
- }
-
- /* Write the string table section data LAST (because we may have
- * added strings with the above logic.
- */
-
- if (!poffInfo->stringTable) fatal(ePOFFCONFUSION);
-
- entriesWritten = fwrite(poffInfo->stringTable, sizeof(ubyte),
- poffInfo->stringTableSection.sh_size, poffFile);
- if (entriesWritten != poffInfo->stringTableSection.sh_size)
- {
- errmsg("Failed to write string table data: %s\n",
- strerror(errno));
- fatal(ePOFFWRITEERROR);
- }
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-void poffWriteFile(poffHandle_t handle, FILE *poffFile)
-{
- poffWriteFileHeader(handle, poffFile);
- poffWriteSectionHeaders(handle, poffFile);
- poffWriteSectionData(handle, poffFile);
-}
-
-/***********************************************************************/
+/********************************************************************** + * libpoff/pfwrite.c + * Write a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <sys/types.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +static uint16_t poffCountSections(poffHandle_t handle); +static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile); +static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile); +static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile); + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +static uint16_t poffCountSections(poffHandle_t handle) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint16_t nSections = 1; /* We always write the string table */ + + /* Count each other section that has stored data */ + + if (HAVE_PROGRAM_SECTION) + nSections++; + + if (HAVE_RODATA_SECTION) + nSections++; + + if (HAVE_SYMBOL_TABLE) + nSections++; + + if (HAVE_RELOC_SECTION) + nSections++; + + if (HAVE_FILE_TABLE) + nSections++; + + if (HAVE_LINE_NUMBER) + nSections++; + + if (HAVE_DEBUG_SECTION) + nSections++; + + return nSections; +} + +/***********************************************************************/ + +static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + size_t entriesWritten; + + /* Get the number of section structures following the file header */ + + poffInfo->fileHeader.fh_shnum = poffCountSections(handle); + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapFileHeader(&poffInfo->fileHeader); + + /* Write the POFF file header */ + + entriesWritten = fwrite(&poffInfo->fileHeader, sizeof(poffFileHeader_t), + 1, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write POFF header: %s\n", strerror(errno)); + fatal(ePOFFWRITEERROR); + } + + /* Restore fields to host order */ + + poffSwapFileHeader(&poffInfo->fileHeader); +} + +/***********************************************************************/ + +static size_t poffWriteSectionHeader(poffSectionHeader_t *pheader, FILE *poffFile) +{ + size_t entriesWritten; + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapSectionHeader(pheader); + + /* Write the POFF section header */ + + entriesWritten = fwrite(pheader, sizeof(poffSectionHeader_t), 1, poffFile); + + /* Restore fields to host order */ + + poffSwapSectionHeader(pheader); + return entriesWritten; +} + +/***********************************************************************/ + +static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + + /* The data starts immediately after the file header and the array + * of section headers. + */ + + uint32_t dataOffset = poffInfo->fileHeader.fh_shoff + + poffInfo->fileHeader.fh_shnum * poffInfo->fileHeader.fh_shsize; + size_t entriesWritten; + + /* Write the program section header (if we have one) */ + + if (HAVE_PROGRAM_SECTION) + { + /* Add the name of the section to the string table */ + + poffInfo->progSection.sh_name = poffAddString(handle, ".text"); + poffInfo->progSection.sh_offset = dataOffset; + dataOffset += poffInfo->progSection.sh_size; + + /* Then write the section header to the output file */ + + entriesWritten = poffWriteSectionHeader(&poffInfo->progSection, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write program section header: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the initialized read-only data section header (if we have one) */ + + if (HAVE_RODATA_SECTION) + { + /* Add the name of the section to the string table */ + + poffInfo->roDataSection.sh_name = poffAddString(handle, ".rodata"); + poffInfo->roDataSection.sh_offset = dataOffset; + dataOffset += poffInfo->roDataSection.sh_size; + + /* Then write the section header to the output file */ + + entriesWritten = poffWriteSectionHeader(&poffInfo->roDataSection, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write data section header: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the symbol table section header (if we have one) */ + + if (HAVE_SYMBOL_TABLE) + { + /* Add the name of the section to the string table */ + + poffInfo->symbolTableSection.sh_name = poffAddString(handle, ".symtab"); + poffInfo->symbolTableSection.sh_offset = dataOffset; + dataOffset += poffInfo->symbolTableSection.sh_size; + + /* Then write the section header to the output file */ + + entriesWritten = poffWriteSectionHeader(&poffInfo->symbolTableSection, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write symbol table section header: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the relocation table section header (if we have one) */ + + if (HAVE_RELOC_SECTION) + { + /* Add the name of the section to the string table */ + + poffInfo->relocSection.sh_name = poffAddString(handle, ".rel"); + poffInfo->relocSection.sh_offset = dataOffset; + dataOffset += poffInfo->relocSection.sh_size; + + /* Then write the section header to the output file */ + + entriesWritten = poffWriteSectionHeader(&poffInfo->relocSection, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write relocation section header: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the file table section header (if we have one) */ + + if (HAVE_FILE_TABLE) + { + /* Add the name of the section to the string table */ + + poffInfo->fileNameTableSection.sh_name = poffAddString(handle, ".filetab"); + poffInfo->fileNameTableSection.sh_offset = dataOffset; + dataOffset += poffInfo->fileNameTableSection.sh_size; + + /* Then write the section header to the output file */ + + entriesWritten = poffWriteSectionHeader(&poffInfo->fileNameTableSection, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write file table section header: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the line number section header (if we have one) */ + + if (HAVE_LINE_NUMBER) + { + /* Add the name of the section to the string table */ + + poffInfo->lineNumberSection.sh_name = poffAddString(handle, ".lineno"); + poffInfo->lineNumberSection.sh_offset = dataOffset; + dataOffset += poffInfo->lineNumberSection.sh_size; + + /* Then write the section header to the output file */ + + entriesWritten = poffWriteSectionHeader(&poffInfo->lineNumberSection, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write line number section header: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the debug function info section header (if we have one) */ + + if (HAVE_DEBUG_SECTION) + { + /* Add the name of the section to the string table */ + + poffInfo->debugFuncSection.sh_name = poffAddString(handle, ".dbgfunc"); + poffInfo->debugFuncSection.sh_offset = dataOffset; + dataOffset += poffInfo->debugFuncSection.sh_size; + + /* Then write the section header to the output file */ + + entriesWritten = poffWriteSectionHeader(&poffInfo->debugFuncSection, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write debug section header: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the string table section header LAST (because we may have + * added strings with the above logic. + */ + + /* Add the name of the section to the string table */ + + poffInfo->stringTableSection.sh_name = poffAddString(handle, ".strtab"); + poffInfo->stringTableSection.sh_offset = dataOffset; + dataOffset += poffInfo->stringTableSection.sh_size; + + /* Then write the section header to the output file */ + + entriesWritten = poffWriteSectionHeader(&poffInfo->stringTableSection, poffFile); + if (entriesWritten != 1) + { + errmsg("Failed to write string table section header: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } +} + +/***********************************************************************/ + +static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + size_t entriesWritten; + + /* Write the program section data (if we have one) */ + + if (HAVE_PROGRAM_SECTION) + { + if (!poffInfo->progSectionData) fatal(ePOFFCONFUSION); + + entriesWritten = fwrite(poffInfo->progSectionData, sizeof(uint8_t), + poffInfo->progSection.sh_size, poffFile); + if (entriesWritten != poffInfo->progSection.sh_size) + { + errmsg("Failed to write program data: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the read-only data section data (if we have one) */ + + if (HAVE_RODATA_SECTION) + { + if (!poffInfo->roDataSectionData) fatal(ePOFFCONFUSION); + + entriesWritten = fwrite(poffInfo->roDataSectionData, sizeof(uint8_t), + poffInfo->roDataSection.sh_size, poffFile); + if (entriesWritten != poffInfo->roDataSection.sh_size) + { + errmsg("Failed to write initialized data: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + } + + /* Write the symbol table section data (if we have one) */ + + if (HAVE_SYMBOL_TABLE) + { + if (!poffInfo->symbolTable) fatal(ePOFFCONFUSION); + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapSymbolTableData(poffInfo); + + /* Write the symbol table entries in big-endian order */ + + entriesWritten = fwrite(poffInfo->symbolTable, sizeof(uint8_t), + poffInfo->symbolTableSection.sh_size, poffFile); + if (entriesWritten != poffInfo->symbolTableSection.sh_size) + { + errmsg("Failed to write symbol table data: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + + /* Restore host data order */ + + poffSwapSymbolTableData(poffInfo); + } + + /* Write the relocation table section data (if we have one) */ + + if (HAVE_RELOC_SECTION) + { + if (!poffInfo->relocTable) fatal(ePOFFCONFUSION); + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapRelocationData(poffInfo); + + /* Write the relocation table entries in big-endian order */ + + entriesWritten = fwrite(poffInfo->relocTable, sizeof(uint8_t), + poffInfo->relocSection.sh_size, poffFile); + if (entriesWritten != poffInfo->relocSection.sh_size) + { + errmsg("Failed to write relocation data: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + + /* Restore host data order */ + + poffSwapRelocationData(poffInfo); + } + + /* Write the file table section data (if we have one) */ + + if (HAVE_FILE_TABLE) + { + if (!poffInfo->fileNameTable) fatal(ePOFFCONFUSION); + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapFileTableData(poffInfo); + + /* Write the file table entries in big-endian order */ + + entriesWritten = fwrite(poffInfo->fileNameTable, sizeof(uint8_t), + poffInfo->fileNameTableSection.sh_size, + poffFile); + if (entriesWritten != poffInfo->fileNameTableSection.sh_size) + { + errmsg("Failed to write filename table data: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + + /* Restore host data order */ + + poffSwapFileTableData(poffInfo); + } + + /* Write the line number section data (if we have one) */ + + if (HAVE_LINE_NUMBER) + { + if (!poffInfo->lineNumberTable) fatal(ePOFFCONFUSION); + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapLineNumberData(poffInfo); + + /* Write the line number table entries in big-endian order */ + + entriesWritten = fwrite(poffInfo->lineNumberTable, sizeof(uint8_t), + poffInfo->lineNumberSection.sh_size, + poffFile); + if (entriesWritten != poffInfo->lineNumberSection.sh_size) + { + errmsg("Failed to write line number table data: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + + /* Restore host order */ + + poffSwapLineNumberData(poffInfo); + } + + /* Write the debug section data (if we have one) */ + + if (HAVE_DEBUG_SECTION) + { + if (!poffInfo->debugFuncTable) fatal(ePOFFCONFUSION); + + /* The POFF file is retained in big-endian order. Fixup fields as necessary */ + + poffSwapDebugData(poffInfo); + + /* Write the debug entries in big-endian order */ + + entriesWritten = fwrite(poffInfo->debugFuncTable, sizeof(uint8_t), + poffInfo->debugFuncSection.sh_size, + poffFile); + if (entriesWritten != poffInfo->debugFuncSection.sh_size) + { + errmsg("Failed to write debug table data: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } + + /* Restore host order */ + + poffSwapDebugData(poffInfo); + } + + /* Write the string table section data LAST (because we may have + * added strings with the above logic. + */ + + if (!poffInfo->stringTable) fatal(ePOFFCONFUSION); + + entriesWritten = fwrite(poffInfo->stringTable, sizeof(uint8_t), + poffInfo->stringTableSection.sh_size, poffFile); + if (entriesWritten != poffInfo->stringTableSection.sh_size) + { + errmsg("Failed to write string table data: %s\n", + strerror(errno)); + fatal(ePOFFWRITEERROR); + } +} + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +void poffWriteFile(poffHandle_t handle, FILE *poffFile) +{ + poffWriteFileHeader(handle, poffFile); + poffWriteSectionHeaders(handle, poffFile); + poffWriteSectionData(handle, poffFile); +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwrodata.c b/misc/pascal/libpoff/pfwrodata.c index 4833a32b52..882eb94d18 100644 --- a/misc/pascal/libpoff/pfwrodata.c +++ b/misc/pascal/libpoff/pfwrodata.c @@ -1,192 +1,193 @@ -/**********************************************************************
- * pfwrodata.c
- * Write to the RODATA section of a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-static uint16 poffCheckRoDataAlloc(poffInfo_t *poffInfo)
-{
- if (!poffInfo->roDataSectionData)
- {
- /* No, allocate it now */
-
- poffInfo->roDataSectionData = (ubyte*)malloc(INITIAL_RODATA_SECTION_SIZE);
- if (!poffInfo->roDataSectionData)
- {
- return eNOMEMORY;
- }
-
- poffInfo->roDataSection.sh_size = 0;
- poffInfo->roDataSectionAlloc = INITIAL_RODATA_SECTION_SIZE;
- }
- return eNOERROR;
-}
-
-static uint16 poffCheckRoDataRealloc(poffInfo_t *poffInfo, uint16 len)
-{
- /* Check if there is room for the new data */
-
- if (poffInfo->roDataSection.sh_size + len > poffInfo->roDataSectionAlloc)
- {
- uint32 newAlloc;
- void *tmp;
-
- /* Make certain that this is big enough (it should be) */
-
- newAlloc = poffInfo->roDataSectionAlloc + RODATA_SECTION_INCREMENT;
- while (poffInfo->roDataSection.sh_size + len > newAlloc)
- {
- newAlloc += RODATA_SECTION_INCREMENT;
- }
-
- /* Reallocate the roDataram data section buffer */
-
- tmp = realloc(poffInfo->roDataSectionData, newAlloc);
- if (!tmp)
- {
- return eNOMEMORY;
- }
-
- /* And set the new size */
-
- poffInfo->roDataSectionAlloc = newAlloc;
- poffInfo->roDataSectionData = (ubyte*)tmp;
- }
- return eNOERROR;
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-#if 0 /* Not used */
-uint32 poffAddRoDataByte(poffHandle_t handle, ubyte dataByte)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint32 offset;
- uint16 errCode;
-
- /* Check if we have allocated a data section buffer yet */
-
- errCode = poffCheckRoDataAlloc(poffInfo);
- if (errCode != eNOERROR)
- {
- fatal(errCode);
- }
-
- /* Check if there is room for a new byte */
-
- errCode = poffCheckRoDataRealloc(poffInfo, 1);
-
- /* Copy data section byte into the data section buffer */
-
- offset = poffInfo->roDataSection.sh_size;
- poffInfo->roDataSectionData[offset] = dataByte;
-
- /* Set the new size of the string table */
-
- poffInfo->roDataSection.sh_size++;
- return offset;
-}
-#endif
-
-/***********************************************************************/
-
-uint32 poffAddRoDataString(poffHandle_t handle, const char *string)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint32 len;
- uint32 offset;
- uint16 errCode;
-
- /* Check if we have allocated a data section buffer yet */
-
- errCode = poffCheckRoDataAlloc(poffInfo);
- if (errCode != eNOERROR)
- {
- fatal(errCode);
- }
-
- /* Check if there is room for a new byte */
-
- len = strlen(string) + 1;
- errCode = poffCheckRoDataRealloc(poffInfo, len);
-
- /* Copy data section byte into the data section buffer */
-
- offset = poffInfo->roDataSection.sh_size;
- memcpy(&poffInfo->roDataSectionData[offset], string, len);
-
- /* Set the new size of the string table */
-
- poffInfo->roDataSection.sh_size += len;
- return offset;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwrodata.c + * Write to the RODATA section of a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +static uint16_t poffCheckRoDataAlloc(poffInfo_t *poffInfo) +{ + if (!poffInfo->roDataSectionData) + { + /* No, allocate it now */ + + poffInfo->roDataSectionData = (uint8_t*)malloc(INITIAL_RODATA_SECTION_SIZE); + if (!poffInfo->roDataSectionData) + { + return eNOMEMORY; + } + + poffInfo->roDataSection.sh_size = 0; + poffInfo->roDataSectionAlloc = INITIAL_RODATA_SECTION_SIZE; + } + return eNOERROR; +} + +static uint16_t poffCheckRoDataRealloc(poffInfo_t *poffInfo, uint16_t len) +{ + /* Check if there is room for the new data */ + + if (poffInfo->roDataSection.sh_size + len > poffInfo->roDataSectionAlloc) + { + uint32_t newAlloc; + void *tmp; + + /* Make certain that this is big enough (it should be) */ + + newAlloc = poffInfo->roDataSectionAlloc + RODATA_SECTION_INCREMENT; + while (poffInfo->roDataSection.sh_size + len > newAlloc) + { + newAlloc += RODATA_SECTION_INCREMENT; + } + + /* Reallocate the roDataram data section buffer */ + + tmp = realloc(poffInfo->roDataSectionData, newAlloc); + if (!tmp) + { + return eNOMEMORY; + } + + /* And set the new size */ + + poffInfo->roDataSectionAlloc = newAlloc; + poffInfo->roDataSectionData = (uint8_t*)tmp; + } + return eNOERROR; +} + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +#if 0 /* Not used */ +uint32_t poffAddRoDataByte(poffHandle_t handle, uint8_t dataByte) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint32_t offset; + uint16_t errCode; + + /* Check if we have allocated a data section buffer yet */ + + errCode = poffCheckRoDataAlloc(poffInfo); + if (errCode != eNOERROR) + { + fatal(errCode); + } + + /* Check if there is room for a new byte */ + + errCode = poffCheckRoDataRealloc(poffInfo, 1); + + /* Copy data section byte into the data section buffer */ + + offset = poffInfo->roDataSection.sh_size; + poffInfo->roDataSectionData[offset] = dataByte; + + /* Set the new size of the string table */ + + poffInfo->roDataSection.sh_size++; + return offset; +} +#endif + +/***********************************************************************/ + +uint32_t poffAddRoDataString(poffHandle_t handle, const char *string) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint32_t len; + uint32_t offset; + uint16_t errCode; + + /* Check if we have allocated a data section buffer yet */ + + errCode = poffCheckRoDataAlloc(poffInfo); + if (errCode != eNOERROR) + { + fatal(errCode); + } + + /* Check if there is room for a new byte */ + + len = strlen(string) + 1; + errCode = poffCheckRoDataRealloc(poffInfo, len); + + /* Copy data section byte into the data section buffer */ + + offset = poffInfo->roDataSection.sh_size; + memcpy(&poffInfo->roDataSectionData[offset], string, len); + + /* Set the new size of the string table */ + + poffInfo->roDataSection.sh_size += len; + return offset; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwstring.c b/misc/pascal/libpoff/pfwstring.c index b1b066e7b7..b2e58c29a9 100644 --- a/misc/pascal/libpoff/pfwstring.c +++ b/misc/pascal/libpoff/pfwstring.c @@ -1,217 +1,218 @@ -/**********************************************************************
- * pfwstring.c
- * Write string table data a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Search the string table for an occurrence of the indicates string.
- * If found, return the offset in the string table to the string; if
- * not found, return -1.
- */
-
-sint32 poffFindString(poffHandle_t handle, const char *string)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- char *sptr = poffInfo->stringTable;
- uint32 offset;
-
- /* Has the string table been allocated yet? */
-
- if (!poffInfo->stringTable) return -1;
-
- /* Handle the NULL string case. Offset zero is reserved for the NULL
- * string and for the zero-size string.
- */
-
- if (!string) return 0;
-
- /* Okay, we will have to search the table */
-
- for (offset = 0;
- offset < poffInfo->stringTableSection.sh_size;
- offset += (strlen(sptr) + 1))
- {
- /* Get a pointer at this offset into the string table */
-
- sptr = &poffInfo->stringTable[offset];
-
- /* Check if the strings match. If so, return the offset */
-
- if (strcmp(sptr, string) == 0) return offset;
- }
-
- /* The string does not exist in the string table */
-
- return -1;
-}
-
-/***********************************************************************/
-/***********************************************************************/
-/* Add a string to the string table and return the offset to the
- * string storage location in the string table section data.
- */
-
-uint32 poffAddString(poffHandle_t handle, const char *string)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- sint32 index;
- int len;
-
- /* Check if we have allocated a string table buffer yet */
-
- if (!poffInfo->stringTable)
- {
- /* No, allocate it now */
-
- poffInfo->stringTable = (char*)malloc(INITIAL_STRING_TABLE_SIZE);
- if (!poffInfo->stringTable)
- {
- fatal(eNOMEMORY);
- }
-
- /* Index 0 is reserved for the NULL string */
-
- poffInfo->stringTable[0] = '\0';
- poffInfo->stringTableSection.sh_size = 1;
- poffInfo->stringTableAlloc = INITIAL_STRING_TABLE_SIZE;
- }
-
- /* Check if the string is already defined in the string table.
- * This is very time consuming, but guaratees that we do not keep
- * duplicate strings in the string table.
- */
-
- index = poffFindString(handle, string);
- if (index < 0)
- {
- /* The string was not found in the string table. Check for the
- * NULL string. In this case, return index == 0. NOTE: This
- * check is pointless. If this is any kind of NULL string, then
- * poffFindString will have returned index == 0.
- */
-
- if ((string == NULL) || ((len = strlen(string)) <= 0))
- {
- index = 0;
- }
- else
- {
- /* Increment the length to include the null terminator */
-
- len++;
-
- /* Check if there is room for the new string */
-
- if (poffInfo->stringTableSection.sh_size + len >
- poffInfo->stringTableAlloc)
- {
- uint32 newAlloc =
- poffInfo->stringTableAlloc + STRING_TABLE_INCREMENT;
- void *tmp;
-
- /* Make sure that the new string will fit in the new allocation
- * size (shouldn't happen)
- */
-
- while (poffInfo->stringTableSection.sh_size + len > newAlloc)
- newAlloc += STRING_TABLE_INCREMENT;
-
- /* Reallocate the string buffer */
-
- tmp = realloc(poffInfo->stringTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- poffInfo->stringTableAlloc = newAlloc;
- poffInfo->stringTable = (char*)tmp;
- }
-
- /* Copy the string into the string table */
-
- index = poffInfo->stringTableSection.sh_size;
- memcpy(&poffInfo->stringTable[index], string, len);
-
- /* Set the new size of the string table */
-
- poffInfo->stringTableSection.sh_size += len;
- }
- }
- return index;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwstring.c + * Write string table data a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Search the string table for an occurrence of the indicates string. + * If found, return the offset in the string table to the string; if + * not found, return -1. + */ + +int32_t poffFindString(poffHandle_t handle, const char *string) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + char *sptr = poffInfo->stringTable; + uint32_t offset; + + /* Has the string table been allocated yet? */ + + if (!poffInfo->stringTable) return -1; + + /* Handle the NULL string case. Offset zero is reserved for the NULL + * string and for the zero-size string. + */ + + if (!string) return 0; + + /* Okay, we will have to search the table */ + + for (offset = 0; + offset < poffInfo->stringTableSection.sh_size; + offset += (strlen(sptr) + 1)) + { + /* Get a pointer at this offset into the string table */ + + sptr = &poffInfo->stringTable[offset]; + + /* Check if the strings match. If so, return the offset */ + + if (strcmp(sptr, string) == 0) return offset; + } + + /* The string does not exist in the string table */ + + return -1; +} + +/***********************************************************************/ +/***********************************************************************/ +/* Add a string to the string table and return the offset to the + * string storage location in the string table section data. + */ + +uint32_t poffAddString(poffHandle_t handle, const char *string) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + int32_t index; + int len; + + /* Check if we have allocated a string table buffer yet */ + + if (!poffInfo->stringTable) + { + /* No, allocate it now */ + + poffInfo->stringTable = (char*)malloc(INITIAL_STRING_TABLE_SIZE); + if (!poffInfo->stringTable) + { + fatal(eNOMEMORY); + } + + /* Index 0 is reserved for the NULL string */ + + poffInfo->stringTable[0] = '\0'; + poffInfo->stringTableSection.sh_size = 1; + poffInfo->stringTableAlloc = INITIAL_STRING_TABLE_SIZE; + } + + /* Check if the string is already defined in the string table. + * This is very time consuming, but guaratees that we do not keep + * duplicate strings in the string table. + */ + + index = poffFindString(handle, string); + if (index < 0) + { + /* The string was not found in the string table. Check for the + * NULL string. In this case, return index == 0. NOTE: This + * check is pointless. If this is any kind of NULL string, then + * poffFindString will have returned index == 0. + */ + + if ((string == NULL) || ((len = strlen(string)) <= 0)) + { + index = 0; + } + else + { + /* Increment the length to include the null terminator */ + + len++; + + /* Check if there is room for the new string */ + + if (poffInfo->stringTableSection.sh_size + len > + poffInfo->stringTableAlloc) + { + uint32_t newAlloc = + poffInfo->stringTableAlloc + STRING_TABLE_INCREMENT; + void *tmp; + + /* Make sure that the new string will fit in the new allocation + * size (shouldn't happen) + */ + + while (poffInfo->stringTableSection.sh_size + len > newAlloc) + newAlloc += STRING_TABLE_INCREMENT; + + /* Reallocate the string buffer */ + + tmp = realloc(poffInfo->stringTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + poffInfo->stringTableAlloc = newAlloc; + poffInfo->stringTable = (char*)tmp; + } + + /* Copy the string into the string table */ + + index = poffInfo->stringTableSection.sh_size; + memcpy(&poffInfo->stringTable[index], string, len); + + /* Set the new size of the string table */ + + poffInfo->stringTableSection.sh_size += len; + } + } + return index; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfwsymbol.c b/misc/pascal/libpoff/pfwsymbol.c index b0bbbaa6e4..4bfd559b36 100644 --- a/misc/pascal/libpoff/pfwsymbol.c +++ b/misc/pascal/libpoff/pfwsymbol.c @@ -1,151 +1,152 @@ -/**********************************************************************
- * pfwsymbol.c
- * Write symbol information to a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************/
-/* Add a symbol to the symbol table section data. Returns index value
- * associated with the symbol entry in the symbol table section data.
- */
-
-uint32 poffAddSymbol(poffHandle_t handle, poffLibSymbol_t *symbol)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- poffSymbol_t *psym;
- uint32 st_name;
- uint32 index;
-
- /* Add the name to the string table */
-
- st_name = poffAddString(poffInfo, symbol->name);
-
- /* Check if we have allocated a symbol table buffer yet */
-
- if (!poffInfo->symbolTable)
- {
- /* No, allocate it now */
-
- poffInfo->symbolTable = (ubyte*)malloc(INITIAL_SYMBOL_TABLE_SIZE);
- if (!poffInfo->symbolTable)
- {
- fatal(eNOMEMORY);
- }
-
- poffInfo->symbolTableSection.sh_size = 0;
- poffInfo->symbolTableAlloc = INITIAL_SYMBOL_TABLE_SIZE;
- }
-
- /* Check if there is room for a new symbol */
-
- if (poffInfo->symbolTableSection.sh_size +
- poffInfo->symbolTableSection.sh_entsize >
- poffInfo->symbolTableAlloc)
- {
- uint32 newAlloc = poffInfo->symbolTableAlloc + SYMBOL_TABLE_INCREMENT;
- ubyte *tmp;
-
- /* Reallocate the file name buffer */
-
- tmp = (ubyte*)realloc(poffInfo->symbolTable, newAlloc);
- if (!tmp)
- {
- fatal(eNOMEMORY);
- }
-
- /* And set the new size */
-
- poffInfo->symbolTableAlloc = newAlloc;
- poffInfo->symbolTable = tmp;
- }
-
- /* Save the new symbol information in the symbol table data */
-
- index = poffInfo->symbolTableSection.sh_size;
- psym = (poffSymbol_t*)&poffInfo->symbolTable[index];
-
- psym->st_type = symbol->type;
- psym->st_align = symbol->align;
- psym->st_flags = symbol->flags;
- psym->st_pad = 0;
- psym->st_name = st_name;
- psym->st_value = symbol->value;
- psym->st_size = symbol->size;
-
- /* Set the new size of the file name table */
-
- poffInfo->symbolTableSection.sh_size += poffInfo->symbolTableSection.sh_entsize;
- return index / poffInfo->symbolTableSection.sh_entsize;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfwsymbol.c + * Write symbol information to a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/*********************************************************************** + * Public Functions + ***********************************************************************/ + +/***********************************************************************/ +/* Add a symbol to the symbol table section data. Returns index value + * associated with the symbol entry in the symbol table section data. + */ + +uint32_t poffAddSymbol(poffHandle_t handle, poffLibSymbol_t *symbol) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + poffSymbol_t *psym; + uint32_t st_name; + uint32_t index; + + /* Add the name to the string table */ + + st_name = poffAddString(poffInfo, symbol->name); + + /* Check if we have allocated a symbol table buffer yet */ + + if (!poffInfo->symbolTable) + { + /* No, allocate it now */ + + poffInfo->symbolTable = (uint8_t*)malloc(INITIAL_SYMBOL_TABLE_SIZE); + if (!poffInfo->symbolTable) + { + fatal(eNOMEMORY); + } + + poffInfo->symbolTableSection.sh_size = 0; + poffInfo->symbolTableAlloc = INITIAL_SYMBOL_TABLE_SIZE; + } + + /* Check if there is room for a new symbol */ + + if (poffInfo->symbolTableSection.sh_size + + poffInfo->symbolTableSection.sh_entsize > + poffInfo->symbolTableAlloc) + { + uint32_t newAlloc = poffInfo->symbolTableAlloc + SYMBOL_TABLE_INCREMENT; + uint8_t *tmp; + + /* Reallocate the file name buffer */ + + tmp = (uint8_t*)realloc(poffInfo->symbolTable, newAlloc); + if (!tmp) + { + fatal(eNOMEMORY); + } + + /* And set the new size */ + + poffInfo->symbolTableAlloc = newAlloc; + poffInfo->symbolTable = tmp; + } + + /* Save the new symbol information in the symbol table data */ + + index = poffInfo->symbolTableSection.sh_size; + psym = (poffSymbol_t*)&poffInfo->symbolTable[index]; + + psym->st_type = symbol->type; + psym->st_align = symbol->align; + psym->st_flags = symbol->flags; + psym->st_pad = 0; + psym->st_name = st_name; + psym->st_value = symbol->value; + psym->st_size = symbol->size; + + /* Set the new size of the file name table */ + + poffInfo->symbolTableSection.sh_size += poffInfo->symbolTableSection.sh_entsize; + return index / poffInfo->symbolTableSection.sh_entsize; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfxprog.c b/misc/pascal/libpoff/pfxprog.c index 3c37836472..e580905778 100644 --- a/misc/pascal/libpoff/pfxprog.c +++ b/misc/pascal/libpoff/pfxprog.c @@ -1,95 +1,96 @@ -/**********************************************************************
- * pfxprog.c
- * Extract program data from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-uint32 poffExtractProgramData(poffHandle_t handle, ubyte **progData)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint32 size;
-
- /* Give the program data to the caller */
-
- *progData = poffInfo->progSectionData;
- size = poffInfo->progSection.sh_size;
-
- /* Indicate the no program data is owned by the container */
-
- poffInfo->progSection.sh_size = 0;
- poffInfo->progSectionData = NULL;
- poffInfo->progSectionAlloc = 0;
- poffInfo->progSectionIndex = 0;
-
- return size;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfxprog.c + * Extract program data from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ + +uint32_t poffExtractProgramData(poffHandle_t handle, uint8_t **progData) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint32_t size; + + /* Give the program data to the caller */ + + *progData = poffInfo->progSectionData; + size = poffInfo->progSection.sh_size; + + /* Indicate the no program data is owned by the container */ + + poffInfo->progSection.sh_size = 0; + poffInfo->progSectionData = NULL; + poffInfo->progSectionAlloc = 0; + poffInfo->progSectionIndex = 0; + + return size; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pfxrodata.c b/misc/pascal/libpoff/pfxrodata.c index a5141b4911..b10eea6424 100644 --- a/misc/pascal/libpoff/pfxrodata.c +++ b/misc/pascal/libpoff/pfxrodata.c @@ -1,94 +1,95 @@ -/**********************************************************************
- * pfxrodata.c
- * Extract program read-only data from a POFF file
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "keywords.h" /* Standard types */
-#include "pedefs.h" /* error code definitions */
-
-#include "perr.h" /* error() */
-#include "pofflib.h" /* POFF library interface */
-#include "pfprivate.h" /* POFF private definitions */
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Global Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/***********************************************************************
- * Private Function Prototypes
- ***********************************************************************/
-
-/***********************************************************************
- * Private Functions
- ***********************************************************************/
-
-/***********************************************************************/
-
-uint32 poffExtractRoData(poffHandle_t handle, ubyte **roData)
-{
- poffInfo_t *poffInfo = (poffInfo_t*)handle;
- uint32 size;
-
- /* Give the program data to the caller */
-
- *roData = poffInfo->roDataSectionData;
- size = poffInfo->roDataSection.sh_size;
-
- /* Indicate the no program data is owned by the container */
-
- poffInfo->roDataSection.sh_size = 0;
- poffInfo->roDataSectionData = NULL;
- poffInfo->roDataSectionAlloc = 0;
-
- return size;
-}
-
-/***********************************************************************/
+/********************************************************************** + * pfxrodata.c + * Extract program read-only data from a POFF file + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "keywords.h" /* Standard types */ +#include "pedefs.h" /* error code definitions */ + +#include "perr.h" /* error() */ +#include "pofflib.h" /* POFF library interface */ +#include "pfprivate.h" /* POFF private definitions */ + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Global Variables + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/*********************************************************************** + * Private Function Prototypes + ***********************************************************************/ + +/*********************************************************************** + * Private Functions + ***********************************************************************/ + +/***********************************************************************/ + +uint32_t poffExtractRoData(poffHandle_t handle, uint8_t **roData) +{ + poffInfo_t *poffInfo = (poffInfo_t*)handle; + uint32_t size; + + /* Give the program data to the caller */ + + *roData = poffInfo->roDataSectionData; + size = poffInfo->roDataSection.sh_size; + + /* Indicate the no program data is owned by the container */ + + poffInfo->roDataSection.sh_size = 0; + poffInfo->roDataSectionData = NULL; + poffInfo->roDataSectionAlloc = 0; + + return size; +} + +/***********************************************************************/ diff --git a/misc/pascal/libpoff/pofferr.c b/misc/pascal/libpoff/pofferr.c index fb42583041..87fdc0265b 100644 --- a/misc/pascal/libpoff/pofferr.c +++ b/misc/pascal/libpoff/pofferr.c @@ -1,93 +1,94 @@ -/**********************************************************************
- * pofferr.c
- * Simple error handlers
- *
- * Copyright (C) 2008 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- **********************************************************************/
-
-/**********************************************************************
- * Included Files
- **********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-#include "keywords.h"
-
-#include "perr.h"
-
-/**********************************************************************
- * Definitions
- **********************************************************************/
-
-/**********************************************************************
- * Private Variables
- **********************************************************************/
-
-/**********************************************************************
- * Private Function Prototypes
- **********************************************************************/
-
-void errmsg(char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
-}
-
-/***********************************************************************/
-
-void warn(uint16 errcode)
-{
- /* Write error record to the error and list files */
-
- fprintf(stderr, "WARNING: %d\n", errcode);
-} /* end warn */
-
-/***********************************************************************/
-
-void error(uint16 errcode)
-{
- fatal(errcode);
-} /* end error */
-
-/***********************************************************************/
-
-void fatal(uint16 errcode)
-{
- fprintf(stderr, "Fatal Error %d -- Aborting\n", errcode);
- exit(errcode);
-} /* end fatal */
-
-/***********************************************************************/
+/********************************************************************** + * pofferr.c + * Simple error handlers + * + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ + +/********************************************************************** + * Included Files + **********************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +#include "keywords.h" + +#include "perr.h" + +/********************************************************************** + * Definitions + **********************************************************************/ + +/********************************************************************** + * Private Variables + **********************************************************************/ + +/********************************************************************** + * Private Function Prototypes + **********************************************************************/ + +void errmsg(char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + (void)vfprintf(stderr, fmt, ap); + va_end(ap); +} + +/***********************************************************************/ + +void warn(uint16_t errcode) +{ + /* Write error record to the error and list files */ + + fprintf(stderr, "WARNING: %d\n", errcode); +} /* end warn */ + +/***********************************************************************/ + +void error(uint16_t errcode) +{ + fatal(errcode); +} /* end error */ + +/***********************************************************************/ + +void fatal(uint16_t errcode) +{ + fprintf(stderr, "Fatal Error %d -- Aborting\n", errcode); + exit(errcode); +} /* end fatal */ + +/***********************************************************************/ |