mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-24 02:29:20 +01:00
Merge pull request #267 from bunnei/apt-shared-font
APT shared font loading
This commit is contained in:
commit
a6791e4fc7
@ -29,19 +29,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Shared data dirs (Sys and shared User for linux)
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define SYSDATA_DIR "sys"
|
|
||||||
#else
|
|
||||||
#ifdef DATA_DIR
|
|
||||||
#define SYSDATA_DIR DATA_DIR "sys"
|
|
||||||
#define SHARED_USER_DIR DATA_DIR USERDATA_DIR DIR_SEP
|
|
||||||
#else
|
|
||||||
#define SYSDATA_DIR "sys"
|
|
||||||
#define SHARED_USER_DIR ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Dirs in both User and Sys
|
// Dirs in both User and Sys
|
||||||
#define EUR_DIR "EUR"
|
#define EUR_DIR "EUR"
|
||||||
#define USA_DIR "USA"
|
#define USA_DIR "USA"
|
||||||
@ -53,6 +40,7 @@
|
|||||||
#define MAPS_DIR "maps"
|
#define MAPS_DIR "maps"
|
||||||
#define CACHE_DIR "cache"
|
#define CACHE_DIR "cache"
|
||||||
#define SDMC_DIR "sdmc"
|
#define SDMC_DIR "sdmc"
|
||||||
|
#define SYSDATA_DIR "sysdata"
|
||||||
#define SHADERCACHE_DIR "shader_cache"
|
#define SHADERCACHE_DIR "shader_cache"
|
||||||
#define STATESAVES_DIR "state_saves"
|
#define STATESAVES_DIR "state_saves"
|
||||||
#define SCREENSHOTS_DIR "screenShots"
|
#define SCREENSHOTS_DIR "screenShots"
|
||||||
@ -70,6 +58,9 @@
|
|||||||
#define DEBUGGER_CONFIG "debugger.ini"
|
#define DEBUGGER_CONFIG "debugger.ini"
|
||||||
#define LOGGER_CONFIG "logger.ini"
|
#define LOGGER_CONFIG "logger.ini"
|
||||||
|
|
||||||
|
// Sys files
|
||||||
|
#define SHARED_FONT "shared_font.bin"
|
||||||
|
|
||||||
// Files in the directory returned by GetUserPath(D_LOGS_IDX)
|
// Files in the directory returned by GetUserPath(D_LOGS_IDX)
|
||||||
#define MAIN_LOG "emu.log"
|
#define MAIN_LOG "emu.log"
|
||||||
|
|
||||||
|
@ -676,6 +676,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
|||||||
paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
|
paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
|
||||||
paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
|
paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
|
||||||
paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
|
paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
|
||||||
|
paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP;
|
||||||
paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
|
paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
|
||||||
paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
|
paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
|
||||||
paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
|
paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
|
||||||
@ -753,19 +754,6 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
|||||||
return paths[DirIDX];
|
return paths[DirIDX];
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::string GetThemeDir(const std::string& theme_name)
|
|
||||||
//{
|
|
||||||
// std::string dir = FileUtil::GetUserPath(D_THEMES_IDX) + theme_name + "/";
|
|
||||||
//
|
|
||||||
//#if !defined(_WIN32)
|
|
||||||
// // If theme does not exist in user's dir load from shared directory
|
|
||||||
// if (!FileUtil::Exists(dir))
|
|
||||||
// dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/";
|
|
||||||
//#endif
|
|
||||||
//
|
|
||||||
// return dir;
|
|
||||||
//}
|
|
||||||
|
|
||||||
size_t WriteStringToFile(bool text_file, const std::string &str, const char *filename)
|
size_t WriteStringToFile(bool text_file, const std::string &str, const char *filename)
|
||||||
{
|
{
|
||||||
return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
|
return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
|
||||||
|
@ -27,6 +27,7 @@ enum {
|
|||||||
D_STATESAVES_IDX,
|
D_STATESAVES_IDX,
|
||||||
D_SCREENSHOTS_IDX,
|
D_SCREENSHOTS_IDX,
|
||||||
D_SDMC_IDX,
|
D_SDMC_IDX,
|
||||||
|
D_SYSDATA_IDX,
|
||||||
D_HIRESTEXTURES_IDX,
|
D_HIRESTEXTURES_IDX,
|
||||||
D_DUMP_IDX,
|
D_DUMP_IDX,
|
||||||
D_DUMPFRAMES_IDX,
|
D_DUMPFRAMES_IDX,
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
#include "common/file_util.h"
|
||||||
|
|
||||||
#include "core/hle/hle.h"
|
#include "core/hle/hle.h"
|
||||||
#include "core/hle/kernel/event.h"
|
#include "core/hle/kernel/event.h"
|
||||||
#include "core/hle/kernel/mutex.h"
|
#include "core/hle/kernel/mutex.h"
|
||||||
|
#include "core/hle/kernel/shared_memory.h"
|
||||||
#include "apt_u.h"
|
#include "apt_u.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -15,7 +17,19 @@
|
|||||||
|
|
||||||
namespace APT_U {
|
namespace APT_U {
|
||||||
|
|
||||||
|
// Address used for shared font (as observed on HW)
|
||||||
|
// TODO(bunnei): This is the hard-coded address where we currently dump the shared font from via
|
||||||
|
// https://github.com/citra-emu/3dsutils. This is technically a hack, and will not work at any
|
||||||
|
// address other than 0x18000000 due to internal pointers in the shared font dump that would need to
|
||||||
|
// be relocated. This might be fixed by dumping the shared font @ address 0x00000000 and then
|
||||||
|
// correctly mapping it in Citra, however we still do not understand how the mapping is determined.
|
||||||
|
static const VAddr SHARED_FONT_VADDR = 0x18000000;
|
||||||
|
|
||||||
|
// Handle to shared memory region designated to for shared system font
|
||||||
|
static Handle shared_font_mem = 0;
|
||||||
|
|
||||||
static Handle lock_handle = 0;
|
static Handle lock_handle = 0;
|
||||||
|
static std::vector<u8> shared_font;
|
||||||
|
|
||||||
/// Signals used by APT functions
|
/// Signals used by APT functions
|
||||||
enum class SignalType : u32 {
|
enum class SignalType : u32 {
|
||||||
@ -84,18 +98,18 @@ void InquireNotification(Service::Interface* self) {
|
|||||||
* state so that this command will return an error if this command is used again if parameters were
|
* state so that this command will return an error if this command is used again if parameters were
|
||||||
* not set again. This is called when the second Initialize event is triggered. It returns a signal
|
* not set again. This is called when the second Initialize event is triggered. It returns a signal
|
||||||
* type indicating why it was triggered.
|
* type indicating why it was triggered.
|
||||||
* Inputs:
|
* Inputs:
|
||||||
* 1 : AppID
|
* 1 : AppID
|
||||||
* 2 : Parameter buffer size, max size is 0x1000
|
* 2 : Parameter buffer size, max size is 0x1000
|
||||||
* Outputs:
|
* Outputs:
|
||||||
* 1 : Result of function, 0 on success, otherwise error code
|
* 1 : Result of function, 0 on success, otherwise error code
|
||||||
* 2 : Unknown, for now assume AppID of the process which sent these parameters
|
* 2 : Unknown, for now assume AppID of the process which sent these parameters
|
||||||
* 3 : Unknown, for now assume Signal type
|
* 3 : Unknown, for now assume Signal type
|
||||||
* 4 : Actual parameter buffer size, this is <= to the the input size
|
* 4 : Actual parameter buffer size, this is <= to the the input size
|
||||||
* 5 : Value
|
* 5 : Value
|
||||||
* 6 : Handle from the source process which set the parameters, likely used for shared memory
|
* 6 : Handle from the source process which set the parameters, likely used for shared memory
|
||||||
* 7 : Size
|
* 7 : Size
|
||||||
* 8 : Output parameter buffer ptr
|
* 8 : Output parameter buffer ptr
|
||||||
*/
|
*/
|
||||||
void ReceiveParameter(Service::Interface* self) {
|
void ReceiveParameter(Service::Interface* self) {
|
||||||
u32* cmd_buff = Service::GetCommandBuffer();
|
u32* cmd_buff = Service::GetCommandBuffer();
|
||||||
@ -115,18 +129,18 @@ void ReceiveParameter(Service::Interface* self) {
|
|||||||
* APT_U::GlanceParameter service function. This is exactly the same as APT_U::ReceiveParameter
|
* APT_U::GlanceParameter service function. This is exactly the same as APT_U::ReceiveParameter
|
||||||
* (except for the word value prior to the output handle), except this will not clear the flag
|
* (except for the word value prior to the output handle), except this will not clear the flag
|
||||||
* (except when responseword[3]==8 || responseword[3]==9) in NS state.
|
* (except when responseword[3]==8 || responseword[3]==9) in NS state.
|
||||||
* Inputs:
|
* Inputs:
|
||||||
* 1 : AppID
|
* 1 : AppID
|
||||||
* 2 : Parameter buffer size, max size is 0x1000
|
* 2 : Parameter buffer size, max size is 0x1000
|
||||||
* Outputs:
|
* Outputs:
|
||||||
* 1 : Result of function, 0 on success, otherwise error code
|
* 1 : Result of function, 0 on success, otherwise error code
|
||||||
* 2 : Unknown, for now assume AppID of the process which sent these parameters
|
* 2 : Unknown, for now assume AppID of the process which sent these parameters
|
||||||
* 3 : Unknown, for now assume Signal type
|
* 3 : Unknown, for now assume Signal type
|
||||||
* 4 : Actual parameter buffer size, this is <= to the the input size
|
* 4 : Actual parameter buffer size, this is <= to the the input size
|
||||||
* 5 : Value
|
* 5 : Value
|
||||||
* 6 : Handle from the source process which set the parameters, likely used for shared memory
|
* 6 : Handle from the source process which set the parameters, likely used for shared memory
|
||||||
* 7 : Size
|
* 7 : Size
|
||||||
* 8 : Output parameter buffer ptr
|
* 8 : Output parameter buffer ptr
|
||||||
*/
|
*/
|
||||||
void GlanceParameter(Service::Interface* self) {
|
void GlanceParameter(Service::Interface* self) {
|
||||||
u32* cmd_buff = Service::GetCommandBuffer();
|
u32* cmd_buff = Service::GetCommandBuffer();
|
||||||
@ -146,14 +160,14 @@ void GlanceParameter(Service::Interface* self) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* APT_U::AppletUtility service function
|
* APT_U::AppletUtility service function
|
||||||
* Inputs:
|
* Inputs:
|
||||||
* 1 : Unknown, but clearly used for something
|
* 1 : Unknown, but clearly used for something
|
||||||
* 2 : Buffer 1 size (purpose is unknown)
|
* 2 : Buffer 1 size (purpose is unknown)
|
||||||
* 3 : Buffer 2 size (purpose is unknown)
|
* 3 : Buffer 2 size (purpose is unknown)
|
||||||
* 5 : Buffer 1 address (purpose is unknown)
|
* 5 : Buffer 1 address (purpose is unknown)
|
||||||
* 65 : Buffer 2 address (purpose is unknown)
|
* 65 : Buffer 2 address (purpose is unknown)
|
||||||
* Outputs:
|
* Outputs:
|
||||||
* 1 : Result of function, 0 on success, otherwise error code
|
* 1 : Result of function, 0 on success, otherwise error code
|
||||||
*/
|
*/
|
||||||
void AppletUtility(Service::Interface* self) {
|
void AppletUtility(Service::Interface* self) {
|
||||||
u32* cmd_buff = Service::GetCommandBuffer();
|
u32* cmd_buff = Service::GetCommandBuffer();
|
||||||
@ -172,6 +186,34 @@ void AppletUtility(Service::Interface* self) {
|
|||||||
buffer1_addr, buffer2_addr);
|
buffer1_addr, buffer2_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APT_U::GetSharedFont service function
|
||||||
|
* Outputs:
|
||||||
|
* 1 : Result of function, 0 on success, otherwise error code
|
||||||
|
* 2 : Virtual address of where shared font will be loaded in memory
|
||||||
|
* 4 : Handle to shared font memory
|
||||||
|
*/
|
||||||
|
void GetSharedFont(Service::Interface* self) {
|
||||||
|
DEBUG_LOG(KERNEL, "called");
|
||||||
|
|
||||||
|
u32* cmd_buff = Service::GetCommandBuffer();
|
||||||
|
|
||||||
|
if (!shared_font.empty()) {
|
||||||
|
// TODO(bunnei): This function shouldn't copy the shared font every time it's called.
|
||||||
|
// Instead, it should probably map the shared font as RO memory. We don't currently have
|
||||||
|
// an easy way to do this, but the copy should be sufficient for now.
|
||||||
|
memcpy(Memory::GetPointer(SHARED_FONT_VADDR), shared_font.data(), shared_font.size());
|
||||||
|
|
||||||
|
cmd_buff[0] = 0x00440082;
|
||||||
|
cmd_buff[1] = 0; // No error
|
||||||
|
cmd_buff[2] = SHARED_FONT_VADDR;
|
||||||
|
cmd_buff[4] = shared_font_mem;
|
||||||
|
} else {
|
||||||
|
cmd_buff[1] = -1; // Generic error (not really possible to verify this on hardware)
|
||||||
|
ERROR_LOG(KERNEL, "called, but %s has not been loaded!", SHARED_FONT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Interface::FunctionInfo FunctionTable[] = {
|
const Interface::FunctionInfo FunctionTable[] = {
|
||||||
{0x00010040, GetLockHandle, "GetLockHandle"},
|
{0x00010040, GetLockHandle, "GetLockHandle"},
|
||||||
{0x00020080, Initialize, "Initialize"},
|
{0x00020080, Initialize, "Initialize"},
|
||||||
@ -240,7 +282,7 @@ const Interface::FunctionInfo FunctionTable[] = {
|
|||||||
{0x00410040, nullptr, "ReceiveCaptureBufferInfo"},
|
{0x00410040, nullptr, "ReceiveCaptureBufferInfo"},
|
||||||
{0x00420080, nullptr, "SleepSystem"},
|
{0x00420080, nullptr, "SleepSystem"},
|
||||||
{0x00430040, nullptr, "NotifyToWait"},
|
{0x00430040, nullptr, "NotifyToWait"},
|
||||||
{0x00440000, nullptr, "GetSharedFont"},
|
{0x00440000, GetSharedFont, "GetSharedFont"},
|
||||||
{0x00450040, nullptr, "GetWirelessRebootInfo"},
|
{0x00450040, nullptr, "GetWirelessRebootInfo"},
|
||||||
{0x00460104, nullptr, "Wrap"},
|
{0x00460104, nullptr, "Wrap"},
|
||||||
{0x00470104, nullptr, "Unwrap"},
|
{0x00470104, nullptr, "Unwrap"},
|
||||||
@ -259,9 +301,33 @@ const Interface::FunctionInfo FunctionTable[] = {
|
|||||||
// Interface class
|
// Interface class
|
||||||
|
|
||||||
Interface::Interface() {
|
Interface::Interface() {
|
||||||
Register(FunctionTable, ARRAY_SIZE(FunctionTable));
|
// Load the shared system font (if available).
|
||||||
|
// The expected format is a decrypted, uncompressed BCFNT file with the 0x80 byte header
|
||||||
|
// generated by the APT:U service. The best way to get is by dumping it from RAM. We've provided
|
||||||
|
// a homebrew app to do this: https://github.com/citra-emu/3dsutils. Put the resulting file
|
||||||
|
// "shared_font.bin" in the Citra "sysdata" directory.
|
||||||
|
|
||||||
|
shared_font.clear();
|
||||||
|
std::string filepath = FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT;
|
||||||
|
|
||||||
|
FileUtil::CreateFullPath(filepath); // Create path if not already created
|
||||||
|
FileUtil::IOFile file(filepath, "rb");
|
||||||
|
|
||||||
|
if (file.IsOpen()) {
|
||||||
|
// Read shared font data
|
||||||
|
shared_font.resize(file.GetSize());
|
||||||
|
file.ReadBytes(shared_font.data(), file.GetSize());
|
||||||
|
|
||||||
|
// Create shared font memory object
|
||||||
|
shared_font_mem = Kernel::CreateSharedMemory("APT_U:shared_font_mem");
|
||||||
|
} else {
|
||||||
|
WARN_LOG(KERNEL, "Unable to load shared font: %s", filepath.c_str());
|
||||||
|
shared_font_mem = 0;
|
||||||
|
}
|
||||||
|
|
||||||
lock_handle = 0;
|
lock_handle = 0;
|
||||||
|
|
||||||
|
Register(FunctionTable, ARRAY_SIZE(FunctionTable));
|
||||||
}
|
}
|
||||||
|
|
||||||
Interface::~Interface() {
|
Interface::~Interface() {
|
||||||
|
@ -43,7 +43,7 @@ static Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1,
|
|||||||
|
|
||||||
// Map GSP heap memory
|
// Map GSP heap memory
|
||||||
case MEMORY_OPERATION_GSP_HEAP:
|
case MEMORY_OPERATION_GSP_HEAP:
|
||||||
*out_addr = Memory::MapBlock_HeapGSP(size, operation, permissions);
|
*out_addr = Memory::MapBlock_HeapLinear(size, operation, permissions);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Unknown ControlMemory operation
|
// Unknown ControlMemory operation
|
||||||
|
@ -18,7 +18,7 @@ static MemArena arena; ///< The MemArena class
|
|||||||
u8* g_exefs_code = nullptr; ///< ExeFS:/.code is loaded here
|
u8* g_exefs_code = nullptr; ///< ExeFS:/.code is loaded here
|
||||||
u8* g_system_mem = nullptr; ///< System memory
|
u8* g_system_mem = nullptr; ///< System memory
|
||||||
u8* g_heap = nullptr; ///< Application heap (main memory)
|
u8* g_heap = nullptr; ///< Application heap (main memory)
|
||||||
u8* g_heap_gsp = nullptr; ///< GSP heap (main memory)
|
u8* g_heap_linear = nullptr; ///< Linear heap
|
||||||
u8* g_vram = nullptr; ///< Video memory (VRAM) pointer
|
u8* g_vram = nullptr; ///< Video memory (VRAM) pointer
|
||||||
u8* g_shared_mem = nullptr; ///< Shared memory
|
u8* g_shared_mem = nullptr; ///< Shared memory
|
||||||
u8* g_kernel_mem; ///< Kernel memory
|
u8* g_kernel_mem; ///< Kernel memory
|
||||||
@ -36,13 +36,13 @@ static u8* physical_kernel_mem; ///< Kernel memory
|
|||||||
|
|
||||||
// We don't declare the IO region in here since its handled by other means.
|
// We don't declare the IO region in here since its handled by other means.
|
||||||
static MemoryView g_views[] = {
|
static MemoryView g_views[] = {
|
||||||
{&g_exefs_code, &physical_exefs_code, EXEFS_CODE_VADDR, EXEFS_CODE_SIZE, 0},
|
{&g_exefs_code, &physical_exefs_code, EXEFS_CODE_VADDR, EXEFS_CODE_SIZE, 0},
|
||||||
{&g_vram, &physical_vram, VRAM_VADDR, VRAM_SIZE, 0},
|
{&g_vram, &physical_vram, VRAM_VADDR, VRAM_SIZE, 0},
|
||||||
{&g_heap, &physical_fcram, HEAP_VADDR, HEAP_SIZE, MV_IS_PRIMARY_RAM},
|
{&g_heap, &physical_fcram, HEAP_VADDR, HEAP_SIZE, MV_IS_PRIMARY_RAM},
|
||||||
{&g_shared_mem, &physical_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE, 0},
|
{&g_shared_mem, &physical_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE, 0},
|
||||||
{&g_system_mem, &physical_system_mem, SYSTEM_MEMORY_VADDR, SYSTEM_MEMORY_SIZE, 0},
|
{&g_system_mem, &physical_system_mem, SYSTEM_MEMORY_VADDR, SYSTEM_MEMORY_SIZE, 0},
|
||||||
{&g_kernel_mem, &physical_kernel_mem, KERNEL_MEMORY_VADDR, KERNEL_MEMORY_SIZE, 0},
|
{&g_kernel_mem, &physical_kernel_mem, KERNEL_MEMORY_VADDR, KERNEL_MEMORY_SIZE, 0},
|
||||||
{&g_heap_gsp, &physical_heap_gsp, HEAP_GSP_VADDR, HEAP_GSP_SIZE, 0},
|
{&g_heap_linear, &physical_heap_gsp, HEAP_LINEAR_VADDR, HEAP_LINEAR_SIZE, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
/*static MemoryView views[] =
|
/*static MemoryView views[] =
|
||||||
|
@ -57,11 +57,11 @@ enum : u32 {
|
|||||||
HEAP_VADDR = 0x08000000,
|
HEAP_VADDR = 0x08000000,
|
||||||
HEAP_VADDR_END = (HEAP_VADDR + HEAP_SIZE),
|
HEAP_VADDR_END = (HEAP_VADDR + HEAP_SIZE),
|
||||||
|
|
||||||
HEAP_GSP_SIZE = 0x02000000, ///< GSP heap size... TODO: Define correctly?
|
HEAP_LINEAR_SIZE = 0x08000000, ///< Linear heap size... TODO: Define correctly?
|
||||||
HEAP_GSP_VADDR = 0x14000000,
|
HEAP_LINEAR_VADDR = 0x14000000,
|
||||||
HEAP_GSP_VADDR_END = (HEAP_GSP_VADDR + HEAP_GSP_SIZE),
|
HEAP_LINEAR_VADDR_END = (HEAP_LINEAR_VADDR + HEAP_LINEAR_SIZE),
|
||||||
HEAP_GSP_PADDR = 0x00000000,
|
HEAP_LINEAR_PADDR = 0x00000000,
|
||||||
HEAP_GSP_PADDR_END = (HEAP_GSP_PADDR + HEAP_GSP_SIZE),
|
HEAP_LINEAR_PADDR_END = (HEAP_LINEAR_PADDR + HEAP_LINEAR_SIZE),
|
||||||
|
|
||||||
HARDWARE_IO_SIZE = 0x01000000,
|
HARDWARE_IO_SIZE = 0x01000000,
|
||||||
HARDWARE_IO_PADDR = 0x10000000, ///< IO physical address start
|
HARDWARE_IO_PADDR = 0x10000000, ///< IO physical address start
|
||||||
@ -112,7 +112,7 @@ extern u8 *g_base;
|
|||||||
// These are guaranteed to point to "low memory" addresses (sub-32-bit).
|
// These are guaranteed to point to "low memory" addresses (sub-32-bit).
|
||||||
// 64-bit: Pointers to low-mem (sub-0x10000000) mirror
|
// 64-bit: Pointers to low-mem (sub-0x10000000) mirror
|
||||||
// 32-bit: Same as the corresponding physical/virtual pointers.
|
// 32-bit: Same as the corresponding physical/virtual pointers.
|
||||||
extern u8* g_heap_gsp; ///< GSP heap (main memory)
|
extern u8* g_heap_linear; ///< Linear heap (main memory)
|
||||||
extern u8* g_heap; ///< Application heap (main memory)
|
extern u8* g_heap; ///< Application heap (main memory)
|
||||||
extern u8* g_vram; ///< Video memory (VRAM)
|
extern u8* g_vram; ///< Video memory (VRAM)
|
||||||
extern u8* g_shared_mem; ///< Shared memory
|
extern u8* g_shared_mem; ///< Shared memory
|
||||||
@ -159,7 +159,7 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions);
|
|||||||
* @param operation Memory map operation type
|
* @param operation Memory map operation type
|
||||||
* @param permissions Control memory permissions
|
* @param permissions Control memory permissions
|
||||||
*/
|
*/
|
||||||
u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions);
|
u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions);
|
||||||
|
|
||||||
inline const char* GetCharPointer(const VAddr address) {
|
inline const char* GetCharPointer(const VAddr address) {
|
||||||
return (const char *)GetPointer(address);
|
return (const char *)GetPointer(address);
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
namespace Memory {
|
namespace Memory {
|
||||||
|
|
||||||
static std::map<u32, MemoryBlock> heap_map;
|
static std::map<u32, MemoryBlock> heap_map;
|
||||||
static std::map<u32, MemoryBlock> heap_gsp_map;
|
static std::map<u32, MemoryBlock> heap_linear_map;
|
||||||
static std::map<u32, MemoryBlock> shared_map;
|
static std::map<u32, MemoryBlock> shared_map;
|
||||||
|
|
||||||
/// Convert a physical address to virtual address
|
/// Convert a physical address to virtual address
|
||||||
@ -67,9 +67,9 @@ inline void Read(T &var, const VAddr vaddr) {
|
|||||||
} else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) {
|
} else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) {
|
||||||
var = *((const T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR]);
|
var = *((const T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR]);
|
||||||
|
|
||||||
// FCRAM - GSP heap
|
// FCRAM - linear heap
|
||||||
} else if ((vaddr >= HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) {
|
} else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) {
|
||||||
var = *((const T*)&g_heap_gsp[vaddr - HEAP_GSP_VADDR]);
|
var = *((const T*)&g_heap_linear[vaddr - HEAP_LINEAR_VADDR]);
|
||||||
|
|
||||||
// FCRAM - application heap
|
// FCRAM - application heap
|
||||||
} else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
|
} else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
|
||||||
@ -112,9 +112,9 @@ inline void Write(const VAddr vaddr, const T data) {
|
|||||||
} else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) {
|
} else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) {
|
||||||
*(T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR] = data;
|
*(T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR] = data;
|
||||||
|
|
||||||
// FCRAM - GSP heap
|
// FCRAM - linear heap
|
||||||
} else if ((vaddr >= HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) {
|
} else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) {
|
||||||
*(T*)&g_heap_gsp[vaddr - HEAP_GSP_VADDR] = data;
|
*(T*)&g_heap_linear[vaddr - HEAP_LINEAR_VADDR] = data;
|
||||||
|
|
||||||
// FCRAM - application heap
|
// FCRAM - application heap
|
||||||
} else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
|
} else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
|
||||||
@ -154,9 +154,9 @@ u8 *GetPointer(const VAddr vaddr) {
|
|||||||
} else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) {
|
} else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) {
|
||||||
return g_exefs_code + (vaddr - EXEFS_CODE_VADDR);
|
return g_exefs_code + (vaddr - EXEFS_CODE_VADDR);
|
||||||
|
|
||||||
// FCRAM - GSP heap
|
// FCRAM - linear heap
|
||||||
} else if ((vaddr >= HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) {
|
} else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) {
|
||||||
return g_heap_gsp + (vaddr - HEAP_GSP_VADDR);
|
return g_heap_linear + (vaddr - HEAP_LINEAR_VADDR);
|
||||||
|
|
||||||
// FCRAM - application heap
|
// FCRAM - application heap
|
||||||
} else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
|
} else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
|
||||||
@ -204,24 +204,24 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps a block of memory on the GSP heap
|
* Maps a block of memory on the linear heap
|
||||||
* @param size Size of block in bytes
|
* @param size Size of block in bytes
|
||||||
* @param operation Memory map operation type
|
* @param operation Memory map operation type
|
||||||
* @param flags Memory allocation flags
|
* @param flags Memory allocation flags
|
||||||
*/
|
*/
|
||||||
u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) {
|
u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) {
|
||||||
MemoryBlock block;
|
MemoryBlock block;
|
||||||
|
|
||||||
block.base_address = HEAP_GSP_VADDR;
|
block.base_address = HEAP_LINEAR_VADDR;
|
||||||
block.size = size;
|
block.size = size;
|
||||||
block.operation = operation;
|
block.operation = operation;
|
||||||
block.permissions = permissions;
|
block.permissions = permissions;
|
||||||
|
|
||||||
if (heap_gsp_map.size() > 0) {
|
if (heap_linear_map.size() > 0) {
|
||||||
const MemoryBlock last_block = heap_gsp_map.rbegin()->second;
|
const MemoryBlock last_block = heap_linear_map.rbegin()->second;
|
||||||
block.address = last_block.address + last_block.size;
|
block.address = last_block.address + last_block.size;
|
||||||
}
|
}
|
||||||
heap_gsp_map[block.GetVirtualAddress()] = block;
|
heap_linear_map[block.GetVirtualAddress()] = block;
|
||||||
|
|
||||||
return block.GetVirtualAddress();
|
return block.GetVirtualAddress();
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ struct Regs {
|
|||||||
u32 address;
|
u32 address;
|
||||||
|
|
||||||
u32 GetPhysicalAddress() const {
|
u32 GetPhysicalAddress() const {
|
||||||
return DecodeAddressRegister(address) - Memory::FCRAM_PADDR + Memory::HEAP_GSP_VADDR;
|
return DecodeAddressRegister(address) - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// texture1 and texture2 store the texture format directly after the address
|
// texture1 and texture2 store the texture format directly after the address
|
||||||
@ -312,7 +312,7 @@ struct Regs {
|
|||||||
|
|
||||||
inline u32 GetBaseAddress() const {
|
inline u32 GetBaseAddress() const {
|
||||||
// TODO: Ugly, should fix PhysicalToVirtualAddress instead
|
// TODO: Ugly, should fix PhysicalToVirtualAddress instead
|
||||||
return DecodeAddressRegister(base_address) - Memory::FCRAM_PADDR + Memory::HEAP_GSP_VADDR;
|
return DecodeAddressRegister(base_address) - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Descriptor for internal vertex attributes
|
// Descriptor for internal vertex attributes
|
||||||
|
Loading…
Reference in New Issue
Block a user