cp #4 ; are we there yet (RAM page == 4?)
jr nz,kernel_copy
- ; copy data to RAM disk
- ; 16 pages, starting from ROM page 4, RAM page 48
- ld a,#4
-ramdisk_copy:
- out (MPGSEL_1),a ; map ROM page to bank #1
- add #44 ; RAM page = ROM page + 44
- out (MPGSEL_2),a ; map RAM page to bank #2
- ld hl,#0x4000 ; source - bank #1 offset
- ld de,#0x8000 ; destination - bank #2 offset
- ld bc,#0x4000 ; count - 16 KiB
- ldir ; copy it
- sub #43 ; next ROM page = RAM page - 44 + 1
- cp #20 ; are we there yet (RAM page == 4 + 16?)
- jr nz,ramdisk_copy
-
+;; ; copy data to RAM disk
+;; ; 16 pages, starting from ROM page 4, RAM page 48
+;; ld a,#4
+;; ramdisk_copy:
+;; out (MPGSEL_1),a ; map ROM page to bank #1
+;; add #44 ; RAM page = ROM page + 44
+;; out (MPGSEL_2),a ; map RAM page to bank #2
+;; ld hl,#0x4000 ; source - bank #1 offset
+;; ld de,#0x8000 ; destination - bank #2 offset
+;; ld bc,#0x4000 ; count - 16 KiB
+;; ldir ; copy it
+;; sub #43 ; next ROM page = RAM page - 44 + 1
+;; cp #20 ; are we there yet (RAM page == 4 + 16?)
+;; jr nz,ramdisk_copy
+;;
; scary... switching memory bank under our feet
ld a,#32 ; map page 32 (RAM) to bank 0
out (MPGSEL_0),a
; imported symbols
.globl _fuzix_main
- .globl init_early
.globl init_hardware
.globl s__INITIALIZER
.globl s__COMMONMEM
; fall through
init_common:
di
+ ld (_boot_from_rom), a
+ or a
+ jr nz, mappedok ; bootrom.s loads us in the correct pages
+
+ ; move kernel to the correct location in RAM
+ ; note that this cannot cope with kernel images larger than 48KB
+ ld hl, #0x0000
+ ld a, #32 ; first page of RAM is page 32
+movenextbank:
+ out (MPGSEL_3), a ; map page at 0xC000 upwards
+ ld de, #0xC000
+ ld bc, #0x4000 ; copy 16KB
+ ldir
+ inc a
+ cp #35 ; done three pages?
+ jr nz, movenextbank
+
+ ; setup the memory paging for kernel
+ out (MPGSEL_3), a ; map page 35 at 0xC000
+ ld a, #32
+ out (MPGSEL_0), a ; map page 32 at 0x0000
+ inc a
+ out (MPGSEL_1), a ; map page 33 at 0x4000
+ inc a
+ out (MPGSEL_2), a ; map page 34 at 0x8000
+
+mappedok:
+ ; switch to stack in high memory
ld sp, #kstack_top
+
; move the common memory where it belongs
ld hl, #s__DATA
ld de, #s__COMMONMEM
ld bc, #l__DATA - 1
ld (hl), #0
ldir
-
- ; save ROM boot flag
- ld (_boot_from_rom), a
-
- ; setup the rest of the memory paging
- call init_early
; Hardware setup
call init_hardware
stop: halt
jr stop
- .area _DATA
-_boot_from_rom: .ds 1
+_boot_from_rom: .db 0
; 2014-02-19 Sergey Kiselev
; Zeta SBC V2 hardware specific code
- .module zeta-v2
+ .module zeta_v2
; exported symbols
- .globl init_early
.globl init_hardware
.globl _program_vectors
.globl map_kernel
; Initialization code
;=========================================================================
.area _DISCARD
-
-init_early:
- ; We want to be at the bottom of the RAM in the physical address space.
- ; This may or may not alredy be the case. We can't read out the current
- ; values of the memory banking registers.
-
- ; We are going to assume that we are loaded in either one 64K chunk
- ; or two 32K chunks, and that this code, plus the stack, live in the
- ; top 16K bank. First we find ourselves in physical memory.
- ld hl, #0x0000 ; go looking for bank 0
- call searchpage ; find it
- ld d, a ; store mapping for low 32K
- ld hl, #0x8000 ; now go looking for bank 3
- call searchpage ; find it
- ld e, a ; store mapping for top 64K
- push de
-
- ; Now we copy ourselves to the right place in physical memory.
- ld a, #32 ; target = first page of RAM
- call copy32k ; copy first 32K
- pop de ; recover memory mapping
- ld d, e ; now for the next 32K
- ld a, #34 ; target = third page of RAM
- call copy32k ; copy second 32K
-
- ; Finally remap all four 16K banks to the bottom of physical memory.
- ld a, #32 ; first page of RAM
- ld c, #MPGSEL_0 ; first bank register
-mappage:
- out (c), a ; map
- inc c ; next bank
- inc a ; next page
- cp #36 ; done last page?
- ret z
- jr mappage
-
-copy32k:
- out (MPGSEL_1), a
- inc a
- push af ; store next RAM page
- ld a, d ; setup source
- out (MPGSEL_0), a
- call copy16k
- inc a
- out (MPGSEL_0), a ; source is now second half
- pop af ; recover next RAM page
- out (MPGSEL_1), a
- ; fall through to copy16k
-copy16k: ; copy bank 0 to bank 1
- ld hl, #0x0000
- ld de, #0x4000
- ld bc, #0x4000
- ldir
- ret
-
-searchpage: ; search for a page of virtual memory in physical memory
- ld a, (hl) ; read a byte
- ld c, a ; save it
- ld b, #32 ; first 512K is ROM on Zeta2
-checkpage:
- ld a, #0x55 ; known value
- ld (hl), a ; write it at a fixed address
- ld a, b ; map the page
- out (MPGSEL_1), a ; at 0x4000
- ld a, (0x4000) ; read test byte from remapped memory
- cp #0x55 ; found it?
- jr nz, nextpage ; no
- ld a, #0x42 ; test with another value (possibly it was 0x55 by chance)
- ld (hl), a ; write it
- ld a, (0x4000) ; read it
- cp #0x42 ; found it?
- jr z, foundpage ; we got one!
-nextpage:
- inc b ; next page
- jr nz, checkpage ; check next page -- note we test pages above 1MB too
- halt ; wrapped to page 0, not found it: shouldn't happen
-foundpage:
- ld a, c ; get back the byte
- ld (hl), a ; put it back before anyone notices
- ld a, b ; return with page number in A
- ret
-
init_hardware:
; program vectors for the kernel
ld hl, #0
call _program_vectors
pop hl
+ ; Stop floppy drive motors
+ ld a, #0x0C
+ out (FDC_DOR), a
+
; initialize UART0
ld a, (_boot_from_rom) ; do not set the baud rate and other
or a ; serial line parameters if the BIOS