6502test: flesh out a little of the 6502 init paths
authorAlan Cox <alan@etchedpixels.co.uk>
Sat, 15 Nov 2014 22:38:40 +0000 (22:38 +0000)
committerAlan Cox <alan@etchedpixels.co.uk>
Sat, 15 Nov 2014 22:38:40 +0000 (22:38 +0000)
Kernel/platform-6502test/commonmem.s
Kernel/platform-6502test/crt0.s
Kernel/platform-6502test/p6502.s
Kernel/platform-6502test/tricks.s
Kernel/platform-6502test/zeropage.inc [new file with mode: 0644]

index 1a20a30..fae9aaa 100644 (file)
 
         .segment "COMMONMEM"
 
+;
+;      In 6502 land these are the C stacks, we will need to handle the
+;      hardware stack separately, and also to save sp,sp+1 etc on irqs
+;
 _ub:    ; first 512 bytes: starts with struct u_block, with the kernel stack working down from above
 _udata:
 kstack_base:
index 2056410..0a954df 100644 (file)
@@ -1,42 +1,54 @@
-               ; Ordering of segments for the linker.
-               ; WRS: Note we list all our segments here, even though
-               ; we don't use them all, because their ordering is set
-               ; when they are first seen.     
-
-               ; imported symbols
+               ; exported symbols
                .export start
 
+               ; imported symbols
+               .import init_early
+               .import init_hardware
+               .import _fuzix_main
+
+               .import  __BSS_RUN__, __BSS_SIZE__
+
+
                ; startup code @0
                .code
+               .include "zeropage.inc"
 
 start:         
-;              orcc #0x10              ; interrupts definitely off
-;              lds #kstack_top
-               ; move the common memory where it belongs    
-               ; we do this dowards, not out of any concern about
-               ; about overlap (although its correct for this) but because
-               ; it deals with linker reloc limits nicely
-;              ldd #s__INITIALIZER
-;              addd #l__COMMONMEM
-;              tfr d,x
-;              ldd #s__COMMONMEM
-;              addd #l__COMMONMEM
-;              tfr d,y
+               sei                     ; interrupts off
+               cld                     ; decimal off
+               ldx #$FF
+               txs                     ; Stack (6502 not C)
                
-;copier:               lda ,-x
-;              sta ,-y
-;              cmpy #s__COMMONMEM
-;              bgt copier
-
-;wiper:                ldx #s__DATA
-;              ldd #l__DATA
-;              clr ,x+
-;              subd #1
-;              bne wiper
-
-;              jsr init_early
-;              jsr init_hardware
-;              jsr _fuzix_main
-;              orcc #0x10
-;stop:         bra stop
+               lda #<kstack_top        ; C stack
+               sta sp
+               lda #>kstack_top
+               sta sp+1 
+
+               ld a,#<__BSS_RUN__
+               sta ptr1
+               ld a,#>__BSS_RUN__
+               sta ptr1+1
+               lda #0
+               tay
+
+               ldx #>__BSS_SIZE__
+               beq bss_wipe_tail
+bss_wiper_1:   sta (ptr1),y
+               iny
+               bne bss_wiper_1
+               inc ptr1+1
+               dex
+               bne bss_wiper_1
+
+bss_wipe_tail:
+               cpy #<__BSS_SIZE__
+               beq gogogo
+               sta (ptr1),y
+               iny
+               bne bss_wipe_tail
 
+               jsr init_early
+               jsr init_hardware
+               jsr _fuzix_main         ; Should never return
+               sei                     ; Spin
+stop:          bra stop
index a54f333..11addf2 100644 (file)
@@ -31,8 +31,8 @@ trapmsg2:   .asciiz ", PC="
 tm_user_sp: .word 0
 
 _trap_monitor:
-;          orcc #0x10
-;          bra _trap_monitor
+           sei
+           bra _trap_monitor
 
 _trap_reboot:
 ;          lda 0xff90
@@ -40,15 +40,14 @@ _trap_reboot:
 ;          jmp 0
 
 _di:
-;          tfr cc,b            ; return the old irq state
-;          orcc #0x10
+           sei                 ; FIXME: save old state in return to C
            rts
 _ei:
-;          andcc #0xef
+           cli                 ; on 6502 cli enables IRQs!!!
            rts
 
-_irqrestore:                   ; B holds the data
-;          tfr b,cc
+_irqrestore:
+           ; FIXME - pull off C stack
            rts
 
 ; -----------------------------------------------------------------------------
@@ -60,14 +59,18 @@ init_early:
             rts
 
 init_hardware:
-;            ; set system RAM size
-;          ldd #256
-;          std _ramsize
-;          ldd #192
-;          std _procmem
-;
+            ; set system RAM size for test purposes
+           lda #1
+           sta _ramsize+1
+           dea
+           sta _ramsize
+           sta _procmem+1
+           lda #192
+           sta _procmem
+
 ;          ; Our vectors are in high memory unlike Z80 but we still
 ;          ; need vectors
+;          FIXME: need to make a C call here
 ;          ldx #0
 ;            jsr _program_vectors
 
@@ -86,26 +89,25 @@ _program_vectors:
 
 ;          jsr map_process
 
-;          ldx #0xFFF2
-;          ldd #badswi_handler
-;          std ,y++
-;          std ,y++                    ; SWI2 and 3 both bad SWI
-;          ldd #firq_handler
-;          std ,y++
+           lda #<vector
+           sta 0xFFFE
+           lda #>vector
+           sta 0xFFFF
+           jsr map_kernel
+           rts
+
+
+vector:
+           ; FIXME: decide whether its an IRQ or syscall and branch
+
 ;            ldd #interrupt_handler
-;          std ,y++
 ;            ldd #unix_syscall_entry
-;          stx ,y++
-;          ldd #nmi_handler
-;          stx ,y
-;          jsr map_kernel
            rts
 
 ;
 ;      Userspace mapping pages 7+  kernel mapping pages 3-5, first common 6
 ;
-;
-;      All registers preserved
+;      Pass the table pointer in zero page ?
 ;
 map_process_always:
 ;          pshs y,u
index feee3a8..2b4672a 100644 (file)
@@ -1,5 +1,5 @@
 ;
-;      6809 version
+;      6502 version
 ;
         .export _switchout
         .export _switchin
@@ -27,8 +27,9 @@ _ramtop:
 ; 
 ; This function can have no arguments or auto variables.
 _switchout:
-;      orcc #0x10              ; irq off
-;        jsr _chksigs
+       sei
+
+        jsr _chksigs
 ;
 ;        ; save machine state
 ;        ldd #0 ; return code set here is ignored, but _switchin can 
@@ -44,9 +45,9 @@ _switchout:
 ;        ; find another process to run (may select this one again) returns it
 ;        ; in X
 ;        jsr _getproc
-;        jsr _switchin
-;        ; we should never get here
-;        jsr _trap_monitor
+        jsr _switchin
+        ; we should never get here
+        jsr _trap_monitor
 
 badswitchmsg: .asciiz "_switchin: FAIL\r\n"
 
diff --git a/Kernel/platform-6502test/zeropage.inc b/Kernel/platform-6502test/zeropage.inc
new file mode 100644 (file)
index 0000000..1ba0358
--- /dev/null
@@ -0,0 +1,26 @@
+;
+; zeropage.inc
+;
+; (C) Copyright 2002-2012, Ullrich von Bassewitz (uz@cc65.org)
+;
+
+; Assembler include file that imports the runtime zero page locations used
+; by the compiler, ready for usage in asm code.
+
+
+        .globalzp       sp, sreg, regsave
+        .globalzp       ptr1, ptr2, ptr3, ptr4
+        .globalzp       tmp1, tmp2, tmp3, tmp4
+        .globalzp       regbank
+  
+; The size of the register bank
+regbanksize     = 6
+
+; The total amount of zero page space used
+zpspace         = 26
+
+; The amount of space that needs to be saved by an interrupt handler that
+; calls C code (does not include the register bank, which is saved by the
+; generated C code if required).
+zpsavespace     = zpspace - regbanksize
+