forked from amberisvibin/chibi-pc09
Compare commits
9 Commits
9c668967d5
...
main
Author | SHA1 | Date | |
---|---|---|---|
e3352fab06
|
|||
b4d44f4e84
|
|||
da1d22988e
|
|||
cc8a9fc95f
|
|||
a0427ad949
|
|||
0845370c43 | |||
347b6fa236 | |||
677b3cb02d
|
|||
c67176e99a
|
3
code/boot/.gitignore
vendored
3
code/boot/.gitignore
vendored
@@ -5,3 +5,6 @@
|
||||
*.s19
|
||||
map.txt
|
||||
build/
|
||||
|
||||
# Build system generated files
|
||||
src/version.s
|
||||
|
@@ -1,31 +1,37 @@
|
||||
# Boot Firmware for CHIBI PC-09
|
||||
|
||||
TODO: Description of what the firmware does for the PC-09.
|
||||
This is the firmware for the CHIBI PC-09. In the future it will provide the
|
||||
CHIBI with initialization code, a UART driver, some self test features.
|
||||
|
||||
## Building the Firmware
|
||||
|
||||
You will need GNU `make`, and [`asm6809`](https://www.6809.org.uk/asm6809) to
|
||||
build the firmware. Obtaining a working copy of `asm6809` could be difficult if
|
||||
you aren't on Debian, Ubuntu, or Windows as instructions for building it are not
|
||||
given on the `asm6809` website. Functional instructions for building from Git or
|
||||
tarball are given here:
|
||||
Building the firmware from source requires [LWTOOLS](http://www.lwtools.ca/) for
|
||||
building S-Records of the ROM, and `mot2bin` from
|
||||
[F9DASM](https://github.com/Arakula/f9dasm) for building binary images. A GNU
|
||||
Make makefile is provided for building on Linux.
|
||||
|
||||
### Using the Makefile
|
||||
|
||||
To generate an S-Record run:
|
||||
|
||||
```sh
|
||||
git clone https://www.6809.org.uk/git/asm6809.git
|
||||
cd asm6809
|
||||
./configure
|
||||
make
|
||||
sudo make install
|
||||
make generate
|
||||
make boot.s19
|
||||
```
|
||||
|
||||
From there all you should have to do to generate a `boot.bin` is:
|
||||
To generate a binary run:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/amberisvibin/chibi-pc09.git
|
||||
cd chibi-pc09/code/boot
|
||||
make generate
|
||||
make
|
||||
```
|
||||
|
||||
The makefile also can clean up after itself:
|
||||
|
||||
```sh
|
||||
make clean
|
||||
```
|
||||
|
||||
## Firmware Licensing
|
||||
|
||||
This firmware like the rest of the CHIBI PC-09 is licensed under the MIT
|
||||
|
33
code/boot/genver.sh
Executable file
33
code/boot/genver.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Script to generate version information
|
||||
|
||||
# Current git tag
|
||||
TAG="$(git describe --always --dirty --tags)"
|
||||
DATE="$(date)"
|
||||
|
||||
# Output filename
|
||||
OUTFILE='src/version.s'
|
||||
|
||||
sed -e "s/<TAG>/$TAG/g" -e "s/<DATE>/$DATE/g" <<EOF > "$OUTFILE"
|
||||
; CHIBI PC-09 Prototype #1 Boot ROM -- Version Information
|
||||
; Copyright (c) 2024-2025 Amber Zeller, Gale Faraday
|
||||
; Licensed under MIT
|
||||
|
||||
; This file generated by genver.sh
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; Boot ROM Version & Build Information
|
||||
;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
SECTION VERSION
|
||||
|
||||
EXPORT VERMSG
|
||||
|
||||
VERMSG
|
||||
fcc "CHIBI PC-09 BOOT ROM <TAG>"
|
||||
fcb \$0A
|
||||
fcn "BUILT <DATE>"
|
||||
EOF
|
6
code/boot/linkscript
Normal file
6
code/boot/linkscript
Normal file
@@ -0,0 +1,6 @@
|
||||
section RESET load 8000
|
||||
section SERIAL
|
||||
section MEMTEST
|
||||
|
||||
section VECTORS high 100000
|
||||
section VERSION high
|
@@ -1,6 +1,6 @@
|
||||
# Makefile for CHIBI PC-09 Firmware
|
||||
|
||||
.PHONY: all clean
|
||||
.PHONY: generate all clean
|
||||
.IGNORE: clean
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
@@ -8,26 +8,52 @@
|
||||
# Project Defaults & Folders
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
TARGET := boot.bin
|
||||
TARGET := boot
|
||||
TARGREC := $(TARGET).s19
|
||||
TARGROM := $(TARGET).bin
|
||||
SRCDIR := src/
|
||||
MAINSRC := $(SRCDIR)boot.s
|
||||
BUILDDIR := build/
|
||||
GENS := $(SRCDIR)version.s
|
||||
SRCS := $(wildcard $(SRCDIR)*.s)
|
||||
OBJS := $(patsubst $(SRCDIR)%.s,$(BUILDDIR)%.o,$(SRCS))
|
||||
INCS := $(wildcard $(SRCDIR)*.inc)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Toolchain Definitions
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
AS := asm6809
|
||||
AS := lwasm
|
||||
LD := lwlink
|
||||
FIX := objcopy
|
||||
|
||||
ASFLAGS := -f obj
|
||||
LDFLAGS := -f srec -m map.txt -s linkscript
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Rules and Phony Targets
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
all: $(TARGET)
|
||||
all: $(TARGROM)
|
||||
|
||||
$(TARGET): $(SRCS) $(INCS)
|
||||
$(AS) -o $(TARGET) $(MAINSRC)
|
||||
# Fix srec into flashable bin file
|
||||
$(TARGROM): $(TARGREC)
|
||||
$(FIX) -I srec -O binary $< $@
|
||||
|
||||
# Link objects
|
||||
$(TARGREC): $(OBJS)
|
||||
$(LD) $(LDFLAGS) -o $@ $^
|
||||
|
||||
# Assemble objects
|
||||
$(OBJS): $(BUILDDIR)%.o : $(SRCDIR)%.s
|
||||
-@mkdir -p $(BUILDDIR)
|
||||
$(AS) $(ASFLAGS) -o $@ $<
|
||||
|
||||
generate: $(GENS)
|
||||
|
||||
$(GENS):
|
||||
./genver.sh
|
||||
|
||||
clean:
|
||||
rm -v $(TARGET)
|
||||
@echo 'Cleaning up intermediary files...'
|
||||
@rm -rv $(TARGROM) $(TARGREC) map.txt $(BUILDDIR)
|
||||
@rm -rv $(GENS)
|
||||
|
@@ -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 "src/hardware.inc"
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; Hardware Initialization Routines
|
||||
;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
SECTION "Reset"
|
||||
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
|
||||
1
|
||||
lda UART_LSR ; if LSR.THRE == 1 then write
|
||||
anda UARTF_LSR_THRE
|
||||
bne 1B ; 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 x ; Get the next value from X
|
||||
cmpb #$00 ; Make sure that mother is non-null
|
||||
beq 2F
|
||||
leax 1,x ; Increment X for our next char
|
||||
1 ; Loop point for UART waiting
|
||||
lda UART_LSR ; Wait for UART to be ready
|
||||
anda UARTF_LSR_THRE
|
||||
bne 1B
|
||||
stb UART_BUFR ; Actually do our write
|
||||
bra OUTSTR ; Reset for the next char
|
||||
2 ; 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
|
||||
1 ; Store 1 in memory
|
||||
lda #1 ; Set [X] to 1
|
||||
sta 0,x
|
||||
cmpa 0,x ; If failed print out an error indicator
|
||||
bne 3F
|
||||
2 ; Loop point for next address
|
||||
asla ; Shift A and [X] left
|
||||
asl 0,x
|
||||
cmpa 0,x ; Compare A and [X]
|
||||
bne 3F
|
||||
cmpa #$80 ; Only test up to $80
|
||||
bne 2B ; Loop if not $80
|
||||
cmpx #$60FF ; Compare X to end of RAM
|
||||
beq 4F ; Finish if we're at the end
|
||||
leax 1,x ; Increment X
|
||||
bra 1B
|
||||
3 ; Write out error indicator
|
||||
ldb #'X
|
||||
jsr OUTCHAR
|
||||
4 ; 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
|
@@ -1,7 +1,9 @@
|
||||
; CHIBI PC-09 Hardware Definitions
|
||||
; Copyright (c) 2024 Amber Zeller, Gale Faraday
|
||||
; Copyright (c) 2024-2025 Amber Zeller, Gale Faraday
|
||||
; Licensed under MIT
|
||||
|
||||
; vim: ft=asm
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; Hardware Base Addresses
|
||||
@@ -13,6 +15,16 @@ UART_BASE EQU $7F00 ; UART Base Address
|
||||
ROM_BASE EQU $8000 ; ROM Base Address and Entry Point
|
||||
VECS_BASE EQU $FFF0 ; Vectors Base Address
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; Stack Base Address and Size Information
|
||||
;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
STACK_BOTTOM EQU $0100 ; Bottom address of system stack
|
||||
STACK_DEPTH EQU $FF ; System stack's depth
|
||||
STACK_TOP EQU STACK_BOTTOM+STACK_DEPTH ; Top address of system stack
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; UART Registers and Flags
|
||||
@@ -93,4 +105,3 @@ UARTF_MSR_DSR EQU %00000100 ; Data Set Ready
|
||||
UARTF_MSR_RI EQU %00000010 ; Ring Indicator
|
||||
UARTF_MSR_DCD EQU %00000001 ; Data Carrier Detect
|
||||
|
||||
; vim: ft=asm
|
||||
|
42
code/boot/src/memtest.s
Normal file
42
code/boot/src/memtest.s
Normal file
@@ -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
|
7
code/boot/src/reset.inc
Normal file
7
code/boot/src/reset.inc
Normal file
@@ -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
|
49
code/boot/src/reset.s
Normal file
49
code/boot/src/reset.s
Normal file
@@ -0,0 +1,49 @@
|
||||
; 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
|
||||
|
||||
CLRSTACK
|
||||
; Initialize the system stack
|
||||
lda #$00 ; Initialize A & X to zero out the stack
|
||||
ldx #$0000
|
||||
NEXT@
|
||||
sta STACK_BOTTOM,x ; Write a zero and progress to the next byte
|
||||
leax 1,x
|
||||
cmpx #STACK_DEPTH ; See if we're at the top of the stack yet
|
||||
blo NEXT@ ; Loop if we aren't at the end yet
|
||||
lds #STACK_TOP ; Set S to top of newly cleared stack
|
||||
|
||||
SERINIT
|
||||
; 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
|
8
code/boot/src/serial.inc
Normal file
8
code/boot/src/serial.inc
Normal file
@@ -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
|
45
code/boot/src/serial.s
Normal file
45
code/boot/src/serial.s
Normal file
@@ -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
|
23
code/boot/src/vecs.s
Normal file
23
code/boot/src/vecs.s
Normal file
@@ -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
|
Reference in New Issue
Block a user