sam: Get to the point we enter the kernel
authorAlan Cox <alan@linux.intel.com>
Fri, 17 Aug 2018 22:23:46 +0000 (23:23 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 17 Aug 2018 22:23:46 +0000 (23:23 +0100)
Fix for binman to allow for our page below code
Assorted logic fixes to the boot and setup code
Make crt0 map the high kernel bank

Video is still broken and we die early in setup but we made it into C

Kernel/platform-sam/Makefile
Kernel/platform-sam/boot.s
Kernel/platform-sam/crt0.s
Kernel/platform-sam/sam.s
Kernel/platform-sam/setup.lnk
Kernel/platform-sam/setup.s
Kernel/tools/binman.c

index e09d60f..d077d33 100644 (file)
@@ -45,10 +45,12 @@ image:      boot setup
        dd if=/dev/zero of=fuzix.raw bs=512 count=1600
        # Boot block at track 4 sector 1
        dd if=boot.bin of=fuzix.raw bs=512 seek=40 count=1 conv=notrunc
-       # Kernel from track 4 sector 2
-       dd if=../fuzix.bin of=fuzix.raw bs=512 seek=41 conv=notrunc
+       # Kernel from track 4 sector 2 highest 32K first
+       dd if=../fuzix.bin of=fuzix.raw bs=512 seek=41 skip=64 count=64 conv=notrunc
+       # Low 32K next
+       dd if=../fuzix.bin of=fuzix.raw bs=512 seek=105 count=64 conv=notrunc
        # Font and setup from 64K further on
-       dd if=setup.bin of=fuzix.raw bs=512 seek=169 conv=notrunc
+       dd if=setup.bin of=fuzix.raw bs=512 seek=169 skip=64 conv=notrunc
        # Now shuffle it into a .mgt file
        ../tools/raw2mgt fuzix.raw fuzix.mgt
 
index 02a3e31..fefb1dc 100644 (file)
@@ -43,7 +43,7 @@ boot:
        jp go
 go:
        ld sp,#go
-       ld de,#0x0401           ; track 4 sector 2 (we are sector 1)
+       ld de,#0x0402           ; track 4 sector 2 (we are sector 1)
        ld a,e                  ; Start in bank 2
        ld hl,#0x8000           ; Which we map high
        out (HIMEM),a
@@ -59,7 +59,7 @@ next_sec:
        ex af,af'
 still_good:
        ld a,e                  ; update the sector register
-       ld (SECTOR),a
+       out (SECTOR),a
 dread: ld a,#CMD_READ          ; Ask for data from the FDC
        out (CMD),a
        ld b,#20                ; Wait for FDC
index d0ef914..e7f0cf5 100644 (file)
 
 ;
 ;      Once the loader completes it jumps here
+;      Our low bank is set, our high bank is still setup
 ;
 start:
+               ; Map the kernel high bank
+               ld a,#4
+               out (251),a
+l1:            jp l1
                ld sp, #kstack_top
                ; move the common memory where it belongs    
                ld hl, #s__DATA
index a841e4b..b437f21 100644 (file)
@@ -281,9 +281,8 @@ rst38:          jp interrupt_high           ; Interrupt handling stub
            nop
            nop
            nop
-           ; 40
-           .ds 0x26
-nmi_handler:           ; FIXME: check ends up at 0066
+           .ds 0x27
+nmi_handler:           ; Should be at 0x66
            retn
 
            .area _PAGEH
index ceacb93..c7322d0 100644 (file)
@@ -1,5 +1,6 @@
 -m
 -i setup.ihx
+-b _BOOTSTRAP=0x8000
 setup.rel
 ../font8x8_exp2.rel
 -e
index 5825b3a..bdce0c5 100644 (file)
        .globl _fontdata_8x8_exp2
        
        .area _BOOTSTRAP
+       .area _FONT
+
+       .area _BOOTSTRAP
 
 MODE3  .equ    0x40            ; I think ?
+LOMEM  .equ    250
+VIDEO  .equ    252
+BORDER .equ    254
 
 bootstrap:
        ; Blue border for debugging
        ld a,#1
-       out (254),a
+       out (BORDER),a
 ;
 ;      The kernel low 32K is currently sitting in 4/5 not 0/1 so
 ;      move it. The upper 32K is already in 2/3
 ;
        ld de,#0x2420
+       ld sp,#here
+here:
        call copy16k
        ld de,#0x2521
        call copy16k
@@ -33,7 +41,7 @@ bootstrap:
 ;
        ; Map bank 4/5 low
        ld a,#0x24
-       out (250),a
+       out (LOMEM),a
        ; Put the font data where it belongs
        ld hl,#_fontdata_8x8_exp2
        ld de,#0xE000-0x8000
@@ -44,26 +52,26 @@ bootstrap:
 ;
        ; Put the video in the right place and set the mode
        ld a,#4 + MODE3
-       out (252),a
+       out (VIDEO),a
        ; Map the kernel low
        ld a,#0x20              ; ROM off bank 0/1
-       out (250),a
+       out (LOMEM),a
        ; Black border to hint where we got to
        xor a
-       out (254),a
+       out (BORDER),a
        jp 0x100
 ;
 ;      Move 16K via a bounce buffer
 ;
 copy16k:
        ld a,d                  ; soure bank
-       out (250),a
+       out (LOMEM),a
        ld a,e
        ld hl,#0x0000
        ld de,#0xC000           ; buffer via bank 7
        ld bc,#0x4000
        ldir
-       out (250),a             ; dest bank
+       out (LOMEM),a           ; dest bank
        ld hl,#0xC000
        ld de,#0x0000
        ld bc,#0x4000
index ab54fd5..d8af156 100644 (file)
@@ -10,7 +10,7 @@ static unsigned int s__CODE, s__CODE2, s__INITIALIZER, s__DATA,
     s__INITIALIZED, s__INITIALIZER, s__COMMONMEM, s__VIDEO, l__INITIALIZED,
     l__GSFINAL, l__GSINIT, l__COMMONMEM, s__FONT, l__FONT, s__DISCARD,
     l__DISCARD, l__CODE, l__CODE2, l__VIDEO, l__DATA, s__CONST, l__CONST,
-    s__HEAP, l__HEAP;
+    s__HEAP, l__HEAP, s__PAGE0 = 0xFFFF;
 
 
 static void ProcessMap(FILE * fp)
@@ -73,6 +73,8 @@ static void ProcessMap(FILE * fp)
                        sscanf(p1, "%x", &s__HEAP);
                if (strcmp(p2, "l__HEAP") == 0)
                        sscanf(p1, "%x", &l__HEAP);
+               if (strcmp(p2, "s__PAGE0") == 0)
+                       sscanf(p1, "%x", &s__PAGE0);
        }
 }
 
@@ -152,6 +154,9 @@ int main(int argc, char *argv[])
 
        /* Our standard layout begins with the code */
        start = s__CODE;
+       /* But for some cases we have a 0 page we need to keep */
+       if (s__PAGE0 != 0xFFFF)
+               start = 0;
 
        /* TODO: Support a proper discardable high discard in other mappings */