tgl6502: switch to 16K banking
authorAlan Cox <alan@linux.intel.com>
Sat, 24 Jan 2015 16:01:44 +0000 (16:01 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 24 Jan 2015 16:01:44 +0000 (16:01 +0000)
No swapping yet (and swap for 16K bank needs some core tweaks). Tested with shell
and login paths but not heavily.

Kernel/platform-tgl6502/Makefile
Kernel/platform-tgl6502/config.h
Kernel/platform-tgl6502/main.c
Kernel/platform-tgl6502/tgl6502.s
Kernel/platform-tgl6502/tricks.s

index 98d60a3..a72be30 100644 (file)
@@ -27,6 +27,6 @@ image:
        tgl6502.o ../start.o ../version.o ../lowlevel-6502.o \
        tricks.o main.o ../timer.o ../kdata.o devrd.o devices.o \
        ../devio.o ../filesys.o ../process.o ../inode.o ../syscall_fs.o \
-       ../syscall_proc.o ../syscall_other.o ../mm.o ../swap.o ../bankfixed.o \
+       ../syscall_proc.o ../syscall_other.o ../mm.o ../swap.o ../bank16k.o \
        ../tty.o ../devsys.o ../syscall_fs2.o ../syscall_exec.o \
        ../usermem.o ../usermem_std-6502.o devtty.o
index bac8e9d..0561c29 100644 (file)
 
 #define CONFIG_CALL_R2L                /* Runtime stacks arguments backwards */
 
-/* For now used BANK_FIXED as we don't yet have sane swap with 16K maps */
-#define CONFIG_BANK_FIXED
-#define MAX_MAPS 2
-#define MAP_SIZE 0xE000
+/*
+ *     The banking is really 8K banks but we run with them in pairs
+ *     We've got 128K - 8 banks of 16K, of which the kernel eats one for data
+ *     (Kernel code is in the ROM banks which are separate)
+ */
+#define CONFIG_BANK16
+#define MAX_MAPS 7
 
+#if 0
 /* And swapping */
 #define SWAPDEV        257     /* FIXME */
 #define SWAP_SIZE      0x70    /* 56K in blocks */
 #define SWAPTOP                0xE000  /* vectors so its a round number of sectors */
 /* FIXME: we need to swap the udata separately */
 #define MAX_SWAPS      32
+/* TODO */
+#endif
 
 #define TICKSPERSEC 10     /* Ticks per second */
 #define PROGBASE    0x2000  /* also data base */
 #define PROGLOAD    0x2000
-#define PROGTOP     0xE000  /* Top of program */
+#define PROGTOP     0xC000  /* Top of program (for debug for now, can go to 10000) */
 
 #define BOOT_TTY 513        /* Set this to default device for stdio, stderr */
 
index db808d3..15a2c57 100644 (file)
@@ -24,9 +24,14 @@ void do_beep(void)
 
 void pagemap_init(void)
 {
-    /* We treat RAM as 2 48K banks + 16K of kernel data */
-    /* 2-8 proc1, 9-15 proc2, 1 kernel data, 0 spare */
-    pagemap_add(9);
+    /* Really 8K banks 0,1,2,... but we pair them up so we have
+    /* 8 x 16 banks numbered 0,2,4,.... , 0 is the kernel, init starts in 2 */
+    pagemap_add(14);
+    pagemap_add(12);
+    pagemap_add(10);
+    pagemap_add(8);
+    pagemap_add(6);
+    pagemap_add(4);
     pagemap_add(2);
 }
 
index 455d137..0d493c3 100644 (file)
@@ -229,13 +229,27 @@ map_kernel:
 ; X,A holds the map table of this process
 map_process_2:
            sta ptr1
+           stx ptr1+1
            tya
            pha
-           stx ptr1+1
            ldy #0
            lda (ptr1),y        ; 4 bytes if needed
-           tax
-           jsr restore_bits
+           clc
+           adc #1
+           sta $FF8B           ; 0x2000 takes on the upper half of the map
+           ldy #1
+           ldx #0
+map_proc_l:
+           lda (ptr1),y        ; do pages 1-3 as maps 2-7
+           sta $FF8C,x
+           inx
+           clc
+           adc #1
+           sta $FF8C,x
+           inx
+           iny
+           cpy #4
+           bne map_proc_l
            pla
            tay
            rts
@@ -249,8 +263,26 @@ map_restore:
            pha
            txa
            pha
-           ldx saved_map
-           jsr restore_bits
+           tya
+           pha
+           ldx saved_map       ; First bank we skip half of
+           inx
+           stx $FF8B           ; 0x2000 takes on the upper half of the map
+           ldy #1
+           ldx #0
+restore_n:
+           lda saved_map,y     ; do pages 1-3 as maps 2-7
+           sta $FF8C,x
+           inx
+           clc
+           adc #1
+           sta $FF8C,x
+           inx
+           iny
+           cpy #4
+           bne restore_n
+           pla
+           tay
            pla
            tax
            pla
@@ -284,12 +316,21 @@ restore_bits:
 ;
 map_save:
            pha
-           lda U_DATA__U_PAGE
-           sta saved_map
+           tya
+           pha
+           ldy #0
+map_save_l:                            ; save the four entries
+           lda U_DATA__U_PAGE,y
+           sta saved_map,y
+           iny
+           cpy #4
+           bne map_save_l 
+           pla
+           tay
            pla
            rts
 
-saved_map:  .byte 0
+saved_map:  .byte 0, 0, 0, 0
 
 ; outchar: Wait for UART TX idle, then print the char in a without
 ; corrupting other registers
index baa4b73..c196027 100644 (file)
@@ -240,31 +240,33 @@ _dofork:
 ;      number.
 ;
 fork_copy:
-       ldx U_DATA__U_PAGE
        ldy #P_TAB__P_PAGE_OFFSET
-       lda (ptr1),y            ; child->p_page
-       tay
-       lda #0                  ; each bank is 56K
+       ldx #0
+       stx tmp1                ; last bank copied (to spot end mark dups)
 copy_loop:
-       stx $FF8C               ; 0x4000
-       sty $FF8D               ; 0x6000
-       pha                     ; Oh for a 65C02 8)
+       lda U_DATA__U_PAGE,x
+       sta $FF8C               ; 0x4000
+       cmp tmp1                ; last map ?
+       beq done_early          ; repeating page -> end of a shorter process
+       lda (ptr1),y            ; child->p_pag[n]
+       sta $FF8D               ; 0x6000
        tya
        pha
        txa
        pha
        jsr bank2bank           ; copies 8K
+       inc $FF8C               ; next 8K
+       inc $FF8D
+       jsr bank2bank
        pla
        tax
        pla
        tay
-       pla
-       inx
        iny
-       clc
-       adc #1
-       cmp #7
+       inx
+       cpx #4
        bne copy_loop
+done_early:
        jmp map_kernel          ; put the kernel mapping back as it should be
        
 bank2bank:                     ;       copy 4K between the blocks mapped