2 * rdf2bin.c - convert an RDOFF object file to flat binary
15 char *getfilename(char *pathname
)
17 char *lastslash
= pathname
- 1;
28 int main(int argc
, char **argv
)
34 int codepad
, datapad
, bsspad
= 0;
37 puts("Usage: rdf2bin [-o relocation-origin] [-p segment-alignment] " "input-file output-file");
38 puts(" rdf2com [-p segment-alignment] input-file output-file");
42 if (!nasm_stricmp(getfilename(*argv
), "rdf2com")) {
48 if (!strcmp(*argv
, "-o")) {
50 origin
= readnum(*argv
, &tmp
);
52 fprintf(stderr
, "rdf2bin: invalid parameter: %s\n", *argv
);
55 } else if (!strcmp(*argv
, "-p")) {
57 align
= readnum(*argv
, &tmp
);
59 fprintf(stderr
, "rdf2bin: invalid parameter: %s\n", *argv
);
62 } else if (!strcmp(*argv
, "-b")) {
64 bsspad
= readnum(*argv
, &tmp
);
66 fprintf(stderr
, "rdf2bin: invalid parameter: %s\n", *argv
);
75 puts("rdf2bin: required parameter missing");
81 rdfperror("rdf2bin", *argv
);
84 printf("relocating %s: origin=%lx, align=%d\n", *argv
, origin
, align
);
87 m
->datarel
= origin
+ m
->f
.seg
[0].length
;
88 if (m
->datarel
% align
!= 0) {
89 codepad
= align
- (m
->datarel
% align
);
90 m
->datarel
+= codepad
;
94 m
->bssrel
= m
->datarel
+ m
->f
.seg
[1].length
;
95 if (m
->bssrel
% align
!= 0) {
96 datapad
= align
- (m
->bssrel
% align
);
101 printf("code: %08lx\ndata: %08lx\nbss: %08lx\n",
102 m
->textrel
, m
->datarel
, m
->bssrel
);
108 of
= fopen(*argv
, "wb");
110 fprintf(stderr
, "rdf2bin: could not open output file %s\n", *argv
);
114 padding
= malloc(align
);
116 fprintf(stderr
, "rdf2bin: out of memory\n");
120 if (fwrite(m
->t
, 1, m
->f
.seg
[0].length
, of
) != m
->f
.seg
[0].length
||
121 fwrite(padding
, 1, codepad
, of
) != codepad
||
122 fwrite(m
->d
, 1, m
->f
.seg
[1].length
, of
) != m
->f
.seg
[1].length
) {
123 fprintf(stderr
, "rdf2bin: error writing to %s\n", *argv
);
128 void *p
= calloc(bsspad
-= (m
->bssrel
- origin
), 1);
129 fwrite(p
, 1, bsspad
, of
);