mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-17 19:21:30 +12:00
[Memory] Add DSP RAM
This commit is contained in:
parent
c34011326e
commit
f858107dd0
2 changed files with 26 additions and 1 deletions
|
@ -34,7 +34,9 @@ namespace VirtualAddrs {
|
||||||
|
|
||||||
// Start of TLS for first thread. Next thread's storage will be at TLSBase + 0x1000, and so on
|
// Start of TLS for first thread. Next thread's storage will be at TLSBase + 0x1000, and so on
|
||||||
TLSBase = 0xFF400000,
|
TLSBase = 0xFF400000,
|
||||||
TLSSize = 0x1000
|
TLSSize = 0x1000,
|
||||||
|
|
||||||
|
DSPMemStart = 0x1FF00000
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +88,8 @@ namespace KernelMemoryTypes {
|
||||||
|
|
||||||
class Memory {
|
class Memory {
|
||||||
u8* fcram;
|
u8* fcram;
|
||||||
|
u8* dspRam;
|
||||||
|
|
||||||
u64& cpuTicks; // Reference to the CPU tick counter
|
u64& cpuTicks; // Reference to the CPU tick counter
|
||||||
using SharedMemoryBlock = KernelMemoryTypes::SharedMemoryBlock;
|
using SharedMemoryBlock = KernelMemoryTypes::SharedMemoryBlock;
|
||||||
|
|
||||||
|
@ -110,6 +114,10 @@ class Memory {
|
||||||
static constexpr u32 FCRAM_PAGE_COUNT = FCRAM_SIZE / pageSize;
|
static constexpr u32 FCRAM_PAGE_COUNT = FCRAM_SIZE / pageSize;
|
||||||
static constexpr u32 FCRAM_APPLICATION_PAGE_COUNT = FCRAM_APPLICATION_SIZE / pageSize;
|
static constexpr u32 FCRAM_APPLICATION_PAGE_COUNT = FCRAM_APPLICATION_SIZE / pageSize;
|
||||||
|
|
||||||
|
static constexpr u32 DSP_RAM_SIZE = 512_KB;
|
||||||
|
static constexpr u32 DSP_CODE_MEMORY_OFFSET = 0_KB;
|
||||||
|
static constexpr u32 DSP_DATA_MEMORY_OFFSET = 256_KB;
|
||||||
|
|
||||||
std::bitset<FCRAM_PAGE_COUNT> usedFCRAMPages;
|
std::bitset<FCRAM_PAGE_COUNT> usedFCRAMPages;
|
||||||
std::optional<u32> findPaddr(u32 size);
|
std::optional<u32> findPaddr(u32 size);
|
||||||
u64 timeSince3DSEpoch();
|
u64 timeSince3DSEpoch();
|
||||||
|
@ -178,4 +186,8 @@ public:
|
||||||
std::optional<NCCH> loadedCXI = std::nullopt;
|
std::optional<NCCH> loadedCXI = std::nullopt;
|
||||||
// File handle for reading the loaded ncch
|
// File handle for reading the loaded ncch
|
||||||
IOFile CXIFile;
|
IOFile CXIFile;
|
||||||
|
|
||||||
|
u8* getDSPMem() { return dspRam; }
|
||||||
|
u8* getDSPDataMem() { return &dspRam[DSP_DATA_MEMORY_OFFSET]; }
|
||||||
|
u8* getDSPCodeMem() { return &dspRam[DSP_CODE_MEMORY_OFFSET]; }
|
||||||
};
|
};
|
|
@ -8,6 +8,8 @@ using namespace KernelMemoryTypes;
|
||||||
|
|
||||||
Memory::Memory(u64& cpuTicks) : cpuTicks(cpuTicks) {
|
Memory::Memory(u64& cpuTicks) : cpuTicks(cpuTicks) {
|
||||||
fcram = new uint8_t[FCRAM_SIZE]();
|
fcram = new uint8_t[FCRAM_SIZE]();
|
||||||
|
dspRam = new uint8_t[DSP_RAM_SIZE]();
|
||||||
|
|
||||||
readTable.resize(totalPageCount, 0);
|
readTable.resize(totalPageCount, 0);
|
||||||
writeTable.resize(totalPageCount, 0);
|
writeTable.resize(totalPageCount, 0);
|
||||||
memoryInfo.reserve(32); // Pre-allocate some room for memory allocation info to avoid dynamic allocs
|
memoryInfo.reserve(32); // Pre-allocate some room for memory allocation info to avoid dynamic allocs
|
||||||
|
@ -49,6 +51,17 @@ void Memory::reset() {
|
||||||
Helpers::panic("Failed to reserve memory for shared memory block");
|
Helpers::panic("Failed to reserve memory for shared memory block");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map DSP RAM as R/W at [0x1FF00000, 0x1FF7FFFF]
|
||||||
|
constexpr u32 dspRamPages = DSP_RAM_SIZE / pageSize; // Number of DSP RAM pages
|
||||||
|
constexpr u32 initialPage = VirtualAddrs::DSPMemStart / pageSize; // First page of DSP RAM in the virtual address space
|
||||||
|
|
||||||
|
for (u32 i = 0; i < dspRamPages; i++) {
|
||||||
|
auto pointer = uintptr_t(&dspRam[i * pageSize]);
|
||||||
|
|
||||||
|
readTable[i + initialPage] = pointer;
|
||||||
|
writeTable[i + initialPage] = pointer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 Memory::read8(u32 vaddr) {
|
u8 Memory::read8(u32 vaddr) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue