Kernel: Fix Z180 startup code for platforms where RAM does not start at physical...
authorWill Sowerbutts <will@sowerbutts.com>
Thu, 1 Jan 2015 15:56:36 +0000 (15:56 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Thu, 1 Jan 2015 16:07:09 +0000 (16:07 +0000)
Kernel/cpu-z180/z180.s

index f0f660a..61f401e 100644 (file)
@@ -60,10 +60,10 @@ z180_init_early:
         in0 a, (MMU_BBR)
         cp #(OS_BANK + FIRST_RAM_BANK)
         jr z, dommu             ; we're in position already
-        cp #15
-        jr nc, finalcopy        ; we're running above 64K
-        ; we are running at least in part below 64K -- copy us up to 128KB temporarily
-        ld a, #0x02
+        cp #(OS_BANK + FIRST_RAM_BANK + 0x10)
+        jr nc, finalcopy        ; greater than -- we're running above 64K
+        ; we are running at least in part in the first 64K of RAM -- copy us up to 128KB temporarily
+        ld a, #((0x20 + FIRST_RAM_BANK) >> 4)
         call copykernel
 .if DEBUGCOMMON
         ld a, #'<'
@@ -73,7 +73,8 @@ z180_init_early:
         ld a, #'='
         call outchar
 .endif
-        ld a, #0x20             ; reprogram the MMU to use the copy at 128KB
+        ; reprogram the MMU to use the copy at 128KB
+        ld a, #(0x20 + FIRST_RAM_BANK)
         out0 (MMU_BBR), a
         out0 (MMU_CBR), a
 .if DEBUGCOMMON
@@ -96,7 +97,8 @@ dommu:
         ld a, #'='
         call outchar
 .endif
-        ld a, #(OS_BANK + FIRST_RAM_BANK)   ; reprogram MMU to use copy at physical
+        ; reprogram the MMU to use the copy at bottom of RAM
+        ld a, #(OS_BANK + FIRST_RAM_BANK)
         out0 (MMU_BBR), a       ; low 60K
         out0 (MMU_CBR), a       ; upper 4K (including our stack)
 .if DEBUGCOMMON