-
Notifications
You must be signed in to change notification settings - Fork 9
/
t_rawbin.c
1742 lines (1569 loc) · 38.3 KB
/
t_rawbin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $VER: vlink t_rawbin.c V0.16i (31.01.22)
*
* This file is part of vlink, a portable linker for multiple
* object formats.
* Copyright (c) 1997-2022 Frank Wille
*/
#include "config.h"
#if defined(RAWBIN1) || defined(RAWBIN2) || \
defined(SREC19) || defined(SREC28) || defined(SREC37) || \
defined(IHEX) || defined(SHEX1) || \
defined(AMSDOS) || defined(APPLEBIN) || defined(ATARICOM) || \
defined(BBC) || defined(CBMPRG) || defined(COCOML) || \
defined(DRAGONBIN) || defined(JAGSRV) || defined(ORICMC) || \
defined(SINCQL)
#define T_RAWBIN_C
#include "vlink.h"
#define MAXGAP 16 /* from MAXGAP bytes on, a new file will be created */
#define MAXSREC 32 /* max. number of bytes in an S1/S2/S3 record */
#define MAXIREC 32 /* max. number of bytes in an ihex record (actually 255) */
#define QDOSHDR_SIZE 30 /* SinclairQL QDOS header */
/* header types */
enum {
HDR_NONE,
HDR_AMSDOS,
HDR_APPLEBIN,
HDR_ATARICOM,
HDR_BBC,
HDR_CBMPRG,
HDR_COCOML,
HDR_DRAGONBIN,
HDR_JAGSRV,
HDR_ORICMC,
HDR_QDOS,
HDR_XTCC
};
/* binary relocs (-q) */
struct BinReloc {
struct BinReloc *next;
lword offset;
};
static unsigned long rawbin_headersize(struct GlobalVars *);
static int rawbin_identify(struct GlobalVars *,char *,uint8_t *,
unsigned long,bool);
static void rawbin_readconv(struct GlobalVars *,struct LinkFile *);
static int rawbin_targetlink(struct GlobalVars *,struct LinkedSection *,
struct Section *);
static void rawbin_writeobject(struct GlobalVars *,FILE *);
static void rawbin_writeshared(struct GlobalVars *,FILE *);
static void rawbin_writeexec(struct GlobalVars *,FILE *,bool,int);
#ifdef RAWBIN1
static void rawbin_writesingle(struct GlobalVars *,FILE *);
#endif
#ifdef RAWBIN2
static void rawbin_writemultiple(struct GlobalVars *,FILE *);
#endif
#ifdef AMSDOS
static unsigned long amsdos_headersize(struct GlobalVars *);
static void amsdos_write(struct GlobalVars *,FILE *);
#endif
#ifdef APPLEBIN
static unsigned long applebin_headersize(struct GlobalVars *);
static void applebin_write(struct GlobalVars *,FILE *);
#endif
#ifdef ATARICOM
static unsigned long ataricom_headersize(struct GlobalVars *);
static void ataricom_write(struct GlobalVars *,FILE *);
#endif
#ifdef BBC
static void bbc_write(struct GlobalVars *,FILE *);
static void bbc_write2(struct GlobalVars *,FILE *);
#endif
#ifdef CBMPRG
static unsigned long cbmprg_headersize(struct GlobalVars *);
static void cbmprg_write(struct GlobalVars *,FILE *);
static void cbmreu_write(struct GlobalVars *,FILE *);
static FILE *bbcload;
#endif
#ifdef COCOML
static unsigned long cocoml_headersize(struct GlobalVars *);
static void cocoml_write(struct GlobalVars *,FILE *);
#endif
#ifdef DRAGONBIN
static unsigned long dragonbin_headersize(struct GlobalVars *);
static void dragonbin_write(struct GlobalVars *,FILE *);
#endif
#ifdef JAGSRV
#define TOSHDR_SIZE 28
#define JAGR_SIZE 18
static unsigned long jagsrv_headersize(struct GlobalVars *);
static void jagsrv_write(struct GlobalVars *,FILE *);
#endif
#ifdef ORICMC
static int oric_options(struct GlobalVars *,int,const char **,int *);
static unsigned long oric_headersize(struct GlobalVars *);
static void oric_write(struct GlobalVars *,FILE *);
#endif
#ifdef SINCQL
static int sincql_options(struct GlobalVars *,int,const char **,int *);
static unsigned long sincql_headersize(struct GlobalVars *);
static void sincql_write(struct GlobalVars *,FILE *);
#endif
#ifdef SREC19
static void srec19_write(struct GlobalVars *,FILE *);
#endif
#ifdef SREC28
static void srec28_write(struct GlobalVars *,FILE *);
#endif
#ifdef SREC37
static void srec37_write(struct GlobalVars *,FILE *);
#endif
#ifdef IHEX
static void ihex_write(struct GlobalVars *,FILE *);
#endif
#ifdef SHEX1
static void shex1_write(struct GlobalVars *,FILE *);
#endif
static lword execaddr;
static FILE *hdrfile;
static long hdroffs;
static lword relocsize;
static struct LinkedSection *hdrsect;
static int autoexec; /* used by oricmc */
static lword stacksize; /* used by sinclairql */
static lword udatasize; /* used by sinclairql */
static const char defaultscript[] =
"SECTIONS {\n"
" .text: { *(.text CODE text) *(seg*) *(.rodata*) }\n"
" .data: { *(.data DATA data) PROVIDE(__edata=.); }\n"
" .bss: { *(.bss BSS bss) *(COMMON) PROVIDE(__end=.); }\n"
" .comment 0 : { *(.comment) }\n"
" PROVIDE(__bsslen=SIZEOF(.bss));\n"
"}\n";
#ifdef RAWBIN1
struct FFFuncs fff_rawbin1 = {
"rawbin1",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
rawbin_writesingle,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
-1, /* endianness undefined, only write */
0, /* addr_bits from input */
0, /* ptr-alignment unknown */
FFF_SECTOUT|FFF_KEEPRELOCS
};
#endif
#ifdef RAWBIN2
struct FFFuncs fff_rawbin2 = {
"rawbin2",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
rawbin_writemultiple,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
-1, /* endianness undefined, only write */
0, /* addr_bits from input */
0, /* ptr-alignment unknown */
FFF_SECTOUT|FFF_KEEPRELOCS
};
#endif
#ifdef AMSDOS
static const char amsdosscript[] =
"MEMORY {\n"
" m: org=., len=0x10000-.\n"
" b1: org=0x4000, len=0x4000\n"
" b2: org=0x4000, len=0x4000\n"
" b3: org=0x4000, len=0x4000\n"
" b4: org=0x4000, len=0x4000\n"
"}\n"
"SECTIONS {\n"
" bin: { *(.text) *(.rodata*) *(.data*) *(.bss) *(COMMON) } > m\n"
" c4 : { *(.c4) } > b1 AT> m\n"
" c5 : { *(.c5) } > b2 AT> m\n"
" c6 : { *(.c6) } > b3 AT> m\n"
" c7 : { *(.c7) } > b4 AT> m\n"
"}\n";
struct FFFuncs fff_amsdos = {
"amsdos",
amsdosscript,
NULL,
NULL,
NULL,
amsdos_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
amsdos_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_LITTLE_ENDIAN_,
16,0,
FFF_SECTOUT
};
#endif
#ifdef APPLEBIN
struct FFFuncs fff_applebin = {
"applebin",
defaultscript,
NULL,
NULL,
NULL,
applebin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
applebin_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_LITTLE_ENDIAN_,
16,0,
FFF_SECTOUT
};
#endif
#ifdef ATARICOM
struct FFFuncs fff_ataricom = {
"ataricom",
defaultscript,
NULL,
NULL,
NULL,
ataricom_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
ataricom_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_LITTLE_ENDIAN_,
16,0,
FFF_SECTOUT
};
#endif
#ifdef BBC
struct FFFuncs fff_bbc = {
"bbc",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
bbc_write,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
_LITTLE_ENDIAN_,
16,0,
FFF_SECTOUT
};
struct FFFuncs fff_bbc2 = {
"bbc2",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
bbc_write2,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
_LITTLE_ENDIAN_,
16,0,
FFF_SECTOUT
};
#endif
#ifdef CBMPRG
struct FFFuncs fff_cbmprg = {
"cbmprg",
defaultscript,
NULL,
NULL,
NULL,
cbmprg_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
cbmprg_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_LITTLE_ENDIAN_,
16,0,
FFF_SECTOUT
};
struct FFFuncs fff_cbmreu = {
"cbmreu",
defaultscript,
NULL,
NULL,
NULL,
cbmprg_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
cbmreu_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_LITTLE_ENDIAN_,
16,0,
FFF_SECTOUT
};
#endif
#ifdef COCOML
struct FFFuncs fff_cocoml = {
"cocoml",
defaultscript,
NULL,
NULL,
NULL,
cocoml_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
cocoml_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_BIG_ENDIAN_,
16,0,
FFF_SECTOUT
};
#endif
#ifdef DRAGONBIN
struct FFFuncs fff_dragonbin = {
"dragonbin",
defaultscript,
NULL,
NULL,
NULL,
dragonbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
dragonbin_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_BIG_ENDIAN_,
16,0,
FFF_SECTOUT
};
#endif
#ifdef JAGSRV
static const char jaguarscript[] =
"SECTIONS {\n"
" . = 0x4000;\n"
" .text: {\n"
" *(.text CODE text)\n"
" }\n"
" . = ALIGN(32);\n"
" .data: {\n"
" VBCC_CONSTRUCTORS\n"
" *(.data DATA data)\n"
" }\n"
" . = ALIGN(32);\n"
" .bss: {\n"
" *(.bss BSS bss)\n"
" *(COMMON)\n"
" _BSS_END = ALIGN(32);\n"
" }\n"
"}\n";
struct FFFuncs fff_jagsrv = {
"jagsrv",
jaguarscript,
NULL,
NULL,
NULL,
jagsrv_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
jagsrv_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_BIG_ENDIAN_,
32,1,
0
};
#endif
#ifdef ORICMC
struct FFFuncs fff_oricmc = {
"oricmc",
defaultscript,
NULL,
NULL,
oric_options,
oric_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
oric_write,
NULL,NULL,
0,
0,
0,
0,
RTAB_UNDEF,0,
_LITTLE_ENDIAN_,
16,0,
FFF_SECTOUT
};
#endif
#ifdef SINCQL
struct FFFuncs fff_sincql = {
"sinclairql",
defaultscript,
NULL,
NULL,
sincql_options,
sincql_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
sincql_write,
NULL,NULL,
0,
0x7ffe,
0,
0,
RTAB_STANDARD,RTAB_STANDARD,
_BIG_ENDIAN_,
32,1,
FFF_BASEINCR|FFF_KEEPRELOCS
};
#endif
#ifdef SREC19
struct FFFuncs fff_srec19 = {
"srec19",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
srec19_write,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
-1, /* endianness undefined, only write */
16,
0, /* ptr-alignment unknown */
FFF_NOFILE
};
#endif
#ifdef SREC28
struct FFFuncs fff_srec28 = {
"srec28",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
srec28_write,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
-1, /* endianness undefined, only write */
32, /* 24 */
0, /* ptr-alignment unknown */
FFF_NOFILE
};
#endif
#ifdef SREC37
struct FFFuncs fff_srec37 = {
"srec37",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
srec37_write,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
-1, /* endianness undefined, only write */
32,
0, /* ptr-alignment unknown */
FFF_NOFILE
};
#endif
#ifdef IHEX
struct FFFuncs fff_ihex = {
"ihex",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
ihex_write,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
-1, /* endianness undefined, only write */
0, /* addr_bits from input */
0, /* ptr-alignment unknown */
FFF_NOFILE
};
#endif
#ifdef SHEX1
struct FFFuncs fff_shex1 = {
"oilhex",
defaultscript,
NULL,
NULL,
NULL,
rawbin_headersize,
rawbin_identify,
rawbin_readconv,
NULL,
rawbin_targetlink,
NULL,
NULL,
NULL,
NULL,NULL,NULL,
rawbin_writeobject,
rawbin_writeshared,
shex1_write,
NULL,NULL,
0,
0x8000,
0,
0,
RTAB_UNDEF,0,
-1, /* endianness undefined, only write */
32,
0, /* ptr-alignment unknown */
FFF_NOFILE
};
#endif
#ifdef ORICMC
static int oric_options(struct GlobalVars *gv,
int argc,const char **argv,int *i)
{
if (!strcmp(argv[*i],"-autox"))
autoexec = 1;
else
return 0;
return 1;
}
#endif
#ifdef SINCQL
static int sincqlhdr = HDR_QDOS;
static int sincql_options(struct GlobalVars *gv,
int argc,const char **argv,int *i)
{
long long val;
if (!strcmp(argv[*i],"-qhdr"))
sincqlhdr = HDR_QDOS;
else if (!strcmp(argv[*i],"-xtcc"))
sincqlhdr = HDR_XTCC;
else if (!strncmp(argv[*i],"-stack=",7)) {
if (sscanf(&argv[*i][7],"%lli",&val) == 1)
stacksize = val;
}
else
return 0;
return 1;
}
#endif
static unsigned long rawbin_headersize(struct GlobalVars *gv)
{
return 0; /* no header - it's pure binary! */
}
#ifdef AMSDOS
static unsigned long amsdos_headersize(struct GlobalVars *gv)
{
return 128;
}
#endif
#ifdef APPLEBIN
static unsigned long applebin_headersize(struct GlobalVars *gv)
{
return 4;
}
#endif
#ifdef ATARICOM
static unsigned long ataricom_headersize(struct GlobalVars *gv)
{
return 2; /* followed by 4 bytes segment header */
}
#endif
#ifdef CBMPRG
static unsigned long cbmprg_headersize(struct GlobalVars *gv)
{
return 2;
}
#endif
#ifdef COCOML
static unsigned long cocoml_headersize(struct GlobalVars *gv)
{
return 0;
}
#endif
#ifdef DRAGONBIN
static unsigned long dragonbin_headersize(struct GlobalVars *gv)
{
return 9;
}
#endif
#ifdef ORICMC
static unsigned long oric_headersize(struct GlobalVars *gv)
{
return 14+strlen(gv->dest_name)+1;
}
#endif
#ifdef JAGSRV
static unsigned long jagsrv_headersize(struct GlobalVars *gv)
{
return TOSHDR_SIZE+JAGR_SIZE; /* uses TOS-executable header */
}
#endif
#ifdef SINCQL
static unsigned long sincql_headersize(struct GlobalVars *gv)
{
if (sincqlhdr == HDR_QDOS)
return QDOSHDR_SIZE;
return 0;
}
#endif
/*****************************************************************/
/* Read Binary */
/*****************************************************************/
static int rawbin_identify(struct GlobalVars *gv,char *name,uint8_t *p,
unsigned long plen,bool lib)
/* identify a binary file */
{
return ID_UNKNOWN; /* binaries are only allowed to be written! */
}
static void rawbin_readconv(struct GlobalVars *gv,struct LinkFile *lf)
{
ierror("rawbin_readconv(): Can't read raw-binaries");
}
static int rawbin_targetlink(struct GlobalVars *gv,struct LinkedSection *ls,
struct Section *s)
/* returns 1, if target requires the combination of the two sections, */
/* returns -1, if target doesn't want to combine them, */
/* returns 0, if target doesn't care - standard linking rules are used. */
{
ierror("rawbin_targetlink(): Impossible to link raw-binaries");
return 0;
}
/*****************************************************************/
/* Write Binary */
/*****************************************************************/
static FILE *open_ascfile(struct GlobalVars *gv)
{
FILE *f;
if ((f = fopen(gv->dest_name,"w")) == NULL) {
error(29,gv->dest_name); /* Can't create output file */
return NULL;
}
untrim_sections(gv); /* always output trailing 0-bytes in ASCII hex-files */
return f;
}
static void savehdroffs(struct GlobalVars *gv,FILE *f,
size_t bytes,struct LinkedSection *ls)
{
/* remember location in file header and skip it */
hdrsect = ls;
hdrfile = f;
hdroffs = ftell(f);
fwritegap(gv,f,bytes);
}
static int rewindtohdr(FILE *f)
{
if (hdrfile == f) {
fseek(f,hdroffs,SEEK_SET);
return 1;
}
return 0;
}
static void even_padding(FILE *f)
{
if (ftell(f) & 1)
fwrite8(f,0); /* make file size even */
}
#ifdef AMSDOS
static void amsdos_header(FILE *f,uint16_t loadaddr,unsigned size)
{
uint8_t buffer[128];
uint16_t checksum;
int i;
memset(buffer,0,128); /* initialize header with zeros */
memset(&buffer[1],' ',11); /* 1 > 11: spaces */
buffer[18] = 2; /* 18 : filetype = 2 - binary */
write16le(&buffer[19],size); /* 19 > 20: data length */
write16le(&buffer[21],loadaddr); /* 21 > 22: load address */
buffer[23] = 0xff; /* 23 : 0xFF */
write16le(&buffer[24],size); /* 24 > 25: logical length */
write16le(&buffer[26],execaddr); /* 26 > 27: entry point */
write32le(&buffer[64],size); /* 64 > 66: filesize (3 bytes) */
for (checksum=0,i=0; i<67; i++)
checksum += buffer[i];
write16le(&buffer[67],checksum); /* 67 > 68: checksum */
fwritex(f,buffer,128);
}
#endif
#ifdef JAGSRV
static void jagsrv_header(FILE *f,uint32_t loadaddr,unsigned size)
{
uint8_t header[TOSHDR_SIZE+JAGR_SIZE];
memset(header,0,TOSHDR_SIZE+JAGR_SIZE);
write16be(&header[0],0x601a);
write32be(&header[2],size+JAGR_SIZE);
memcpy(&header[TOSHDR_SIZE+0],"JAGR",4);
write16be(&header[TOSHDR_SIZE+4],3); /* command 3: Load & Run */
write32be(&header[TOSHDR_SIZE+6],loadaddr);
write32be(&header[TOSHDR_SIZE+10],size);
write32be(&header[TOSHDR_SIZE+14],execaddr);
fwritex(f,header,TOSHDR_SIZE+JAGR_SIZE);
}
#endif
static int rawbin_segheader(struct GlobalVars *gv,FILE *f,
struct LinkedSection *ls,int header)
{
/* write a segment/section header, when needed */