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
)
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_stricmp(getfilename(*argv
),"rdf2com")) {
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
);
67 puts("rdf2bin: required parameter missing");
74 rdfperror("rdf2bin",*argv
);
77 printf("relocating %s: origin=%lx, align=%d\n",*argv
,origin
,align
);
80 m
->datarel
= origin
+ m
->f
.code_len
;
81 if (m
->datarel
% align
!= 0) {
82 codepad
= align
- (m
->datarel
% align
);
83 m
->datarel
+= codepad
;
88 m
->bssrel
= m
->datarel
+ m
->f
.data_len
;
89 if (m
->bssrel
% align
!= 0) {
90 datapad
= align
- (m
->bssrel
% align
);
96 printf("code: %08lx\ndata: %08lx\nbss: %08lx\n",
97 m
->textrel
, m
->datarel
, m
->bssrel
);
103 of
= fopen(*argv
,"wb");
105 fprintf(stderr
,"rdf2bin: could not open output file %s\n",*argv
);
109 padding
= malloc(align
);
111 fprintf(stderr
,"rdf2bin: out of memory\n");
115 if (fwrite(m
->t
,1,m
->f
.code_len
,of
) != m
->f
.code_len
||
116 fwrite(padding
,1,codepad
,of
) != codepad
||
117 fwrite(m
->d
,1,m
->f
.data_len
,of
) != m
->f
.data_len
)
119 fprintf(stderr
,"rdf2bin: error writing to %s\n", *argv
);