From 677b3cb02d4a82a171e296a98db93a78eff0ee64 Mon Sep 17 00:00:00 2001 From: Gale Faraday Date: Sun, 31 Aug 2025 14:42:14 -0500 Subject: [PATCH] feat: modularized with lwtools build system --- code/boot/linkscript | 4 +- code/boot/makefile | 2 +- code/boot/src/boot.s | 118 --------------------------------------- code/boot/src/memtest.s | 42 ++++++++++++++ code/boot/src/reset.inc | 7 +++ code/boot/src/reset.s | 35 ++++++++++++ code/boot/src/serial.inc | 8 +++ code/boot/src/serial.s | 45 +++++++++++++++ code/boot/src/vecs.s | 23 ++++++++ 9 files changed, 164 insertions(+), 120 deletions(-) delete mode 100644 code/boot/src/boot.s create mode 100644 code/boot/src/memtest.s create mode 100644 code/boot/src/reset.inc create mode 100644 code/boot/src/reset.s create mode 100644 code/boot/src/serial.inc create mode 100644 code/boot/src/serial.s create mode 100644 code/boot/src/vecs.s diff --git a/code/boot/linkscript b/code/boot/linkscript index 4bfb66f..e36add1 100644 --- a/code/boot/linkscript +++ b/code/boot/linkscript @@ -1,3 +1,5 @@ -section CODE load 8000 +section RESET load 8000 +section SERIAL +section MEMTEST section VECTORS high 100000 diff --git a/code/boot/makefile b/code/boot/makefile index 81b3316..b6207fa 100644 --- a/code/boot/makefile +++ b/code/boot/makefile @@ -39,7 +39,7 @@ $(TARGROM): $(TARGET).s19 # Link objects $(TARGET).s19: $(OBJS) - $(LD) $(LDFLAGS) -o $@ $< + $(LD) $(LDFLAGS) -o $@ $^ # Assemble objects $(OBJS): $(BUILDDIR)%.o : $(SRCDIR)%.s diff --git a/code/boot/src/boot.s b/code/boot/src/boot.s deleted file mode 100644 index 5c31e6d..0000000 --- a/code/boot/src/boot.s +++ /dev/null @@ -1,118 +0,0 @@ -; CHIBI PC-09 Prototype #1 Boot ROM -- Hardware Initialization and Reset Vecs -; Copyright (c) 2024 Amber Zeller, Gale Faraday -; Licensed under MIT - - INCLUDE "hardware.inc" - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; Hardware Initialization Routines -;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - SECTION CODE - ;ORG ROM_BASE - -RESET - ; 8n1 Serial Enable DLAB - lda #UARTF_LCR_WLS | UARTF_LCR_DLAB - sta UART_LCR - - ; REVIEW: Potential endianness hiccough here - ldd #$0C00 ; Set divisor to 12 (9600 baud) - sta UART_DLM - stb UART_DLL - - lda #(UARTF_LCR_WLS) ; 8n1 serial, disable DLAB - sta UART_LCR - - lda #(UARTF_MCR_RTS) ; Enable Request-to-Send - sta UART_MCR - - lda #'H ; send 'H' - sta UART_BUFR - -WAIT - sync ; Wait for interrupts - nop - bra WAIT - - ;SECTION "Serial" - -; Writes a char to the UART in non FIFO mode, preserves A. -; @param b: char to write -OUTCHAR - pshs a ; Preserve A -NOTREADY@ - lda UART_LSR ; if LSR.THRE == 1 then write - anda UARTF_LSR_THRE - bne NOTREADY@ ; Loop if UART not ready yet - stb UART_BUFR ; Write char - puls a ; Restore A - rts - -; Writes a null terminated string to the UART in non FIFO mode, clobbers A and -; B. -; @param x: null terminated string start address. -OUTSTR - ldb 0,x ; Get the next value from X - cmpb #$00 ; Make sure that we aren't at a terminator - beq END@ - leax 1,x ; Increment X for our next char -NOTREADY@ ; Loop point for UART waiting - lda UART_LSR ; Wait for UART to be ready - anda UARTF_LSR_THRE - bne NOTREADY@ - stb UART_BUFR ; Actually do our write - bra OUTSTR ; Reset for the next char -END@ ; Jump point for end of routine - rts - - ;SECTION "Memtest" - -; RAM testing routine. Ported to 6809 from 6800, based on source for ROBIT-2 for -; MIKBUG. -RAMTEST - ldx #SRAM_BASE -AGAIN@ ; Store 1 in memory - lda #1 ; Set [X] to 1 - sta 0,x - cmpa 0,x ; If failed print out an error indicator - bne ERR@ -NEXT@ ; Loop point for next address - asla ; Shift A and [X] left - asl 0,x - cmpa 0,x ; Compare A and [X] - bne ERR@ - cmpa #$80 ; Only test up to $80 - bne NEXT@ ; Loop if not $80 - cmpx #$60FF ; Compare X to end of RAM - beq PASS@ ; Finish if we're at the end - leax 1,x ; Increment X - bra AGAIN@ -ERR@ ; Write out error indicator - ldb #'X - jsr OUTCHAR -PASS@ ; Pass test - ldb #'P - jsr OUTCHAR - rts - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; Interrupt and Reset Vectors -;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - SECTION VECTORS - ;ORG VECS_BASE - -VECTORS - fdb $0000 ; Reserved - fdb $0000 ; SWI3 - fdb $0000 ; SWI2 - fdb $0000 ; FIRQ - fdb $0000 ; IRQ - fdb $0000 ; SWI - fdb $0000 ; NMI - fdb RESET ; Reset diff --git a/code/boot/src/memtest.s b/code/boot/src/memtest.s new file mode 100644 index 0000000..8c1cdc4 --- /dev/null +++ b/code/boot/src/memtest.s @@ -0,0 +1,42 @@ +; CHIBI PC-09 Prototype #1 Boot ROM -- Memory Testing Routines +; Copyright (c) 2024-2025 Amber Zeller, Gale Faraday +; Licensed under MIT + + INCLUDE "hardware.inc" + INCLUDE "serial.inc" + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Memory Testing Routines +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + SECTION MEMTEST + +; RAM testing routine. Ported to 6809 from 6800, based on source for ROBIT-2 for +; MIKBUG. +RAMTEST + ldx #SRAM_BASE +AGAIN@ ; Store 1 in memory + lda #1 ; Set [X] to 1 + sta 0,x + cmpa 0,x ; If failed print out an error indicator + bne ERR@ +NEXT@ ; Loop point for next address + asla ; Shift A and [X] left + asl 0,x + cmpa 0,x ; Compare A and [X] + bne ERR@ + cmpa #$80 ; Only test up to $80 + bne NEXT@ ; Loop if not $80 + cmpx #$60FF ; Compare X to end of RAM + beq PASS@ ; Finish if we're at the end + leax 1,x ; Increment X + bra AGAIN@ +ERR@ ; Write out error indicator + ldb #'X + jsr OUTCHAR +PASS@ ; Pass test + ldb #'P + jsr OUTCHAR + rts diff --git a/code/boot/src/reset.inc b/code/boot/src/reset.inc new file mode 100644 index 0000000..cde2374 --- /dev/null +++ b/code/boot/src/reset.inc @@ -0,0 +1,7 @@ +; CHIBI PC-09 Prototype #1 -- Reset Handler Header +; Copyright (c) 2025 Amber Zeller, Gale Faraday +; Licensed under MIT + +; vim: ft=asm + +RESET IMPORT diff --git a/code/boot/src/reset.s b/code/boot/src/reset.s new file mode 100644 index 0000000..32a96a1 --- /dev/null +++ b/code/boot/src/reset.s @@ -0,0 +1,35 @@ +; CHIBI PC-09 Prototype #1 Boot ROM -- Reset Handler +; Copyright (c) 2024-2025 Amber Zeller, Gale Faraday +; Licensed under MIT + + INCLUDE "hardware.inc" + INCLUDE "serial.inc" + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Hardware Initialization Routines +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + SECTION RESET + + EXPORT RESET + +RESET + ; 8n1 Serial Enable DLAB + lda #UARTF_LCR_WLS | UARTF_LCR_DLAB + sta UART_LCR + ; REVIEW: Potential endianness hiccough here + ldd #$0C00 ; Set divisor to 12 (9600 baud) + sta UART_DLM + stb UART_DLL + lda #(UARTF_LCR_WLS) ; 8n1 serial, disable DLAB + sta UART_LCR + lda #(UARTF_MCR_RTS) ; Enable Request-to-Send + sta UART_MCR + lda #'H ; send 'H' + sta UART_BUFR +WAIT@ + sync ; Wait for interrupts + nop + bra WAIT@ diff --git a/code/boot/src/serial.inc b/code/boot/src/serial.inc new file mode 100644 index 0000000..64c4f60 --- /dev/null +++ b/code/boot/src/serial.inc @@ -0,0 +1,8 @@ +; CHIBI PC-09 Prototype #1 -- Serial Driver Header +; Copyright (c) 2025 Amber Zeller, Gale Faraday +; Licensed under MIT + +; vim: ft=asm + +OUTCHAR IMPORT +OUTSTR IMPORT diff --git a/code/boot/src/serial.s b/code/boot/src/serial.s new file mode 100644 index 0000000..f43d2d9 --- /dev/null +++ b/code/boot/src/serial.s @@ -0,0 +1,45 @@ +; CHIBI PC-09 Prototype #1 Boot ROM -- Serial Driver +; Copyright (c) 2024-2025 Amber Zeller, Gale Faraday +; Licensed under MIT + + INCLUDE "hardware.inc" + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Serial UART Driver +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + SECTION SERIAL + + EXPORT OUTCHAR + EXPORT OUTSTR + +; Writes a char to the UART in non FIFO mode, preserves A. +; @param b: char to write +OUTCHAR + pshs a ; Preserve A +NOTREADY@ + lda UART_LSR ; if LSR.THRE == 1 then write + anda UARTF_LSR_THRE + bne NOTREADY@ ; Loop if UART not ready yet + stb UART_BUFR ; Write char + puls a ; Restore A + rts + +; Writes a null terminated string to the UART in non FIFO mode, clobbers A and +; B. +; @param x: null terminated string start address. +OUTSTR + ldb 0,x ; Get the next value from X + cmpb #$00 ; Make sure that we aren't at a terminator + beq END@ + leax 1,x ; Increment X for our next char +NOTREADY@ ; Loop point for UART waiting + lda UART_LSR ; Wait for UART to be ready + anda UARTF_LSR_THRE + bne NOTREADY@ + stb UART_BUFR ; Actually do our write + bra OUTSTR ; Reset for the next char +END@ ; Jump point for end of routine + rts diff --git a/code/boot/src/vecs.s b/code/boot/src/vecs.s new file mode 100644 index 0000000..3162a2c --- /dev/null +++ b/code/boot/src/vecs.s @@ -0,0 +1,23 @@ +; CHIBI PC-09 Prototype #1 Boot ROM -- Interrupt and Reset Vectors +; Copyright (c) 2024-2025 Amber Zeller, Gale Faraday +; Licensed under MIT + + INCLUDE "reset.inc" + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Interrupt and Reset Vectors +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + SECTION VECTORS + +VECTORS + fdb $0000 ; Reserved + fdb $0000 ; SWI3 + fdb $0000 ; SWI2 + fdb $0000 ; FIRQ + fdb $0000 ; IRQ + fdb $0000 ; SWI + fdb $0000 ; NMI + fdb RESET ; Reset