diff --git a/sw/bios/Makefile b/sw/bios/Makefile new file mode 100644 index 0000000..ac2d520 --- /dev/null +++ b/sw/bios/Makefile @@ -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) + diff --git a/sw/bootloader/boot.s b/sw/bios/boot.s similarity index 100% rename from sw/bootloader/boot.s rename to sw/bios/boot.s diff --git a/sw/bootloader/devices/board_io.h b/sw/bios/devices/board_io.h similarity index 100% rename from sw/bootloader/devices/board_io.h rename to sw/bios/devices/board_io.h diff --git a/sw/bootloader/devices/board_io.s b/sw/bios/devices/board_io.s similarity index 100% rename from sw/bootloader/devices/board_io.s rename to sw/bios/devices/board_io.s diff --git a/sw/bootloader/devices/conio.s b/sw/bios/devices/conio.s similarity index 100% rename from sw/bootloader/devices/conio.s rename to sw/bios/devices/conio.s diff --git a/sw/bootloader/devices/interrupt.h b/sw/bios/devices/interrupt.h similarity index 100% rename from sw/bootloader/devices/interrupt.h rename to sw/bios/devices/interrupt.h diff --git a/sw/bootloader/devices/interrupt.s b/sw/bios/devices/interrupt.s similarity index 62% rename from sw/bootloader/devices/interrupt.s rename to sw/bios/devices/interrupt.s index 39e6b2a..34cb908 100644 --- a/sw/bootloader/devices/interrupt.s +++ b/sw/bios/devices/interrupt.s @@ -7,6 +7,7 @@ ; Checks for a BRK instruction and returns from all valid interrupts. .import _handle_irq +.import _cputc, _clrscr .export _irq_int, _nmi_int @@ -44,5 +45,53 @@ irq: PLA ; Restore accumulator contents ; --------------------------------------------------------------------------- ; BRK detected, stop -break: JMP break ; If BRK is detected, something very bad - ; has happened, so stop running +break: + + +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. diff --git a/sw/bootloader/devices/io.inc65 b/sw/bios/devices/io.inc65 similarity index 100% rename from sw/bootloader/devices/io.inc65 rename to sw/bios/devices/io.inc65 diff --git a/sw/bootloader/devices/sd_card.c b/sw/bios/devices/sd_card.c similarity index 100% rename from sw/bootloader/devices/sd_card.c rename to sw/bios/devices/sd_card.c diff --git a/sw/bootloader/devices/sd_card.h b/sw/bios/devices/sd_card.h similarity index 100% rename from sw/bootloader/devices/sd_card.h rename to sw/bios/devices/sd_card.h diff --git a/sw/bootloader/devices/sd_card_asm.s b/sw/bios/devices/sd_card_asm.s similarity index 100% rename from sw/bootloader/devices/sd_card_asm.s rename to sw/bios/devices/sd_card_asm.s diff --git a/sw/bootloader/devices/sd_print.c b/sw/bios/devices/sd_print.c similarity index 100% rename from sw/bootloader/devices/sd_print.c rename to sw/bios/devices/sd_print.c diff --git a/sw/bootloader/devices/sd_print.h b/sw/bios/devices/sd_print.h similarity index 100% rename from sw/bootloader/devices/sd_print.h rename to sw/bios/devices/sd_print.h diff --git a/sw/bootloader/devices/spi.h b/sw/bios/devices/spi.h similarity index 100% rename from sw/bootloader/devices/spi.h rename to sw/bios/devices/spi.h diff --git a/sw/bootloader/devices/spi.s b/sw/bios/devices/spi.s similarity index 100% rename from sw/bootloader/devices/spi.s rename to sw/bios/devices/spi.s diff --git a/sw/bootloader/devices/uart.h b/sw/bios/devices/uart.h similarity index 100% rename from sw/bootloader/devices/uart.h rename to sw/bios/devices/uart.h diff --git a/sw/bootloader/devices/uart.s b/sw/bios/devices/uart.s similarity index 100% rename from sw/bootloader/devices/uart.s rename to sw/bios/devices/uart.s diff --git a/sw/bootloader/filesystem/fat.c b/sw/bios/filesystem/fat.c similarity index 100% rename from sw/bootloader/filesystem/fat.c rename to sw/bios/filesystem/fat.c diff --git a/sw/bootloader/filesystem/fat.h b/sw/bios/filesystem/fat.h similarity index 100% rename from sw/bootloader/filesystem/fat.h rename to sw/bios/filesystem/fat.h diff --git a/sw/bootloader/filesystem/o65.c b/sw/bios/filesystem/o65.c similarity index 100% rename from sw/bootloader/filesystem/o65.c rename to sw/bios/filesystem/o65.c diff --git a/sw/bootloader/filesystem/o65.h b/sw/bios/filesystem/o65.h similarity index 100% rename from sw/bootloader/filesystem/o65.h rename to sw/bios/filesystem/o65.h diff --git a/sw/bootloader/irq.c b/sw/bios/irq.c similarity index 100% rename from sw/bootloader/irq.c rename to sw/bios/irq.c diff --git a/sw/bios/link.ld b/sw/bios/link.ld new file mode 100644 index 0000000..b1a51cf --- /dev/null +++ b/sw/bios/link.ld @@ -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 +} diff --git a/sw/bootloader/main.c b/sw/bios/main.c similarity index 100% rename from sw/bootloader/main.c rename to sw/bios/main.c diff --git a/sw/bootloader/vectors.s b/sw/bios/vectors.s similarity index 100% rename from sw/bootloader/vectors.s rename to sw/bios/vectors.s diff --git a/sw/bootloader/Makefile b/sw/bootloader/Makefile index ac2d520..89937af 100644 --- a/sw/bootloader/Makefile +++ b/sw/bootloader/Makefile @@ -1,39 +1,23 @@ 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) + objcopy --input-target=binary --output-target=ihex $(BIN) $(HEX) $(BIN): $(OBJS) @@ -47,7 +31,6 @@ $(BIN): $(OBJS) $(LISTS): mkdir -p $(addprefix $(LISTS)/,$(sort $(dir $(SRCS)))) - mkdir $(LISTS)/$(sort $(dir $(TEST_SRCS))) .PHONY: clean clean: diff --git a/sw/bootloader/bootloader.s b/sw/bootloader/bootloader.s new file mode 100644 index 0000000..d22b578 --- /dev/null +++ b/sw/bootloader/bootloader.s @@ -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 + diff --git a/sw/bootloader/link.ld b/sw/bootloader/link.ld index b1a51cf..d0725d6 100644 --- a/sw/bootloader/link.ld +++ b/sw/bootloader/link.ld @@ -1,35 +1,8 @@ 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; + BOOT: start = $8000, size = $200, 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 + BOOTSECTOR: load = BOOT, start = $8000; } diff --git a/sw/bootloader/tests/test_main.c b/sw/bootloader/tests/test_main.c deleted file mode 100644 index 99e3dd8..0000000 --- a/sw/bootloader/tests/test_main.c +++ /dev/null @@ -1,89 +0,0 @@ -#include - -#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; -} \ No newline at end of file