2 * rdf2bin.c - convert an RDOFF object file to flat binary
17 char *getfilename(char *pathname
)
19 char *lastslash
= pathname
- 1;
30 int main(int argc
, char **argv
)
36 int codepad
, datapad
, bsspad
= 0;
39 puts("Usage: rdf2bin [-o relocation-origin] [-p segment-alignment] " "input-file output-file");
40 puts(" rdf2com [-p segment-alignment] input-file output-file");
44 if (!nasm_stricmp(getfilename(*argv
), "rdf2com")) {
50 if (!strcmp(*argv
, "-o")) {
52 origin
= readnum(*argv
, &err
);
54 fprintf(stderr
, "rdf2bin: invalid parameter: %s\n", *argv
);
57 } else if (!strcmp(*argv
, "-p")) {
59 align
= readnum(*argv
, &err
);
61 fprintf(stderr
, "rdf2bin: invalid parameter: %s\n", *argv
);
64 } else if (!strcmp(*argv
, "-b")) {
66 bsspad
= readnum(*argv
, &err
);
68 fprintf(stderr
, "rdf2bin: invalid parameter: %s\n", *argv
);
77 puts("rdf2bin: required parameter missing");
83 rdfperror("rdf2bin", *argv
);
86 printf("relocating %s: origin=%"PRIx32
", align=%d\n", *argv
, origin
, align
);
89 m
->datarel
= origin
+ m
->f
.seg
[0].length
;
90 if (m
->datarel
% align
!= 0) {
91 codepad
= align
- (m
->datarel
% align
);
92 m
->datarel
+= codepad
;
96 m
->bssrel
= m
->datarel
+ m
->f
.seg
[1].length
;
97 if (m
->bssrel
% align
!= 0) {
98 datapad
= align
- (m
->bssrel
% align
);
103 printf("code: %08"PRIx32
"\ndata: %08"PRIx32
"\nbss: %08"PRIx32
"\n",
104 m
->textrel
, m
->datarel
, m
->bssrel
);
110 of
= fopen(*argv
, "wb");
112 fprintf(stderr
, "rdf2bin: could not open output file %s\n", *argv
);
116 padding
= malloc(align
);
118 fprintf(stderr
, "rdf2bin: out of memory\n");
122 if (fwrite(m
->t
, 1, m
->f
.seg
[0].length
, of
) != (size_t)m
->f
.seg
[0].length
||
123 fwrite(padding
, 1, codepad
, of
) != (size_t)codepad
||
124 fwrite(m
->d
, 1, m
->f
.seg
[1].length
, of
) != (size_t)m
->f
.seg
[1].length
) {
125 fprintf(stderr
, "rdf2bin: error writing to %s\n", *argv
);
130 void *p
= calloc(bsspad
-= (m
->bssrel
- origin
), 1);
131 fwrite(p
, 1, bsspad
, of
);