msx2: move memory sizing to bootstrap
authorgeijoenr <enric.geijo@gmail.com>
Sat, 21 Feb 2015 12:57:45 +0000 (12:57 +0000)
committergeijoenr <enric.geijo@gmail.com>
Sat, 21 Feb 2015 12:59:09 +0000 (12:59 +0000)
Kernel/platform-msx2/bootrom.s
Kernel/platform-msx2/crt0.s
Kernel/platform-msx2/msx2.s

index ee1ab9f..f171737 100644 (file)
@@ -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:
index 017e77d..fbc4181 100644 (file)
@@ -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
index 6df0d12..b5e7871 100644 (file)
             .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