#include #include #include #include #include "asm.h" template void writeTo(const char* memoryType) { auto logValue = [](uint32_t value){ if (wasExceptionThrown()) { printf("%-10s ", "--CRASH--"); } else { printf("%#10x ", value); } }; printf("%-10s (0x%08x) ", memoryType, address); uint32_t value = 0x12345678; T preservedValue = *((volatile T*)address); if constexpr (sizeof(T) >= 1) { *((volatile T*)address) = 0; asm_write_8(address, value); uint32_t result8 = *((volatile T*)address); logValue(result8); } if constexpr (sizeof(T) >= 2) { *((volatile T*)address) = 0; asm_write_16(address, value); uint32_t result16 = *((volatile T*)address); logValue(result16); } if constexpr (sizeof(T) >= 4) { *((volatile T*)address) = 0; asm_write_32(address, value); uint32_t result32 = *((volatile T*)address); logValue(result32); } *((volatile T*)address) = preservedValue; printf("\n"); } template void runTests() { printf("\nReading as %dbit, writing as:\n", sizeof(T)*8); printf("SEGMENT ( ADDRESS) "); if constexpr (sizeof(T) >= 1) printf("8bit "); if constexpr (sizeof(T) >= 2) printf("16bit "); if constexpr (sizeof(T) >= 4) printf("32bit "); printf("\n"); write32(0x1f801020, 0x00001325); // COM_DELAY writeTo("RAM"); writeTo("BIOS"); // RO writeTo("SCRATCHPAD"); // write32(0x1F801000, 0x1F000000); // Exp1 base // write32(0x1F801008, 0x0013243F); // Exp1 Delay/Size // writeTo("EXPANSION1"); // Stalls the console ¯\_(ツ)_/¯ write32(0x1F801004, 0x1F802000); // Exp2 base write32(0x1F80101C, 0x00070777); // Exp2 Delay/Size writeTo("EXPANSION2"); write32(0x1F80100C, 0x00003022); // Exp3 Delay/Size writeTo("EXPANSION3"); writeTo("DMA0_ADDR"); writeTo("DMAC_CTRL"); writeTo("DMAC_INTR"); writeTo("JOY_MODE"); // Crash on 32bit writeTo("JOY_CTRL"); writeTo("SIO_MODE"); // Crash on 32bit writeTo("SIO_CTRL"); // writeTo("RAM_SIZE"); // Stalls the console writeTo("I_MASK"); writeTo("T0_TARGET"); write32(0x1f801018, 0x00020943); // CDROM Delay/Size writeTo("CDROM_STAT"); writeTo("GPUSTAT"); writeTo("MDECSTAT"); write32(0x1F801014, 0x220931E1); // SPU Delay/Size writeTo("SPUCNT"); // Crash on 32bit // writeTo("CACHECTRL"); // Stalls the console } int main() { initVideo(320, 240); clearScreen(); printf("\ncpu/io-access-bitwidth\n"); printf("Test how writes with different bitwidths behaves for different io devices\n"); printf("Note: Disable \"Exception Handling Surveillance\" in Caetla first\"\n"); EnterCriticalSection(); hookUnresolvedExceptionHandler(exceptionHandler); wasExceptionThrown(); // Clear flag runTests(); runTests(); runTests(); printf("Done.\n"); ExitCriticalSection(); for (;;) { VSync(false); } return 0; }