Skip to content

Commit

Permalink
Fix COFF export format
Browse files Browse the repository at this point in the history
  • Loading branch information
djipi committed Aug 21, 2024
1 parent 32a331c commit 543bfe7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions jiffi2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Supported formats of the Atari Jaguar.

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

Version 1.0.2 - 06-23-2024
- Added a Visual Studio 2022 project
Expand Down
38 changes: 35 additions & 3 deletions src/coff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "time.h"


#define COFF_F (COFF_F_RELFLG | COFF_F_EXEC)
#define COFF_F (COFF_F_RELFLG | /* COFF_F_LNNO | COFF_F_LSYMS | */ COFF_F_EXEC)

typedef struct coffh
{
Expand All @@ -15,17 +15,42 @@ coffh;

coffh TabCoffHdr = {
{
// magic number
0x1, 0x50,
// number of sections
0x0, 0x03,
// time & date stamp
0x0, 0x0, 0x0, 0x0,
// file pointer to symtab
0x0, 0x0, 0x0, 0x0,
// number of symtab entries
0x0, 0x0, 0x0, 0x0,
// sizeof (optional hdr)
((COFF_AOUTSZ & 0xff00) >> 8), (COFF_AOUTSZ & 0xff),
// flags
((COFF_F & 0xff00) >> 8), (COFF_F & 0xff)
},
{
((COFF_ZMAGIC & 0xff00) >> 8), (COFF_ZMAGIC & 0xff), // magic number
0x1, 0x07, // version stamp
// magic number / type of file
#if 0
((COFF_ZMAGIC & 0xff00) >> 8), (COFF_ZMAGIC & 0xff),
#else
0x0, 0x0,
#endif
// version stamp
0x1, 0x07,
// text size in bytes
0x0, 0x0, 0x0, 0x0,
// data size in bytes
0x0, 0x0, 0x0, 0x0,
// bss size in bytes
0x0, 0x0, 0x0, 0x0,
// entry pt.
0x0, 0x0, 0x0, 0x0,
//
0x0, 0x0, 0x0, 0x0,
//
0x0, 0x0, 0x0, 0x0
},
{
// .text
Expand Down Expand Up @@ -91,14 +116,21 @@ int create_coff(void)
// create the coff file
if (!fopen_s(&file2, buffer, "wb") && file2)
{
#if 0
// set time creation
time_t TimeStamp, Time;
Time = time(&TimeStamp);
*(uint32_t*)TabCoffHdr.fhdr.f_timdat = !endianess ? SWAP32(Time) : Time;
#endif
// header initialisations
*(uint32_t*)TabCoffHdr.ahdr.tsize = !endianess ? SWAP32(linj) : linj;
*(uint32_t*)TabCoffHdr.ahdr.text_start = !endianess ? SWAP32(runadr) : runadr;
*(uint32_t*)TabCoffHdr.ahdr.entry = !endianess ? SWAP32(loadadr) : loadadr;
// text header initialisations
*(uint32_t*)TabCoffHdr.shdr[0].s_paddr = !endianess ? SWAP32(loadadr) : loadadr;
*(uint32_t*)TabCoffHdr.shdr[0].s_vaddr = !endianess ? SWAP32(loadadr) : loadadr;
*(uint32_t*)TabCoffHdr.shdr[0].s_size = !endianess ? SWAP32(linj) : linj;
*(uint32_t*)TabCoffHdr.shdr[0].s_scnptr = !endianess ? SWAP32(sizeof(TabCoffHdr)) : sizeof(TabCoffHdr);
// write file and "optional" headers
fwrite(&TabCoffHdr, sizeof(TabCoffHdr), 1, file2);
// Dump the file
Expand Down

0 comments on commit 543bfe7

Please sign in to comment.