Create boot environment
The boot environment will read the boot sector from the sd card, verify that it has the boot signature at the end, then jump to the start of it. From there, there should be a bootloader written to the boot segment that can handle the rest. It might be tight to fit everything into the boot sector but do remember that you do not have to initialize or select the sd card, and those functions take up a lot of space.
This commit is contained in:
42
sw/boot/Makefile
Normal file
42
sw/boot/Makefile
Normal file
@@ -0,0 +1,42 @@
|
||||
CC=cl65
|
||||
CFLAGS=-T -t none -I. --cpu "65C02"
|
||||
test: CFLAGS=-T -t sim65c02 -I.
|
||||
LDFLAGS=-C link.ld -m $(NAME).map
|
||||
SIM=sim65
|
||||
SIMARGS=-v -c -x 1000000
|
||||
|
||||
NAME=bootrom
|
||||
|
||||
TEST_BIN=test.bin
|
||||
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
|
||||
|
||||
17
sw/boot/boot.s
Normal file
17
sw/boot/boot.s
Normal file
@@ -0,0 +1,17 @@
|
||||
; 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"
|
||||
|
||||
.segment "STARTUP"
|
||||
|
||||
.import _load_bootsect
|
||||
|
||||
_init: ldx #$ff
|
||||
txs
|
||||
cld
|
||||
|
||||
jsr _load_bootsect
|
||||
jmp $1000
|
||||
|
||||
1
sw/boot/devices/io.inc65
Symbolic link
1
sw/boot/devices/io.inc65
Symbolic link
@@ -0,0 +1 @@
|
||||
../../kernel/devices/io.inc65
|
||||
1
sw/boot/devices/sd_card.c
Symbolic link
1
sw/boot/devices/sd_card.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../../kernel/devices/sd_card.c
|
||||
1
sw/boot/devices/sd_card.h
Symbolic link
1
sw/boot/devices/sd_card.h
Symbolic link
@@ -0,0 +1 @@
|
||||
../../kernel/devices/sd_card.h
|
||||
1
sw/boot/devices/sd_card_asm.s
Symbolic link
1
sw/boot/devices/sd_card_asm.s
Symbolic link
@@ -0,0 +1 @@
|
||||
../../kernel/devices/sd_card_asm.s
|
||||
18
sw/boot/link.ld
Normal file
18
sw/boot/link.ld
Normal file
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
}
|
||||
|
||||
29
sw/boot/load_bootsect.c
Normal file
29
sw/boot/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;
|
||||
}
|
||||
Reference in New Issue
Block a user