diff --git a/base.mk b/base.mk index 6d99611..b6e3f3f 100644 --- a/base.mk +++ b/base.mk @@ -103,10 +103,10 @@ endef $(AS) $(AARCH) $(AFLAGS) $(DEBUG) $< -o $@ %.o: %.c - $(CC) $(CARCH) $(CFLAGS) -std=c23 $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@ + $(CC) $(CARCH) $(CFLAGS) -std=gnu23 $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@ %.o: %.cpp - $(CXX) $(CARCH) $(CFLAGS) $(CXXFLAGS) $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@ + $(CXX) $(CARCH) $(CFLAGS) -std=c++23 $(CXXFLAGS) $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@ %.elf: $(LD) $(LDFLAGS) -L $(LIB) -T $(LDSCRIPT) $^ -o $@ diff --git a/common.mk b/common.mk index cebe704..03ad6bd 100644 --- a/common.mk +++ b/common.mk @@ -3,11 +3,9 @@ GENERATED ?= AARCH = --isa=sh4 --little -CARCH = -m4-single-only -ml +CARCH ?= -m4-single-only -ml CFLAGS += -mfsca -funsafe-math-optimizations -ffast-math -CXXFLAGS += -std=c++23 - OBJARCH = -O elf32-shl -B sh4 TARGET = sh4-none-elf- diff --git a/example/example.mk b/example/example.mk index 5c44e08..89d71d5 100644 --- a/example/example.mk +++ b/example/example.mk @@ -388,9 +388,9 @@ SERIAL_TRANSFER_OBJ = \ example/serial_transfer.o \ sh7091/serial.o \ serial_load.o \ - maple/maple.o \ - font/portfolio_6x8/portfolio_6x8.data.o \ crc32.o +# maple/maple.o \ +# font/portfolio_6x8/portfolio_6x8.data.o \ example/serial_transfer.elf: LDSCRIPT = $(LIB)/loader.lds example/serial_transfer.elf: $(START_OBJ) $(SERIAL_TRANSFER_OBJ) diff --git a/example/serial_transfer.cpp b/example/serial_transfer.cpp index 406d739..529f8d0 100644 --- a/example/serial_transfer.cpp +++ b/example/serial_transfer.cpp @@ -405,11 +405,13 @@ void main() constexpr uint32_t serial_speed = 0; serial_load::init(serial_speed); + /* const uint8_t * font = reinterpret_cast(&_binary_font_portfolio_6x8); auto renderer0 = maple::display::font_renderer(font); framebuffer[0] = renderer0.fb; auto renderer1 = maple::display::font_renderer(font); framebuffer[1] = renderer1.fb; + */ // reset serial status sh7091.SCIF.SCFSR2 = 0; @@ -463,10 +465,11 @@ void main() } } + //serial::string("."); serial_load::tick(poll_state); - render(renderer0, renderer1); + //render(renderer0, renderer1); - poll_state.want_start = 1; - handle_maple(poll_state); + //poll_state.want_start = 1; + //handle_maple(poll_state); } } diff --git a/serial_load.cpp b/serial_load.cpp index fde73b9..0eb6da5 100644 --- a/serial_load.cpp +++ b/serial_load.cpp @@ -2,10 +2,14 @@ #include "sh7091/serial.hpp" #include "sh7091/serial_dma.hpp" +#include "sh7091/cache.hpp" #include "serial_load.hpp" #include "crc32.h" +#include "align.hpp" +#include "memory.hpp" + namespace serial_load { struct state state; @@ -162,7 +166,7 @@ void recv(struct maple_poll_state& poll_state, uint8_t c) } } // invalid command - move(&state.buf.u8[0], &state.buf.u8[1], state.len - 1); + memory::move(&state.buf.u8[0], &state.buf.u8[1], state.len - 1); state.len -= 1; break; } @@ -185,6 +189,16 @@ void tick(struct maple_poll_state& poll_state) if (dar1 > state.reply_crc.offset) { uint32_t len = dar1 - state.reply_crc.offset; const uint8_t * buf = reinterpret_cast(state.reply_crc.offset); + const uint8_t * buf32 = reinterpret_cast((state.reply_crc.offset / 32) * 32); // round down + + // purge operand cache blocks for the data written by DMA, rounding up twice + for (uint32_t i = 0; i < align_32byte(len) + 32; i += 32) { + asm volatile ("ocbp @%0" + : // output + : "r" (reinterpret_cast(&buf32[i])) // input + ); + } + state.reply_crc.value = crc32_update(state.reply_crc.value, buf, len); state.reply_crc.offset += len; } @@ -248,6 +262,9 @@ void tick(struct maple_poll_state& poll_state) if ((sh7091.SCIF.SCFSR2 & transmission_end) != transmission_end) return; + // clear the cache before jumping + cache::init(); + const uint32_t dest = state.buf.arg[0]; jump_to_func(dest); diff --git a/sh7091/cache.cpp b/sh7091/cache.cpp index ee12709..a99bf57 100644 --- a/sh7091/cache.cpp +++ b/sh7091/cache.cpp @@ -12,10 +12,12 @@ namespace cache { void init() { for (int i = 0; i < 256; i++) { + // clear all V bits of the IC address array sh7091_ic_a[i][0] = 0; } for (int i = 0; i < 512; i++) { + // clear all V bits of the OC address array sh7091_oc_a[i][0] = 0; }