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:
38
sw/bios/Makefile
Normal file
38
sw/bios/Makefile
Normal 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
14
sw/bios/boot.s
Normal 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
|
||||
|
||||
55
sw/bios/devices/interrupt.s
Normal file
55
sw/bios/devices/interrupt.s
Normal 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
1
sw/bios/devices/io.inc65
Symbolic link
@@ -0,0 +1 @@
|
||||
../../kernel/devices/io.inc65
|
||||
1
sw/bios/devices/sd_card.c
Symbolic link
1
sw/bios/devices/sd_card.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../../kernel/devices/sd_card.c
|
||||
1
sw/bios/devices/sd_card.h
Symbolic link
1
sw/bios/devices/sd_card.h
Symbolic link
@@ -0,0 +1 @@
|
||||
../../kernel/devices/sd_card.h
|
||||
1
sw/bios/devices/sd_card_asm.s
Symbolic link
1
sw/bios/devices/sd_card_asm.s
Symbolic link
@@ -0,0 +1 @@
|
||||
../../kernel/devices/sd_card_asm.s
|
||||
19
sw/bios/link.ld
Normal file
19
sw/bios/link.ld
Normal 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
29
sw/bios/load_bootsect.c
Normal 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
14
sw/bios/vectors.s
Normal 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
|
||||
Reference in New Issue
Block a user