From 0c50529d9050446a1496fa2d93c2e7c4b65def37 Mon Sep 17 00:00:00 2001 From: geijoenr Date: Sat, 21 Feb 2015 12:57:45 +0000 Subject: [PATCH] msx2: move memory sizing to bootstrap --- Kernel/platform-msx2/bootrom.s | 66 +++++++++++++++++++++++++++++++- Kernel/platform-msx2/crt0.s | 22 ++++++++++- Kernel/platform-msx2/msx2.s | 70 ---------------------------------- 3 files changed, 86 insertions(+), 72 deletions(-) diff --git a/Kernel/platform-msx2/bootrom.s b/Kernel/platform-msx2/bootrom.s index ee1ab9fc..f171737f 100644 --- a/Kernel/platform-msx2/bootrom.s +++ b/Kernel/platform-msx2/bootrom.s @@ -36,6 +36,12 @@ bootstrap: ld hl,#PAGE2_BASE call enaslt + ; + ; find ram size + ; + call size_memory + push hl + ld b,#3 ; starting ram page (copy to 3,2,1,4) ld c,#2 ; starting rom page (copy from 2,3,4,5,6,7,8,9) @@ -82,15 +88,19 @@ done: call find_rom ld e,a + pop hl ; re-stash ram size + ld a, #4 out (RAM_PAGE3),a + ld sp,#0xe100 + push hl + ld bc,(BIOS_VERSION1) ; localization and interrupt frequency ld hl,(BIOS_VDP_IOPORT) ; vdp ports inc h inc l ld a,(BIOS_MACHINE_TYPE) ; machine type - ld sp,#0xe100 push de push bc push hl @@ -115,6 +125,60 @@ done: jp 0x100 + ; + ; Size currently selected memory mapper + ; +size_memory: + ld bc, #0x03FE ; make sure ram page 3 is selected + out (c), b + ld hl, #0x8000 + ld (hl), #0xAA ; we know there is a low page! + ld bc, #0x04FE ; continue with page 4 +ramscan_2: + ld a, #0xAA +ramscan: + out (c), b + cp (hl) ; is it 0xAA + jr z, ramwrapped ; we've wrapped (hopefully) + inc b + jr nz, ramscan + jr ramerror ; not an error we *could* have 256 pages! +ramwrapped: + ld a, #3 + out (c), a + ld (hl), #0x55 + out (c), b + ld a, (hl) + cp #0x55 + jr z, ramerror ; Cool we wrapped both change to 0x55 + ; Fluke RAM was 0xAA already + ld a, #3 + out (c), a + ld a, #0xAA + ld (hl), a ; put the marker back as 0xAA + inc b + jr nz, ramscan_2 ; Continue our memory walk +ramerror: ; Ok so there are 256-b-3 pages of 16K) + ld a,#3 + out (c), a ; always put page 0 back + ; + ; Address map back to normal so can update kernel data + ; + dec b ; take into account we started at page 3 + dec b + dec b + ld l, b + ld h, #0 + ld a, l + or a ; zero count -> 256 pages + jr nz, pageslt256 + inc h +pageslt256: + ; hl contains num of pages + ret + + + ; find slot currently set in page 1 ; returns slot in reg a using FxxxSSPP format (see enaslt) find_rom: diff --git a/Kernel/platform-msx2/crt0.s b/Kernel/platform-msx2/crt0.s index 017e77d6..fbc4181c 100644 --- a/Kernel/platform-msx2/crt0.s +++ b/Kernel/platform-msx2/crt0.s @@ -31,6 +31,9 @@ .globl l__COMMONMEM .globl s__INITIALIZER .globl kstack_top + .globl _ramsize + .globl _procmem + .globl _msxmaps ; Just for the benefit of the map file .globl start @@ -60,12 +63,13 @@ start: ld a, #'@' out (OPENMSX_DEBUG2), a ; - ; unstash info bits + ; unstash info bits and memory size ; pop af pop hl pop bc pop de + pop ix ld sp, #kstack_top ; @@ -106,6 +110,22 @@ start: ld (hl), #0 ldir + ; finally update memory size + ; + push ix + pop hl + ld (_msxmaps), hl + add hl, hl ; x 16 for Kb + add hl, hl + add hl, hl + add hl, hl + + ; set system RAM size in KB + ld (_ramsize), hl + ld de, #0xFFD0 + add hl, de ; subtract 48K for the kernel + ld (_procmem), hl + call init_early call init_hardware call _fuzix_main diff --git a/Kernel/platform-msx2/msx2.s b/Kernel/platform-msx2/msx2.s index 6df0d12c..b5e78710 100644 --- a/Kernel/platform-msx2/msx2.s +++ b/Kernel/platform-msx2/msx2.s @@ -27,11 +27,6 @@ .globl _trap_monitor .globl outchar - ; imported symbols - .globl _ramsize - .globl _procmem - .globl _msxmaps - .globl _tty_inproc .globl unix_syscall_entry .globl trap_illegal @@ -98,9 +93,6 @@ init_early: ret init_hardware: - ; Size RAM - call size_memory - ; set up interrupt vectors for the kernel mapped low page and ; data area ld hl, #0 @@ -133,68 +125,6 @@ init_hardware: .area _COMMONMEM -; -; Size currently selected memory mapper (this should be done during bootstrap) -; -size_memory: - ld bc, #0x03FC ; make sure ram page 3 is selected - out (c), b - ld hl, #0x3FFF ; careful, there is code in page 3 - ld (hl), #0xAA ; we know there is a low page! - ld bc, #0x04FC ; continue with page 4 -ramscan_2: - ld a, #0xAA -ramscan: - out (c), b - cp (hl) ; is it 0xAA - jr z, ramwrapped ; we've wrapped (hopefully) - inc b - jr nz, ramscan - jr ramerror ; not an error we *could* have 256 pages! -ramwrapped: - ld a, #3 - out (c), a - ld (hl), #0x55 - out (c), b - ld a, (hl) - cp #0x55 - jr z, ramerror ; Cool we wrapped both change to 0x55 - ; Fluke RAM was 0xAA already - ld a, #3 - out (c), a - ld a, #0xAA - ld (hl), a ; put the marker back as 0xAA - inc b - jr nz, ramscan_2 ; Continue our memory walk -ramerror: ; Ok so there are 256-b-3 pages of 16K) - ld a,#3 - out (c), a ; always put page 0 back - ; - ; Address map back to normal so can update kernel data - ; - dec b ; take into account we started at page 3 - dec b - dec b - ld l, b - ld h, #0 - ld a, l - or a ; zero count -> 256 pages - jr nz, pageslt256 - inc h -pageslt256: - ld (_msxmaps), hl - add hl, hl ; x 16 for Kb - add hl, hl - add hl, hl - add hl, hl - - ; set system RAM size in KB - ld (_ramsize), hl - ld de, #0xFFD0 - add hl, de ; subtract 48K for the kernel - ld (_procmem), hl - ret - _program_vectors: ; we are called, with interrupts disabled, by both newproc() and crt0 ; will exit with interrupts off -- 2.34.1