From 2b39a74aa096099b5ec027b51ed3a28795563e67 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 10 Jan 2015 21:46:50 +0000 Subject: [PATCH] 6502: save the zero page magic bits on interrupt, other minor fixups --- Kernel/cpu-6809/cpu.h | 3 +++ Kernel/cpu-z80/cpu.h | 3 +++ Kernel/include/kernel.h | 12 +++++------ Kernel/lowlevel-6502.s | 32 +++++++++++++++++++++++++++-- Kernel/platform-tgl6502/commonmem.s | 11 ++++++++++ Kernel/platform-tgl6502/ld65.cfg | 2 +- Kernel/platform-tgl6502/tgl6502.s | 7 +++---- Kernel/platform-tgl6502/tricks.s | 2 +- Kernel/process.c | 6 +++--- 9 files changed, 61 insertions(+), 17 deletions(-) diff --git a/Kernel/cpu-6809/cpu.h b/Kernel/cpu-6809/cpu.h index 6b1ff9ed..8ec0e33c 100644 --- a/Kernel/cpu-6809/cpu.h +++ b/Kernel/cpu-6809/cpu.h @@ -47,6 +47,9 @@ typedef union { /* this structure is endian dependent */ #define cpu_to_le16(x) swab(x) #define le16_to_cpu(x) swab(x) +/* 6809 gcc already uses register calling whenever it can */ +#define __fastcall__ + #ifdef CONFIG_BANKED #define CODE1 __attribute__((far("1"))) #define CODE2 __attribute__((far("2"))) diff --git a/Kernel/cpu-z80/cpu.h b/Kernel/cpu-z80/cpu.h index 437d4a23..7ed070d7 100644 --- a/Kernel/cpu-z80/cpu.h +++ b/Kernel/cpu-z80/cpu.h @@ -55,6 +55,9 @@ typedef union { /* this structure is endian dependent */ #define VIDEO #define DISCARD +/* No fastcall in SDCC */ +#define __fastcall__ + #define cpu_to_le16(x) (x) #define le16_to_cpu(x) (x) #define cpu_to_le32(x) (x) diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index 30c8df37..ff4388a1 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -573,9 +573,9 @@ COMMON int _uzero(uint8_t *user, usize_t count); /* platform/tricks.s */ COMMON void switchout(void); -COMMON void doexec(uint16_t start_addr); -COMMON void switchin(ptptr process); -COMMON int16_t dofork(ptptr child); +COMMON void __fastcall__ doexec(uint16_t start_addr); +COMMON void __fastcall__ switchin(ptptr process); +COMMON int16_t __fastcall__ dofork(ptptr child); /* devio.c */ CODE1 uint8_t *bread (uint16_t dev, blkno_t blk, bool rewrite); @@ -667,12 +667,12 @@ CODE2 unsigned int ugetsys(unsigned char *to, unsigned int size); CODE2 void psleep(void *event); CODE2 void wakeup(void *event); CODE2 void pwake(ptptr p); -CODE2 ptptr getproc(void); -CODE2 void newproc(ptptr p); +CODE2 ptptr __fastcall__ getproc(void); +CODE2 void __fastcall__ newproc(ptptr p); CODE2 ptptr ptab_alloc(void); CODE2 void ssig(ptptr proc, uint16_t sig); CODE2 void chksigs(void); -COMMON void program_vectors(uint16_t *pageptr); +COMMON void __fastcall__ program_vectors(uint16_t *pageptr); CODE2 void sgrpsig(uint16_t pgrp, uint16_t sig); CODE2 void unix_syscall(void); CODE2 void timer_interrupt(void); diff --git a/Kernel/lowlevel-6502.s b/Kernel/lowlevel-6502.s index 6e6d4ea6..c48feae8 100644 --- a/Kernel/lowlevel-6502.s +++ b/Kernel/lowlevel-6502.s @@ -21,6 +21,7 @@ .import _platform_interrupt_i .import platform_doexec .import _inint + .import CTemp .include "platform/zeropage.inc" .include "platform/kernel.def" @@ -60,11 +61,12 @@ 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 +; x,a holds the target address ; _doexec: sei - lda #0 - sta _kernel_flag + ldy #0 + sty _kernel_flag jsr map_process_always jmp platform_doexec @@ -76,7 +78,11 @@ _doexec: ; Caller on the exit side is responsible for stack switches and ; checking for signals ; +; The C world here is fairly ugly. We have to stash various bits of +; zero page magic because its not re-entrant. +; interrupt_handler: + jsr stash_zp ; Save zero page bits jsr map_save jsr map_kernel lda #1 @@ -91,10 +97,32 @@ interrupt_handler: interrupt_k: jsr map_restore int_switch: + jsr stash_zp ; Zero page stuff reverse lda #0 sta _inint rts +; +; The following is taken from the debugger example as referenced in +; the compiler documentation. We swap a stashed ZP in our commondata +; with an IRQ handler one. The commondata is per process and we depend +; upon this to make it all work +; +; Swap the C temporaries +; +stash_zp: + ldy #zpsavespace-1 +Swap1: ldx CTemp,y + lda nmi_trap lda #