Rename boot to bios, add sd call

Adds a call that you can make to the BIOS to read sd blocks. Useful for
the bootloader where there is not much space
This commit is contained in:
Byron Lathi
2022-04-18 20:24:29 -05:00
parent 64f6f0b397
commit 54328722ab
10 changed files with 72 additions and 9 deletions

38
sw/bios/Makefile Normal file
View File

@@ -0,0 +1,38 @@
CC=cl65
CFLAGS=-T -t none -I. --cpu "65C02"
test: CFLAGS=-T -t sim65c02 -I.
LDFLAGS=-C link.ld -m $(NAME).map
NAME=bios
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

14
sw/bios/boot.s Normal file
View File

@@ -0,0 +1,14 @@
.include "zeropage.inc"
.segment "STARTUP"
.export _init
.import _load_bootsect
_init: ldx #$ff
txs
cld
jsr _load_bootsect
jmp $1000

View File

@@ -0,0 +1,55 @@
.include "io.inc65"
.export _irq_int, _nmi_int
.importzp sreg, ptr1
.segment "CODE"
; IRQ
_irq_int:
jmp (irqmap,x)
_nmi_int:
rti
irqmap:
.addr handle_invalid
.addr handle_sd_read
handle_invalid:
rti
; 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
handle_sd_read:
sta SD_ARG ; send command
sty SD_ARG+1
stz SD_ARG+2
stz SD_ARG+3
lda #$11
sta SD_CMD
@1: lda SD_CMD ; wait for status flag
and #$01
beq @1
@2: lda SD_CMD ; wait for data
and #$02
beq @2
ldy #$00
@loop: lda SD_DATA ; copy first 256 bytes
sta (sreg),y
iny
bne @loop
ldy #$00 ; copy second 256 bytes
inc sreg+1
@loop2: lda SD_DATA
sta (sreg),y
iny
bne @loop2
rti

1
sw/bios/devices/io.inc65 Symbolic link
View File

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

1
sw/bios/devices/sd_card.c Symbolic link
View File

@@ -0,0 +1 @@
../../kernel/devices/sd_card.c

1
sw/bios/devices/sd_card.h Symbolic link
View File

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

View File

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

19
sw/bios/link.ld Normal file
View File

@@ -0,0 +1,19 @@
MEMORY
{
ZP: start = $0, size = $100, type = rw, define = yes;
SDRAM: start = $1000, size = $6ef0, type = rw, define = yes;
ROM: start = $8000, size = $8000, fill = yes, fillval = $ff, file = %O;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp, define = yes;
DATA: load = ROM, type = rw, define = yes, run = SDRAM;
BSS: load = SDRAM, type = bss, define = yes;
HEAP: load = SDRAM, type = bss, optional = yes;
STARTUP: load = ROM, type = ro;
ONCE: load = ROM, type = ro, optional = yes;
CODE: load = ROM, type = ro;
RODATA: load = ROM, type = ro;
VECTORS: load = ROM, type = ro, start = $FFFA;
}

29
sw/bios/load_bootsect.c Normal file
View File

@@ -0,0 +1,29 @@
#include <stdint.h>
#include "devices/sd_card.h"
#define BOOTSECTOR_LOAD_ADDRESS 0x1000
#define BOOTSIG_0 0x55
#define BOOTSIG_1 0xaa
//Should probably do this in asm
void load_bootsect() {
uint32_t rca;
uint8_t sig[2];
sd_init();
rca = sd_get_rca();
sd_select_card(rca);
sd_readblock(0, (uint8_t*)BOOTSECTOR_LOAD_ADDRESS);
sig[0] = ((uint8_t*)BOOTSECTOR_LOAD_ADDRESS)[510];
sig[1] = ((uint8_t*)BOOTSECTOR_LOAD_ADDRESS)[511];
if (sig[0] != BOOTSIG_0 || sig[1] != BOOTSIG_1) {
for(;;); //maybe figure out a way to have an error message here
}
return;
}

14
sw/bios/vectors.s Normal file
View File

@@ -0,0 +1,14 @@
; ---------------------------------------------------------------------------
; vectors.s
; ---------------------------------------------------------------------------
;
; Defines the interrupt vector table.
.import _init
.import _nmi_int, _irq_int
.segment "VECTORS"
.addr _nmi_int ; NMI vector
.addr _init ; Reset vector
.addr _irq_int ; IRQ/BRK vector