mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-13 10:48:29 +12:00
* Fix typo (#680) Co-authored-by: Noumi <139501014+noumidev@users.noreply.github.com> * More PTM stuff Co-Authored-By: Noumi <139501014+noumidev@users.noreply.github.com> * Make system language configurable * Fix building crypto++ for x64 target on Apple silicon MacOS * Attempt to switch to M1 runners again * Prevent selecting Vulkan renderer in Qt frontend and present a message * Libretro: Add system language option * Only enable audio by default on libretro for now * CMake: Bump version * Store configuration file in AppData root if not in working directory (#693) * Store configuration file in AppData root if not in working directory This fixes MacOS app bundles, as the emulator cannot write the config file into the app bundle. * Remove duplicate fs calls * I'm an idiot sandwich --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> * GL: Add usingGLES to driverInfo struct (#694) * Wayland fixes part 1 * Support GLES on desktop * Qt: Fix Wayland support Qt will only create a Wayland surface when show() is called on the main window and on the ScreenWidget. Thus, call the function before creating the GL context. Doesn't cause regressions on XWayland, untested in other platforms. Fixes #586 * No need to call screen->show() twice * Fix disabling Wayland & building on some distros (#700) * GLES: Properly stub out logic ops * Fix git versioning * Android_Build: Implement ccache (#703) * Android_Build: Implement ccache * Update Android_Build.yml * Update Android_Build.yml --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> * Removed dead Citra link in readme (#706) * CRO: Lighter icache flushes * Implement Luma icache SVCs * Add missing SVC logs * GPU: Add sw texture copies * Use vk::detail::DynamicLoader instead of vk::DynamicLoader (#710) * Use vk::detail::DynamicLoader instead of vk::DynamicLoader * Update renderer_vk.cpp * Vk: Fix typo * Vk: Lock CI runners to SDK version 1.3.301 temporarily * Vk: Fixing CI pt 2 * Vulkan: Fixing CI pt 3 * Vk: Fix typo * Temporarily give 80MB to all processes (#715) * Try to cross-compile Libretro core for arm64 (#717) * Try to cross-compile Libretro core for arm64 * Bonk * Update Hydra_Build.yml * [WIP] Libretro: Add audio support (#714) * Libretro: Add audio support * Adding audio interface part 1 * Audio device pt 2 * More audio device * More audio device * Morea uudi odevice * More audio device * More audio device * More audio device --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> * Libretro audio device: Fix frame count * Mark audio devices as final * Add toggle for libretro audio device (#719) * Very important work (#720) * Very important work * Most important fix * Add more HLE service calls for eshop (#721) * CI: Fix Vulkan SDK action (#723) * GPU registers: Fix writes to some registers ignoring the mask (#725) Co-authored-by: henry <23128103+atem2069@users.noreply.github.com> * OLED theme * OLED theme config fix (#736) Co-authored-by: smiRaphi <neogt404@gmail.com> * Adding Swedish translation * Fix Metal renderer compilation on iOS * [Core] Improve iOS compilation workflow * [Qt] Hook Swedish to UI * AppDataDocumentProvider: Typo (#740) * More iOS work * More iOS progress * More iOS work * AppDataDocumentProvider: Add missing ``COLUMN_FLAGS`` in the default document projectation (#741) Fixes unable to copy files from device to app's internal storage problem * More iOS work * ios: Simplify MTKView interface (still doesn't work though) * ios: Pass CAMetalLayer instead of void* to Obj-C++ bridging header * Fix bridging cast * FINALLY IOS GRAPHICS * ios: Remove printf spam * Metal: Reimplement some texture formats on iOS * metal: implement texture decoder * metal: check for format support * metal: implement texture swizzling * metal: remove unused texture functions * Shadergen types: Add Metal & MSL * Format * Undo submodule changes * Readme: Add Chonkystation 3 * Metal: Use std::unique_ptr for texture decode * AppDataDocumentProvider: Allow to remove documents (#744) * AppDataDocumentProvider: Allow to remove documents * Typo * Metal renderer fixes for iOS * iOS driver: Add doc comments * iOS: Add frontend & frontend build files (#746) * iOS: Add SwiftUI part to repo * Add iOS build script * Update SDL2 submodule * Fix iOS build script * CI: Update xcode tools for iOS * Update iOS_Build.yml * Update iOS build * Lower XCode version * A * Update project.pbxproj * Update iOS_Build.yml * Update iOS_Build.yml * Update build.sh * iOS: Fail on build error * iOS: Add file picker (#747) * iOS: Add file picker * Fix lock placement * Qt: Add runpog icon (#752) * Update discord-rpc submodule (#753) * Remove cryptoppwin submodule (#754) * Add optional texture hashing * Fix build on new Vk SDK (#757) Co-authored-by: Nadia Holmquist Pedersen <893884+nadiaholmquist@users.noreply.github.com> * CI: Use new Vulkan SDK --------- Co-authored-by: Noumi <139501014+noumidev@users.noreply.github.com> Co-authored-by: Thomas <thomas@thomasw.dev> Co-authored-by: Thomas <twvd@users.noreply.github.com> Co-authored-by: Daniel López Guimaraes <danielectra@outlook.com> Co-authored-by: Jonian Guveli <jonian@hardpixel.eu> Co-authored-by: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Co-authored-by: Auxy6858 <71662994+Auxy6858@users.noreply.github.com> Co-authored-by: Paris Oplopoios <parisoplop@gmail.com> Co-authored-by: henry <23128103+atem2069@users.noreply.github.com> Co-authored-by: smiRaphi <neogt404@gmail.com> Co-authored-by: smiRaphi <87574679+smiRaphi@users.noreply.github.com> Co-authored-by: Daniel Nylander <po@danielnylander.se> Co-authored-by: Samuliak <samuliak77@gmail.com> Co-authored-by: Albert <45282415+ggrtk@users.noreply.github.com> Co-authored-by: Nadia Holmquist Pedersen <893884+nadiaholmquist@users.noreply.github.com>
226 lines
No EOL
6.8 KiB
C++
226 lines
No EOL
6.8 KiB
C++
#include "kernel.hpp"
|
|
|
|
namespace Operation {
|
|
enum : u32 {
|
|
Free = 1,
|
|
Reserve = 2,
|
|
Commit = 3,
|
|
Map = 4,
|
|
Unmap = 5,
|
|
Protect = 6,
|
|
AppRegion = 0x100,
|
|
SysRegion = 0x200,
|
|
BaseRegion = 0x300,
|
|
Linear = 0x10000
|
|
};
|
|
}
|
|
|
|
namespace MemoryPermissions {
|
|
enum : u32 {
|
|
None = 0, // ---
|
|
Read = 1, // R--
|
|
Write = 2, // -W-
|
|
ReadWrite = 3, // RW-
|
|
Execute = 4, // --X
|
|
ReadExecute = 5, // R-X
|
|
WriteExecute = 6, // -WX
|
|
ReadWriteExecute = 7, // RWX
|
|
|
|
DontCare = 0x10000000
|
|
};
|
|
}
|
|
|
|
// Returns whether "value" is aligned to a page boundary (Ie a boundary of 4096 bytes)
|
|
static constexpr bool isAligned(u32 value) {
|
|
return (value & 0xFFF) == 0;
|
|
}
|
|
|
|
// Result ControlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size,
|
|
// MemoryOperation operation, MemoryPermission permissions)
|
|
// This has a weird ABI documented here https://www.3dbrew.org/wiki/Kernel_ABI
|
|
// TODO: Does this need to write to outaddr?
|
|
void Kernel::controlMemory() {
|
|
u32 operation = regs[0]; // The base address is written here
|
|
u32 addr0 = regs[1];
|
|
u32 addr1 = regs[2];
|
|
u32 size = regs[3];
|
|
u32 perms = regs[4];
|
|
|
|
if (perms == MemoryPermissions::DontCare) {
|
|
perms = MemoryPermissions::ReadWrite; // We make "don't care" equivalent to read-write
|
|
Helpers::panic("Unimplemented allocation permission: DONTCARE");
|
|
}
|
|
|
|
// Naturally the bits are in reverse order
|
|
bool r = perms & 0b001;
|
|
bool w = perms & 0b010;
|
|
bool x = perms & 0b100;
|
|
bool linear = operation & Operation::Linear;
|
|
|
|
if (x)
|
|
Helpers::panic("ControlMemory: attempted to allocate executable memory");
|
|
|
|
if (!isAligned(addr0) || !isAligned(addr1) || !isAligned(size)) {
|
|
Helpers::panic("ControlMemory: Unaligned parameters\nAddr0: %08X\nAddr1: %08X\nSize: %08X", addr0, addr1, size);
|
|
}
|
|
|
|
logSVC("ControlMemory(addr0 = %08X, addr1 = %08X, size = %08X, operation = %X (%c%c%c)%s\n",
|
|
addr0, addr1, size, operation, r ? 'r' : '-', w ? 'w' : '-', x ? 'x' : '-', linear ? ", linear" : ""
|
|
);
|
|
|
|
switch (operation & 0xFF) {
|
|
case Operation::Commit: {
|
|
std::optional<u32> address = mem.allocateMemory(addr0, 0, size, linear, r, w, x, true);
|
|
if (!address.has_value())
|
|
Helpers::panic("ControlMemory: Failed to allocate memory");
|
|
|
|
regs[1] = address.value();
|
|
break;
|
|
}
|
|
|
|
case Operation::Map:
|
|
mem.mirrorMapping(addr0, addr1, size);
|
|
break;
|
|
|
|
case Operation::Protect:
|
|
Helpers::warn("Ignoring mprotect! Hope nothing goes wrong but if the game accesses invalid memory or crashes then we prolly need to implement this\n");
|
|
break;
|
|
|
|
default: Helpers::warn("ControlMemory: unknown operation %X\n", operation); break;
|
|
}
|
|
|
|
regs[0] = Result::Success;
|
|
}
|
|
|
|
// Result QueryMemory(MemoryInfo* memInfo, PageInfo* pageInfo, u32 addr)
|
|
void Kernel::queryMemory() {
|
|
const u32 memInfo = regs[0];
|
|
const u32 pageInfo = regs[1];
|
|
const u32 addr = regs[2];
|
|
|
|
logSVC("QueryMemory(mem info pointer = %08X, page info pointer = %08X, addr = %08X)\n", memInfo, pageInfo, addr);
|
|
|
|
const auto info = mem.queryMemory(addr);
|
|
regs[0] = Result::Success;
|
|
regs[1] = info.baseAddr;
|
|
regs[2] = info.size;
|
|
regs[3] = info.perms;
|
|
regs[4] = info.state;
|
|
regs[5] = 0; // page flags
|
|
}
|
|
|
|
// Result MapMemoryBlock(Handle memblock, u32 addr, MemoryPermission myPermissions, MemoryPermission otherPermission)
|
|
void Kernel::mapMemoryBlock() {
|
|
const Handle block = regs[0];
|
|
u32 addr = regs[1];
|
|
const u32 myPerms = regs[2];
|
|
const u32 otherPerms = regs[3];
|
|
logSVC("MapMemoryBlock(block = %X, addr = %08X, myPerms = %X, otherPerms = %X\n", block, addr, myPerms, otherPerms);
|
|
|
|
if (!isAligned(addr)) [[unlikely]] {
|
|
Helpers::panic("MapMemoryBlock: Unaligned address");
|
|
}
|
|
|
|
if (KernelHandles::isSharedMemHandle(block)) {
|
|
if (block == KernelHandles::FontSharedMemHandle && addr == 0) {
|
|
addr = getSharedFontVaddr();
|
|
}
|
|
|
|
u8* ptr = mem.mapSharedMemory(block, addr, myPerms, otherPerms); // Map shared memory block
|
|
|
|
// Pass pointer to shared memory to the appropriate service
|
|
switch (block) {
|
|
case KernelHandles::HIDSharedMemHandle:
|
|
serviceManager.setHIDSharedMem(ptr);
|
|
break;
|
|
|
|
case KernelHandles::GSPSharedMemHandle:
|
|
serviceManager.setGSPSharedMem(ptr);
|
|
break;
|
|
|
|
case KernelHandles::FontSharedMemHandle:
|
|
mem.copySharedFont(ptr, addr);
|
|
break;
|
|
|
|
case KernelHandles::CSNDSharedMemHandle:
|
|
serviceManager.setCSNDSharedMem(ptr);
|
|
printf("Mapping CSND memory block\n");
|
|
break;
|
|
|
|
case KernelHandles::APTCaptureSharedMemHandle: break;
|
|
default: Helpers::panic("Mapping unknown shared memory block: %X", block);
|
|
}
|
|
} else {
|
|
Helpers::panic("MapMemoryBlock where the handle does not refer to a known piece of kernel shared mem");
|
|
}
|
|
|
|
regs[0] = Result::Success;
|
|
}
|
|
|
|
HorizonHandle Kernel::makeMemoryBlock(u32 addr, u32 size, u32 myPermission, u32 otherPermission) {
|
|
Handle ret = makeObject(KernelObjectType::MemoryBlock);
|
|
objects[ret].data = new MemoryBlock(addr, size, myPermission, otherPermission);
|
|
|
|
return ret;
|
|
}
|
|
|
|
void Kernel::createMemoryBlock() {
|
|
const u32 addr = regs[1];
|
|
const u32 size = regs[2];
|
|
u32 myPermission = regs[3];
|
|
u32 otherPermission = mem.read32(regs[13] + 4); // This is placed on the stack rather than r4
|
|
logSVC("CreateMemoryBlock (addr = %08X, size = %08X, myPermission = %d, otherPermission = %d)\n", addr, size, myPermission, otherPermission);
|
|
|
|
// Returns whether a permission is valid
|
|
auto isPermValid = [](u32 permission) {
|
|
switch (permission) {
|
|
case MemoryPermissions::None:
|
|
case MemoryPermissions::Read:
|
|
case MemoryPermissions::Write:
|
|
case MemoryPermissions::ReadWrite:
|
|
case MemoryPermissions::DontCare:
|
|
return true;
|
|
|
|
default: // Permissions with the executable flag enabled or invalid permissions are not allowed
|
|
return false;
|
|
}
|
|
};
|
|
|
|
// Throw error if the size of the shared memory block is not aligned to page boundary
|
|
if (!isAligned(size)) {
|
|
regs[0] = Result::OS::MisalignedSize;
|
|
return;
|
|
}
|
|
|
|
// Throw error if one of the permissions is not valid
|
|
if (!isPermValid(myPermission) || !isPermValid(otherPermission)) {
|
|
regs[0] = Result::OS::InvalidCombination;
|
|
return;
|
|
}
|
|
|
|
// TODO: The address needs to be in a specific range otherwise it throws an invalid address error
|
|
|
|
if (addr == 0)
|
|
Helpers::panic("CreateMemoryBlock: Tried to use addr = 0");
|
|
|
|
// Implement "Don't care" permission as RW
|
|
if (myPermission == MemoryPermissions::DontCare) myPermission = MemoryPermissions::ReadWrite;
|
|
if (otherPermission == MemoryPermissions::DontCare) otherPermission = MemoryPermissions::ReadWrite;
|
|
|
|
regs[0] = Result::Success;
|
|
regs[1] = makeMemoryBlock(addr, size, myPermission, otherPermission);
|
|
}
|
|
|
|
void Kernel::unmapMemoryBlock() {
|
|
Handle block = regs[0];
|
|
u32 addr = regs[1];
|
|
logSVC("Unmap memory block (block handle = %X, addr = %08X)\n", block, addr);
|
|
|
|
Helpers::warn("Stubbed svcUnmapMemoryBlock!");
|
|
regs[0] = Result::Success;
|
|
}
|
|
|
|
u32 Kernel::getSharedFontVaddr() {
|
|
// Place shared font at the very beginning of system FCRAM
|
|
return mem.getLinearHeapVaddr() + Memory::FCRAM_APPLICATION_SIZE;
|
|
} |