From c842a3a002946d0d12e3107e38a6a0dda6523748 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 17 Dec 2014 00:33:11 +0000 Subject: [PATCH] 6502: Clean up the expanded 6502 bits This now assembles at least, I doubt it actually does anything useful. --- Kernel/lowlevel-6502.s | 31 ++++++++++++++------ Kernel/platform-6502test/crt0.s | 9 +++--- Kernel/platform-6502test/p6502.s | 47 +++++++++++++++++++------------ Kernel/platform-6502test/tricks.s | 2 ++ 4 files changed, 58 insertions(+), 31 deletions(-) diff --git a/Kernel/lowlevel-6502.s b/Kernel/lowlevel-6502.s index 36e83b70..9928048f 100644 --- a/Kernel/lowlevel-6502.s +++ b/Kernel/lowlevel-6502.s @@ -13,8 +13,18 @@ .import outchar .import _kernel_flag .import _unix_syscall_i + .import nmi_trap + .import map_restore + .import map_save + .import map_process_always + .import map_kernel + .import _platform_interrupt_i + .import platform_doexec + .import _inint .include "platform/zeropage.inc" + .include "platform/kernel.def" + .include "kernel02.def" .segment "COMMONMEM" ; @@ -55,11 +65,11 @@ unix_sig_exit: ; doexec is a special case syscall exit path. As we may have no ; common we have to hand the last bits off to the platform code ; -_doexec +_doexec: sei lda #0 sta _kernel_flag - call map_process_always + jsr map_process_always jmp platform_doexec ; @@ -81,7 +91,7 @@ interrupt_handler: lda _kernel_flag bne interrupt_k jsr map_process_always ; may have switched task - jr int_switch + jmp int_switch interrupt_k: jsr map_restore int_switch: @@ -100,13 +110,13 @@ outstring: sta ptr1 stx ptr1+1 ldy #0 -outstringhexl: +outstringl: lda (ptr1),y cmp #0 beq outdone1 - call outcharhex + jsr outcharhex iny - jmp outstringhexl + jmp outstringl outstringhex: ; string in X,A sta ptr1 @@ -116,7 +126,7 @@ outstringhexl: lda (ptr1),y cmp #0 beq outdone1 - call outcharhex + jsr outcharhex iny jmp outstringhexl @@ -127,6 +137,7 @@ outnewline: lda #10 jsr outchar pla +outdone1: rts outcharhex: @@ -136,9 +147,11 @@ outcharhex: lsr a lsr a lsr a - add #'0' + clc + adc #48 ; ascii zero jsr outchar pla and #$0f - add #'0' + clc + adc #48 jmp outchar diff --git a/Kernel/platform-6502test/crt0.s b/Kernel/platform-6502test/crt0.s index 0a954df0..ebb1b846 100644 --- a/Kernel/platform-6502test/crt0.s +++ b/Kernel/platform-6502test/crt0.s @@ -5,6 +5,7 @@ .import init_early .import init_hardware .import _fuzix_main + .import kstack_top .import __BSS_RUN__, __BSS_SIZE__ @@ -24,9 +25,9 @@ start: lda #>kstack_top sta sp+1 - ld a,#<__BSS_RUN__ + lda #<__BSS_RUN__ sta ptr1 - ld a,#>__BSS_RUN__ + lda #>__BSS_RUN__ sta ptr1+1 lda #0 tay @@ -46,9 +47,9 @@ bss_wipe_tail: sta (ptr1),y iny bne bss_wipe_tail - +gogogo: jsr init_early jsr init_hardware jsr _fuzix_main ; Should never return sei ; Spin -stop: bra stop +stop: jmp stop diff --git a/Kernel/platform-6502test/p6502.s b/Kernel/platform-6502test/p6502.s index 440ed45d..733e1bc4 100644 --- a/Kernel/platform-6502test/p6502.s +++ b/Kernel/platform-6502test/p6502.s @@ -23,11 +23,18 @@ .import _procmem .import nmi_handler .import unix_syscall_entry + .import _kernel_flag + .import kstack_top + .import istack_switched_sp .include "kernel.def" .include "../kernel02.def" .include "zeropage.inc" +; +; syscall is jsr [$00fe] +; +syscall = $FE ; ----------------------------------------------------------------------------- ; COMMON MEMORY BANK (0xF000 upwards) ; ----------------------------------------------------------------------------- @@ -115,12 +122,10 @@ program_vectors_k: ; However tempting it may be to use BRK for system calls we ; can't do this on an NMOS 6502 because the chip has brain ; dead IRQ handling buts that could simply "lose" the syscall! - lda #JSR - sta syscall lda #syscall_entry - sta syscall+2 + sta syscall+1 jsr map_kernel rts @@ -155,28 +160,30 @@ map_process_always: ldx #>U_DATA__U_PAGE jsr map_process_2 pla - ret + rts ; ; X,A points to the map table of this process ; map_process: cmp #0 bne map_process_2 - cpx + cpx #0 bne map_process_2 ; ; Map in the kernel below the current common, all registers preserved ; map_kernel: + pha lda #1 ; for 6509 clean up any far copy ptr sta 1 + pla rts ; X,A holds the map table of this process map_process_2: + sta ptr1 tya pha - sta ptr1 sty ptr1+1 ldy #0 lda (ptr1),y ; 4 bytes if needed @@ -247,7 +254,7 @@ vector: inx inx lda $0100,X - and a, $10 + and #$10 ; ; FIXME: either don't care about brk or ship it somewhere like ; kill -SIGTRAP @@ -265,7 +272,7 @@ vector: ; Stack has gone for a walk if we were not coming from kernel tsx stx istack_switched_sp ; in uarea/stacks - ldx #0xC0 + ldx #$C0 txs ; our istack jsr interrupt_handler ldx istack_switched_sp @@ -287,6 +294,7 @@ vector_um: pla ; discard saved idirect irqout: +bogon: pla tya pla @@ -308,16 +316,19 @@ syscall_entry: sta ptr2 lda #>U_DATA__U_ARGN sta ptr2+1 - lda #1 - sta 1 ; magic far copy hackery - ldx #0 - txy -copy_args: lda (ptr1), x ; copy the arguments from current bank - sta (ptr2), y ; will write into bank 1 - inx + ldy #0 + +copy_args: lda (ptr1),y ; copy the arguments from current bank + tax + lda #1 + sta 1 ; bank 1 please + txa + sta (ptr2),y ; will write into bank 1 + lda #0 + sta 1 iny - cpx #8 + cpy #8 bne copy_args ldy tmp1 ; syscall code ; @@ -328,7 +339,7 @@ copy_args: lda (ptr1), x ; copy the arguments from current bank sta 0 ; kernel banks sta 1 ; -; We are now suddenely in the kernel copy of this, and our stack is +; We are now suddenly in the kernel copy of this, and our stack is ; missing in action. Access to userspace is not available ; ; On a 6509 this also means our C stack is missing in action, which diff --git a/Kernel/platform-6502test/tricks.s b/Kernel/platform-6502test/tricks.s index 2b4672ab..a43fff23 100644 --- a/Kernel/platform-6502test/tricks.s +++ b/Kernel/platform-6502test/tricks.s @@ -6,6 +6,8 @@ .export _dofork .export _ramtop + .import _chksigs + .import _trap_monitor .include "kernel.def" .include "../kernel02.def" -- 2.34.1