.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:
- ; 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
tm_user_sp: .word 0
_trap_monitor:
-; orcc #0x10
-; bra _trap_monitor
+ sei
+ bra _trap_monitor
_trap_reboot:
; lda 0xff90
; 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
; -----------------------------------------------------------------------------
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
; 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
;
-; 6809 version
+; 6502 version
;
.export _switchout
.export _switchin
;
; 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
; ; 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"
--- /dev/null
+;
+; 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
+