commit
2f2dc59ec2
|
@ -41,7 +41,7 @@ add_executable(shadps4
|
|||
src/Core/PS4/HLE/Kernel/Objects/physical_memory.cpp
|
||||
src/Util/string_util.cpp
|
||||
src/Util/string_util.cpp
|
||||
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h")
|
||||
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h")
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY})
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace HLE::Kernel::Objects {
|
|||
static u64 AlignUp(u64 pos, u64 align) { return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos); }
|
||||
|
||||
bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut, int memoryType) {
|
||||
Lib::LockMutexGuard lock(m_mutex);
|
||||
u64 find_free_pos = 0;
|
||||
|
||||
// iterate through allocated blocked and find the next free position
|
||||
|
@ -39,6 +40,7 @@ bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignmen
|
|||
return false;
|
||||
}
|
||||
bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, VirtualMemory::MemoryMode cpu_mode, GPU::MemoryMode gpu_mode) {
|
||||
Lib::LockMutexGuard lock(m_mutex);
|
||||
for (auto& b : m_allocatedBlocks) {
|
||||
if (phys_addr >= b.start_addr && phys_addr < b.start_addr + b.size) {
|
||||
if (b.map_virtual_addr != 0 || b.map_size != 0) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <Core/virtual_memory.h>
|
||||
#include <Core/PS4/GPU/gpu_memory.h>
|
||||
#include <vector>
|
||||
#include "Lib/Threads.h"
|
||||
|
||||
namespace HLE::Kernel::Objects {
|
||||
|
||||
|
@ -27,6 +28,7 @@ class PhysicalMemory {
|
|||
|
||||
private:
|
||||
std::vector<AllocatedBlock> m_allocatedBlocks;
|
||||
Lib::Mutex m_mutex;
|
||||
};
|
||||
|
||||
} // namespace HLE::Kernel::Objects
|
|
@ -67,22 +67,20 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u
|
|||
|
||||
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
if (len == 0 || !is16KBAligned(len))
|
||||
{
|
||||
if (len == 0 || !is16KBAligned(len)) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL len invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (!is16KBAligned(directMemoryStart))
|
||||
{
|
||||
if (!is16KBAligned(directMemoryStart)) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL directMemoryStart invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (alignment != 0 || (!isPowerOfTwo(alignment) && !is16KBAligned(alignment)))
|
||||
{
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
if (alignment != 0) {
|
||||
if ((!isPowerOfTwo(alignment) && !is16KBAligned(alignment))){
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
auto* physical_memory = Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance();
|
||||
|
||||
LOG_INFO_IF(log_file_memory, "len = {}\n", log_hex_full(len));
|
||||
LOG_INFO_IF(log_file_memory, "prot = {}\n", log_hex_full(prot));
|
||||
|
@ -94,7 +92,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
|
|||
GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess;
|
||||
|
||||
switch (prot) {
|
||||
case 0x33://SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL
|
||||
case 0x33: // SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL
|
||||
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
|
||||
gpu_mode = GPU::MemoryMode::ReadWrite;
|
||||
break;
|
||||
|
@ -116,6 +114,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
|
|||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
}
|
||||
|
||||
auto* physical_memory = Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance();
|
||||
if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
@ -123,7 +122,6 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
|
|||
if (gpu_mode != GPU::MemoryMode::NoAccess) {
|
||||
GPU::MemorySetAllocArea(out_addr, len);
|
||||
}
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ static std::string encodeId(u64 nVal)
|
|||
}
|
||||
Module* Linker::LoadModule(const std::string& elf_name)
|
||||
{
|
||||
Lib::LockMutexGuard lock(m_mutex);
|
||||
auto* m = new Module;
|
||||
m->linker = this;
|
||||
m->elf = new Elf;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <vector>
|
||||
#include "Loader/Elf.h"
|
||||
#include "Loader/SymbolsResolver.h"
|
||||
#include "Lib/Threads.h"
|
||||
|
||||
struct DynamicModuleInfo;
|
||||
class Linker;
|
||||
|
@ -129,4 +130,5 @@ public:
|
|||
|
||||
std::vector<Module*> m_modules;
|
||||
SymbolsResolver* m_HLEsymbols = nullptr;
|
||||
Lib::Mutex m_mutex;
|
||||
};
|
|
@ -121,5 +121,11 @@ class LockMutexGuard {
|
|||
|
||||
private:
|
||||
Mutex& m_mutex;
|
||||
|
||||
public:
|
||||
LockMutexGuard(const LockMutexGuard&) = delete;
|
||||
LockMutexGuard& operator=(const LockMutexGuard&) = delete;
|
||||
LockMutexGuard(LockMutexGuard&&) noexcept = delete;
|
||||
LockMutexGuard& operator=(LockMutexGuard&&) noexcept = delete;
|
||||
};
|
||||
} // namespace Lib
|
|
@ -0,0 +1,9 @@
|
|||
#include "emulator.h"
|
||||
|
||||
namespace Emulator {
|
||||
void emuInit() {}
|
||||
void emuRun() {
|
||||
for (;;) {
|
||||
}
|
||||
}
|
||||
} // namespace emulator
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
namespace Emulator {
|
||||
void emuInit();
|
||||
void emuRun();
|
||||
}
|
16
src/main.cpp
16
src/main.cpp
|
@ -30,6 +30,7 @@
|
|||
#include <Zydis/Zydis.h>
|
||||
#include "Core/PS4/HLE/Libs.h"
|
||||
#include "Lib/Threads.h"
|
||||
#include <emulator.h>
|
||||
|
||||
// Main code
|
||||
int main(int argc, char* argv[])
|
||||
|
@ -40,15 +41,24 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
logging::init(true); // init logging
|
||||
Emulator::emuInit();
|
||||
Lib::InitThreads();
|
||||
const char* const path = argv[1]; //argument 1 is the path of self file to boot
|
||||
// const char* const path = "F:\\ps4games\\CUSA03840 - Resident Evil 6\\eboot.bin";
|
||||
const char* const path = argv[1]; // argument 1 is the path of self file to boot
|
||||
|
||||
auto* linker = Singleton<Linker>::Instance();
|
||||
HLE::Libs::Init_HLE_Libs(linker->getHLESymbols());
|
||||
auto *module =linker->LoadModule(path);//load main executable
|
||||
|
||||
linker->Execute();
|
||||
Lib::Thread mainthread(
|
||||
[](void*) {
|
||||
auto* linker = Singleton<Linker>::Instance();
|
||||
linker->Execute();
|
||||
},
|
||||
nullptr);
|
||||
mainthread.DetachThread();
|
||||
Emulator::emuRun();
|
||||
mainthread.JoinThread();
|
||||
|
||||
#if 0
|
||||
// Setup SDL
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMEPAD) != 0)
|
||||
|
|
Loading…
Reference in New Issue