From 91d60a6ca43bb6eefe82a607a34561b6383782d7 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Sat, 16 Mar 2024 17:40:31 -0600 Subject: [PATCH] hb: R/W SD data all at once instead of in blocks --- hb/dldi/source/dcache.s | 73 ++++++++++++++++++++++++++++ hb/dldi/source/iointerface.c | 92 +++++++++++++++++++++++++++--------- 2 files changed, 142 insertions(+), 23 deletions(-) create mode 100644 hb/dldi/source/dcache.s diff --git a/hb/dldi/source/dcache.s b/hb/dldi/source/dcache.s new file mode 100644 index 000000000..a81e55dd5 --- /dev/null +++ b/hb/dldi/source/dcache.s @@ -0,0 +1,73 @@ +/*--------------------------------------------------------------------------------- + + Copyright (C) 2005 + Michael Noland (joat) + Jason Rogers (dovoto) + Dave Murphy (WinterMute) + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any + damages arising from the use of this software. + + Permission is granted to anyone to use this software for any + purpose, including commercial applications, and to alter it and + redistribute it freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you + must not claim that you wrote the original software. If you use + this software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and + must not be misrepresented as being the original software. + 3. This notice may not be removed or altered from any source + distribution. + +---------------------------------------------------------------------------------*/ +#include + +//--------------------------------------------------------------------------------- + .arm +//--------------------------------------------------------------------------------- +BEGIN_ASM_FUNC DC_FlushRange +/*--------------------------------------------------------------------------------- + Clean and invalidate a range +---------------------------------------------------------------------------------*/ + add r1, r1, r0 + bic r0, r0, #(CACHE_LINE_SIZE - 1) +.flush: + mcr p15, 0, r0, c7, c14, 1 @ clean and flush address + add r0, r0, #CACHE_LINE_SIZE + cmp r0, r1 + blt .flush + +drainWriteBuffer: + mov r0, #0 + mcr p15, 0, r0, c7, c10, 4 @ drain write buffer + bx lr + +//--------------------------------------------------------------------------------- +BEGIN_ASM_FUNC DC_InvalidateAll +/*--------------------------------------------------------------------------------- + Clean and invalidate entire data cache +---------------------------------------------------------------------------------*/ + mov r0, #0 + mcr p15, 0, r0, c7, c6, 0 + bx lr + +//--------------------------------------------------------------------------------- +BEGIN_ASM_FUNC DC_InvalidateRange +/*--------------------------------------------------------------------------------- + Invalidate a range +---------------------------------------------------------------------------------*/ + add r1, r1, r0 + tst r0, #CACHE_LINE_SIZE - 1 + mcrne p15, 0, r0, c7, c10, 1 @ clean D entry + tst r1, #CACHE_LINE_SIZE - 1 + mcrne p15, 0, r1, c7, c10, 1 @ clean D entry + bic r0, r0, #CACHE_LINE_SIZE - 1 +.invalidate: + mcr p15, 0, r0, c7, c6, 1 + add r0, r0, #CACHE_LINE_SIZE + cmp r0, r1 + blt .invalidate + bx lr diff --git a/hb/dldi/source/iointerface.c b/hb/dldi/source/iointerface.c index 1d1129eb0..3762d5330 100644 --- a/hb/dldi/source/iointerface.c +++ b/hb/dldi/source/iointerface.c @@ -45,6 +45,27 @@ #include "locations.h" #include "aeabi.h" +/*! \fn DC_FlushRange(const void *base, u32 size) + \brief flush the data cache for a range of addresses to memory. + \param base base address of the region to flush. + \param size size of the region to flush. +*/ +void DC_FlushRange(const void *base, u32 size); + + +/*! \fn DC_InvalidateAll() + \brief invalidate the entire data cache. +*/ +void DC_InvalidateAll(); + + +/*! \fn DC_InvalidateRange(const void *base, u32 size) + \brief invalidate the data cache for a range of addresses. + \param base base address of the region to invalidate + \param size size of the region to invalidate. +*/ +void DC_InvalidateRange(const void *base, u32 size); + extern char ioType[4]; extern u32 dataStartOffset; //extern vu32 word_command; // word_command_offset @@ -165,29 +186,42 @@ bool sd_ReadSectors(sec_t sector, sec_t numSectors,void* buffer) { //nocashMessage("sd_ReadSectors"); FifoMessage msg; int result = 0; - sec_t startsector, readsectors; + if ((u32)buffer < 0x02000000 || (u32)buffer >= 0x04000000) { + sec_t startsector, readsectors; + + int max_reads = ((1 << allocated_space) / 512) - 11; + + for(int numreads =0; numreads= 0x04000000) { + sec_t startsector, readsectors; - int max_reads = ((1 << allocated_space) / 512) - 11; + int max_reads = ((1 << allocated_space) / 512) - 11; - for(int numreads =0; numreads