From 9431ca57f4e4258c26abb905cb7408577e57b44a Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 25 Sep 2017 15:30:36 +0100 Subject: [PATCH] 65c816: fix various bugs in the core code With the platform bugs also fixed this takes us to the point that we start running init and begin to make progress until we take an interrupt in user mode, at which point badness happens --- Kernel/lowlevel-65c816.s | 54 +++++++++++++++++++++++++------------ Kernel/usermem_std-65c816.s | 2 +- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Kernel/lowlevel-65c816.s b/Kernel/lowlevel-65c816.s index 4be0465c..13665969 100644 --- a/Kernel/lowlevel-65c816.s +++ b/Kernel/lowlevel-65c816.s @@ -299,52 +299,72 @@ signal_out: ; _doexec: sta tmp1 - stx tmp1+1 + stx tmp1+1 ; address to execute from sei stz _kernel_flag + rep #$30 .i16 .a16 + ldx tmp1 ; target address + sep #$20 .a8 + lda U_DATA__U_PAGE ; get our bank - clc - adc U_DATA__U_PAGE ; two * bank + asl a adc #STACK_BANKOFF ; plus offset xba ; swap to xx00 lda #$FF ; stack top is xxff tcs ; Set CPU stack at xxFF + rep #$20 + .a16 + inc ; gives us the DP at xx+100 pha pld - ; Split I/D will need to change this logic - lda U_DATA__U_PAGE ; our bank - jsr setdp - ; We are now on the correct DP and CPU stack - ; So fix up the syscall vector + + ; + ; From this point onwards exec is referencing the user DP + ; user S and kernel B (data) + ; + + sep #$20 + .a8 + + ; Fix up the syscall vector + ldy #syscall_vector - sty syscall + sty syscall ; stores into user DP ; And the C stack pointer ldy U_DATA__U_ISP sty sp ; sp is in DP so we write user version - sep #$30 - .i8 - .a8 - ; Will need to change for split I/D + + ; + ; From here we are entirely referencing user data but kernel + ; code + ; + ; (Will need to change for split I/D) + lda U_DATA__U_PAGE ; bank pha ; switch to userdata bank plb + pha ; stack bank for rtl - rep #$10 - .i16 + + dex ; Points to end of last instruction + ; for a return phx ; Execution address within bank - cli lda #0 ; tay ; DP base is 0 - sep #$10 + + sep #$30 + .a8 .i8 + + cli rtl ; diff --git a/Kernel/usermem_std-65c816.s b/Kernel/usermem_std-65c816.s index 1d7c36ed..d42934ef 100644 --- a/Kernel/usermem_std-65c816.s +++ b/Kernel/usermem_std-65c816.s @@ -154,7 +154,7 @@ __uput: sta ptr3 stx ptr3+1 lda U_DATA__U_PAGE - sta uputpatch+2 + sta uputpatch+1 phb .i16 .a16 -- 2.34.1