diff --git a/config/boot.mk b/config/boot.mk new file mode 100644 index 0000000..881cb88 --- /dev/null +++ b/config/boot.mk @@ -0,0 +1,10 @@ +BOOT_SRC := $(wildcard src/boot/*.s) + +BOOT_OBJ := $(BOOT_SRC:.s=.o) + +BOOT_LDFLAGS := --list-file build/boot.lst + +build/boot.bin: $(BOOT_OBJ) + @echo "Linking $@..." + @$(LD) -o $@ config/boot.scm $(LDFLAGS) $(BOOT_LDFLAGS) $^ + @mv build/boot.raw $@ \ No newline at end of file diff --git a/config/boot.scm b/config/boot.scm new file mode 100644 index 0000000..0880d47 --- /dev/null +++ b/config/boot.scm @@ -0,0 +1,36 @@ +(define memories '( + + (memory Code + (address (#x008000 . #x0080FF)) + (section code) + (section cdata) + (section switch) + ) + + (memory Data + (address (#x008100 . #x0081FF)) + (section near) + (section data) + (section znear) + (section zdata) + ) + + (memory Stack + (address (#x000100 . #x0001FF)) + (section (stack #x00100)) + ) + + (memory DirectPage + (address (#x000000 . #x0000FF)) + (section + (registers #x000004) + (ztiny) + ) + ) + + (block stack (size #x100)) ; machine stack size + + (base-address _DirectPageStart DirectPage 0) + + (base-address _NearBaseAddress Data 0) +)) diff --git a/config/kernel.scm b/config/kernel.scm index 0b39f6c..35cf3ef 100755 --- a/config/kernel.scm +++ b/config/kernel.scm @@ -9,16 +9,17 @@ (section heap) ) - (memory BOOT - (address (#x008000 . #x0082FF)) - (scatter-to boot_rom) - (section boot) + (memory LOROM + (address (#x008000 . #x00FFFF)) + (scatter-to low_rom) + (section (boot #x008000)) + (section irq_handlers) ) (memory ROM (address (#xC00000 . #xC0FFFF)) - (section (boot_rom #xC08000)) - (section (code #xC08300)) + (section (low_rom #xC08000)) + (section code) (section farcode) (section cdata) (section switch) @@ -27,8 +28,6 @@ (section chuge) (section ihuge) (section data_init_table) - (section (irq_trampolines #xC0F000)) - (section (irq_vectors #xC0FF80)) ) (memory Stack diff --git a/src/kernel/boot.s b/src/kernel/boot.s index 92d4398..3cf2c3d 100755 --- a/src/kernel/boot.s +++ b/src/kernel/boot.s @@ -7,6 +7,8 @@ #include "sentinel65x.h" + .extern __program_root_section + .section boot, noreorder .asciz "WDC" w65c265s_init: @@ -54,4 +56,4 @@ delay_y w65c265s_sram_off // And we are booted enough to jump to high ROM. - jmp long:0xC08300 \ No newline at end of file + jmp long:__program_root_section \ No newline at end of file diff --git a/src/kernel/cop_trampoline.s b/src/kernel/cop_trampoline.s new file mode 100644 index 0000000..e4191ef --- /dev/null +++ b/src/kernel/cop_trampoline.s @@ -0,0 +1,28 @@ +#include "macros.h" + + .section znear,bss +cop_handler_result_c: + .space 2 +cop_handler_result_x: + .space 2 +cop_handler_result_y: + .space 2 + + .section `$$interruptVector_0x00ffb4`,text + .public cop_trampoline + .word cop_trampoline + .section irq_handlers,text + .extern cop_handler +cop_trampoline: + rep #48 + + ; Simple calling convention: first argument in C, the rest on the stack. + phx + phy + call cop_handler + + ; And fetch the results: + lda cop_handler_result_c + ldx cop_handler_result_x + ldy cop_handler_result_y + rti \ No newline at end of file diff --git a/src/kernel/irq.c b/src/kernel/irq.c index 91e4416..04ca61c 100755 --- a/src/kernel/irq.c +++ b/src/kernel/irq.c @@ -7,23 +7,30 @@ #include -// Return values from handlers, if any, should be stored in -// DP[0] for the C register, DP[4] for the X register, and -// DP[6] for the Y register. -extern uint16_t Dp[4]; - #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-parameter" +#pragma clang diagnostic ignored "-Wunused-variable" +#pragma clang section text="irq_handlers" -void cop_handler(uint16_t arg_c, uint16_t arg_x, uint16_t arg_y) { - switch (arg_c & 0x00FF) { - case 0: - //soft_reset(); - break; - default: - //cop_error_invalid_call(); - break; - } +// These are used by the COP trampoline to put the results +// into the C, X, and Y registers. +extern uint16_t cop_handler_result_c; +extern uint16_t cop_handler_result_x; +extern uint16_t cop_handler_result_y; + +__attribute__((simple_call)) +void cop_handler(uint16_t function, + uint16_t arg_x, + uint16_t arg_y) { + + switch (function) { + case 0: + break; + default: + break; + } + + return; } void irq_handler(void) { diff --git a/src/kernel/irq_trampoline.s b/src/kernel/irq_trampoline.s deleted file mode 100755 index d8e1782..0000000 --- a/src/kernel/irq_trampoline.s +++ /dev/null @@ -1,374 +0,0 @@ -//; SPDX-License-Identifier: MIT -//; -//; bios/irq_trampoline.s -//; IRQ trampoline code for Sentinel 65X -//; -//; The two sections below are visible in ROM when the CPU's -//; on-chip ROM is disabled. They must be copied to RAM if -//; on-board ROM is to be disabled. -//; -//; -//; Copyright © 2024 Kyle J Cardoza - -#include "macros.h" -#include "sentinel65x.h" - - .extern _Dp - - .extern irq_handler - .extern cop_handler - - ; This section gets copied to 0x00F000 - .section irq_trampolines - -reserved_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -timer0_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -timer1_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -timer2_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -timer3_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -timer4_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -timer5_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -timer6_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -timer7_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -pe56_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -ne57_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -pe60_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -pe62_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -ne64_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -ne66_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -pib_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -level_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - - call long:irq_handler - jump interrupt_return - - -uart_0_rx_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -uart_0_tx_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -uart_1_rx_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -uart_1_tx_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -uart_2_rx_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -uart_2_tx_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -uart_3_rx_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -uart_3_tx_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -cop_irq: - phb - phd - rep #0b00110000 - stx _Dp+4 - sty _Dp+6 - call cop_handler - rep #0b00110000 - lda _Dp+0 - ldx _Dp+4 - ldy _Dp+6 - pld - plb - rti - -brk_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -abort_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - jump interrupt_return - -nmi_irq: - phb - phd - rep #0b00110000 - pha - phx - phy - .extern nmi_handler - long_a - call long:nmi_handler - jump interrupt_return - -interrupt_return: - rep #0b00110000 - ply - plx - pla - pld - plb - jump interrupt_return - - ; This section gets copied to 0x00FF80 - .section irq_vectors -; Native mode IRQ vectors - .word .word0(timer0_irq) - .word .word0(timer1_irq) - .word .word0(timer2_irq) - .word .word0(timer3_irq) - .word .word0(timer4_irq) - .word .word0(timer5_irq) - .word .word0(timer6_irq) - .word .word0(timer7_irq) - .word .word0(pe56_irq) - .word .word0(ne57_irq) - .word .word0(pe60_irq) - .word .word0(pe62_irq) - .word .word0(ne64_irq) - .word .word0(ne66_irq) - .word .word0(pib_irq) - .word .word0(level_irq) - .word .word0(uart_0_rx_irq) - .word .word0(uart_0_tx_irq) - .word .word0(uart_1_rx_irq) - .word .word0(uart_1_tx_irq) - .word .word0(uart_2_rx_irq) - .word .word0(uart_2_tx_irq) - .word .word0(uart_3_rx_irq) - .word .word0(uart_3_tx_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(cop_irq) - .word .word0(brk_irq) - .word .word0(abort_irq) - .word .word0(nmi_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - - ; Emulation mode is not supported right now. - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) - .word .word0(reserved_irq) \ No newline at end of file