From 69dda55681459f05e68c85e7dbcd8c91859a3224 Mon Sep 17 00:00:00 2001 From: Polprzewodnikowy Date: Sat, 24 Sep 2022 20:02:31 +0200 Subject: [PATCH] cache stuff --- sw/bootloader/src/exception.S | 10 ++++++++-- sw/bootloader/src/io.c | 11 ++++++----- sw/bootloader/src/io.h | 2 +- sw/bootloader/src/startup.S | 1 - sw/bootloader/src/vr4300.h | 3 +++ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/sw/bootloader/src/exception.S b/sw/bootloader/src/exception.S index daca4c0..0919434 100644 --- a/sw/bootloader/src/exception.S +++ b/sw/bootloader/src/exception.S @@ -175,13 +175,19 @@ exception_install: add $t5, $t5, $t4 2: lw $t6, 0($t3) - sw $t6, 0($t4) - cache HIT_INVALIDATE_I, 0($t4) addiu $t3, 4 + sw $t6, 0($t4) addiu $t4, 4 bne $t4, $t5, 2b addiu $t1, VECTOR_SIZE bne $t1, $t2, 1b + li $t0, VECTOR_LOCATION + li $t1, (VECTOR_SIZE * VECTOR_NUM) + add $t1, $t0, $t1 +3: + cache HIT_INVALIDATE_I, 0($t0) + addiu $t0, CACHE_LINE_SIZE_I + bne $t0, $t1, 3b jr $ra diff --git a/sw/bootloader/src/io.c b/sw/bootloader/src/io.c index 39bc4ef..d3fa90a 100644 --- a/sw/bootloader/src/io.c +++ b/sw/bootloader/src/io.c @@ -1,4 +1,5 @@ #include "io.h" +#include "vr4300.h" static void cache_operation (uint8_t operation, uint8_t line_size, void *address, size_t length) { @@ -13,16 +14,16 @@ static void cache_operation (uint8_t operation, uint8_t line_size, void *address } } -void cache_data_hit_invalidate (void *address, size_t length) { - cache_operation(0x11, 16, address, length); +void cache_data_hit_writeback_invalidate (void *address, size_t length) { + cache_operation(HIT_WRITE_BACK_INVALIDATE_D, CACHE_LINE_SIZE_D, address, length); } void cache_data_hit_writeback (void *address, size_t length) { - cache_operation(0x19, 16, address, length); + cache_operation(HIT_WRITE_BACK_D, CACHE_LINE_SIZE_D, address, length); } void cache_inst_hit_invalidate (void *address, size_t length) { - cache_operation(0x10, 32, address, length); + cache_operation(HIT_INVALIDATE_I, CACHE_LINE_SIZE_I, address, length); } uint32_t io_read (io32_t *address) { @@ -50,11 +51,11 @@ void pi_io_write (io32_t *address, uint32_t value) { } void pi_dma_read (io32_t *address, void *buffer, size_t length) { + cache_data_hit_writeback_invalidate(buffer, length); io_write(&PI->PADDR, (uint32_t) (PHYSICAL(address))); io_write(&PI->MADDR, (uint32_t) (PHYSICAL(buffer))); io_write(&PI->WDMA, length - 1); while (pi_busy()); - cache_data_hit_invalidate(buffer, length); } void pi_dma_write (io32_t *address, void *buffer, size_t length) { diff --git a/sw/bootloader/src/io.h b/sw/bootloader/src/io.h index c3e11e5..03d3a18 100644 --- a/sw/bootloader/src/io.h +++ b/sw/bootloader/src/io.h @@ -286,7 +286,7 @@ void pi_dma_write (io32_t *address, void *buffer, size_t length); uint32_t si_busy (void); uint32_t si_io_read (io32_t *address); void si_io_write (io32_t *address, uint32_t value); -void cache_data_hit_invalidate (void *address, size_t length); +void cache_data_hit_writeback_invalidate (void *address, size_t length); void cache_data_hit_writeback (void *address, size_t length); void cache_inst_hit_invalidate (void *address, size_t length); diff --git a/sw/bootloader/src/startup.S b/sw/bootloader/src/startup.S index 04f640b..2b2fe03 100644 --- a/sw/bootloader/src/startup.S +++ b/sw/bootloader/src/startup.S @@ -40,7 +40,6 @@ bss_init: la $a1, _ebss 1: sd $zero, 0($a0) - cache HIT_WRITE_BACK_D, 0($a0) addiu $a0, 8 bltu $a0, $a1, 1b diff --git a/sw/bootloader/src/vr4300.h b/sw/bootloader/src/vr4300.h index e25ba45..58b3617 100644 --- a/sw/bootloader/src/vr4300.h +++ b/sw/bootloader/src/vr4300.h @@ -3,8 +3,11 @@ #define HIT_INVALIDATE_I ((4 << 2) | 0) +#define HIT_WRITE_BACK_INVALIDATE_D ((5 << 2) | 1) #define HIT_WRITE_BACK_D ((6 << 2) | 1) +#define CACHE_LINE_SIZE_I (32) +#define CACHE_LINE_SIZE_D (16) #define C0_BADVADDR $8 #define C0_COUNT $9