Initial NXFLAT debug fixes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1943 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2009-06-25 00:05:11 +00:00
parent ca79f124d4
commit fdecac3ce3
8 changed files with 101 additions and 43 deletions
+6 -2
View File
@@ -215,10 +215,12 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
hdr = (FAR struct nxflat_hdr_s*)loadinfo->ispace;
/* From this, we can get the list of relocation entries. */
/* From this, we can get the offset to the list of relocation entries */
offset = ntohl(hdr->h_relocstart);
nrelocs = ntohs(hdr->h_reloccount);
nrelocs = ntohl(hdr->h_reloccount);
/* The value of the relocation list that we get from the header is a
* file offset. We will have to convert this to an offset into the
@@ -226,7 +228,9 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
* list.
*/
DEBUGASSERT(offset >= loadinfo->isize && offset < (loadinfo->isize + loadinfo->dsize));
DEBUGASSERT(offset >= loadinfo->isize);
DEBUGASSERT(offset + nrelocs * sizeof(struct nxflat_reloc_s) <= (loadinfo->isize + loadinfo->dsize));
relocs = (FAR struct nxflat_reloc_s*)(offset - loadinfo->isize + loadinfo->dspace->region);
/* Now, traverse the relocation list of and bind each GOT relocation. */
+1 -1
View File
@@ -105,7 +105,7 @@ int nxflat_init(const char *filename, struct nxflat_hdr_s *header,
/* Read the NXFLAT header from offset 0 */
ret = nxflat_read(loadinfo, (char*)&header, sizeof(struct nxflat_hdr_s), 0);
ret = nxflat_read(loadinfo, (char*)header, sizeof(struct nxflat_hdr_s), 0);
if (ret < 0)
{
bdbg("Failed to read NXFLAT header: %d\n", ret);
+21 -25
View File
@@ -107,6 +107,8 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
{
off_t doffset; /* Offset to .data in the NXFLAT file */
uint32 dreadsize; /* Total number of bytes of .data to be read */
uint32 relocsize; /* Memory needed to hold relocations */
uint32 extrasize; /* MAX(BSS size, relocsize) */
int ret = OK;
/* Calculate the extra space we need to allocate. This extra space will be
@@ -114,40 +116,34 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
* temporarily to hold relocation information. So the allocated size of this
* region will either be the size of .data + size of.bss section OR, the
* size of .data + the relocation entries, whichever is larger
*
* This is the amount of memory that we have to have to hold the
* relocations.
*/
{
uint32 relocsize;
uint32 extrasize;
relocsize = loadinfo->reloccount * sizeof(struct nxflat_reloc_s);
/* This is the amount of memory that we have to have to hold the
* relocations.
*/
/* In the file, the relocations should lie at the same offset as BSS.
* The additional amount that we allocate have to be either (1) the
* BSS size, or (2) the size of the relocation records, whicher is
* larger.
*/
relocsize = loadinfo->reloccount * sizeof(uint32);
extrasize = MAX(loadinfo->bsssize, relocsize);
/* In the file, the relocations should lie at the same offset as BSS.
* The additional amount that we allocate have to be either (1) the
* BSS size, or (2) the size of the relocation records, whicher is
* larger.
*/
/* Use this additional amount to adjust the total size of the dspace
* region.
*/
extrasize = MAX(loadinfo->bsssize, relocsize);
loadinfo->dsize = loadinfo->datasize + extrasize;
/* Use this addtional amount to adjust the total size of the dspace
* region.
*/
/* The number of bytes of data that we have to read from the file is
* the data size plus the size of the relocation table.
*/
loadinfo->dsize = loadinfo->datasize + extrasize;
dreadsize = loadinfo->datasize + relocsize;
/* The number of bytes of data that we have to read from the file is
* the data size plus the size of the relocation table.
*/
dreadsize = loadinfo->datasize + relocsize;
}
/* We'll need this a few times as well. */
/* We'll need this a few times. */
doffset = loadinfo->isize;
+33
View File
@@ -53,6 +53,10 @@
* Pre-Processor Definitions
****************************************************************************/
#undef NXFLAT_DUMP_READDATA /* Define to dump all file data read */
#define DUMPER lib_rawprintf /* If NXFLAT_DUMP_READDATA is defined, this
* is the API used to dump data */
/****************************************************************************
* Private Constant Data
****************************************************************************/
@@ -61,6 +65,31 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxflat_dumpreaddata
****************************************************************************/
#if defined(NXFLAT_DUMP_READDATA)
static inline void nxflat_dumpreaddata(char *buffer, int buflen)
{
uint32 *buf32 = (uint32*)buffer;
int i;
int j;
for (i = 0; i < buflen; i += 32)
{
DUMPER("%04x:", i);
for (j = 0; j < 32; j += sizeof(uint32))
{
DUMPER(" %08x", *buf32++);
}
DUMPER("\n");
}
}
#else
# define nxflat_dumpreaddata(b,n)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -85,6 +114,8 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize,
int bytesleft; /* Number of bytes of .data left to read */
int bytesread; /* Total number of bytes read */
bvdbg("Read %d bytes from offset %d\n", readsize, offset);
/* Seek to the position in the object file where the initialized
* data is saved.
*/
@@ -126,6 +157,8 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize,
}
}
while (bytesread < readsize);
nxflat_dumpreaddata(buffer, readsize);
return OK;
}
+1 -1
View File
@@ -90,7 +90,7 @@ int nxflat_verifyheader(const struct nxflat_hdr_s *header)
if (strncmp(header->h_magic, NXFLAT_MAGIC, 4) != 0)
{
bdbg("Unrecognized magic=\"%c%c%c%c\"",
bdbg("Unrecognized magic=\"%c%c%c%c\"\n",
header->h_magic[0], header->h_magic[1],
header->h_magic[2], header->h_magic[3]);
return -ENOEXEC;