1 /* rdf2bin: convert an RDOFF object file to flat binary */
14 char *getfilename(char * pathname
)
16 char * lastslash
= pathname
- 1;
20 if (*i
== '/') lastslash
= i
;
26 int main(int argc
, char **argv
)
32 int codepad
, datapad
, bsspad
=0;
35 puts("Usage: rdf2bin [-o relocation-origin] [-p segment-alignment] "
36 "input-file output-file");
37 puts(" rdf2com [-p segment-alignment] input-file output-file");
41 if (! nasm_strnicmp(getfilename(*argv
),"rdf2com",7)) {
47 if (! strcmp(*argv
,"-o")) {
49 origin
= readnum(*argv
, &tmp
);
51 fprintf(stderr
,"rdf2bin: invalid parameter: %s\n",*argv
);
54 } else if (! strcmp(*argv
,"-p")) {
56 align
= readnum(*argv
, &tmp
);
58 fprintf(stderr
,"rdf2bin: invalid parameter: %s\n",*argv
);
61 } else if (! strcmp(*argv
,"-b")) {
63 bsspad
= readnum(*argv
, &tmp
);
65 fprintf(stderr
,"rdf2bin: invalid parameter: %s\n",*argv
);
74 puts("rdf2bin: required parameter missing");
80 rdfperror("rdf2bin",*argv
);
83 printf("relocating %s: origin=%lx, align=%d\n",*argv
,origin
,align
);
86 m
->datarel
= origin
+ m
->f
.seg
[0].length
;
87 if (m
->datarel
% align
!= 0) {
88 codepad
= align
- (m
->datarel
% align
);
89 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
);
102 printf("code: %08lx\ndata: %08lx\nbss: %08lx\n",
103 m
->textrel
, m
->datarel
, m
->bssrel
);
109 of
= fopen(*argv
,"wb");
111 fprintf(stderr
,"rdf2bin: could not open output file %s\n",*argv
);
115 padding
= malloc(align
);
117 fprintf(stderr
,"rdf2bin: out of memory\n");
121 if (fwrite(m
->t
,1,m
->f
.seg
[0].length
,of
) != m
->f
.seg
[0].length
||
122 fwrite(padding
,1,codepad
,of
) != codepad
||
123 fwrite(m
->d
,1,m
->f
.seg
[1].length
,of
) != 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
);