Skip to content

Commit

Permalink
dehunk payload via trap & provide a faux-dos library
Browse files Browse the repository at this point in the history
  • Loading branch information
erique committed Mar 31, 2024
1 parent b063d34 commit a6cb748
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 63 deletions.
Binary file modified bootrom.bin
Binary file not shown.
145 changes: 118 additions & 27 deletions bootrom.s
Original file line number Diff line number Diff line change
@@ -1,27 +1,118 @@
; 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:
; /opt/amiga/bin/vasmm68k_mot -Fbin -L out.txt -o bootrom.bin bootrom.s -no-opt -cnop=0 -I /opt/amiga/m68k-amigaos/ndk-include

include "exec/resident.i"
include "exec/nodes.i"
include "exec/libraries.i"

include "lvo/exec_lib.i"

org $f10000

JUMP_CUT

.tag: dc.w RTC_MATCHWORD
dc.l .tag
dc.l .end
dc.b RTF_COLDSTART
dc.b 1 ; version
dc.b NT_UNKNOWN
dc.b -40 ; prio
dc.l .name
dc.l .id
dc.l .init
.name: dc.b "jump cut",0
.id: dc.b "jump cut 1.0 (1.1.2024)",$d,$a,0
even
cnop 0,4
.init:
jsr $f0ff90
move.l d0,d7
beq.b .nopayload

suba.l a0,a0
asl.l #2,d7
move.l d7,a3
moveq.l #0,d0
jmp 4(a3)

.nopayload:
rts

.end:

cnop 0,16

DOS:

.tag: dc.w RTC_MATCHWORD
dc.l .tag
dc.l .end
dc.b RTF_COLDSTART
dc.b 99 ; version
dc.b 9 ; nt_library
dc.b 0 ; prio
dc.l .name
dc.l .id
dc.l .init

.name: dc.b "dos.library",0
.id: dc.b "dos 99 (1.1.2099)",$d,$a,0
even

cnop 0,4

.init:
movem.l d2-d7/a2-a6,-(sp)
move.l $4.w,a6
lea .func(pc),a0
suba.l a1,a1
suba.l a2,a2
move.l #LIB_SIZE,d0
jsr _LVOMakeLibrary(a6)
move.l d0,d2
beq.b .fail
movea.l d0,a1

move.b #NT_LIBRARY,LN_TYPE(a1)
move.l #.name,LN_NAME(a1)
move.b #LIBF_SUMUSED|LIBF_CHANGED,LIB_FLAGS(a1)
move.w #99,LIB_VERSION(a1)
move.w #99,LIB_REVISION(a1)
move.l #.id,LIB_IDSTRING(a1)

jsr _LVOAddLibrary(a6)

.fail move.l d2,d0
movem.l (sp)+,d2-d7/a2-a6
rts

.libopen
addq.w #1,LIB_OPENCNT(a6)
move.l a6,d0
rts

.libclose
subq.w #1,LIB_OPENCNT(a6)
moveq #0,d0
rts

.dummy move.l #0,d0
rts

.shortfunc macro
dc.w (\1-.func)
endm

.func
dc.w -1
.shortfunc .libopen
.shortfunc .libclose
.shortfunc .dummy ; expunge
.shortfunc .dummy ; null

rept 100
.shortfunc .dummy
endr
dc.w -1

.end:
59 changes: 27 additions & 32 deletions src/quaesar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
#include "memory.h"
#include "reloc.h"

#include "threaddep/thread.h"
#include "autoconf.h"
#include "native2amiga.h"
#include "memory.h"
#include "custom.h"
#include "newcpu.h"

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

Expand Down Expand Up @@ -88,71 +95,59 @@ int main(int argc, char** argv) {

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

currprefs.start_debugger = 1;
currprefs.uaeboard = 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;
TrapContext* currentContext = 0;

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;
return memory_get_real_address(addr);
}

// 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;
}
size += 4; // add space to store size

TrapContext* ctx = currentContext;
uaecptr ret = uae_AllocMem(ctx, size + 4, flags, trap_get_long(ctx, 4));

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() {
uae_u32 REGPARAM2 dehunk_payload (TrapContext *ctx) {
FILE* fh = fopen(options.input.c_str(), "rb");

if (!fh)
return 0;

currentContext = ctx;

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

currentContext = 0;

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;
return do_byteswap_32(segList);
}
5 changes: 5 additions & 0 deletions uae_src/autoconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ void rtarea_init(void)
calltrap (deftrapres (uae_puts, TRAPFLAG_NO_RETVAL, _T("uae_puts")));
dw (RTS);

org (rtarea_base + 0xFF90);
uae_u32 REGPARAM2 dehunk_payload (TrapContext *ctx);
calltrap (deftrapres (dehunk_payload, TRAPFLAG_DORET | TRAPFLAG_EXTRA_STACK, _T("dehunk_payload")));
dw(RTS);

org (a);

uae_boot_rom_size = here () - rtarea_base;
Expand Down
4 changes: 0 additions & 4 deletions uae_src/newcpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6595,10 +6595,6 @@ void m68k_go (int may_quit)
if (cpu_hardreset) {
memory_clear ();
write_log (_T("hardreset, memory cleared\n"));

void unpack_payload();
unpack_payload();

}
#ifdef DEBUGGER
if (debug_dma) {
Expand Down

0 comments on commit a6cb748

Please sign in to comment.