Skip to content

Commit 543bfe7

Browse files
committed
Fix COFF export format
1 parent 32a331c commit 543bfe7

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

jiffi2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Supported formats of the Atari Jaguar.
1313

1414
Version 1.0.3 - 08-20-2024
1515
- Fix potential crash with a VMA & LMA different address in the binary ELF
16+
- Fix COFF export format
1617

1718
Version 1.0.2 - 06-23-2024
1819
- Added a Visual Studio 2022 project

src/coff.cpp

+35-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "time.h"
44

55

6-
#define COFF_F (COFF_F_RELFLG | COFF_F_EXEC)
6+
#define COFF_F (COFF_F_RELFLG | /* COFF_F_LNNO | COFF_F_LSYMS | */ COFF_F_EXEC)
77

88
typedef struct coffh
99
{
@@ -15,17 +15,42 @@ coffh;
1515

1616
coffh TabCoffHdr = {
1717
{
18+
// magic number
1819
0x1, 0x50,
20+
// number of sections
1921
0x0, 0x03,
22+
// time & date stamp
2023
0x0, 0x0, 0x0, 0x0,
24+
// file pointer to symtab
2125
0x0, 0x0, 0x0, 0x0,
26+
// number of symtab entries
2227
0x0, 0x0, 0x0, 0x0,
28+
// sizeof (optional hdr)
2329
((COFF_AOUTSZ & 0xff00) >> 8), (COFF_AOUTSZ & 0xff),
30+
// flags
2431
((COFF_F & 0xff00) >> 8), (COFF_F & 0xff)
2532
},
2633
{
27-
((COFF_ZMAGIC & 0xff00) >> 8), (COFF_ZMAGIC & 0xff), // magic number
28-
0x1, 0x07, // version stamp
34+
// magic number / type of file
35+
#if 0
36+
((COFF_ZMAGIC & 0xff00) >> 8), (COFF_ZMAGIC & 0xff),
37+
#else
38+
0x0, 0x0,
39+
#endif
40+
// version stamp
41+
0x1, 0x07,
42+
// text size in bytes
43+
0x0, 0x0, 0x0, 0x0,
44+
// data size in bytes
45+
0x0, 0x0, 0x0, 0x0,
46+
// bss size in bytes
47+
0x0, 0x0, 0x0, 0x0,
48+
// entry pt.
49+
0x0, 0x0, 0x0, 0x0,
50+
//
51+
0x0, 0x0, 0x0, 0x0,
52+
//
53+
0x0, 0x0, 0x0, 0x0
2954
},
3055
{
3156
// .text
@@ -91,14 +116,21 @@ int create_coff(void)
91116
// create the coff file
92117
if (!fopen_s(&file2, buffer, "wb") && file2)
93118
{
119+
#if 0
94120
// set time creation
95121
time_t TimeStamp, Time;
96122
Time = time(&TimeStamp);
97123
*(uint32_t*)TabCoffHdr.fhdr.f_timdat = !endianess ? SWAP32(Time) : Time;
124+
#endif
98125
// header initialisations
99126
*(uint32_t*)TabCoffHdr.ahdr.tsize = !endianess ? SWAP32(linj) : linj;
100127
*(uint32_t*)TabCoffHdr.ahdr.text_start = !endianess ? SWAP32(runadr) : runadr;
101128
*(uint32_t*)TabCoffHdr.ahdr.entry = !endianess ? SWAP32(loadadr) : loadadr;
129+
// text header initialisations
130+
*(uint32_t*)TabCoffHdr.shdr[0].s_paddr = !endianess ? SWAP32(loadadr) : loadadr;
131+
*(uint32_t*)TabCoffHdr.shdr[0].s_vaddr = !endianess ? SWAP32(loadadr) : loadadr;
132+
*(uint32_t*)TabCoffHdr.shdr[0].s_size = !endianess ? SWAP32(linj) : linj;
133+
*(uint32_t*)TabCoffHdr.shdr[0].s_scnptr = !endianess ? SWAP32(sizeof(TabCoffHdr)) : sizeof(TabCoffHdr);
102134
// write file and "optional" headers
103135
fwrite(&TabCoffHdr, sizeof(TabCoffHdr), 1, file2);
104136
// Dump the file

0 commit comments

Comments
 (0)