From f7da4dde41e724e0d85aca03ebded171cb8f528b Mon Sep 17 00:00:00 2001 From: geijoenr Date: Fri, 2 Jan 2015 23:56:12 +0100 Subject: [PATCH] msx2: fix boot from 64kb roms adding more stuff can make the COMMONMEM to extend beyond bank2, in that case we need a 64Kb rom and also copy over rom bank3. --- Kernel/platform-msx2/bootrom.s | 62 +++++++++++++++++++++++++++------- Kernel/platform-msx2/crt0.s | 28 +++++++++------ Kernel/platform-msx2/msx2.s | 17 +++++----- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/Kernel/platform-msx2/bootrom.s b/Kernel/platform-msx2/bootrom.s index c69408d6..084db9e1 100644 --- a/Kernel/platform-msx2/bootrom.s +++ b/Kernel/platform-msx2/bootrom.s @@ -6,9 +6,11 @@ .dw 0,0,0,0,0,0 .globl enaslt - .globl slotrom - .globl slotram + .globl _slotrom + .globl _slotram .globl find_ram + .globl kstack_top + ; At this point the BIOS has detected the cartridge AB signature and ; jumped here; we have the rom bios in bank 0, ram in bank 3, and rom @@ -23,31 +25,63 @@ bootstrap: ld ix,#0x00d5 call #0x015f + ; read slot registers from bios before overwritting them + call find_ram + ld hl,#0x8000 + call enaslt ; set bank 2 to ram + + ld a, #4 + out (0xFE),a + call find_ram - ld (slotram),a + ld d,a call find_rom - ld (slotrom),a + ld e,a + exx - ; set cartridge rom in bank 0 and ram in bank 2 - ld hl,#0 + ld hl,#0xc000 + ld sp,#0xa000 ; keep stack in ram + call enaslt ; set bank 3 to rom + + ; copy kernel page 0 from bank 3 to ram in bank 2 + ; it contains the common area if the rom > 48Kb + ld hl, #0xc000 + ld de, #0x8000 + ld bc, #0x4000 + ldir + exx + + push de + ld hl,#0xc000 ; set bank 3 back to ram + ld a,d call enaslt - ld a,(slotram) - ld hl,#0x8000 + pop de ; store slot data in ram now + ld a, #4 + out (0xFF),a + ld a,d + ld (_slotram),a + ld a,e + ld (_slotrom),a + + ld sp, #kstack_top ; move stack to final location + + ; set cartridge rom in bank 0 + ld hl,#0 call enaslt - ld a, #3 - out (0xFE),a ; copy kernel page 3 to ram + ld a, #3 + out (0xFE),a ld hl, #0x0 ld de, #0x8000 ld bc, #0x4000 ldir ; set ram in bank 0 and cartridge rom in bank 2 - ld a,(slotram) + ld a,(_slotram) ld hl,#0 call enaslt - ld a,(slotrom) + ld a,(_slotrom) ld hl,#0x8000 call enaslt @@ -72,9 +106,11 @@ bootstrap: out (0xFD), a ld a, #1 out (0xFE), a + ld a, #4 + out (0xFF),a ; set bank 2 to ram - ld a,(slotram) + ld a,(_slotram) ld hl,#0x8000 call enaslt diff --git a/Kernel/platform-msx2/crt0.s b/Kernel/platform-msx2/crt0.s index 79c3a406..cd3d0859 100644 --- a/Kernel/platform-msx2/crt0.s +++ b/Kernel/platform-msx2/crt0.s @@ -36,7 +36,8 @@ ; Just for the benefit of the map file .globl start .globl enaslt - .globl slotram + .globl _slotram + .globl _slotrom .globl find_ram ; startup code @0x100 @@ -58,29 +59,34 @@ start: out (0x2f), a ; read slot before switching ram page - ld a,(slotram) + ld a,(_slotram) ld hl,#0x4000 call enaslt - ld a, #4 ; 0 holds 8K of stuff we might want - out (0xff), a ; if we go the OS route, so use 4 - ; plus "0" is magic so this saves - ; shifting them all by one. - - - ld sp, #kstack_top - + ld a,(_slotram) + ld d,a + ld a,(_slotrom) + ld e,a + exx ; move the common memory where it belongs ld hl, #s__INITIALIZER ld de, #s__COMMONMEM ld bc, #l__COMMONMEM ldir - ; move the discardable memory where it belongs + ; move the discardable memory where it belongs ld de, #s__DISCARD ld bc, #l__DISCARD ldir + exx + ; restore slot data + ld a,d + ld (_slotram),a + ld a,e + ld (_slotrom),a + + ; then zero the data area ld hl, #s__DATA ld de, #s__DATA + 1 diff --git a/Kernel/platform-msx2/msx2.s b/Kernel/platform-msx2/msx2.s index b9095e59..86a803f3 100644 --- a/Kernel/platform-msx2/msx2.s +++ b/Kernel/platform-msx2/msx2.s @@ -44,8 +44,8 @@ ; stuff to save .globl _vdpport .globl _infobits - .globl slotrom - .globl slotram + .globl _slotrom + .globl _slotram ; ; vdp - we must initialize this bit early for the vt @@ -84,12 +84,6 @@ _trap_reboot: _kernel_flag: .db 1 - -slotrom: - .db 0 -slotram: - .db 0 - ; ----------------------------------------------------------------------------- ; KERNEL MEMORY BANK (below 0xF000, only accessible when the kernel is mapped) ; ----------------------------------------------------------------------------- @@ -273,6 +267,7 @@ map_kernel: call map_process_2 pop hl ret + map_process_2: push de push af @@ -320,11 +315,15 @@ map_savearea: .db 0,0,0,0 map_kernel_data: .db 3,2,1,4 +_slotrom: + .db 0 +_slotram: + .db 0 ; emulator debug port for now outchar: push af out (0x2F), a pop af - ret + ret -- 2.34.1