#include "copyright.h"#include <filehdr.h>#include <aouthdr.h>#include <scnhdr.h>#include <reloc.h>#include <syms.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <limits.h>#include <stdio.h>Go to the source code of this file.
Defines | |
| #define | MAIN |
| #define | StackSize 1024 |
| #define | ReadStruct(f, s) Read(f,(char *)&s,sizeof(s)) |
Functions | |
| char * | malloc () |
| void | Read (int fd, char *buf, int nBytes) |
| void | Write (int fd, char *buf, int nBytes) |
| main (int argc, char **argv) | |
|
|
Definition at line 15 of file coff2flat.c. |
|
|
Definition at line 32 of file coff2flat.c. Referenced by main. |
|
|
Definition at line 31 of file coff2flat.c. Referenced by main. |
|
||||||||||||
|
Definition at line 55 of file coff2flat.c. References close, exit, filehdr::f_magic, filehdr::f_nscns, lseek, aouthdr::magic, malloc, MIPSELMAGIC, OMAGIC, open, Read, ReadStruct, scnhdr::s_paddr, scnhdr::s_size, StackSize, and Write.
00056 {
00057 int fdIn, fdOut, numsections, i, top, tmp;
00058 struct filehdr fileh;
00059 struct aouthdr systemh;
00060 struct scnhdr *sections;
00061 char *buffer;
00062
00063 if (argc < 2) {
00064 fprintf(stderr, "Usage: %s <coffFileName> <flatFileName>\n", argv[0]);
00065 exit(1);
00066 }
00067
00068 /* open the object file (input) */
00069 fdIn = open(argv[1], O_RDONLY, 0);
00070 if (fdIn == -1) {
00071 perror(argv[1]);
00072 exit(1);
00073 }
00074
00075 /* open the flat file (output) */
00076 fdOut = open(argv[2], O_RDWR|O_CREAT|O_TRUNC, 0666);
00077 if (fdIn == -1) {
00078 perror(argv[2]);
00079 exit(1);
00080 }
00081
00082 /* Read in the file header and check the magic number. */
00083 ReadStruct(fdIn,fileh);
00084 if (fileh.f_magic != MIPSELMAGIC) {
00085 fprintf(stderr, "File is not a MIPSEL COFF file\n");
00086 exit(1);
00087 }
00088
00089 /* Read in the system header and check the magic number */
00090 ReadStruct(fdIn,systemh);
00091 if (systemh.magic != OMAGIC) {
00092 fprintf(stderr, "File is not a OMAGIC file\n");
00093 exit(1);
00094 }
00095
00096 /* Read in the section headers. */
00097 numsections = fileh.f_nscns;
00098 sections = (struct scnhdr *)malloc(fileh.f_nscns * sizeof(struct scnhdr));
00099 Read(fdIn, (char *) sections, fileh.f_nscns * sizeof(struct scnhdr));
00100
00101 /* Copy the segments in */
00102 printf("Loading %d sections:\n", fileh.f_nscns);
00103 for (top = 0, i = 0; i < fileh.f_nscns; i++) {
00104 printf("\t\"%s\", filepos 0x%x, mempos 0x%x, size 0x%x\n",
00105 sections[i].s_name, sections[i].s_scnptr,
00106 sections[i].s_paddr, sections[i].s_size);
00107 if ((sections[i].s_paddr + sections[i].s_size) > top)
00108 top = sections[i].s_paddr + sections[i].s_size;
00109 if (strcmp(sections[i].s_name, ".bss") && /* no need to copy if .bss */
00110 strcmp(sections[i].s_name, ".sbss")) {
00111 lseek(fdIn, sections[i].s_scnptr, 0);
00112 buffer = malloc(sections[i].s_size);
00113 Read(fdIn, buffer, sections[i].s_size);
00114 Write(fdOut, buffer, sections[i].s_size);
00115 free(buffer);
00116 }
00117 }
00118 /* put a blank word at the end, so we know where the end is! */
00119 printf("Adding stack of size: %d\n", StackSize);
00120 lseek(fdOut, top + StackSize - 4, 0);
00121 tmp = 0;
00122 Write(fdOut, (char *)&tmp, 4);
00123
00124 close(fdIn);
00125 close(fdOut);
00126 }
|
|
|
Referenced by main. |
|
||||||||||||||||
|
Definition at line 37 of file coff2flat.c.
|
|
||||||||||||||||
|
Definition at line 46 of file coff2flat.c.
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002