2022-05-31 18:28:17 +00:00
|
|
|
|
#include "global.h"
|
|
|
|
|
|
2024-01-31 00:30:27 +00:00
|
|
|
|
size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr) {
|
2022-05-31 18:28:17 +00:00
|
|
|
|
s32 pad[3];
|
|
|
|
|
uintptr_t end;
|
2023-02-27 08:14:02 +00:00
|
|
|
|
OverlayRelocationSection* ovlRelocs;
|
2024-01-31 00:30:27 +00:00
|
|
|
|
u32 relocSectionOffset = 0;
|
|
|
|
|
s32 size = vromEnd - vromStart;
|
2022-05-31 18:28:17 +00:00
|
|
|
|
|
|
|
|
|
if (gOverlayLogSeverity >= 3) {
|
2024-08-27 12:32:33 +00:00
|
|
|
|
PRINTF(
|
|
|
|
|
T("\nダイナミックリンクファンクションのロードを開始します\n", "\nStart loading dynamic link function\n"));
|
2022-05-31 18:28:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 00:30:27 +00:00
|
|
|
|
size = vromEnd - vromStart;
|
|
|
|
|
end = (uintptr_t)allocatedRamAddr + size;
|
|
|
|
|
|
2022-05-31 18:28:17 +00:00
|
|
|
|
if (gOverlayLogSeverity >= 3) {
|
2024-08-27 12:32:33 +00:00
|
|
|
|
PRINTF(T("TEXT,DATA,RODATA+relをDMA転送します(%08x-%08x)\n",
|
|
|
|
|
"DMA transfer of TEXT, DATA, RODATA + rel (%08x-%08x)\n"),
|
|
|
|
|
allocatedRamAddr, end);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 08:14:02 +00:00
|
|
|
|
// DMA the overlay, wait until transfer completes
|
|
|
|
|
DmaMgr_RequestSync(allocatedRamAddr, vromStart, size);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
|
2023-02-27 08:14:02 +00:00
|
|
|
|
// The overlay file is expected to contain a 32-bit offset from the end of the file to the start of the
|
|
|
|
|
// relocation section.
|
|
|
|
|
relocSectionOffset = ((s32*)end)[-1];
|
|
|
|
|
ovlRelocs = (OverlayRelocationSection*)(end - relocSectionOffset);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
|
|
|
|
|
if (gOverlayLogSeverity >= 3) {
|
2024-01-12 15:38:13 +00:00
|
|
|
|
PRINTF("TEXT(%08x), DATA(%08x), RODATA(%08x), BSS(%08x)\n", ovlRelocs->textSize, ovlRelocs->dataSize,
|
|
|
|
|
ovlRelocs->rodataSize, ovlRelocs->bssSize);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gOverlayLogSeverity >= 3) {
|
2024-08-27 12:32:33 +00:00
|
|
|
|
PRINTF(T("リロケーションします\n", "Relocate\n"));
|
2022-05-31 18:28:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 08:14:02 +00:00
|
|
|
|
// Relocate pointers in overlay code and data
|
|
|
|
|
Overlay_Relocate(allocatedRamAddr, ovlRelocs, vramStart);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
|
2023-02-27 08:14:02 +00:00
|
|
|
|
// Clear bss if present, bss is located immediately following the relocations
|
|
|
|
|
if (ovlRelocs->bssSize != 0) {
|
2022-05-31 18:28:17 +00:00
|
|
|
|
if (gOverlayLogSeverity >= 3) {
|
2024-08-27 12:32:33 +00:00
|
|
|
|
PRINTF(T("BSS領域をクリアします(%08x-%08x)\n", "Clear BSS area (%08x-%08x)\n"), end,
|
|
|
|
|
end + ovlRelocs->bssSize);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
}
|
2024-01-31 00:30:27 +00:00
|
|
|
|
bzero((void*)end, ovlRelocs->bssSize);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 00:30:27 +00:00
|
|
|
|
size = (uintptr_t)(ovlRelocs->relocations + ovlRelocs->nRelocations) - (uintptr_t)ovlRelocs;
|
2023-02-27 08:14:02 +00:00
|
|
|
|
|
2022-05-31 18:28:17 +00:00
|
|
|
|
if (gOverlayLogSeverity >= 3) {
|
2024-08-27 12:32:33 +00:00
|
|
|
|
PRINTF(T("REL領域をクリアします(%08x-%08x)\n", "Clear REL area (%08x-%08x)\n"), ovlRelocs,
|
|
|
|
|
(uintptr_t)ovlRelocs + size);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 08:14:02 +00:00
|
|
|
|
// Clear relocations, this space remains allocated and goes unused
|
|
|
|
|
bzero(ovlRelocs, size);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
|
2023-02-27 08:14:02 +00:00
|
|
|
|
// Manually flush caches
|
|
|
|
|
size = (uintptr_t)vramEnd - (uintptr_t)vramStart;
|
|
|
|
|
osWritebackDCache(allocatedRamAddr, size);
|
|
|
|
|
osInvalICache(allocatedRamAddr, size);
|
2022-05-31 18:28:17 +00:00
|
|
|
|
|
|
|
|
|
if (gOverlayLogSeverity >= 3) {
|
2024-08-27 12:32:33 +00:00
|
|
|
|
PRINTF(
|
|
|
|
|
T("ダイナミックリンクファンクションのロードを終了します\n\n", "Finish loading dynamic link function\n\n"));
|
2022-05-31 18:28:17 +00:00
|
|
|
|
}
|
2024-01-31 00:30:27 +00:00
|
|
|
|
|
2022-05-31 18:28:17 +00:00
|
|
|
|
return size;
|
|
|
|
|
}
|