2 * rdf2bin.c - convert an RDOFF object file to flat binary
15 char *getfilename(char * pathname
)
17 char * lastslash
= pathname
- 1;
21 if (*i
== '/') lastslash
= i
;
27 int main(int argc
, char **argv
)
33 int codepad
, datapad
, bsspad
=0;
36 puts("Usage: rdf2bin [-o relocation-origin] [-p segment-alignment] "
37 "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
;
95 m
->bssrel
= m
->datarel
+ m
->f
.seg
[1].length
;
96 if (m
->bssrel
% align
!= 0) {
97 datapad
= align
- (m
->bssrel
% align
);
103 printf("code: %08lx\ndata: %08lx\nbss: %08lx\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
) != m
->f
.seg
[0].length
||
123 fwrite(padding
,1,codepad
,of
) != codepad
||
124 fwrite(m
->d
,1,m
->f
.seg
[1].length
,of
) != m
->f
.seg
[1].length
)
126 fprintf(stderr
,"rdf2bin: error writing to %s\n", *argv
);
131 void *p
= calloc(bsspad
-=(m
->bssrel
- origin
),1);
132 fwrite(p
,1,bsspad
,of
);