diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-02-06 15:24:18 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-02-06 15:24:18 +0000 |
commit | bb5ede8152f14cc757ff4ee6f44ff3128c3ff144 (patch) | |
tree | db2726eb2b79bde890812a8227dae075f8ca2a3b /misc/pascal/libpoff/pfwrite.c | |
parent | a26dad80f4d004a4a0f6effedc803b3902389b39 (diff) | |
download | nuttx-bb5ede8152f14cc757ff4ee6f44ff3128c3ff144.tar.gz nuttx-bb5ede8152f14cc757ff4ee6f44ff3128c3ff144.tar.bz2 nuttx-bb5ede8152f14cc757ff4ee6f44ff3128c3ff144.zip |
Standardize to big-endian binary
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@637 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'misc/pascal/libpoff/pfwrite.c')
-rw-r--r-- | misc/pascal/libpoff/pfwrite.c | 115 |
1 files changed, 89 insertions, 26 deletions
diff --git a/misc/pascal/libpoff/pfwrite.c b/misc/pascal/libpoff/pfwrite.c index 75eac9497..c655dba71 100644 --- a/misc/pascal/libpoff/pfwrite.c +++ b/misc/pascal/libpoff/pfwrite.c @@ -1,5 +1,5 @@ /**********************************************************************
- * pfwrite.c
+ * libpoff/pfwrite.c
* Write a POFF file
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
@@ -116,6 +116,10 @@ static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile) 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),
@@ -125,6 +129,30 @@ static void poffWriteFileHeader(poffHandle_t handle, FILE *poffFile) 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;
}
/***********************************************************************/
@@ -153,9 +181,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) /* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->progSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->progSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write program section header: %s\n",
@@ -176,9 +202,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) /* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->roDataSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->roDataSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write data section header: %s\n",
@@ -199,9 +223,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) /* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->symbolTableSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->symbolTableSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write symbol table section header: %s\n",
@@ -222,9 +244,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) /* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->relocSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->relocSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write relocation section header: %s\n",
@@ -245,9 +265,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) /* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->fileNameTableSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->fileNameTableSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write file table section header: %s\n",
@@ -268,9 +286,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) /* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->lineNumberSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->lineNumberSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write line number section header: %s\n",
@@ -291,9 +307,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) /* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->debugFuncSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->debugFuncSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write debug section header: %s\n",
@@ -314,9 +328,7 @@ static void poffWriteSectionHeaders(poffHandle_t handle, FILE *poffFile) /* Then write the section header to the output file */
- entriesWritten = fwrite(&poffInfo->stringTableSection,
- sizeof(poffSectionHeader_t),
- 1, poffFile);
+ entriesWritten = poffWriteSectionHeader(&poffInfo->stringTableSection, poffFile);
if (entriesWritten != 1)
{
errmsg("Failed to write string table section header: %s\n",
@@ -370,6 +382,12 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) {
if (!poffInfo->symbolTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapSymbolTableData(poffInfo);
+
+ /* Write the symbol table entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->symbolTable, sizeof(ubyte),
poffInfo->symbolTableSection.sh_size, poffFile);
if (entriesWritten != poffInfo->symbolTableSection.sh_size)
@@ -378,6 +396,11 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host data order */
+
+ poffSwapSymbolTableData(poffInfo);
+
}
/* Write the relocation table section data (if we have one) */
@@ -386,6 +409,12 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) {
if (!poffInfo->relocTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapRelocationData(poffInfo);
+
+ /* Write the relocation table entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->relocTable, sizeof(ubyte),
poffInfo->relocSection.sh_size, poffFile);
if (entriesWritten != poffInfo->relocSection.sh_size)
@@ -394,6 +423,10 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host data order */
+
+ poffSwapRelocationData(poffInfo);
}
/* Write the file table section data (if we have one) */
@@ -402,6 +435,12 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) {
if (!poffInfo->fileNameTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapFileTableData(poffInfo);
+
+ /* Write the file table entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->fileNameTable, sizeof(ubyte),
poffInfo->fileNameTableSection.sh_size,
poffFile);
@@ -411,6 +450,10 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host data order */
+
+ poffSwapFileTableData(poffInfo);
}
/* Write the line number section data (if we have one) */
@@ -419,6 +462,12 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) {
if (!poffInfo->lineNumberTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapLineNumberData(poffInfo);
+
+ /* Write the line number table entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->lineNumberTable, sizeof(ubyte),
poffInfo->lineNumberSection.sh_size,
poffFile);
@@ -428,14 +477,24 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host order */
+
+ poffSwapLineNumberData(poffInfo);
}
- /* Write the line number section data (if we have one) */
+ /* Write the debug section data (if we have one) */
if (HAVE_DEBUG_SECTION)
{
if (!poffInfo->debugFuncTable) fatal(ePOFFCONFUSION);
+ /* The POFF file is retained in big-endian order. Fixup fields as necessary */
+
+ poffSwapDebugData(poffInfo);
+
+ /* Write the debug entries in big-endian order */
+
entriesWritten = fwrite(poffInfo->debugFuncTable, sizeof(ubyte),
poffInfo->debugFuncSection.sh_size,
poffFile);
@@ -445,6 +504,10 @@ static void poffWriteSectionData(poffHandle_t handle, FILE *poffFile) strerror(errno));
fatal(ePOFFWRITEERROR);
}
+
+ /* Restore host order */
+
+ poffSwapDebugData(poffInfo);
}
/* Write the string table section data LAST (because we may have
|