From: Alan Cox Date: Sat, 30 May 2015 12:09:34 +0000 (+0100) Subject: lowlevel-z80: put back the basics for the zero pointer trap X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5d511239dbd8e1cca6f2ac4f9394e64be1e2861c;p=FUZIX.git lowlevel-z80: put back the basics for the zero pointer trap --- diff --git a/Kernel/lowlevel-z80.s b/Kernel/lowlevel-z80.s index 79af2d4d..f8499bf4 100644 --- a/Kernel/lowlevel-z80.s +++ b/Kernel/lowlevel-z80.s @@ -116,6 +116,11 @@ deliver_signals_2: signal_return: pop hl ; argument di + ; + ; We must keep IRQ disabled in the kernel mapped + ; element of this processing, as we don't want to + ; set INSYS flags here. + ; ld (U_DATA__U_SYSCALL_SP), sp ld sp, #kstack_top call map_kernel @@ -159,6 +164,9 @@ unix_syscall_entry: ld de, #U_DATA__U_ARGN ldir ; copy + ld a, #1 + ld (U_DATA__U_INSYS), a + ; save process stack pointer ld (U_DATA__U_SYSCALL_SP), sp ; switch to kernel stack @@ -178,11 +186,17 @@ unix_syscall_entry: ; 1. fork() will return twice from _unix_syscall ; 2. execve() will not return here but will hit _doexec() ; + ; The fork case returns with a different U_DATA mapped so the + ; U_DATA referencing code is fine, but globals are usually not di + call map_process_always + xor a + ld (U_DATA__U_INSYS), a + ; Back to the user stack ld sp, (U_DATA__U_SYSCALL_SP) @@ -274,20 +288,6 @@ _doexec: ei jp (hl) -; -; Trap handlers -; -; Enter with HL being the signal to send ourself -; -trap_signal: - push hl - ld hl, (U_DATA__U_PTAB); - push hl - call _ssig - pop hl - pop hl - ret - ; ; Called from process context (hopefully) ; @@ -354,7 +354,6 @@ interrupt_handler: push hl push ix push iy - di ; Some platforms (MSX for example) have devices we *must* ; service irrespective of kernel state in order to shut them @@ -380,6 +379,8 @@ interrupt_handler: ld (istack_switched_sp), sp ld sp, #istack_top + ld a, (0) + call map_save ; ; FIXME: re-implement sanity checks and add a stack one @@ -388,6 +389,9 @@ interrupt_handler: ; We need the kernel mapped for the IRQ handling call map_kernel + cp #0xC3 + call nz, null_pointer_trap + ; So the kernel can check rapidly for interrupt status ; FIXME: move to the C code ld a, #1 @@ -452,6 +456,23 @@ interrupt_pop: ei ; Must be instruction before ret ret ; runs in the ei interrupt shadow +; +; Called with the kernel mapped, mid interrupt and on the IRQ stack +; +null_pointer_trap: + ld a, #0xC3 + ld (0), a + +trap_signal: + push hl + ld hl, (U_DATA__U_PTAB); + push hl + call _ssig + pop hl + pop hl + ret + + ; ; Pre-emption. We need to get off the interrupt stack, switch task ; and clean up the IRQ state carefully diff --git a/Kernel/process.c b/Kernel/process.c index 25df8fb1..b9a46709 100644 --- a/Kernel/process.c +++ b/Kernel/process.c @@ -387,7 +387,6 @@ void timer_interrupt(void) void unix_syscall(void) { // NO LOCAL VARIABLES PLEASE - udata.u_insys = true; udata.u_error = 0; /* Fuzix saves the Stack Pointer and arguments in the @@ -422,7 +421,6 @@ void unix_syscall(void) switchout(); } ei(); - udata.u_insys = false; } void sgrpsig(uint16_t pgrp, uint16_t sig)