diff --git a/.gitignore b/.gitignore index cb22a96..2772ddd 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.map *.list *.bin +*.hex *.o diff --git a/Makefile b/Makefile index ef47ba5..2ef8bbd 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -ROM_TARGET=test_code/loop_test +ROM_TARGET=bootloader INIT_HEX=hw/super6502_fpga/init_hex.mem HEX=sw/$(ROM_TARGET)/$(notdir $(ROM_TARGET)).bin diff --git a/hw/super6502_fpga/src/sim/Makefile b/hw/super6502_fpga/src/sim/Makefile index 413056d..e2c7c69 100644 --- a/hw/super6502_fpga/src/sim/Makefile +++ b/hw/super6502_fpga/src/sim/Makefile @@ -23,7 +23,7 @@ all: waves waves: $(TB_NAME) # ./$(TB_NAME) -fst - ./obj_dir/Vsim_top + ./obj_dir/Vsim_top | tee run.log $(TB_NAME): $(SUPER6502_FPGA_SOURCES) $(SIM_SOURCES) $(COPY_FILES) $(SD_IMAGE) # $(IVERILOG) -g2005-sv $(FLAGS) -s $@ -o $@ $(INCLUDE) $(SUPER6502_FPGA_SOURCES) $(SIM_SOURCES) -I ../../ diff --git a/hw/super6502_fpga/src/sim/hvl/sim_top.sv b/hw/super6502_fpga/src/sim/hvl/sim_top.sv index f774e93..d488396 100644 --- a/hw/super6502_fpga/src/sim/hvl/sim_top.sv +++ b/hw/super6502_fpga/src/sim/hvl/sim_top.sv @@ -197,8 +197,12 @@ initial begin button_resetn <= '0; repeat(10) @(clk_cpu); button_resetn <= '1; - repeat(20000) @(posedge clk_cpu); + repeat(2000) @(posedge clk_cpu); $finish(); end +always @(posedge w_cpu0_sync) begin + $display("[%t] CPU Executed %x:%x", $time(), w_cpu0_addr, w_cpu0_data_from_dut); +end + endmodule diff --git a/sw/Makefile b/sw/Makefile new file mode 100644 index 0000000..b6730f7 --- /dev/null +++ b/sw/Makefile @@ -0,0 +1,19 @@ +SD_IMAGE = sd_image.bin +BOOTLOADER = bootloader/bootloader.bin + +all: $(SD_IMAGE) $(BOOTLOADER) + +$(BOOTLOADER): + $(MAKE) -C bootloader bootloader.bin + +$(SD_IMAGE): + dd if=/dev/zero of=$@ bs=1M count=256 + /sbin/mkfs.vfat $@ + udisksctl loop-setup --file $@ + udisksctl mount -b /dev/loop1 + udisksctl unmount -b /dev/loop1 + udisksctl loop-delete -b /dev/loop1 + +clean: + rm -rf $(SD_IMAGE) + rm -rf $(BOOTLOADER) \ No newline at end of file diff --git a/sw/bootloader/Makefile b/sw/bootloader/Makefile new file mode 100644 index 0000000..bf556ec --- /dev/null +++ b/sw/bootloader/Makefile @@ -0,0 +1,38 @@ +CC=../toolchain/cc65/bin/cl65 +LD=../toolchain/cc65/bin/cl65 +CFLAGS=-T -t none -I. --cpu "65C02" +LDFLAGS=-C link.ld -m $(NAME).map + +NAME=bootloader + +BIN=$(NAME).bin +HEX=$(NAME).hex + +LISTS=lists + +SRCS=$(wildcard *.s) $(wildcard *.c) +SRCS+=$(wildcard **/*.s) $(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=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)))) + +.PHONY: clean +clean: + rm -rf $(OBJS) $(BIN) $(HEX) $(LISTS) $(NAME).map + diff --git a/sw/bootloader/bootloader.s b/sw/bootloader/bootloader.s new file mode 100644 index 0000000..fbd3b02 --- /dev/null +++ b/sw/bootloader/bootloader.s @@ -0,0 +1,25 @@ +.export _init, _nmi_int, _irq_int + +.segment "VECTORS" + +.addr _nmi_int ; NMI vector +.addr _init ; Reset vector +.addr _irq_int ; IRQ/BRK vector + +SDRAM= $200 + +.code + +_nmi_int: +_irq_int: + +_init: + lda #$00 +@start: + sta SDRAM + cmp SDRAM + bne @end + ina + bra @start + +@end: bra @end \ No newline at end of file diff --git a/sw/bootloader/link.ld b/sw/bootloader/link.ld new file mode 100644 index 0000000..bc63183 --- /dev/null +++ b/sw/bootloader/link.ld @@ -0,0 +1,30 @@ +MEMORY +{ + RAM: start = $0000, size = $200; + ROM: start = $F000, size = $1000, file = %O; +} + +SEGMENTS { + ZEROPAGE: load = RAM, type = zp, define = yes; + DATA: load = ROM, type = rw, define = 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/kernel/Makefile b/sw/kernel/Makefile new file mode 100644 index 0000000..b357a32 --- /dev/null +++ b/sw/kernel/Makefile @@ -0,0 +1,39 @@ +CC=../toolchain/cc65/bin/cl65 +LD=../toolchain/cc65/bin/cl65 +CFLAGS=-T -t none -I. --cpu "65C02" +LDFLAGS=-C link.ld -m $(NAME).map + +NAME=bootloader + +BIN=$(NAME).bin +HEX=$(NAME).hex + +LISTS=lists + +SRCS=$(wildcard *.s) $(wildcard *.c) +SRCS+=$(wildcard **/*.s) $(wildcard **/*.c) +OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS))) +OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS))) + +# Make sure the kernel linked to correct address, no relocation! +all: $(HEX) + +$(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)))) + +.PHONY: clean +clean: + rm -rf $(OBJS) $(BIN) $(HEX) $(LISTS) $(NAME).map + diff --git a/sw/kernel/kernel.s b/sw/kernel/kernel.s new file mode 100644 index 0000000..380c16d --- /dev/null +++ b/sw/kernel/kernel.s @@ -0,0 +1,9 @@ +.segment "ENTRY" + +.addr main + + +.code + +main: + bra main \ No newline at end of file diff --git a/sw/kernel/link.ld b/sw/kernel/link.ld new file mode 100644 index 0000000..9e2386d --- /dev/null +++ b/sw/kernel/link.ld @@ -0,0 +1,30 @@ +MEMORY +{ + RAM: start = $0000, size = $200; + KERNEL: start = $8000, size = $7000, file = %O; +} + +SEGMENTS { + ZEROPAGE: load = RAM, type = zp, define = yes; + ENTRY: load = KERNEL, type = ro, start = $8000; + DATA: load = KERNEL, type = rw, define = yes; + CODE: load = KERNEL, type = ro; + RODATA: load = KERNEL, type = ro; +} + +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 +}