Skip to content

Commit

Permalink
hacky dehunking from F0 bootrom
Browse files Browse the repository at this point in the history
  • Loading branch information
erique committed Mar 30, 2024
1 parent ced01b1 commit de022bf
Show file tree
Hide file tree
Showing 9 changed files with 686 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ add_executable(quaesar
src/input.cpp
src/quaesar.cpp
src/adf.cpp
src/reloc.cpp
)

if (APPLE OR LINUX OR UNIX)
Expand Down
Binary file added bootrom.bin
Binary file not shown.
27 changes: 27 additions & 0 deletions bootrom.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; vasmm68k_mot -Fbin -L out.txt -o bootrom.bin bootrom.s

org $f00000

jmp (a5)

tag: dc.w $4afc
dc.l tag
dc.l end
dc.b 1
dc.b 1 ; version
dc.b 0
dc.b -35 ; prio
dc.l name
dc.l name
dc.l init
name: dc.b "jump cut",0
even
init:
suba.l a0,a0
move.l $0.w,d7
asl.l #2,d7
move.l d7,a3
moveq.l #0,d0
jmp 4(a3)

end:
95 changes: 95 additions & 0 deletions src/doshunks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#ifndef DOS_DOSHUNKS_H
#define DOS_DOSHUNKS_H
/*
** $VER: doshunks.h 36.9 (2.6.92)
** Includes Release 40.13
**
** Hunk definitions for object and load modules.
**
** (C) Copyright 1989-1993 Commodore-Amiga, Inc.
** All Rights Reserved
*/

/* hunk types */
#define HUNK_UNIT 999
#define HUNK_NAME 1000
#define HUNK_CODE 1001
#define HUNK_DATA 1002
#define HUNK_BSS 1003
#define HUNK_RELOC32 1004
#define HUNK_ABSRELOC32 HUNK_RELOC32
#define HUNK_RELOC16 1005
#define HUNK_RELRELOC16 HUNK_RELOC16
#define HUNK_RELOC8 1006
#define HUNK_RELRELOC8 HUNK_RELOC8
#define HUNK_EXT 1007
#define HUNK_SYMBOL 1008
#define HUNK_DEBUG 1009
#define HUNK_END 1010
#define HUNK_HEADER 1011

#define HUNK_OVERLAY 1013
#define HUNK_BREAK 1014

#define HUNK_DREL32 1015
#define HUNK_DREL16 1016
#define HUNK_DREL8 1017

#define HUNK_LIB 1018
#define HUNK_INDEX 1019

/*
* Note: V37 LoadSeg uses 1015 (HUNK_DREL32) by mistake. This will continue
* to be supported in future versions, since HUNK_DREL32 is illegal in load files
* anyways. Future versions will support both 1015 and 1020, though anything
* that should be usable under V37 should use 1015.
*/
#define HUNK_RELOC32SHORT 1020

/* see ext_xxx below. New for V39 (note that LoadSeg only handles RELRELOC32).*/
#define HUNK_RELRELOC32 1021
#define HUNK_ABSRELOC16 1022

/*
* Any hunks that have the HUNKB_ADVISORY bit set will be ignored if they
* aren't understood. When ignored, they're treated like HUNK_DEBUG hunks.
* NOTE: this handling of HUNKB_ADVISORY started as of V39 dos.library! If
* lading such executables is attempted under <V39 dos, it will fail with a
* bad hunk type.
*/
#define HUNKB_ADVISORY 29
#define HUNKB_CHIP 30
#define HUNKB_FAST 31
#define HUNKF_ADVISORY (1L<<29)
#define HUNKF_CHIP (1L<<30)
#define HUNKF_FAST (1L<<31)


/* hunk_ext sub-types */
#define EXT_SYMB 0 /* symbol table */
#define EXT_DEF 1 /* relocatable definition */
#define EXT_ABS 2 /* Absolute definition */
#define EXT_RES 3 /* no longer supported */
#define EXT_REF32 129 /* 32 bit absolute reference to symbol */
#define EXT_ABSREF32 EXT_REF32
#define EXT_COMMON 130 /* 32 bit absolute reference to COMMON block */
#define EXT_ABSCOMMON EXT_COMMON
#define EXT_REF16 131 /* 16 bit PC-relative reference to symbol */
#define EXT_RELREF16 EXT_REF16
#define EXT_REF8 132 /* 8 bit PC-relative reference to symbol */
#define EXT_RELREF8 EXT_REF8
#define EXT_DEXT32 133 /* 32 bit data relative reference */
#define EXT_DEXT16 134 /* 16 bit data relative reference */
#define EXT_DEXT8 135 /* 8 bit data relative reference */

/* These are to support some of the '020 and up modes that are rarely used */
#define EXT_RELREF32 136 /* 32 bit PC-relative reference to symbol */
#define EXT_RELCOMMON 137 /* 32 bit PC-relative reference to COMMON block */

/* for completeness... All 680x0's support this */
#define EXT_ABSREF16 138 /* 16 bit absolute reference to symbol */

/* this only exists on '020's and above, in the (d8,An,Xn) address mode */
#define EXT_ABSREF8 139 /* 8 bit absolute reference to symbol */

#endif /* DOS_DOSHUNKS_H */
4 changes: 2 additions & 2 deletions src/dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,8 @@ int custom_fsdb_used_as_nname(a_inode_struct*, char const*) {
}

int debuggable() {
UNIMPLEMENTED();
return 0;
// UNIMPLEMENTED();
return 1;
}

void debugger_change(int) {
Expand Down
81 changes: 80 additions & 1 deletion src/quaesar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// WTF SDL!
#undef main

#include "memory.h"
#include "reloc.h"

extern void real_main(int argc, TCHAR** argv);
extern void keyboard_settrans();

Expand All @@ -36,11 +39,14 @@ bool ends_with(const char* str, const char* suffix) {
return strcmp(str + str_len - suffix_len, suffix) == 0;
}



Options options;

// dummy main
int main(int argc, char** argv) {
syncbase = 1000000;

Options options;
CLI::App app{"Quaesar"};

app.add_option("input", options.input, "Executable or image file (adf, dms)")->check(CLI::ExistingFile);
Expand Down Expand Up @@ -83,7 +89,80 @@ int main(int argc, char** argv) {
return 1;
}

// TODO make this automatic and/or a cmdline arg
struct romboard *rb = &currprefs.romboards[0];
rb->size = 0x20000;
rb->start_address = 0xf00000;
rb->end_address = 0xf20000;
strcpy(rb->lf.loadfile, "bootrom.bin");

currprefs.start_debugger = 1;

real_main(argc, argv);

return 0;
}

// TODO should init this based on the actual memory map
static uint32_t chip_ptr = 0x010000;
static uint32_t fast_ptr = 0xc10000;

static void* MapToReal(APTR addr)
{
// this should use the real api
// but first we need to get just-in-time dehunking via trap calls...
void* p = memory_get_real_address(addr);

uae_u8* base = 0;
if (chipmem_bank.start <= addr && addr <= chipmem_bank.start + chipmem_bank.allocated_size)
base = chipmem_bank.baseaddr - chipmem_bank.start;
else if (bogomem_bank.start <= addr && addr <= bogomem_bank.start + bogomem_bank.allocated_size)
base = bogomem_bank.baseaddr - bogomem_bank.start;
void* ret = base + addr;
return ret;
}

// this MUST call AllocVec for compatibility reasons
static APTR AllocAmiga(uint32_t size, uint32_t flags)
{
size += 4; // store size
uint32_t ret = 0;
if (flags & (1UL<<1))
{
ret = chip_ptr;
chip_ptr += size;
}
else
{
ret = fast_ptr;
fast_ptr += size;
}
memset(MapToReal(ret), 0x00, size);
uint32_t* p = (uint32_t*)MapToReal(ret);
do_put_mem_long(p, size); // fake allocvec
return ret + 4;
}

static uint32_t Read(void* readhandle, void* buffer, uint32_t length)
{
return fread(buffer, 1, length, (FILE*)readhandle);
}

void unpack_payload()
{
FILE* fh = fopen(options.input.c_str(), "rb");

struct LoadSegFuncs funcs;
funcs.read = Read;
funcs.alloc = AllocAmiga;
funcs.map = MapToReal;
BPTR segList = CustomLoadSeg(fh, &funcs);

fclose(fh);

// uint32_t be;
// do_put_mem_long(&be, segList);
// uint32_t jmpAddr = (be) << 2;
// do_put_mem_long((uae_u32*)chipmem_bank.baseaddr, jmpAddr);
*((uae_u32*)chipmem_bank.baseaddr) = segList;
}
Loading

0 comments on commit de022bf

Please sign in to comment.