Replace magic numbers with defines for Arm11 userland memory regions; clean up and enhance osConvertVirtToPhys

This commit is contained in:
fincs 2020-07-01 20:48:18 +02:00
parent dfbfc1564f
commit 53cbfc231f
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
4 changed files with 51 additions and 14 deletions

View File

@ -26,6 +26,36 @@
/// Retrieves the revision version from a packed system version.
#define GET_VERSION_REVISION(version) (((version)>> 8)&0xFF)
#define OS_HEAP_AREA_BEGIN 0x08000000 ///< Start of the heap area in the virtual address space
#define OS_HEAP_AREA_END 0x0E000000 ///< End of the heap area in the virtual address space
#define OS_MAP_AREA_BEGIN 0x10000000 ///< Start of the mappable area in the virtual address space
#define OS_MAP_AREA_END 0x14000000 ///< End of the mappable area in the virtual address space
#define OS_OLD_FCRAM_VADDR 0x14000000 ///< Old pre-8.x linear FCRAM mapping virtual address
#define OS_OLD_FCRAM_PADDR 0x20000000 ///< Old pre-8.x linear FCRAM mapping physical address
#define OS_OLD_FCRAM_SIZE 0x8000000 ///< Old pre-8.x linear FCRAM mapping size (128 MiB)
#define OS_QTMRAM_VADDR 0x1E800000 ///< New3DS QTM memory virtual address
#define OS_QTMRAM_PADDR 0x1F000000 ///< New3DS QTM memory physical address
#define OS_QTMRAM_SIZE 0x400000 ///< New3DS QTM memory size (4 MiB; last 128 KiB reserved by kernel)
#define OS_MMIO_VADDR 0x1EC00000 ///< Memory mapped IO range virtual address
#define OS_MMIO_PADDR 0x10100000 ///< Memory mapped IO range physical address
#define OS_MMIO_SIZE 0x400000 ///< Memory mapped IO range size (4 MiB)
#define OS_VRAM_VADDR 0x1F000000 ///< VRAM virtual address
#define OS_VRAM_PADDR 0x18000000 ///< VRAM physical address
#define OS_VRAM_SIZE 0x600000 ///< VRAM size (6 MiB)
#define OS_DSPRAM_VADDR 0x1FF00000 ///< DSP memory virtual address
#define OS_DSPRAM_PADDR 0x1FF00000 ///< DSP memory physical address
#define OS_DSPRAM_SIZE 0x80000 ///< DSP memory size (512 KiB)
#define OS_FCRAM_VADDR 0x30000000 ///< Linear FCRAM mapping virtual address
#define OS_FCRAM_PADDR 0x20000000 ///< Linear FCRAM mapping physical address
#define OS_FCRAM_SIZE 0x10000000 ///< Linear FCRAM mapping size (256 MiB)
/// Tick counter.
typedef struct
{

View File

@ -1,6 +1,7 @@
extern "C"
{
#include <3ds/types.h>
#include <3ds/os.h>
#include <3ds/allocator/vram.h>
#include <3ds/util/rbtree.h>
}
@ -12,7 +13,7 @@ static MemPool sVramPool;
static bool vramInit()
{
auto blk = MemBlock::Create((u8*)0x1F000000, 0x00600000);
auto blk = MemBlock::Create((u8*)OS_VRAM_VADDR, OS_VRAM_SIZE);
if (blk)
{
sVramPool.AddBlock(blk);

View File

@ -29,14 +29,18 @@ __attribute__((weak)) bool __ctru_speedup = false;
u32 osConvertVirtToPhys(const void* addr) {
//---------------------------------------------------------------------------------
u32 vaddr = (u32)addr;
if(vaddr >= 0x14000000 && vaddr < 0x1c000000)
return vaddr + 0x0c000000; // LINEAR heap
if(vaddr >= 0x1F000000 && vaddr < 0x1F600000)
return vaddr - 0x07000000; // VRAM
if(vaddr >= 0x1FF00000 && vaddr < 0x1FF80000)
return vaddr + 0x00000000; // DSP memory
if(vaddr >= 0x30000000 && vaddr < 0x40000000)
return vaddr - 0x10000000; // Only available under FIRM v8+ for certain processes.
#define CONVERT_REGION(_name) \
if (vaddr >= OS_##_name##_VADDR && vaddr < (OS_##_name##_VADDR + OS_##_name##_SIZE)) \
return vaddr + (OS_##_name##_PADDR - OS_##_name##_VADDR);
CONVERT_REGION(FCRAM);
CONVERT_REGION(VRAM);
CONVERT_REGION(OLD_FCRAM);
CONVERT_REGION(DSPRAM);
CONVERT_REGION(QTMRAM);
CONVERT_REGION(MMIO);
#undef CONVERT_REGION
return 0;
}
@ -44,9 +48,11 @@ u32 osConvertVirtToPhys(const void* addr) {
void* osConvertOldLINEARMemToNew(const void* addr) {
//---------------------------------------------------------------------------------
u32 vaddr = (u32)addr;
if(vaddr >= 0x30000000 && vaddr < 0x40000000)return (void*)vaddr;
if(vaddr >= 0x14000000 && vaddr < 0x1c000000)return (void*)(vaddr+0x1c000000);
return 0;
if (vaddr >= OS_FCRAM_VADDR && vaddr < (OS_FCRAM_VADDR+OS_FCRAM_SIZE))
return (void*)vaddr;
if (vaddr >= OS_OLD_FCRAM_VADDR && vaddr < (OS_FCRAM_VADDR+OS_OLD_FCRAM_SIZE))
return (void*)(vaddr + (OS_FCRAM_VADDR-OS_OLD_FCRAM_VADDR));
return NULL;
}
//---------------------------------------------------------------------------------

View File

@ -33,14 +33,14 @@ void __attribute__((weak)) __system_allocateHeaps(void) {
}
// Allocate the application heap
__ctru_heap = 0x08000000;
__ctru_heap = OS_HEAP_AREA_BEGIN;
svcControlMemory(&tmp, __ctru_heap, 0x0, __ctru_heap_size, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE);
// Allocate the linear heap
svcControlMemory(&__ctru_linear_heap, 0x0, 0x0, __ctru_linear_heap_size, MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
// Mappable allocator init
mappableInit(0x10000000, 0x14000000);
mappableInit(OS_MAP_AREA_BEGIN, OS_MAP_AREA_END);
// Set up newlib heap
fake_heap_start = (char*)__ctru_heap;