Rename bootloader to bios, add actual bootloader
This commit is contained in:
56
sw/bios/Makefile
Normal file
56
sw/bios/Makefile
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
CC=../cc65/bin/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=bootloader
|
||||||
|
|
||||||
|
TEST_BIN=test.bin
|
||||||
|
BIN=$(NAME).bin
|
||||||
|
HEX=$(NAME).hex
|
||||||
|
|
||||||
|
LISTS=lists
|
||||||
|
TESTS=tests
|
||||||
|
|
||||||
|
SRCS=$(wildcard *.s) $(wildcard *.c)
|
||||||
|
SRCS+=$(filter-out $(wildcard tests/*), $(wildcard **/*.s)) $(filter-out $(wildcard tests/*) $(wildcard filesystem/*), $(wildcard **/*.c))
|
||||||
|
OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS)))
|
||||||
|
OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS)))
|
||||||
|
|
||||||
|
TEST_SRCS=$(wildcard $(TESTS)/*.s) $(wildcard $(TESTS)/*.c)
|
||||||
|
TEST_OBJS+=$(patsubst %.s,%.o,$(filter %s,$(TEST_SRCS)))
|
||||||
|
TEST_OBJS+=$(patsubst %.c,%.o,$(filter %c,$(TEST_SRCS)))
|
||||||
|
TEST_OBJS+=$(filter-out boot.o,$(filter-out main.o,$(filter-out vectors.o,$(OBJS))))
|
||||||
|
|
||||||
|
all: $(HEX)
|
||||||
|
|
||||||
|
test: $(TEST_BIN)
|
||||||
|
$(SIM) $(SIMARGS) $(TEST_BIN)
|
||||||
|
|
||||||
|
$(TEST_BIN): $(OBJS) $(TEST_OBJS)
|
||||||
|
$(CC) $(CFLAGS) $(TEST_OBJS) -o $@
|
||||||
|
|
||||||
|
$(HEX): $(BIN)
|
||||||
|
objcopy --input-target=binary --output-target=verilog $(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))))
|
||||||
|
mkdir $(LISTS)/$(sort $(dir $(TEST_SRCS)))
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -rf $(OBJS) $(BIN) $(HEX) $(LISTS) $(NAME).map
|
||||||
|
rm -rf $(TEST_OBJS) $(TEST_BIN)
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
; Checks for a BRK instruction and returns from all valid interrupts.
|
; Checks for a BRK instruction and returns from all valid interrupts.
|
||||||
|
|
||||||
.import _handle_irq
|
.import _handle_irq
|
||||||
|
.import _cputc, _clrscr
|
||||||
|
|
||||||
.export _irq_int, _nmi_int
|
.export _irq_int, _nmi_int
|
||||||
|
|
||||||
@@ -44,5 +45,53 @@ irq: PLA ; Restore accumulator contents
|
|||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; BRK detected, stop
|
; BRK detected, stop
|
||||||
|
|
||||||
break: JMP break ; If BRK is detected, something very bad
|
break:
|
||||||
; has happened, so stop running
|
|
||||||
|
|
||||||
|
bios_table:
|
||||||
|
.addr _console_clear
|
||||||
|
.addr _console_read_char
|
||||||
|
.addr _console_write_char
|
||||||
|
|
||||||
|
|
||||||
|
_console_clear:
|
||||||
|
jsr _clrscr
|
||||||
|
rti
|
||||||
|
|
||||||
|
_console_read_char:
|
||||||
|
; not supported
|
||||||
|
rti
|
||||||
|
|
||||||
|
_console_write_char:
|
||||||
|
jsr _cputc
|
||||||
|
rti
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; What functions do we need?
|
||||||
|
; UART
|
||||||
|
; clear
|
||||||
|
; write character
|
||||||
|
; read character
|
||||||
|
; DISK
|
||||||
|
; init (or should it just init on boot?)
|
||||||
|
; read sector into memory
|
||||||
|
; FS
|
||||||
|
; init (if disk init succeeds, should it always try?)
|
||||||
|
; find add
|
||||||
|
|
||||||
|
; I think that is all we need for now?
|
||||||
|
; How do we call the functions?
|
||||||
|
|
||||||
|
; we have to call `brk` to trigger the interrupt
|
||||||
|
; in any of the three registers we can have arguments
|
||||||
|
; or we could have them pushed to the stack, assuming
|
||||||
|
; the stack is in the same location
|
||||||
|
; Or you could pass a pointer which points to an array
|
||||||
|
; of arguments
|
||||||
|
|
||||||
|
; for things like clear, read/write character, and init you don't
|
||||||
|
; need any arguments.
|
||||||
|
|
||||||
|
; jump table index needs to be in x, but also needs to be a multiple
|
||||||
|
; of 2.
|
||||||
35
sw/bios/link.ld
Normal file
35
sw/bios/link.ld
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
ZP: start = $0, size = $100, type = rw, define = yes;
|
||||||
|
SDRAM: start = $200, size = $7cf0, type = rw, define = yes;
|
||||||
|
ROM: start = $F000, size = $1000, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
FEATURES {
|
||||||
|
CONDES: segment = STARTUP,
|
||||||
|
type = constructor,
|
||||||
|
label = __CONSTRUCTOR_TABLE__,
|
||||||
|
count = __CONSTRUCTOR_COUNT__;
|
||||||
|
CONDES: segment = STARTUP,
|
||||||
|
type = destructor,
|
||||||
|
label = __DESTRUCTOR_TABLE__,
|
||||||
|
count = __DESTRUCTOR_COUNT__;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYMBOLS {
|
||||||
|
# Define the stack size for the application
|
||||||
|
__STACKSIZE__: value = $0200, type = weak;
|
||||||
|
__STACKSTART__: type = weak, value = $0800; # 2k stack
|
||||||
|
}
|
||||||
@@ -1,39 +1,23 @@
|
|||||||
CC=../cc65/bin/cl65
|
CC=../cc65/bin/cl65
|
||||||
CFLAGS=-T -t none -I. --cpu "65C02"
|
CFLAGS=-T -t none -I. --cpu "65C02"
|
||||||
test: CFLAGS=-T -t sim65c02 -I.
|
|
||||||
LDFLAGS=-C link.ld -m $(NAME).map
|
LDFLAGS=-C link.ld -m $(NAME).map
|
||||||
SIM=sim65
|
|
||||||
SIMARGS=-v -c -x 1000000
|
|
||||||
|
|
||||||
NAME=bootloader
|
NAME=bootloader
|
||||||
|
|
||||||
TEST_BIN=test.bin
|
|
||||||
BIN=$(NAME).bin
|
BIN=$(NAME).bin
|
||||||
HEX=$(NAME).hex
|
HEX=$(NAME).hex
|
||||||
|
|
||||||
LISTS=lists
|
LISTS=lists
|
||||||
TESTS=tests
|
|
||||||
|
|
||||||
SRCS=$(wildcard *.s) $(wildcard *.c)
|
SRCS=$(wildcard *.s) $(wildcard *.c)
|
||||||
SRCS+=$(filter-out $(wildcard tests/*), $(wildcard **/*.s)) $(filter-out $(wildcard tests/*) $(wildcard filesystem/*), $(wildcard **/*.c))
|
|
||||||
OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS)))
|
OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS)))
|
||||||
OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS)))
|
OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS)))
|
||||||
|
|
||||||
TEST_SRCS=$(wildcard $(TESTS)/*.s) $(wildcard $(TESTS)/*.c)
|
|
||||||
TEST_OBJS+=$(patsubst %.s,%.o,$(filter %s,$(TEST_SRCS)))
|
|
||||||
TEST_OBJS+=$(patsubst %.c,%.o,$(filter %c,$(TEST_SRCS)))
|
|
||||||
TEST_OBJS+=$(filter-out boot.o,$(filter-out main.o,$(filter-out vectors.o,$(OBJS))))
|
|
||||||
|
|
||||||
all: $(HEX)
|
all: $(HEX)
|
||||||
|
|
||||||
test: $(TEST_BIN)
|
|
||||||
$(SIM) $(SIMARGS) $(TEST_BIN)
|
|
||||||
|
|
||||||
$(TEST_BIN): $(OBJS) $(TEST_OBJS)
|
|
||||||
$(CC) $(CFLAGS) $(TEST_OBJS) -o $@
|
|
||||||
|
|
||||||
$(HEX): $(BIN)
|
$(HEX): $(BIN)
|
||||||
objcopy --input-target=binary --output-target=verilog $(BIN) $(HEX)
|
objcopy --input-target=binary --output-target=ihex $(BIN) $(HEX)
|
||||||
|
|
||||||
|
|
||||||
$(BIN): $(OBJS)
|
$(BIN): $(OBJS)
|
||||||
@@ -47,7 +31,6 @@ $(BIN): $(OBJS)
|
|||||||
|
|
||||||
$(LISTS):
|
$(LISTS):
|
||||||
mkdir -p $(addprefix $(LISTS)/,$(sort $(dir $(SRCS))))
|
mkdir -p $(addprefix $(LISTS)/,$(sort $(dir $(SRCS))))
|
||||||
mkdir $(LISTS)/$(sort $(dir $(TEST_SRCS)))
|
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
23
sw/bootloader/bootloader.s
Normal file
23
sw/bootloader/bootloader.s
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
.segment "BOOTSECTOR"
|
||||||
|
|
||||||
|
|
||||||
|
_start:
|
||||||
|
jmp _main
|
||||||
|
|
||||||
|
.byte "SUPR6502"
|
||||||
|
|
||||||
|
_main:
|
||||||
|
brk
|
||||||
|
|
||||||
|
_end:
|
||||||
|
|
||||||
|
.res (446+_start-_end)
|
||||||
|
|
||||||
|
.res 16
|
||||||
|
.res 16
|
||||||
|
.res 16
|
||||||
|
.res 16
|
||||||
|
|
||||||
|
.byte $55
|
||||||
|
.byte $AA
|
||||||
|
|
||||||
@@ -1,35 +1,8 @@
|
|||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
ZP: start = $0, size = $100, type = rw, define = yes;
|
BOOT: start = $8000, size = $200, file = %O;
|
||||||
SDRAM: start = $200, size = $7cf0, type = rw, define = yes;
|
|
||||||
ROM: start = $F000, size = $1000, file = %O;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SEGMENTS {
|
SEGMENTS {
|
||||||
ZEROPAGE: load = ZP, type = zp, define = yes;
|
BOOTSECTOR: load = BOOT, start = $8000;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
FEATURES {
|
|
||||||
CONDES: segment = STARTUP,
|
|
||||||
type = constructor,
|
|
||||||
label = __CONSTRUCTOR_TABLE__,
|
|
||||||
count = __CONSTRUCTOR_COUNT__;
|
|
||||||
CONDES: segment = STARTUP,
|
|
||||||
type = destructor,
|
|
||||||
label = __DESTRUCTOR_TABLE__,
|
|
||||||
count = __DESTRUCTOR_COUNT__;
|
|
||||||
}
|
|
||||||
|
|
||||||
SYMBOLS {
|
|
||||||
# Define the stack size for the application
|
|
||||||
__STACKSIZE__: value = $0200, type = weak;
|
|
||||||
__STACKSTART__: type = weak, value = $0800; # 2k stack
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "devices/board_io.h"
|
|
||||||
#include "devices/uart.h"
|
|
||||||
#include "devices/interrupt.h"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int retval = 0;
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("\nStarting tests...\n\n");
|
|
||||||
|
|
||||||
printf("Testing hex_set_8...\n");
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
if (hex_set_8(i+1, i)) {
|
|
||||||
printf("Failed to write to idx %d!\n", i);
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
if (*(uint8_t*)0x7ff0+i != i+1) {
|
|
||||||
printf("Incorrect value at idx %d!\n", i);
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hex_set_8(0xab, 3)) {
|
|
||||||
printf("Writing to idx 3 should fail!\n");
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
printf("Done!\n\n");
|
|
||||||
|
|
||||||
printf("Testing hex_set_16...\n");
|
|
||||||
if (hex_set_16(0xabcd)){
|
|
||||||
printf("Failed to write!\n");
|
|
||||||
}
|
|
||||||
if (*(uint16_t*)0x7ff0 != 0xabcd) {
|
|
||||||
printf("Incorrect value!\n", i);
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
printf("Done!\n\n");
|
|
||||||
|
|
||||||
printf("Testing hex_set_24...\n");
|
|
||||||
if (hex_set_24(0xabcdef)){
|
|
||||||
printf("Failed to write!\n");
|
|
||||||
}
|
|
||||||
if (*(uint16_t*)0x7ff0 != 0xcdef && *(uint8_t*)0x7ff2 != 0xab) {
|
|
||||||
printf("Incorrect value!\n", i);
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
printf("Done!\n\n");
|
|
||||||
|
|
||||||
printf("Testing hex_enable...\n");
|
|
||||||
hex_enable(0xa5);
|
|
||||||
if (*(uint8_t*)0x7ff3 != 0xa5) {
|
|
||||||
printf("Incorrect value!\n", i);
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
printf("Done!\n\n");
|
|
||||||
|
|
||||||
printf("Testing uart_txb_block...\n");
|
|
||||||
*(uint8_t*)0x7ff5 = 0;
|
|
||||||
uart_txb_block(0xa5);
|
|
||||||
if (*(uint8_t*)0x7ff4 != 0xa5) {
|
|
||||||
printf("Incorrect value!\n", i);
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
printf("Done!\n\n");
|
|
||||||
|
|
||||||
printf("Testing uart_status...\n");
|
|
||||||
*(uint8_t*)0x7ff5 = 0xa5;
|
|
||||||
if (uart_status() != 0xa5) {
|
|
||||||
printf("Incorrect value!\n", i);
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
printf("Done!\n\n");
|
|
||||||
|
|
||||||
|
|
||||||
printf("Testing irq_get_status...\n");
|
|
||||||
*(uint8_t*)0x7fff = 0xa5;
|
|
||||||
if (irq_get_status() != 0xa5) {
|
|
||||||
printf("Incorrect value!\n", i);
|
|
||||||
retval++;
|
|
||||||
}
|
|
||||||
printf("Done!\n\n");
|
|
||||||
|
|
||||||
|
|
||||||
return retval != 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user