From 2c6f333966745e7bf59cfa97374604757318f3a7 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 14:02:43 -0500 Subject: [PATCH 01/11] Remove unused char c --- sw/irq.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sw/irq.c b/sw/irq.c index f1baddc..313ea7d 100644 --- a/sw/irq.c +++ b/sw/irq.c @@ -10,7 +10,6 @@ char lastchar; void handle_irq() { uint8_t status; - char c; status = irq_get_status(); From 0cecf166c755adf583f4cbc754d00726ab60e8ce Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 14:02:57 -0500 Subject: [PATCH 02/11] Add definitions and structures for o65 files These can be used to read and parse o65 files. --- sw/o65.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 sw/o65.h diff --git a/sw/o65.h b/sw/o65.h new file mode 100644 index 0000000..6191a25 --- /dev/null +++ b/sw/o65.h @@ -0,0 +1,65 @@ +#ifndef _O65_H +#define _O65_H + +#include + +#define O65_NON_C64 0x0001 +#define O65_MAGIC_0 0x6f +#define O65_MAGIC_1 0x36 +#define O65_MAGIC_2 0x35 + +#define O65_OPT_FILENAME 0 +#define O65_OPT_OS 1 +#define O65_OPT_ASSEMBLER 2 +#define O65_OPT_AUTHOR 3 +#define O65_OPT_DATE 4 + +#define O65_OS_OSA65 1 +#define O65_OS_LUNIX 2 +#define O65_OS_CC65 3 +#define O65_OS_OPENCBM 4 +#define O65_OS_SUPER6502 5 + +typedef union { + struct { + int cpu : 1; + int reloc : 1; + int size : 1; + int obj : 1; + int simple : 1; + int chain : 1; + int bsszero : 1; + int cpu2 : 4; + int align : 2; + }; + uint16_t _mode; +} o65_mode_t; + +typedef struct { + uint16_t c64_marker; + uint8_t magic[3]; + uint8_t version; + + o65_mode_t mode; + + uint16_t tbase; + uint16_t tlen; + uint16_t dbase; + uint16_t dlen; + uint16_t bbase; + uint16_t blen; + uint16_t zbase; + uint16_t zlen; + uint16_t stack; + +} o65_header_t; + +typedef struct { + uint8_t olen; + uint8_t type; + uint8_t data[1]; //This is actually variable length +} o65_opt; + +#endif + + From 59da06c509123a2e6430e5c252dca0bf71187de3 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 14:05:33 -0500 Subject: [PATCH 03/11] Add basic test program This adds a test program which can be loaded and executed by the host. It simply returns a value in the `a` register. The linker script is modified so that it will output an o65 file, and the memory sgments are changed as well. There is no STARTUP segment defined, so it uses the default `none` crt0, which sets up the stack and does initialization and deconstruction. The Makefile is modified to not turn the output into an intel hex file, and instead keep it as the o65 file. --- sw/test_exec/Makefile | 41 ++++ sw/test_exec/link.ld | 43 ++++ sw/test_exec/main.c | 3 + sw/test_exec/out.txt | 289 +++++++++++++++++++++++++ sw/test_exec/out2.txt | 488 ++++++++++++++++++++++++++++++++++++++++++ sw/test_exec/test.o65 | Bin 0 -> 297 bytes 6 files changed, 864 insertions(+) create mode 100644 sw/test_exec/Makefile create mode 100644 sw/test_exec/link.ld create mode 100644 sw/test_exec/main.c create mode 100644 sw/test_exec/out.txt create mode 100644 sw/test_exec/out2.txt create mode 100644 sw/test_exec/test.o65 diff --git a/sw/test_exec/Makefile b/sw/test_exec/Makefile new file mode 100644 index 0000000..8aec806 --- /dev/null +++ b/sw/test_exec/Makefile @@ -0,0 +1,41 @@ +CC=~/Software/cc65/bin/cl65 +CFLAGS=-v -T -t none -I. --cpu "65C02" +test: CFLAGS=-T -t sim65c02 -I. +LDFLAGS=-v -C link.ld -m $(NAME).map +SIM=sim65 +SIMARGS=-v -c -x 1000000 + +NAME=test + +BIN=$(NAME).o65 +HEX=$(NAME).hex + +LISTS=lists + +SRCS=$(wildcard *.s) $(wildcard *.c) +OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS))) +OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS))) + +all: $(BIN) + +$(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 + rm -rf $(TEST_OBJS) $(TEST_BIN) + diff --git a/sw/test_exec/link.ld b/sw/test_exec/link.ld new file mode 100644 index 0000000..ade4e99 --- /dev/null +++ b/sw/test_exec/link.ld @@ -0,0 +1,43 @@ +MEMORY +{ + ZP: start = $0, size = $100, type = rw, define = yes; + SDRAM: start = $1000, size = $6ef0, type = rw, define = yes; +} + +FILES { + %O: format = o65; +} + +SEGMENTS { + ZEROPAGE: load = ZP, type = zp, define = yes; + DATA: load = SDRAM, type = rw, define = yes, run = SDRAM; + BSS: load = SDRAM, type = bss, define = yes; + HEAP: load = SDRAM, type = bss, optional = yes; + STARTUP: load = SDRAM, type = ro; + ONCE: load = SDRAM, type = ro, optional = yes; + CODE: load = SDRAM, type = ro; + RODATA: load = SDRAM, 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 + +} + +FORMATS { + o65: os = 5, version = 0, type = small, + export = _main; + } diff --git a/sw/test_exec/main.c b/sw/test_exec/main.c new file mode 100644 index 0000000..ad40be3 --- /dev/null +++ b/sw/test_exec/main.c @@ -0,0 +1,3 @@ +int main() { + return 0x41; +} \ No newline at end of file diff --git a/sw/test_exec/out.txt b/sw/test_exec/out.txt new file mode 100644 index 0000000..863dd89 --- /dev/null +++ b/sw/test_exec/out.txt @@ -0,0 +1,289 @@ +mkdir -p lists/./ +~/Software/cc65/bin/cl65 -T -t none -I. --cpu "65C02" -l lists/main.c.list -c main.c -o main.o +~/Software/cc65/bin/cl65 -T -t none -I. --cpu "65C02" -C link.ld -m test.map main.o -o test.o65 +Writing a bunch of data! +1 0 6f 36 35 + +Writing size value 1025 +Writing size value 0 +Writing size value 1000 +Writing size value 0 +Writing size value 1025 +Writing size value 0 +Writing size value 0 +Writing size value 0 +Writing size value 0 +Writing a bunch of data! +74 65 73 74 2e 6f 36 35 0 + +Writing a bunch of data! +6c 64 36 35 20 56 32 2e 31 39 20 2d 20 47 69 74 20 30 38 35 31 34 37 34 37 35 0 + +Writing a bunch of data! +46 72 69 20 41 70 72 20 31 35 20 31 36 3a 30 34 3a 30 31 20 32 30 32 32 0 + +Writing a bunch of data! +5 0 + +WRITING TEXT SEGWrite seg count: 4, dowrite: 1 +Writing a bunch of data! +a9 + +Writing a bunch of data! +a2 + +Writing a bunch of data! +85 + +Writing a bunch of data! +86 + +Writing a bunch of data! +20 + +Writing a bunch of data! +20 + +Writing a bunch of data! +20 + +Writing a bunch of data! +48 + +Writing a bunch of data! +20 + +Writing a bunch of data! +68 + +Writing a bunch of data! +60 + +Writing a bunch of data! +a0 + +Writing a bunch of data! +f0 + +Writing a bunch of data! +7 + +Writing a bunch of data! +a9 + +Writing a bunch of data! +a2 + +Writing a bunch of data! +4c + +Writing a bunch of data! +60 + +Writing a bunch of data! +a2 cc + +Writing a bunch of data! +a9 dd + +Writing a bunch of data! +4c + +Writing a bunch of data! +60 + +Writing a bunch of data! +a0 + +Writing a bunch of data! +f0 + +Writing a bunch of data! +7 + +Writing a bunch of data! +a9 + +Writing a bunch of data! +a2 + +Writing a bunch of data! +4c + +Writing a bunch of data! +60 + +Writing a bunch of data! +a9 + +Writing a bunch of data! +85 + +Writing a bunch of data! +a9 + +Writing a bunch of data! +85 + +Writing a bunch of data! +a9 0 + +Writing a bunch of data! +a8 + +Writing a bunch of data! +a2 + +Writing a bunch of data! +f0 + +Writing a bunch of data! +a + +Writing a bunch of data! +91 + +Writing a bunch of data! +c8 + +Writing a bunch of data! +d0 + +Writing a bunch of data! +fb + +Writing a bunch of data! +e6 + +Writing a bunch of data! +ca + +Writing a bunch of data! +d0 + +Writing a bunch of data! +f6 + +Writing a bunch of data! +c0 + +Writing a bunch of data! +f0 + +Writing a bunch of data! +5 + +Writing a bunch of data! +91 + +Writing a bunch of data! +c8 + +Writing a bunch of data! +d0 + +Writing a bunch of data! +f7 + +Writing a bunch of data! +60 + +Text count: 4 +Text Size: 90 +WRITING DATA SEGWrite seg count: 1, dowrite: 1 +Writing a bunch of data! +8d + +Writing a bunch of data! +8e + +Writing a bunch of data! +8d + +Writing a bunch of data! +8e + +Writing a bunch of data! +88 + +Writing a bunch of data! +b9 ff ff + +Writing a bunch of data! +8d + +Writing a bunch of data! +88 + +Writing a bunch of data! +b9 ff ff + +Writing a bunch of data! +8d + +Writing a bunch of data! +8c + +Writing a bunch of data! +20 ff ff + +Writing a bunch of data! +a0 ff + +Writing a bunch of data! +d0 + +Writing a bunch of data! +e8 + +Writing a bunch of data! +60 + +Data count: 1 +Data Size: 37 +Write seg count: 1, dowrite: 0 +Writing zp seg (this should just be a few)Write seg count: 1, dowrite: 0 +WRITING IMPORTSWriting size value 0 +ExtSymCount: 0 +WRITING TEXT RELOCATION + + +Writing a bunch of data! +6 25 2 25 2 82 3 82 3 82 4 82 9 22 2 42 3c 2 83 8 82 8 22 2 42 3c 2 83 4 24 2 25 2 44 0 2 25 9 25 5 25 9 25 0 + +Writing a bunch of data! +2 83 3 83 3 83 3 83 7 83 7 83 3 83 0 + +Writing size value 1 +Writing a bunch of data! +5f 6d 61 69 6e 0 + +Writing size value 1048 +Writing a bunch of data! +1 0 6f 36 35 + +Writing size value 1025 +Writing size value 5a +Writing size value 1000 +Writing size value 25 +Writing size value 1025 +Writing size value 0 +Writing size value 0 +Writing size value 1a +Writing size value 0 +Writing a bunch of data! +74 65 73 74 2e 6f 36 35 0 + +Writing a bunch of data! +6c 64 36 35 20 56 32 2e 31 39 20 2d 20 47 69 74 20 30 38 35 31 34 37 34 37 35 0 + +Writing a bunch of data! +46 72 69 20 41 70 72 20 31 35 20 31 36 3a 30 34 3a 30 31 20 32 30 32 32 0 + +Writing a bunch of data! +5 0 + +Text Base: 1025 +Text Size: 5a +Data Base: 1000 +Data Size: 25 diff --git a/sw/test_exec/out2.txt b/sw/test_exec/out2.txt new file mode 100644 index 0000000..b60e9a4 --- /dev/null +++ b/sw/test_exec/out2.txt @@ -0,0 +1,488 @@ +mkdir -p lists/./ +~/Software/cc65/bin/cl65 -v -T -t none -I. --cpu "65C02" -l lists/main.c.list -c main.c -o main.o +0 errors and 0 warnings generated. +Opened output file 'main.s' +Wrote output to 'main.s' +Closed output file 'main.s' +~/Software/cc65/bin/cl65 -v -T -t none -I. --cpu "65C02" -v -C link.ld -m test.map main.o -o test.o65 +Module 'main.o': Found segment 'CODE', size = 8, alignment = 1, type = 2 +Module 'main.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 +Module 'main.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 +Module 'main.o': Found segment 'DATA', size = 0, alignment = 1, type = 2 +Module 'main.o': Found segment 'ZEROPAGE', size = 0, alignment = 1, type = 1 +Module 'main.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 +Module 'condes.o': Found segment 'CODE', size = 12, alignment = 1, type = 2 +Module 'condes.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 +Module 'condes.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 +Module 'condes.o': Found segment 'DATA', size = 37, alignment = 1, type = 2 +Module 'condes.o': Found segment 'ZEROPAGE', size = 0, alignment = 1, type = 1 +Module 'condes.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 +Module 'condes.o': Found segment 'ONCE', size = 12, alignment = 1, type = 2 +Module 'crt0.o': Found segment 'CODE', size = 0, alignment = 1, type = 2 +Module 'crt0.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 +Module 'crt0.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 +Module 'crt0.o': Found segment 'DATA', size = 0, alignment = 1, type = 2 +Module 'crt0.o': Found segment 'ZEROPAGE', size = 0, alignment = 1, type = 1 +Module 'crt0.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 +Module 'crt0.o': Found segment 'STARTUP', size = 23, alignment = 1, type = 2 +Module 'zerobss.o': Found segment 'CODE', size = 35, alignment = 1, type = 2 +Module 'zerobss.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 +Module 'zerobss.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 +Module 'zerobss.o': Found segment 'DATA', size = 0, alignment = 1, type = 2 +Module 'zerobss.o': Found segment 'ZEROPAGE', size = 0, alignment = 1, type = 1 +Module 'zerobss.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 +Module 'zeropage.o': Found segment 'CODE', size = 0, alignment = 1, type = 2 +Module 'zeropage.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 +Module 'zeropage.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 +Module 'zeropage.o': Found segment 'DATA', size = 0, alignment = 1, type = 2 +Module 'zeropage.o': Found segment 'ZEROPAGE', size = 26, alignment = 1, type = 1 +Module 'zeropage.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 +Opened 'test.o65'... +Writing size value 1025 +Writing size value 0 +Writing size value 1000 +Writing size value 0 +Writing size value 1025 +Writing size value 0 +Writing size value 0 +Writing size value 0 +Writing size value 0 +WRITING TEXT SEG Writing 'STARTUP' + Section from "crt0.o" + Filling 0x0 bytes with 0x00 + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Section from "[linker generated]" + Filling 0x0 bytes with 0x00 + Section from "[linker generated]" + Filling 0x0 bytes with 0x00 + Writing 'ONCE' + Section from "condes.o" + Filling 0x0 bytes with 0x00 + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Writing 'CODE' + Section from "main.o" + Filling 0x0 bytes with 0x00 + Fragment with 0x2 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Section from "condes.o" + Filling 0x0 bytes with 0x00 + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Section from "crt0.o" + Filling 0x0 bytes with 0x00 + Section from "zerobss.o" + Filling 0x0 bytes with 0x00 + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Section from "zeropage.o" + Filling 0x0 bytes with 0x00 + Writing 'RODATA' + Section from "main.o" + Filling 0x0 bytes with 0x00 + Section from "condes.o" + Filling 0x0 bytes with 0x00 + Section from "crt0.o" + Filling 0x0 bytes with 0x00 + Section from "zerobss.o" + Filling 0x0 bytes with 0x00 + Section from "zeropage.o" + Filling 0x0 bytes with 0x00 +Text count: 4 +Text Size: 90 +WRITING DATA SEG Writing 'DATA' + Section from "main.o" + Filling 0x0 bytes with 0x00 + Section from "condes.o" + Filling 0x0 bytes with 0x00 + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x3 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x3 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x2 bytes + Fragment with 0x3 bytes + Fragment with 0x2 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Fragment with 0x1 bytes + Section from "crt0.o" + Filling 0x0 bytes with 0x00 + Section from "zerobss.o" + Filling 0x0 bytes with 0x00 + Section from "zeropage.o" + Filling 0x0 bytes with 0x00 +Data count: 1 +Data Size: 37 + Writing 'BSS' +Writing zp seg (this should just be a few) Writing 'ZEROPAGE' +WRITING IMPORTSWriting size value 0 +ExtSymCount: 0 +WRITING TEXT RELOCATION + + +Writing size value 1 +Writing size value 1048 +Writing size value 1025 +Writing size value 5a +Writing size value 1000 +Writing size value 25 +Writing size value 1025 +Writing size value 0 +Writing size value 0 +Writing size value 1a +Writing size value 0 +Text Base: 1025 +Text Size: 5a +Data Base: 1000 +Data Size: 25 +Segment: CODE (55) + Section: + Literal (2 bytes): + A2 CC + Literal (2 bytes): + A9 DD + Literal (1 bytes): + 4C + Expression (2 bytes): + SEC $0007 + + Literal (1 bytes): + 60 + Section: + Literal (1 bytes): + A0 + Expression (1 bytes): + SYM() $0002 * BYTE0 + Literal (1 bytes): + F0 + Literal (1 bytes): + 07 + Literal (1 bytes): + A9 + Expression (1 bytes): + SYM() BYTE0 + Literal (1 bytes): + A2 + Expression (1 bytes): + SYM() BYTE1 + Literal (1 bytes): + 4C + Expression (2 bytes): + SEC + Literal (1 bytes): + 60 + Section: + Section: + Literal (1 bytes): + A9 + Expression (1 bytes): + SYM() BYTE0 + Literal (1 bytes): + 85 + Expression (1 bytes): + SYM() + Literal (1 bytes): + A9 + Expression (1 bytes): + SYM() BYTE1 + Literal (1 bytes): + 85 + Expression (1 bytes): + SYM() $0001 + + Literal (2 bytes): + A9 00 + Literal (1 bytes): + A8 + Literal (1 bytes): + A2 + Expression (1 bytes): + SYM() BYTE1 + Literal (1 bytes): + F0 + Literal (1 bytes): + 0A + Literal (1 bytes): + 91 + Expression (1 bytes): + SYM() + Literal (1 bytes): + C8 + Literal (1 bytes): + D0 + Literal (1 bytes): + FB + Literal (1 bytes): + E6 + Expression (1 bytes): + SYM() $0001 + + Literal (1 bytes): + CA + Literal (1 bytes): + D0 + Literal (1 bytes): + F6 + Literal (1 bytes): + C0 + Expression (1 bytes): + SYM() BYTE0 + Literal (1 bytes): + F0 + Literal (1 bytes): + 05 + Literal (1 bytes): + 91 + Expression (1 bytes): + SYM() + Literal (1 bytes): + C8 + Literal (1 bytes): + D0 + Literal (1 bytes): + F7 + Literal (1 bytes): + 60 + Section: +Segment: RODATA (0) + Section: + Section: + Section: + Section: + Section: +Segment: BSS (0) + Section: + Section: + Section: + Section: + Section: +Segment: DATA (37) + Section: + Section: + Literal (1 bytes): + 8D + Expression (2 bytes): + SEC $000D + $0001 + + Literal (1 bytes): + 8E + Expression (2 bytes): + SEC $000D + $0002 + + Literal (1 bytes): + 8D + Expression (2 bytes): + SEC $0014 + $0001 + + Literal (1 bytes): + 8E + Expression (2 bytes): + SEC $0014 + $0002 + + Literal (1 bytes): + 88 + Literal (3 bytes): + B9 FF FF + Literal (1 bytes): + 8D + Expression (2 bytes): + SEC $001D + $0002 + + Literal (1 bytes): + 88 + Literal (3 bytes): + B9 FF FF + Literal (1 bytes): + 8D + Expression (2 bytes): + SEC $001D + $0001 + + Literal (1 bytes): + 8C + Expression (2 bytes): + SEC $0020 + $0001 + + Literal (3 bytes): + 20 FF FF + Literal (2 bytes): + A0 FF + Literal (1 bytes): + D0 + Literal (1 bytes): + E8 + Literal (1 bytes): + 60 + Section: + Section: + Section: +Segment: ZEROPAGE (26) + Section: + Section: + Section: + Section: + Section: + Empty space (2 bytes) + Empty space (2 bytes) + Empty space (4 bytes) + Empty space (2 bytes) + Empty space (2 bytes) + Empty space (2 bytes) + Empty space (2 bytes) + Empty space (1 bytes) + Empty space (1 bytes) + Empty space (1 bytes) + Empty space (1 bytes) + Empty space (6 bytes) +Segment: NULL (0) + Section: + Section: + Section: + Section: + Section: +Segment: ONCE (12) + Section: + Literal (1 bytes): + A0 + Expression (1 bytes): + SYM() $0002 * BYTE0 + Literal (1 bytes): + F0 + Literal (1 bytes): + 07 + Literal (1 bytes): + A9 + Expression (1 bytes): + SYM() BYTE0 + Literal (1 bytes): + A2 + Expression (1 bytes): + SYM() BYTE1 + Literal (1 bytes): + 4C + Expression (2 bytes): + SEC + Literal (1 bytes): + 60 +Segment: STARTUP (23) + Section: + Literal (1 bytes): + A9 + Expression (1 bytes): + SYM() BYTE0 + Literal (1 bytes): + A2 + Expression (1 bytes): + SYM() BYTE1 + Literal (1 bytes): + 85 + Expression (1 bytes): + SYM() + Literal (1 bytes): + 86 + Expression (1 bytes): + SYM() $0001 + + Literal (1 bytes): + 20 + Expression (2 bytes): + SYM() + Literal (1 bytes): + 20 + Expression (2 bytes): + SYM() + Literal (1 bytes): + 20 + Expression (2 bytes): + SYM() + Literal (1 bytes): + 48 + Literal (1 bytes): + 20 + Expression (2 bytes): + SYM() + Literal (1 bytes): + 68 + Literal (1 bytes): + 60 + Section: + Section: +CONDES(0): 0 symbols +CONDES(1): 0 symbols +CONDES(2): 0 symbols +CONDES(3): 0 symbols +CONDES(4): 0 symbols +CONDES(5): 0 symbols +CONDES(6): 0 symbols diff --git a/sw/test_exec/test.o65 b/sw/test_exec/test.o65 new file mode 100644 index 0000000000000000000000000000000000000000..d34296e9a2d8a1d2859fe8417e6ac276c86fb4c9 GIT binary patch literal 297 zcmZQ%$Tu@(U|>)ch+<$6PzBOJ4ucdBb2F5r7MJLOq-B|MQp`*h!i@9`EfsVX+%roQ z3@l6yP0UTqO&O$F+=?<491DsR3{4db&8!S9tW1m)j0}v77+4rt85mYFEaGToXk%1} z5m2xZQ1B4&PzVsnNLaw|fqkXTA^{%;frLe8R^IjT7eEnP$ Date: Sat, 16 Apr 2022 14:10:54 -0500 Subject: [PATCH 04/11] Add parsing of o65 files Prints out information about the first file found on the SD card, if it is an o65 file. --- sw/main.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/sw/main.c b/sw/main.c index 30332d0..003bf75 100644 --- a/sw/main.c +++ b/sw/main.c @@ -6,6 +6,7 @@ #include "mapper.h" #include "sd_card.h" #include "fat.h" +#include "o65.h" uint8_t buf[512]; @@ -76,6 +77,8 @@ int main() { dos_dentry_t* dos_dentry; uint32_t cluster; + o65_header_t* header; + uint16_t reserved_count; uint32_t sectors_per_fat; @@ -192,14 +195,32 @@ int main() { cprintf("DOS name: %.8s.%.3s\n", &dos_dentry->filename, &dos_dentry->extension); - cluster = (dos_dentry->first_cluster_h << 16) + dos_dentry->first_cluster_l; + cluster = ((uint32_t)dos_dentry->first_cluster_h << 16) + dos_dentry->first_cluster_l; cprintf("Cluster: %ld\n", cluster); cprintf("File location: %lx\n", data_region_start + (cluster - 2) * 8); sd_readblock(data_region_start + (cluster - 2) * 8); - cprintf("File contents: %s\n", buf); + header = (o65_header_t*)buf; + + if (header->c64_marker == O65_NON_C64 && + header->magic[0] == O65_MAGIC_0 && + header->magic[1] == O65_MAGIC_1 && + header->magic[2] == O65_MAGIC_2) { + cprintf("Found a valid o65 file!\n\n"); + + cprintf("tbase: %x\n", header->tbase); + cprintf("tlen: %x\n", header->tlen); + cprintf("dbase: %x\n", header->dbase); + cprintf("dlen: %x\n", header->dlen); + cprintf("bbase: %x\n", header->bbase); + cprintf("blen: %x\n", header->blen); + cprintf("zbase: %x\n", header->zbase); + cprintf("zlen: %x\n", header->zlen); + cprintf("stack: %x\n", header->stack); + } + cprintf("Done!\n"); From e30768d4c2e86d2c35af9ab762b080a3973435c1 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 14:22:16 -0500 Subject: [PATCH 05/11] Rename o65_opt to o65_opt_t --- sw/o65.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw/o65.h b/sw/o65.h index 6191a25..1871ec9 100644 --- a/sw/o65.h +++ b/sw/o65.h @@ -58,7 +58,7 @@ typedef struct { uint8_t olen; uint8_t type; uint8_t data[1]; //This is actually variable length -} o65_opt; +} o65_opt_t; #endif From 016e9edee741154a56bee7ad3696abf7b647a5f1 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 14:22:26 -0500 Subject: [PATCH 06/11] More o65 parsing Prints out the options now too. --- sw/main.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sw/main.c b/sw/main.c index 003bf75..99ba2d0 100644 --- a/sw/main.c +++ b/sw/main.c @@ -78,6 +78,7 @@ int main() { uint32_t cluster; o65_header_t* header; + o65_opt_t* o65_opt; uint16_t reserved_count; @@ -219,6 +220,32 @@ int main() { cprintf("zbase: %x\n", header->zbase); cprintf("zlen: %x\n", header->zlen); cprintf("stack: %x\n", header->stack); + cprintf("\n"); + + o65_opt = (o65_opt_t*)(buf + sizeof(o65_header_t)); + while (o65_opt->olen) + { + cprintf("Option Length: %d\n", o65_opt->olen); + cprintf("Option Type: %x ", o65_opt->type); + switch (o65_opt->type) { + case O65_OPT_FILENAME: cprintf("Filename\n"); break; + case O65_OPT_OS: cprintf("OS\n"); break; + case O65_OPT_ASSEMBLER: cprintf("Assembler\n"); break; + case O65_OPT_AUTHOR: cprintf("Author\n"); break; + case O65_OPT_DATE: cprintf("Creation Date\n"); break; + default: cprintf("Invalid\n"); break; + } + + if (o65_opt->type != O65_OPT_OS) { + for (i = 0; i < o65_opt->olen - 2; i++) { + cprintf("%c", o65_opt->data[i]); + } + } else { + cprintf("%x", o65_opt->data[0]); + } + cprintf("\n\n"); + o65_opt = (o65_opt_t*)((uint8_t*)o65_opt + o65_opt->olen); + } } From 7e7bdd3b4a870f46ca0a9d599f578154a6dc46bb Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 14:27:18 -0500 Subject: [PATCH 07/11] Use the system cl65, don't use verbose mode I had used these to try and help figure out the structure of the o65 file but this is not needed anymore --- sw/test_exec/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sw/test_exec/Makefile b/sw/test_exec/Makefile index 8aec806..cfcfe6d 100644 --- a/sw/test_exec/Makefile +++ b/sw/test_exec/Makefile @@ -1,7 +1,7 @@ -CC=~/Software/cc65/bin/cl65 -CFLAGS=-v -T -t none -I. --cpu "65C02" +CC=cl65 +CFLAGS=-T -t none -I. --cpu "65C02" test: CFLAGS=-T -t sim65c02 -I. -LDFLAGS=-v -C link.ld -m $(NAME).map +LDFLAGS=-C link.ld -m $(NAME).map SIM=sim65 SIMARGS=-v -c -x 1000000 From 4be5366aee94d996d9f23078545aae616ac3d528 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 14:28:40 -0500 Subject: [PATCH 08/11] Do not track o65 files These are object files still, which means we do not want to track them. --- sw/.gitignore | 1 + sw/test_exec/test.o65 | Bin 297 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 sw/test_exec/test.o65 diff --git a/sw/.gitignore b/sw/.gitignore index 3e1502e..ec73f2b 100644 --- a/sw/.gitignore +++ b/sw/.gitignore @@ -3,6 +3,7 @@ # Object files *.o +*.o65 *.ko *.obj *.elf diff --git a/sw/test_exec/test.o65 b/sw/test_exec/test.o65 deleted file mode 100644 index d34296e9a2d8a1d2859fe8417e6ac276c86fb4c9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 297 zcmZQ%$Tu@(U|>)ch+<$6PzBOJ4ucdBb2F5r7MJLOq-B|MQp`*h!i@9`EfsVX+%roQ z3@l6yP0UTqO&O$F+=?<491DsR3{4db&8!S9tW1m)j0}v77+4rt85mYFEaGToXk%1} z5m2xZQ1B4&PzVsnNLaw|fqkXTA^{%;frLe8R^IjT7eEnP$ Date: Sat, 16 Apr 2022 14:30:34 -0500 Subject: [PATCH 09/11] Remove compilation output files These were used to help understand the o65 file format, but are not needed and shouldn't have been commited anyway. --- sw/test_exec/out.txt | 289 ------------------------- sw/test_exec/out2.txt | 488 ------------------------------------------ 2 files changed, 777 deletions(-) delete mode 100644 sw/test_exec/out.txt delete mode 100644 sw/test_exec/out2.txt diff --git a/sw/test_exec/out.txt b/sw/test_exec/out.txt deleted file mode 100644 index 863dd89..0000000 --- a/sw/test_exec/out.txt +++ /dev/null @@ -1,289 +0,0 @@ -mkdir -p lists/./ -~/Software/cc65/bin/cl65 -T -t none -I. --cpu "65C02" -l lists/main.c.list -c main.c -o main.o -~/Software/cc65/bin/cl65 -T -t none -I. --cpu "65C02" -C link.ld -m test.map main.o -o test.o65 -Writing a bunch of data! -1 0 6f 36 35 - -Writing size value 1025 -Writing size value 0 -Writing size value 1000 -Writing size value 0 -Writing size value 1025 -Writing size value 0 -Writing size value 0 -Writing size value 0 -Writing size value 0 -Writing a bunch of data! -74 65 73 74 2e 6f 36 35 0 - -Writing a bunch of data! -6c 64 36 35 20 56 32 2e 31 39 20 2d 20 47 69 74 20 30 38 35 31 34 37 34 37 35 0 - -Writing a bunch of data! -46 72 69 20 41 70 72 20 31 35 20 31 36 3a 30 34 3a 30 31 20 32 30 32 32 0 - -Writing a bunch of data! -5 0 - -WRITING TEXT SEGWrite seg count: 4, dowrite: 1 -Writing a bunch of data! -a9 - -Writing a bunch of data! -a2 - -Writing a bunch of data! -85 - -Writing a bunch of data! -86 - -Writing a bunch of data! -20 - -Writing a bunch of data! -20 - -Writing a bunch of data! -20 - -Writing a bunch of data! -48 - -Writing a bunch of data! -20 - -Writing a bunch of data! -68 - -Writing a bunch of data! -60 - -Writing a bunch of data! -a0 - -Writing a bunch of data! -f0 - -Writing a bunch of data! -7 - -Writing a bunch of data! -a9 - -Writing a bunch of data! -a2 - -Writing a bunch of data! -4c - -Writing a bunch of data! -60 - -Writing a bunch of data! -a2 cc - -Writing a bunch of data! -a9 dd - -Writing a bunch of data! -4c - -Writing a bunch of data! -60 - -Writing a bunch of data! -a0 - -Writing a bunch of data! -f0 - -Writing a bunch of data! -7 - -Writing a bunch of data! -a9 - -Writing a bunch of data! -a2 - -Writing a bunch of data! -4c - -Writing a bunch of data! -60 - -Writing a bunch of data! -a9 - -Writing a bunch of data! -85 - -Writing a bunch of data! -a9 - -Writing a bunch of data! -85 - -Writing a bunch of data! -a9 0 - -Writing a bunch of data! -a8 - -Writing a bunch of data! -a2 - -Writing a bunch of data! -f0 - -Writing a bunch of data! -a - -Writing a bunch of data! -91 - -Writing a bunch of data! -c8 - -Writing a bunch of data! -d0 - -Writing a bunch of data! -fb - -Writing a bunch of data! -e6 - -Writing a bunch of data! -ca - -Writing a bunch of data! -d0 - -Writing a bunch of data! -f6 - -Writing a bunch of data! -c0 - -Writing a bunch of data! -f0 - -Writing a bunch of data! -5 - -Writing a bunch of data! -91 - -Writing a bunch of data! -c8 - -Writing a bunch of data! -d0 - -Writing a bunch of data! -f7 - -Writing a bunch of data! -60 - -Text count: 4 -Text Size: 90 -WRITING DATA SEGWrite seg count: 1, dowrite: 1 -Writing a bunch of data! -8d - -Writing a bunch of data! -8e - -Writing a bunch of data! -8d - -Writing a bunch of data! -8e - -Writing a bunch of data! -88 - -Writing a bunch of data! -b9 ff ff - -Writing a bunch of data! -8d - -Writing a bunch of data! -88 - -Writing a bunch of data! -b9 ff ff - -Writing a bunch of data! -8d - -Writing a bunch of data! -8c - -Writing a bunch of data! -20 ff ff - -Writing a bunch of data! -a0 ff - -Writing a bunch of data! -d0 - -Writing a bunch of data! -e8 - -Writing a bunch of data! -60 - -Data count: 1 -Data Size: 37 -Write seg count: 1, dowrite: 0 -Writing zp seg (this should just be a few)Write seg count: 1, dowrite: 0 -WRITING IMPORTSWriting size value 0 -ExtSymCount: 0 -WRITING TEXT RELOCATION - - -Writing a bunch of data! -6 25 2 25 2 82 3 82 3 82 4 82 9 22 2 42 3c 2 83 8 82 8 22 2 42 3c 2 83 4 24 2 25 2 44 0 2 25 9 25 5 25 9 25 0 - -Writing a bunch of data! -2 83 3 83 3 83 3 83 7 83 7 83 3 83 0 - -Writing size value 1 -Writing a bunch of data! -5f 6d 61 69 6e 0 - -Writing size value 1048 -Writing a bunch of data! -1 0 6f 36 35 - -Writing size value 1025 -Writing size value 5a -Writing size value 1000 -Writing size value 25 -Writing size value 1025 -Writing size value 0 -Writing size value 0 -Writing size value 1a -Writing size value 0 -Writing a bunch of data! -74 65 73 74 2e 6f 36 35 0 - -Writing a bunch of data! -6c 64 36 35 20 56 32 2e 31 39 20 2d 20 47 69 74 20 30 38 35 31 34 37 34 37 35 0 - -Writing a bunch of data! -46 72 69 20 41 70 72 20 31 35 20 31 36 3a 30 34 3a 30 31 20 32 30 32 32 0 - -Writing a bunch of data! -5 0 - -Text Base: 1025 -Text Size: 5a -Data Base: 1000 -Data Size: 25 diff --git a/sw/test_exec/out2.txt b/sw/test_exec/out2.txt deleted file mode 100644 index b60e9a4..0000000 --- a/sw/test_exec/out2.txt +++ /dev/null @@ -1,488 +0,0 @@ -mkdir -p lists/./ -~/Software/cc65/bin/cl65 -v -T -t none -I. --cpu "65C02" -l lists/main.c.list -c main.c -o main.o -0 errors and 0 warnings generated. -Opened output file 'main.s' -Wrote output to 'main.s' -Closed output file 'main.s' -~/Software/cc65/bin/cl65 -v -T -t none -I. --cpu "65C02" -v -C link.ld -m test.map main.o -o test.o65 -Module 'main.o': Found segment 'CODE', size = 8, alignment = 1, type = 2 -Module 'main.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 -Module 'main.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 -Module 'main.o': Found segment 'DATA', size = 0, alignment = 1, type = 2 -Module 'main.o': Found segment 'ZEROPAGE', size = 0, alignment = 1, type = 1 -Module 'main.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 -Module 'condes.o': Found segment 'CODE', size = 12, alignment = 1, type = 2 -Module 'condes.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 -Module 'condes.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 -Module 'condes.o': Found segment 'DATA', size = 37, alignment = 1, type = 2 -Module 'condes.o': Found segment 'ZEROPAGE', size = 0, alignment = 1, type = 1 -Module 'condes.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 -Module 'condes.o': Found segment 'ONCE', size = 12, alignment = 1, type = 2 -Module 'crt0.o': Found segment 'CODE', size = 0, alignment = 1, type = 2 -Module 'crt0.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 -Module 'crt0.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 -Module 'crt0.o': Found segment 'DATA', size = 0, alignment = 1, type = 2 -Module 'crt0.o': Found segment 'ZEROPAGE', size = 0, alignment = 1, type = 1 -Module 'crt0.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 -Module 'crt0.o': Found segment 'STARTUP', size = 23, alignment = 1, type = 2 -Module 'zerobss.o': Found segment 'CODE', size = 35, alignment = 1, type = 2 -Module 'zerobss.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 -Module 'zerobss.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 -Module 'zerobss.o': Found segment 'DATA', size = 0, alignment = 1, type = 2 -Module 'zerobss.o': Found segment 'ZEROPAGE', size = 0, alignment = 1, type = 1 -Module 'zerobss.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 -Module 'zeropage.o': Found segment 'CODE', size = 0, alignment = 1, type = 2 -Module 'zeropage.o': Found segment 'RODATA', size = 0, alignment = 1, type = 2 -Module 'zeropage.o': Found segment 'BSS', size = 0, alignment = 1, type = 2 -Module 'zeropage.o': Found segment 'DATA', size = 0, alignment = 1, type = 2 -Module 'zeropage.o': Found segment 'ZEROPAGE', size = 26, alignment = 1, type = 1 -Module 'zeropage.o': Found segment 'NULL', size = 0, alignment = 1, type = 2 -Opened 'test.o65'... -Writing size value 1025 -Writing size value 0 -Writing size value 1000 -Writing size value 0 -Writing size value 1025 -Writing size value 0 -Writing size value 0 -Writing size value 0 -Writing size value 0 -WRITING TEXT SEG Writing 'STARTUP' - Section from "crt0.o" - Filling 0x0 bytes with 0x00 - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Section from "[linker generated]" - Filling 0x0 bytes with 0x00 - Section from "[linker generated]" - Filling 0x0 bytes with 0x00 - Writing 'ONCE' - Section from "condes.o" - Filling 0x0 bytes with 0x00 - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Writing 'CODE' - Section from "main.o" - Filling 0x0 bytes with 0x00 - Fragment with 0x2 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Section from "condes.o" - Filling 0x0 bytes with 0x00 - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Section from "crt0.o" - Filling 0x0 bytes with 0x00 - Section from "zerobss.o" - Filling 0x0 bytes with 0x00 - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Section from "zeropage.o" - Filling 0x0 bytes with 0x00 - Writing 'RODATA' - Section from "main.o" - Filling 0x0 bytes with 0x00 - Section from "condes.o" - Filling 0x0 bytes with 0x00 - Section from "crt0.o" - Filling 0x0 bytes with 0x00 - Section from "zerobss.o" - Filling 0x0 bytes with 0x00 - Section from "zeropage.o" - Filling 0x0 bytes with 0x00 -Text count: 4 -Text Size: 90 -WRITING DATA SEG Writing 'DATA' - Section from "main.o" - Filling 0x0 bytes with 0x00 - Section from "condes.o" - Filling 0x0 bytes with 0x00 - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x3 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x3 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x2 bytes - Fragment with 0x3 bytes - Fragment with 0x2 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Fragment with 0x1 bytes - Section from "crt0.o" - Filling 0x0 bytes with 0x00 - Section from "zerobss.o" - Filling 0x0 bytes with 0x00 - Section from "zeropage.o" - Filling 0x0 bytes with 0x00 -Data count: 1 -Data Size: 37 - Writing 'BSS' -Writing zp seg (this should just be a few) Writing 'ZEROPAGE' -WRITING IMPORTSWriting size value 0 -ExtSymCount: 0 -WRITING TEXT RELOCATION - - -Writing size value 1 -Writing size value 1048 -Writing size value 1025 -Writing size value 5a -Writing size value 1000 -Writing size value 25 -Writing size value 1025 -Writing size value 0 -Writing size value 0 -Writing size value 1a -Writing size value 0 -Text Base: 1025 -Text Size: 5a -Data Base: 1000 -Data Size: 25 -Segment: CODE (55) - Section: - Literal (2 bytes): - A2 CC - Literal (2 bytes): - A9 DD - Literal (1 bytes): - 4C - Expression (2 bytes): - SEC $0007 + - Literal (1 bytes): - 60 - Section: - Literal (1 bytes): - A0 - Expression (1 bytes): - SYM() $0002 * BYTE0 - Literal (1 bytes): - F0 - Literal (1 bytes): - 07 - Literal (1 bytes): - A9 - Expression (1 bytes): - SYM() BYTE0 - Literal (1 bytes): - A2 - Expression (1 bytes): - SYM() BYTE1 - Literal (1 bytes): - 4C - Expression (2 bytes): - SEC - Literal (1 bytes): - 60 - Section: - Section: - Literal (1 bytes): - A9 - Expression (1 bytes): - SYM() BYTE0 - Literal (1 bytes): - 85 - Expression (1 bytes): - SYM() - Literal (1 bytes): - A9 - Expression (1 bytes): - SYM() BYTE1 - Literal (1 bytes): - 85 - Expression (1 bytes): - SYM() $0001 + - Literal (2 bytes): - A9 00 - Literal (1 bytes): - A8 - Literal (1 bytes): - A2 - Expression (1 bytes): - SYM() BYTE1 - Literal (1 bytes): - F0 - Literal (1 bytes): - 0A - Literal (1 bytes): - 91 - Expression (1 bytes): - SYM() - Literal (1 bytes): - C8 - Literal (1 bytes): - D0 - Literal (1 bytes): - FB - Literal (1 bytes): - E6 - Expression (1 bytes): - SYM() $0001 + - Literal (1 bytes): - CA - Literal (1 bytes): - D0 - Literal (1 bytes): - F6 - Literal (1 bytes): - C0 - Expression (1 bytes): - SYM() BYTE0 - Literal (1 bytes): - F0 - Literal (1 bytes): - 05 - Literal (1 bytes): - 91 - Expression (1 bytes): - SYM() - Literal (1 bytes): - C8 - Literal (1 bytes): - D0 - Literal (1 bytes): - F7 - Literal (1 bytes): - 60 - Section: -Segment: RODATA (0) - Section: - Section: - Section: - Section: - Section: -Segment: BSS (0) - Section: - Section: - Section: - Section: - Section: -Segment: DATA (37) - Section: - Section: - Literal (1 bytes): - 8D - Expression (2 bytes): - SEC $000D + $0001 + - Literal (1 bytes): - 8E - Expression (2 bytes): - SEC $000D + $0002 + - Literal (1 bytes): - 8D - Expression (2 bytes): - SEC $0014 + $0001 + - Literal (1 bytes): - 8E - Expression (2 bytes): - SEC $0014 + $0002 + - Literal (1 bytes): - 88 - Literal (3 bytes): - B9 FF FF - Literal (1 bytes): - 8D - Expression (2 bytes): - SEC $001D + $0002 + - Literal (1 bytes): - 88 - Literal (3 bytes): - B9 FF FF - Literal (1 bytes): - 8D - Expression (2 bytes): - SEC $001D + $0001 + - Literal (1 bytes): - 8C - Expression (2 bytes): - SEC $0020 + $0001 + - Literal (3 bytes): - 20 FF FF - Literal (2 bytes): - A0 FF - Literal (1 bytes): - D0 - Literal (1 bytes): - E8 - Literal (1 bytes): - 60 - Section: - Section: - Section: -Segment: ZEROPAGE (26) - Section: - Section: - Section: - Section: - Section: - Empty space (2 bytes) - Empty space (2 bytes) - Empty space (4 bytes) - Empty space (2 bytes) - Empty space (2 bytes) - Empty space (2 bytes) - Empty space (2 bytes) - Empty space (1 bytes) - Empty space (1 bytes) - Empty space (1 bytes) - Empty space (1 bytes) - Empty space (6 bytes) -Segment: NULL (0) - Section: - Section: - Section: - Section: - Section: -Segment: ONCE (12) - Section: - Literal (1 bytes): - A0 - Expression (1 bytes): - SYM() $0002 * BYTE0 - Literal (1 bytes): - F0 - Literal (1 bytes): - 07 - Literal (1 bytes): - A9 - Expression (1 bytes): - SYM() BYTE0 - Literal (1 bytes): - A2 - Expression (1 bytes): - SYM() BYTE1 - Literal (1 bytes): - 4C - Expression (2 bytes): - SEC - Literal (1 bytes): - 60 -Segment: STARTUP (23) - Section: - Literal (1 bytes): - A9 - Expression (1 bytes): - SYM() BYTE0 - Literal (1 bytes): - A2 - Expression (1 bytes): - SYM() BYTE1 - Literal (1 bytes): - 85 - Expression (1 bytes): - SYM() - Literal (1 bytes): - 86 - Expression (1 bytes): - SYM() $0001 + - Literal (1 bytes): - 20 - Expression (2 bytes): - SYM() - Literal (1 bytes): - 20 - Expression (2 bytes): - SYM() - Literal (1 bytes): - 20 - Expression (2 bytes): - SYM() - Literal (1 bytes): - 48 - Literal (1 bytes): - 20 - Expression (2 bytes): - SYM() - Literal (1 bytes): - 68 - Literal (1 bytes): - 60 - Section: - Section: -CONDES(0): 0 symbols -CONDES(1): 0 symbols -CONDES(2): 0 symbols -CONDES(3): 0 symbols -CONDES(4): 0 symbols -CONDES(5): 0 symbols -CONDES(6): 0 symbols From 2786ec0940b534f138ffc77ef06948ef7d602e27 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 14:56:41 -0500 Subject: [PATCH 10/11] Execute code read from the SD card This will read the data from the sd card, copy it to the originally linked address (no relocation), then execute it. I am lazy and wrote it in C using weird function pointer casting but this would probably be more efficient if it were to be written in assembly instead. The test program simply returns 'A', but that is enough to prove that it is actually running. --- sw/main.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/sw/main.c b/sw/main.c index 99ba2d0..08b05fa 100644 --- a/sw/main.c +++ b/sw/main.c @@ -1,5 +1,6 @@ #include #include +#include #include "board_io.h" #include "uart.h" @@ -79,7 +80,15 @@ int main() { o65_header_t* header; o65_opt_t* o65_opt; + uint8_t* seg_ptr; + uint16_t code_base; + uint16_t data_base; + uint16_t code_len; + uint16_t data_len; + + uint8_t (*exec)(void); + uint8_t ret; uint16_t reserved_count; uint32_t sectors_per_fat; @@ -222,6 +231,12 @@ int main() { cprintf("stack: %x\n", header->stack); cprintf("\n"); + code_base = header->tbase; + data_base = header->dbase; + code_len = header->tlen; + data_len = header->dlen; + + o65_opt = (o65_opt_t*)(buf + sizeof(o65_header_t)); while (o65_opt->olen) { @@ -246,6 +261,48 @@ int main() { cprintf("\n\n"); o65_opt = (o65_opt_t*)((uint8_t*)o65_opt + o65_opt->olen); } + + seg_ptr = (uint8_t*)o65_opt + 1; + + cprintf("Code: \n"); + for (i = 0; i < code_len; i++) { + cprintf("%x ", seg_ptr[i]); + } + cprintf("\n\n"); + + memcpy((uint8_t*)code_base, seg_ptr, code_len); + + seg_ptr+=code_len; + + cprintf("Data: \n"); + for (i = 0; i < data_len; i++) { + cprintf("%x ", seg_ptr[i]); + } + cprintf("\n\n"); + + memcpy((uint8_t*)data_base, seg_ptr, data_len); + + cprintf("Memory Copied!\n"); + cprintf("Code: \n"); + for (i = 0; i < code_len; i++) { + cprintf("%x ", ((uint8_t*)code_base)[i]); + } + cprintf("\n\n"); + cprintf("Data: \n"); + for (i = 0; i < data_len; i++) { + cprintf("%x ", ((uint8_t*)data_base)[i]); + } + cprintf("\n\n"); + + exec = (int(*)(void))code_base; + + ret = 0; + + ret = (*exec)(); + + cprintf("ret: %x\n", ret); + + } From a94b26dc3c20d1bba56640865288fbfab427574a Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 16 Apr 2022 19:24:21 -0500 Subject: [PATCH 11/11] Change code and data base to be pointers These are technically pointers, so lets type them as such. --- sw/main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sw/main.c b/sw/main.c index 08b05fa..39423a6 100644 --- a/sw/main.c +++ b/sw/main.c @@ -82,8 +82,8 @@ int main() { o65_opt_t* o65_opt; uint8_t* seg_ptr; - uint16_t code_base; - uint16_t data_base; + uint8_t* code_base; + uint8_t* data_base; uint16_t code_len; uint16_t data_len; @@ -231,8 +231,8 @@ int main() { cprintf("stack: %x\n", header->stack); cprintf("\n"); - code_base = header->tbase; - data_base = header->dbase; + code_base = (uint8_t*)header->tbase; + data_base = (uint8_t*)header->dbase; code_len = header->tlen; data_len = header->dlen; @@ -285,16 +285,16 @@ int main() { cprintf("Memory Copied!\n"); cprintf("Code: \n"); for (i = 0; i < code_len; i++) { - cprintf("%x ", ((uint8_t*)code_base)[i]); + cprintf("%x ", code_base[i]); } cprintf("\n\n"); cprintf("Data: \n"); for (i = 0; i < data_len; i++) { - cprintf("%x ", ((uint8_t*)data_base)[i]); + cprintf("%x ", data_base[i]); } cprintf("\n\n"); - exec = (int(*)(void))code_base; + exec = (uint8_t (*)(void))code_base; ret = 0;