mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-30 04:33:34 +08:00
Completes coding of the PWM module
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4200 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
############################################################################
|
||||
# libpoff/Make.defs
|
||||
# NuttX runtime makefile fragment
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
POFF_ASRCS =
|
||||
POFF_CSRCS = pfhandle.c pfproghandle.c pftprog.c \
|
||||
pfsymhandle.c pftsymbol.c pofferr.c \
|
||||
pfwhdr.c pfwrodata.c pfwsymbol.c pfwfname.c \
|
||||
pfwprog.c pfwlineno.c pfwdbgfunc.c pfwreloc.c pfwstring.c \
|
||||
pfwrite.c pfrhdr.c pfrsymbol.c pfrfname.c \
|
||||
pfrprog.c pfrlineno.c pfrdbgfunc.c pfrrawlineno.c \
|
||||
pfrrawreloc.c pfrstring.c pfread.c pfrseek.c \
|
||||
pfrelease.c pfdbgcontainer.c pfdbgdiscard.c \
|
||||
pfxprog.c pfxrodata.c pfiprog.c pfirodata.c \
|
||||
pfdhdr.c pfdsymbol.c pfdreloc.c pflabel.c \
|
||||
pfdbginfo.c pfswap.c
|
||||
@@ -0,0 +1,47 @@
|
||||
# ----------------------------------------------------------------------
|
||||
# libpoff/Makefile
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Directories
|
||||
|
||||
PASCAL = ${shell pwd}/..
|
||||
|
||||
include $(PASCAL)/Make.config
|
||||
include $(PASCAL)/Make.defs
|
||||
|
||||
INCDIR = $(PASCAL)/include
|
||||
LIBDIR = $(PASCAL)/lib
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Objects and targets
|
||||
|
||||
LIBPOFFSRCS = pfhandle.c pfproghandle.c pftprog.c \
|
||||
pfsymhandle.c pftsymbol.c pofferr.c \
|
||||
pfwhdr.c pfwrodata.c pfwsymbol.c pfwfname.c \
|
||||
pfwprog.c pfwlineno.c pfwdbgfunc.c pfwreloc.c pfwstring.c \
|
||||
pfwrite.c pfrhdr.c pfrsymbol.c pfrfname.c \
|
||||
pfrprog.c pfrlineno.c pfrdbgfunc.c pfrrawlineno.c \
|
||||
pfrrawreloc.c pfrstring.c pfread.c pfrseek.c \
|
||||
pfrelease.c pfdbgcontainer.c pfdbgdiscard.c \
|
||||
pfxprog.c pfxrodata.c pfiprog.c pfirodata.c \
|
||||
pfdhdr.c pfdsymbol.c pfdreloc.c pflabel.c \
|
||||
pflineno.c pfdbginfo.c pfswap.c
|
||||
LIBPOFFOBJS = $(LIBPOFFSRCS:.c=.o)
|
||||
|
||||
all: libpoff.a
|
||||
.PHONY: all libpoff.a clean
|
||||
|
||||
$(OBJS): %.o: %.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(LIBDIR)/libpoff.a: $(LIBPOFFOBJS)
|
||||
$(RM) $@
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
libpoff.a: $(LIBDIR)/libpoff.a
|
||||
|
||||
clean:
|
||||
$(RM) libpoff.a *.o core *~
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
@@ -0,0 +1,106 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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);
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,94 @@
|
||||
/**********************************************************************
|
||||
* pfdbgdiscard.c
|
||||
* Discard debug function 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 "pofflib.h" /* POFF library interface */
|
||||
#include "pfprivate.h" /* POFF private definitions */
|
||||
|
||||
/**********************************************************************
|
||||
* Definitions
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Global Variables
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Private Variables
|
||||
**********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Private Function Prototypes
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Private Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Public Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffDiscardDebugFuncInfo(poffHandle_t handle)
|
||||
{
|
||||
poffInfo_t *poffInfo = (poffInfo_t*)handle;
|
||||
|
||||
/* Deallocate any buffered data */
|
||||
|
||||
if (poffInfo->debugFuncTable)
|
||||
{
|
||||
free(poffInfo->debugFuncTable);
|
||||
}
|
||||
|
||||
/* And erase any knowledge of the debug info */
|
||||
|
||||
poffInfo->debugFuncSection.sh_size = 0;
|
||||
poffInfo->debugFuncTable = NULL;
|
||||
poffInfo->debugFuncTableAlloc = 0;
|
||||
poffInfo->debugFuncIndex = 0;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,158 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,182 @@
|
||||
/**********************************************************************
|
||||
* pfdhdr.c
|
||||
* Dump the contents of POFF file and section headers
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <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 *poffFhTypes[FHT_NTYPES] =
|
||||
{
|
||||
"NONE ", /* Shouldn't happen */
|
||||
"EXEC ", /* Pascal program executable */
|
||||
"SHLIB ", /* Pascal shared library */
|
||||
"PROGRAM ", /* Pascal program object */
|
||||
"UNIT " /* Pascal unit object */
|
||||
};
|
||||
|
||||
static const char *poffShTypes[SHT_NTYPES] =
|
||||
{
|
||||
"NULL ", /* Shouldn't happen */
|
||||
"PROGDATA", /* Program data */
|
||||
"SYMTAB ", /* Symbol table */
|
||||
"STRTAB ", /* String table */
|
||||
"REL ", /* Relocation data */
|
||||
"FILETAB ", /* File table */
|
||||
"LINENO ", /* Line number data */
|
||||
"DEBUG " /* Func/Proc debug data */
|
||||
};
|
||||
|
||||
/***********************************************************************
|
||||
* Private Function Prototypes
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Private Functions
|
||||
***********************************************************************/
|
||||
|
||||
static void poffDumpSectionHeader(poffHandle_t handle,
|
||||
poffSectionHeader_t *shdr,
|
||||
FILE *outFile)
|
||||
{
|
||||
poffInfo_t *poffInfo = (poffInfo_t*)handle;
|
||||
|
||||
fprintf(outFile, "%-10s %8s 0x%02x 0x%04x 0x%08lx 0x%08lx %ld\n",
|
||||
poffGetString(poffInfo, shdr->sh_name),
|
||||
poffShTypes[shdr->sh_type], shdr->sh_flags,
|
||||
shdr->sh_entsize, shdr->sh_addr, shdr->sh_offset,
|
||||
shdr->sh_size);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Public Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffDumpFileHeader(poffHandle_t handle, FILE *outFile)
|
||||
{
|
||||
poffInfo_t *poffInfo = (poffInfo_t*)handle;
|
||||
|
||||
fprintf(outFile, "\nPOFF File Header:\n");
|
||||
fprintf(outFile, " fh_ident: %c%c%c%c\n",
|
||||
poffInfo->fileHeader.fh_ident[0], poffInfo->fileHeader.fh_ident[1],
|
||||
poffInfo->fileHeader.fh_ident[2], poffInfo->fileHeader.fh_ident[3]);
|
||||
fprintf(outFile, " fh_version: %d\n", poffInfo->fileHeader.fh_version);
|
||||
fprintf(outFile, " fh_type: %s\n",
|
||||
poffFhTypes[poffInfo->fileHeader.fh_type]);
|
||||
fprintf(outFile, " fh_shsize: %d\n", poffInfo->fileHeader.fh_shsize);
|
||||
fprintf(outFile, " fh_shnum: %d\n", poffInfo->fileHeader.fh_shnum);
|
||||
fprintf(outFile, " fh_name: %s\n",
|
||||
poffGetString(poffInfo, poffInfo->fileHeader.fh_name));
|
||||
fprintf(outFile, " fh_entry: 0x%08lx\n", poffInfo->fileHeader.fh_entry);
|
||||
fprintf(outFile, " fh_shoff: 0x%08lx\n", poffInfo->fileHeader.fh_shoff);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffDumpSectionHeaders(poffHandle_t handle, FILE *outFile)
|
||||
{
|
||||
poffInfo_t *poffInfo = (poffInfo_t*)handle;
|
||||
|
||||
fprintf(outFile, "\nPOFF Section Headers:\n");
|
||||
fprintf(outFile, "NAME TYPE FLAG ENTSZE ADDRESS OFFSET SIZE\n");
|
||||
|
||||
if (poffInfo->progSection.sh_size > 0)
|
||||
{
|
||||
poffDumpSectionHeader(handle, &poffInfo->progSection, outFile);
|
||||
}
|
||||
|
||||
if (poffInfo->roDataSection.sh_size > 0)
|
||||
{
|
||||
poffDumpSectionHeader(handle, &poffInfo->roDataSection, outFile);
|
||||
}
|
||||
|
||||
if (poffInfo->symbolTableSection.sh_size > 0)
|
||||
{
|
||||
poffDumpSectionHeader(handle, &poffInfo->symbolTableSection, outFile);
|
||||
}
|
||||
|
||||
if (poffInfo->stringTableSection.sh_size > 0)
|
||||
{
|
||||
poffDumpSectionHeader(handle, &poffInfo->stringTableSection, outFile);
|
||||
}
|
||||
|
||||
if (poffInfo->relocSection.sh_size > 0)
|
||||
{
|
||||
poffDumpSectionHeader(handle, &poffInfo->relocSection, outFile);
|
||||
}
|
||||
|
||||
if (poffInfo->fileNameTableSection.sh_size > 0)
|
||||
{
|
||||
poffDumpSectionHeader(handle, &poffInfo->fileNameTableSection, outFile);
|
||||
}
|
||||
|
||||
if (poffInfo->lineNumberSection.sh_size > 0)
|
||||
{
|
||||
poffDumpSectionHeader(handle, &poffInfo->lineNumberSection, outFile);
|
||||
}
|
||||
|
||||
if (poffInfo->debugFuncSection.sh_size > 0)
|
||||
{
|
||||
poffDumpSectionHeader(handle, &poffInfo->debugFuncSection, outFile);
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,108 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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);
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,117 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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);
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,195 @@
|
||||
/**********************************************************************
|
||||
* pfhandle.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 "keywords.h" /* Standard types */
|
||||
#include "pfprivate.h" /* POFF private definitions */
|
||||
#include "pofflib.h" /* Public interfaces */
|
||||
|
||||
/**********************************************************************
|
||||
* Definitions
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Global Variables
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Private Variables
|
||||
**********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Private Function Prototypes
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Private Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Public Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
/* Set all global data structures to a known state */
|
||||
|
||||
poffHandle_t poffCreateHandle(void)
|
||||
{
|
||||
poffInfo_t *poffInfo;
|
||||
|
||||
/* Create a new POFF handle */
|
||||
|
||||
poffInfo = (poffInfo_t*)malloc(sizeof(poffInfo_t));
|
||||
if (poffInfo != NULL)
|
||||
{
|
||||
/* Set everthing to zero */
|
||||
|
||||
memset(poffInfo, 0, sizeof(poffInfo_t));
|
||||
|
||||
/* Initialize POFF file header */
|
||||
|
||||
poffInfo->fileHeader.fh_ident[FHI_MAG0] = FHI_POFF_MAG0;
|
||||
poffInfo->fileHeader.fh_ident[FHI_MAG1] = FHI_POFF_MAG1;
|
||||
poffInfo->fileHeader.fh_ident[FHI_MAG2] = FHI_POFF_MAG2;
|
||||
poffInfo->fileHeader.fh_ident[FHI_MAG3] = FHI_POFF_MAG3;
|
||||
poffInfo->fileHeader.fh_version = FHV_CURRENT;
|
||||
poffInfo->fileHeader.fh_shsize = sizeof(poffSectionHeader_t);
|
||||
poffInfo->fileHeader.fh_shoff = sizeof(poffFileHeader_t);
|
||||
|
||||
/* Initialize the program section header */
|
||||
|
||||
poffInfo->progSection.sh_type = SHT_PROGDATA;
|
||||
poffInfo->progSection.sh_flags = SHF_ALLOC | SHF_EXEC;
|
||||
|
||||
/* Initialize the initialized data section header */
|
||||
|
||||
poffInfo->roDataSection.sh_type = SHT_PROGDATA;
|
||||
poffInfo->roDataSection.sh_flags = SHF_WRITE | SHF_ALLOC;
|
||||
|
||||
/* Initialize the symbol table section header */
|
||||
|
||||
poffInfo->symbolTableSection.sh_type = SHT_SYMTAB;
|
||||
poffInfo->symbolTableSection.sh_entsize = sizeof(poffSymbol_t);
|
||||
|
||||
/* Initialize the string table section header */
|
||||
|
||||
poffInfo->stringTableSection.sh_type = SHT_STRTAB;
|
||||
|
||||
/* Initialize the relocation table section header */
|
||||
|
||||
poffInfo->relocSection.sh_type = SHT_REL;
|
||||
poffInfo->relocSection.sh_entsize = sizeof(poffRelocation_t);
|
||||
|
||||
/* Initialize the file table section header */
|
||||
|
||||
poffInfo->fileNameTableSection.sh_type = SHT_FILETAB;
|
||||
poffInfo->fileNameTableSection.sh_entsize = sizeof(poffFileTab_t);
|
||||
|
||||
/* Initialize the line number section header */
|
||||
|
||||
poffInfo->lineNumberSection.sh_type = SHT_LINENO;
|
||||
poffInfo->lineNumberSection.sh_entsize = sizeof(poffLineNumber_t);
|
||||
|
||||
/* Initialize the debug function info section header */
|
||||
|
||||
poffInfo->debugFuncSection.sh_type = SHT_DEBUG;
|
||||
poffInfo->debugFuncSection.sh_entsize = sizeof(poffDebugFuncInfo_t);
|
||||
}
|
||||
return poffInfo;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffDestroyHandle(poffHandle_t handle)
|
||||
{
|
||||
poffInfo_t *poffInfo = (poffInfo_t*)handle;
|
||||
|
||||
/* Free all of the allocated, in-memory data */
|
||||
|
||||
if (poffInfo->progSectionData)
|
||||
free(poffInfo->progSectionData);
|
||||
|
||||
if (poffInfo->roDataSectionData)
|
||||
free(poffInfo->roDataSectionData);
|
||||
|
||||
if (poffInfo->symbolTable)
|
||||
free(poffInfo->symbolTable);
|
||||
|
||||
if (poffInfo->stringTable)
|
||||
free(poffInfo->stringTable);
|
||||
|
||||
if (poffInfo->relocTable)
|
||||
free(poffInfo->relocTable);
|
||||
|
||||
if (poffInfo->fileNameTable)
|
||||
free(poffInfo->fileNameTable);
|
||||
|
||||
if (poffInfo->lineNumberTable)
|
||||
free(poffInfo->lineNumberTable);
|
||||
|
||||
if (poffInfo->debugFuncTable)
|
||||
free(poffInfo->debugFuncTable);
|
||||
|
||||
/* Free the container */
|
||||
|
||||
free(handle);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffResetAccess(poffHandle_t handle)
|
||||
{
|
||||
poffInfo_t *poffInfo = (poffInfo_t*)handle;
|
||||
|
||||
/* Reset read/write indices */
|
||||
|
||||
poffInfo->symbolIndex = 0;
|
||||
poffInfo->progSectionIndex = 0;
|
||||
poffInfo->relocIndex = 0;
|
||||
poffInfo->fileNameIndex = 0;
|
||||
poffInfo->lineNumberIndex = 0;
|
||||
poffInfo->debugFuncIndex = 0;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,103 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,285 @@
|
||||
/**********************************************************************
|
||||
* pflabel.c
|
||||
* Label resolution logic
|
||||
*
|
||||
* 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"
|
||||
#include "pdefs.h"
|
||||
#include "pedefs.h"
|
||||
#include "perr.h"
|
||||
#include "poff.h"
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor Definitions
|
||||
**********************************************************************/
|
||||
|
||||
#define INITIAL_DEFINED_ALLOCATION (1024*sizeof(optDefinedLabelRef_t))
|
||||
#define DEFINED_INCREMENT (256*sizeof(optDefinedLabelRef_t))
|
||||
|
||||
#define INITIAL_UNDEFINED_ALLOCATION (1024*sizeof(optUndefinedLabelRef_t))
|
||||
#define UNDEFINED_INCREMENT (256*sizeof(optUndefinedLabelRef_t))
|
||||
|
||||
/**********************************************************************
|
||||
* Private Types
|
||||
**********************************************************************/
|
||||
|
||||
struct optDefinedLabelRef_s
|
||||
{
|
||||
uint32_t label;
|
||||
uint32_t pc;
|
||||
};
|
||||
typedef struct optDefinedLabelRef_s optDefinedLabelRef_t;
|
||||
|
||||
struct optUndefinedLabelRef_s
|
||||
{
|
||||
uint32_t label;
|
||||
uint32_t symIndex;
|
||||
};
|
||||
typedef struct optUndefinedLabelRef_s optUndefinedLabelRef_t;
|
||||
|
||||
/**********************************************************************
|
||||
* Private Data
|
||||
**********************************************************************/
|
||||
|
||||
static optDefinedLabelRef_t *definedLabelRefs = NULL;
|
||||
static uint32_t definedLabelRefAlloc = 0;
|
||||
static uint32_t nDefinedLabelRefs = 0;
|
||||
|
||||
static optUndefinedLabelRef_t *undefinedLabelRefs = NULL;
|
||||
static uint32_t undefinedLabelRefAlloc = 0;
|
||||
static uint32_t nUndefinedLabelRefs = 0;
|
||||
|
||||
/**********************************************************************
|
||||
* Private Function Prototypes
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Private Inline Functions
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Private Functions
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static void poffCheckDefinedLabelAlloc(void)
|
||||
{
|
||||
/* Has the label reference table been allocated */
|
||||
|
||||
if (!definedLabelRefs)
|
||||
{
|
||||
/* No, allocate it now */
|
||||
|
||||
definedLabelRefs = (optDefinedLabelRef_t*)
|
||||
malloc(INITIAL_DEFINED_ALLOCATION);
|
||||
|
||||
if (!definedLabelRefs)
|
||||
{
|
||||
fatal(eNOMEMORY);
|
||||
}
|
||||
definedLabelRefAlloc = INITIAL_DEFINED_ALLOCATION;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static void poffCheckDefinedLabelRealloc(void)
|
||||
{
|
||||
/* Check if there is room for the new data */
|
||||
|
||||
if (((nDefinedLabelRefs + 1)*sizeof(optDefinedLabelRef_t)) >
|
||||
definedLabelRefAlloc)
|
||||
{
|
||||
uint32_t newAlloc = definedLabelRefAlloc + DEFINED_INCREMENT;
|
||||
void *tmp;
|
||||
|
||||
/* Reallocate the label reference tabel */
|
||||
|
||||
tmp = realloc(definedLabelRefs, newAlloc);
|
||||
if (!tmp)
|
||||
{
|
||||
fatal(eNOMEMORY);
|
||||
}
|
||||
|
||||
/* And set the new size */
|
||||
|
||||
definedLabelRefAlloc = newAlloc;
|
||||
definedLabelRefs = (optDefinedLabelRef_t*)tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static void poffCheckUndefinedLabelAlloc(void)
|
||||
{
|
||||
/* Has the label reference table been allocated */
|
||||
|
||||
if (!undefinedLabelRefs)
|
||||
{
|
||||
/* No, allocate it now */
|
||||
|
||||
undefinedLabelRefs = (optUndefinedLabelRef_t*)
|
||||
malloc(INITIAL_UNDEFINED_ALLOCATION);
|
||||
|
||||
if (!undefinedLabelRefs)
|
||||
{
|
||||
fatal(eNOMEMORY);
|
||||
}
|
||||
undefinedLabelRefAlloc = INITIAL_UNDEFINED_ALLOCATION;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static void poffCheckUndefinedLabelRealloc(void)
|
||||
{
|
||||
/* Check if there is room for the new data */
|
||||
|
||||
if (((nUndefinedLabelRefs + 1)*sizeof(optUndefinedLabelRef_t)) >
|
||||
undefinedLabelRefAlloc)
|
||||
{
|
||||
uint32_t newAlloc = undefinedLabelRefAlloc + UNDEFINED_INCREMENT;
|
||||
void *tmp;
|
||||
|
||||
/* Reallocate the label reference tabel */
|
||||
|
||||
tmp = realloc(undefinedLabelRefs, newAlloc);
|
||||
if (!tmp)
|
||||
{
|
||||
fatal(eNOMEMORY);
|
||||
}
|
||||
|
||||
/* And set the new size */
|
||||
|
||||
undefinedLabelRefAlloc = newAlloc;
|
||||
undefinedLabelRefs = (optUndefinedLabelRef_t*)tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Global Functions
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void poffAddToDefinedLabelTable(uint32_t label, uint32_t pc)
|
||||
{
|
||||
/* Make sure we have memory to do this. If not, we will crash */
|
||||
|
||||
poffCheckDefinedLabelAlloc();
|
||||
poffCheckDefinedLabelRealloc();
|
||||
|
||||
/* Add the label to the table */
|
||||
|
||||
definedLabelRefs[nDefinedLabelRefs].label = label;
|
||||
definedLabelRefs[nDefinedLabelRefs].pc = pc;
|
||||
nDefinedLabelRefs++;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void poffAddToUndefinedLabelTable(uint32_t label, uint32_t symIndex)
|
||||
{
|
||||
/* Make sure we have memory to do this. If not, we will crash */
|
||||
|
||||
poffCheckUndefinedLabelAlloc();
|
||||
poffCheckUndefinedLabelRealloc();
|
||||
|
||||
/* Add the label to the table */
|
||||
|
||||
undefinedLabelRefs[nUndefinedLabelRefs].label = label;
|
||||
undefinedLabelRefs[nUndefinedLabelRefs].symIndex = symIndex;
|
||||
nUndefinedLabelRefs++;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
int poffGetSymIndexForUndefinedLabel(uint32_t label)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nUndefinedLabelRefs; i++)
|
||||
{
|
||||
if (undefinedLabelRefs[i].label == label)
|
||||
{
|
||||
return undefinedLabelRefs[i].symIndex;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
int poffGetPcForDefinedLabel(uint32_t label)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nDefinedLabelRefs; i++)
|
||||
{
|
||||
if (definedLabelRefs[i].label == label)
|
||||
{
|
||||
return definedLabelRefs[i].pc;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void poffReleaseLabelReferences(void)
|
||||
{
|
||||
if (definedLabelRefs)
|
||||
{
|
||||
free(definedLabelRefs);
|
||||
}
|
||||
if (undefinedLabelRefs)
|
||||
{
|
||||
free(undefinedLabelRefs);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,190 @@
|
||||
/***************************************************************************
|
||||
* pfprivate.h
|
||||
* Contains command, internal, private definitions used by
|
||||
* the POFF library. These were not intended for exportation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __PFPRIVATE_H
|
||||
#define __PFPRIVATE_H
|
||||
|
||||
/***************************************************************************
|
||||
* Included Files
|
||||
***************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "keywords.h"
|
||||
#include "poff.h"
|
||||
#include "paslib.h" /* Endian-ness support */
|
||||
|
||||
/***************************************************************************
|
||||
* Pre-processor Definitions
|
||||
***************************************************************************/
|
||||
|
||||
#define INITIAL_STRING_TABLE_SIZE 4096
|
||||
#define STRING_TABLE_INCREMENT 1024
|
||||
|
||||
#define INITIAL_SYMBOL_TABLE_SIZE 256*sizeof(poffSymbol_t)
|
||||
#define SYMBOL_TABLE_INCREMENT 64*sizeof(poffSymbol_t)
|
||||
|
||||
#define INITIAL_FILENAME_TABLE_SIZE 64*sizeof(poffFileTab_t)
|
||||
#define FILENAME_TABLE_INCREMENT 64*sizeof(poffFileTab_t)
|
||||
|
||||
#define INITIAL_RELOC_TABLE_SIZE 128*sizeof(poffRelocation_t)
|
||||
#define RELOC_TABLE_INCREMENT 64*sizeof(poffRelocation_t)
|
||||
|
||||
#define INITIAL_LINENUMBER_TABLE_SIZE 2048*sizeof(poffLineNumber_t)
|
||||
#define LINENUMBER_TABLE_INCREMENT 512*sizeof(poffLineNumber_t)
|
||||
|
||||
#define INITIAL_DEBUGFUNC_TABLE_SIZE 128*sizeof(poffDebugFuncInfo_t)
|
||||
#define DEBUGFUNC_TABLE_INCREMENT 64*sizeof(poffDebugFuncInfo_t)
|
||||
|
||||
#define INITIAL_PROG_SECTION_SIZE 8096
|
||||
#define PROG_SECTION_INCREMENT 2048
|
||||
|
||||
#define INITIAL_RODATA_SECTION_SIZE 4096
|
||||
#define RODATA_SECTION_INCREMENT 1024
|
||||
|
||||
#define HAVE_PROGRAM_SECTION (poffInfo->progSection.sh_size > 0)
|
||||
#define HAVE_RODATA_SECTION (poffInfo->roDataSection.sh_size > 0)
|
||||
#define HAVE_SYMBOL_TABLE (poffInfo->symbolTableSection.sh_size > 0)
|
||||
#define HAVE_STRING_TABLE (poffInfo->stringTableSection.sh_size > 0)
|
||||
#define HAVE_RELOC_SECTION (poffInfo->relocSection.sh_size > 0)
|
||||
#define HAVE_FILE_TABLE (poffInfo->fileNameTableSection.sh_size > 0)
|
||||
#define HAVE_LINE_NUMBER (poffInfo->lineNumberSection.sh_size > 0)
|
||||
#define HAVE_DEBUG_SECTION (poffInfo->debugFuncSection.sh_size > 0)
|
||||
|
||||
#ifndef CONFIG_POFF_SWAPNEEDED
|
||||
# define poffSwapFileHeader(p)
|
||||
# define poffSwapSectionHeader(p)
|
||||
# define poffSwapSymbolTableData(p)
|
||||
# define poffSwapRelocationData(p)
|
||||
# define poffSwapFileTableData(p)
|
||||
# define poffSwapLineNumberData(p)
|
||||
# define poffSwapDebugData(p)
|
||||
#endif
|
||||
|
||||
/***************************************************************************
|
||||
* Public Types
|
||||
***************************************************************************/
|
||||
|
||||
struct poffInfo_s
|
||||
{
|
||||
/* POFF file header */
|
||||
|
||||
poffFileHeader_t fileHeader;
|
||||
|
||||
/* Section headers: */
|
||||
|
||||
poffSectionHeader_t progSection;
|
||||
poffSectionHeader_t roDataSection;
|
||||
poffSectionHeader_t symbolTableSection;
|
||||
poffSectionHeader_t stringTableSection;
|
||||
poffSectionHeader_t relocSection;
|
||||
poffSectionHeader_t fileNameTableSection;
|
||||
poffSectionHeader_t lineNumberSection;
|
||||
poffSectionHeader_t debugFuncSection;
|
||||
|
||||
/* In-memory section data */
|
||||
|
||||
uint8_t *progSectionData;
|
||||
uint8_t *roDataSectionData;
|
||||
uint8_t *symbolTable;
|
||||
char *stringTable;
|
||||
uint8_t *relocTable;
|
||||
poffFileTab_t *fileNameTable;
|
||||
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_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_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_t progSectionSize;
|
||||
uint32_t progSectionAlloc;
|
||||
uint8_t *progSectionData;
|
||||
};
|
||||
typedef struct poffProgInfo_s poffProgInfo_t;
|
||||
|
||||
struct poffSymInfo_s
|
||||
{
|
||||
uint32_t symbolTableSize;
|
||||
uint32_t symbolTableAlloc;
|
||||
uint8_t *symbolTable;
|
||||
};
|
||||
typedef struct poffSymInfo_s poffSymInfo_t;
|
||||
|
||||
/***************************************************************************
|
||||
* Public Variables
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* Public Function Prototypes
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef CONFIG_POFF_SWAPNEEDED
|
||||
extern void poffSwapFileHeader(poffFileHeader_t *pFileHeader);
|
||||
extern void poffSwapSectionHeader(poffSectionHeader_t *pSectionHeader);
|
||||
extern void poffSwapSymbolTableData(poffInfo_t *poffInfo);
|
||||
extern void poffSwapRelocationData(poffInfo_t *poffInfo);
|
||||
extern void poffSwapFileTableData(poffInfo_t *poffInfo);
|
||||
extern void poffSwapLineNumberData(poffInfo_t *poffInfo);
|
||||
extern void poffSwapDebugData(poffInfo_t *poffInfo);
|
||||
#endif
|
||||
|
||||
#endif /* __PFPRIVATE_H */
|
||||
@@ -0,0 +1,127 @@
|
||||
/**********************************************************************
|
||||
* pfproghandle.c
|
||||
* POFF temporary progdata support
|
||||
*
|
||||
* 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
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Public Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
/* Set all global data structures to a known state */
|
||||
|
||||
poffProgHandle_t poffCreateProgHandle(void)
|
||||
{
|
||||
poffProgInfo_t *poffProgInfo;
|
||||
|
||||
/* Create a new POFF handle */
|
||||
|
||||
poffProgInfo = (poffProgInfo_t*)malloc(sizeof(poffProgInfo_t));
|
||||
if (poffProgInfo != NULL)
|
||||
{
|
||||
/* Set everthing to zero */
|
||||
|
||||
memset(poffProgInfo, 0, sizeof(poffProgInfo_t));
|
||||
}
|
||||
return poffProgInfo;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffDestroyProgHandle(poffProgHandle_t handle)
|
||||
{
|
||||
/* Free all of the allocated, in-memory data */
|
||||
|
||||
poffResetProgHandle(handle);
|
||||
|
||||
/* Free the container */
|
||||
|
||||
free(handle);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffResetProgHandle(poffProgHandle_t handle)
|
||||
{
|
||||
poffProgInfo_t *poffProgInfo = (poffProgInfo_t*)handle;
|
||||
|
||||
/* Free all of the allocated, in-memory data */
|
||||
|
||||
if (poffProgInfo->progSectionData)
|
||||
{
|
||||
free(poffProgInfo->progSectionData);
|
||||
}
|
||||
|
||||
/* Reset everything to the initial state */
|
||||
|
||||
poffProgInfo->progSectionData = NULL;
|
||||
poffProgInfo->progSectionSize = 0;
|
||||
poffProgInfo->progSectionAlloc = 0;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,131 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,361 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,94 @@
|
||||
/**********************************************************************
|
||||
* pfrelease.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 "keywords.h" /* Standard types */
|
||||
|
||||
#include "pfprivate.h" /* POFF private definitions */
|
||||
#include "pofflib.h" /* Public interfaces */
|
||||
|
||||
/**********************************************************************
|
||||
* Definitions
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Global Variables
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Private Variables
|
||||
**********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Private Function Prototypes
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Private Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Public Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffReleaseProgData(poffHandle_t handle)
|
||||
{
|
||||
poffInfo_t *poffInfo = (poffInfo_t*)handle;
|
||||
|
||||
/* Discard any existing program section data */
|
||||
|
||||
if (poffInfo->progSectionData)
|
||||
{
|
||||
free(poffInfo->progSectionData);
|
||||
poffInfo->progSectionData = NULL;
|
||||
}
|
||||
|
||||
/* Indicate that there is no program data */
|
||||
|
||||
poffInfo->progSection.sh_size = 0;
|
||||
poffInfo->progSectionAlloc = 0;
|
||||
poffInfo->progSectionIndex = 0;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,117 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,118 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,128 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,91 @@
|
||||
/**********************************************************************
|
||||
* pfrprog.c
|
||||
* Read 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
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
int poffGetProgByte(poffHandle_t handle)
|
||||
{
|
||||
poffInfo_t *poffInfo = (poffInfo_t*)handle;
|
||||
int retval = EOF;
|
||||
|
||||
/* Check if there is more data that has not yet been read */
|
||||
|
||||
if ((poffInfo->progSectionIndex < poffInfo->progSection.sh_size) &&
|
||||
(poffInfo->progSectionData != NULL))
|
||||
{
|
||||
retval = (int)poffInfo->progSectionData[poffInfo->progSectionIndex];
|
||||
poffInfo->progSectionIndex++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,111 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,108 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,116 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,91 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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>";
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,108 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,252 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,127 @@
|
||||
/**********************************************************************
|
||||
* pfsymhandle.c
|
||||
* POFF temporary symdata support
|
||||
*
|
||||
* 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
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Public Functions
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
/* Set all global data structures to a known state */
|
||||
|
||||
poffSymHandle_t poffCreateSymHandle(void)
|
||||
{
|
||||
poffSymInfo_t *poffSymInfo;
|
||||
|
||||
/* Create a new POFF handle */
|
||||
|
||||
poffSymInfo = (poffSymInfo_t*)malloc(sizeof(poffSymInfo_t));
|
||||
if (poffSymInfo != NULL)
|
||||
{
|
||||
/* Set everthing to zero */
|
||||
|
||||
memset(poffSymInfo, 0, sizeof(poffSymInfo_t));
|
||||
}
|
||||
return poffSymInfo;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffDestroySymHandle(poffSymHandle_t handle)
|
||||
{
|
||||
/* Free all of the allocated, in-memory data */
|
||||
|
||||
poffResetSymHandle(handle);
|
||||
|
||||
/* Free the container */
|
||||
|
||||
free(handle);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void poffResetSymHandle(poffSymHandle_t handle)
|
||||
{
|
||||
poffSymInfo_t *poffSymInfo = (poffSymInfo_t*)handle;
|
||||
|
||||
/* Free all of the allocated, in-memory data */
|
||||
|
||||
if (poffSymInfo->symbolTable)
|
||||
{
|
||||
free(poffSymInfo->symbolTable);
|
||||
}
|
||||
|
||||
/* Reset everything to the initial state */
|
||||
|
||||
poffSymInfo->symbolTable = NULL;
|
||||
poffSymInfo->symbolTableSize = 0;
|
||||
poffSymInfo->symbolTableAlloc = 0;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,225 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,189 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,174 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
*Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,146 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,116 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,165 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,128 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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++;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,162 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,541 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,193 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,218 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,152 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,96 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,95 @@
|
||||
/**********************************************************************
|
||||
* 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 */
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -0,0 +1,94 @@
|
||||
/**********************************************************************
|
||||
* 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"
|
||||
|
||||
/**********************************************************************
|
||||
* Pre-processor 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 */
|
||||
|
||||
/***********************************************************************/
|
||||
Reference in New Issue
Block a user