Add preliminary bootloader

This bootloader right now just prints the letter A, but should be
capable of reading blocks from the SD card into memory.
This commit is contained in:
Byron Lathi
2022-04-18 20:25:08 -05:00
parent 54328722ab
commit 9dd460a47f
10 changed files with 129 additions and 0 deletions

41
sw/bootloader/Makefile Normal file
View File

@@ -0,0 +1,41 @@
CC=cl65
CFLAGS=-T -t none -I. --cpu "65C02" -DNO_SD_INIT
test: CFLAGS=-T -t sim65c02 -I.
LDFLAGS=-C link.ld -m $(NAME).map
SIM=sim65
SIMARGS=-v -c -x 1000000
NAME=bootloader
BIN=$(NAME).bin
HEX=$(NAME).hex
LISTS=lists
SRCS=$(wildcard *.s) $(wildcard *.c)
SRCS+=$(filter-out $(wildcard tests/*), $(wildcard **/*.s)) $(filter-out $(wildcard tests/*), $(wildcard **/*.c))
OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS)))
OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS)))
all: $(HEX)
$(HEX): $(BIN)
objcopy --input-target=binary --output-target=ihex $(BIN) $(HEX)
$(BIN): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@
%.o: %.c $(LISTS)
$(CC) $(CFLAGS) -l $(LISTS)/$<.list -c $< -o $@
%.o: %.s $(LISTS)
$(CC) $(CFLAGS) -l $(LISTS)/$<.list -c $< -o $@
$(LISTS):
mkdir -p $(addprefix $(LISTS)/,$(sort $(dir $(SRCS))))
.PHONY: clean
clean:
rm -rf $(OBJS) $(BIN) $(HEX) $(LISTS) $(NAME).map

0
sw/bootloader/bios_calls Normal file
View File

View File

@@ -0,0 +1,8 @@
#ifndef _BIOS_CALLS_H
#define _BIOS_CALLS_H
#include <stdint.h>
void sd_readblock(uint16_t addr, void* buf);
#endif

View File

@@ -0,0 +1,23 @@
.export _sd_readblock
.autoimport
.importzp sreg
; sreg is the pointer to store the data
; a/y is the block address
; send command 17 with the block address of 00/y/a
; void sd_readblock(uint16_t addr, void* buf);
_sd_readblock:
sta sreg ; move buf pointer to sreg
stx sreg+1
jsr popax ; move addr to a/y
tya
ldx #$1 ; call interrupt 1
brk
rts

26
sw/bootloader/boot.s Normal file
View File

@@ -0,0 +1,26 @@
; We need to to read the boot sector from the
; SD card, verify the last 2 bytes, then jump to the
; beginning of it.
.include "zeropage.inc"
.import _load_bootsect
.export _init, _boot
.segment "STARTUP"
_init: jmp _boot
.segment "CODE"
_boot: ldx #$ff
txs
cld
jsr _load_bootsect
jmp $1000
.segment "SIGN"
.byte $55
.byte $aa

1
sw/bootloader/io.inc65 Symbolic link
View File

@@ -0,0 +1 @@
../kernel/devices/io.inc65

17
sw/bootloader/link.ld Normal file
View File

@@ -0,0 +1,17 @@
MEMORY
{
ZP: start = $0, size = $100, type = rw, define = yes;
BOOTSECT: start = $1000, size = $200, file = %O;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp, define = yes;
DATA: load = BOOTSECT, type = rw, define = yes;
BSS: load = BOOTSECT, type = bss, define = yes;
HEAP: load = BOOTSECT, type = bss, optional = yes;
STARTUP: load = BOOTSECT, type = ro, start = $1000;
CODE: load = BOOTSECT, type = ro, start = $105a;
RODATA: load = BOOTSECT, type = ro;
SIGN: load = BOOTSECT, type = ro, start = $11fe;
}

11
sw/bootloader/main.c Normal file
View File

@@ -0,0 +1,11 @@
#include <stdint.h>
#include "bios_calls.h"
#include "uart.h"
//Should probably do this in asm
void load_bootsect() {
uart_txb_block('A');
for (;;);
return;
}

1
sw/bootloader/uart.h Symbolic link
View File

@@ -0,0 +1 @@
../kernel/devices/uart.h

1
sw/bootloader/uart.s Symbolic link
View File

@@ -0,0 +1 @@
../kernel/devices/uart.s