Merge pull request #123 from shadps4-emu/sonicmania_work

Sonicmania work
This commit is contained in:
georgemoralis 2024-05-02 17:36:59 +03:00 committed by GitHub
commit 7d6a717599
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 177 additions and 6 deletions

View File

@ -101,7 +101,11 @@ set(GNM_LIB src/core/libraries/gnmdriver/gnmdriver.cpp
src/core/libraries/gnmdriver/gnmdriver.h src/core/libraries/gnmdriver/gnmdriver.h
) )
set(KERNEL_LIB src/core/libraries/kernel/cpu_management.cpp set(KERNEL_LIB src/core/libraries/kernel/memory/flexible_memory.cpp
src/core/libraries/kernel/memory/flexible_memory.h
src/core/libraries/kernel/memory/kernel_memory.cpp
src/core/libraries/kernel/memory/kernel_memory.h
src/core/libraries/kernel/cpu_management.cpp
src/core/libraries/kernel/cpu_management.h src/core/libraries/kernel/cpu_management.h
src/core/libraries/kernel/event_queue.cpp src/core/libraries/kernel/event_queue.cpp
src/core/libraries/kernel/event_queue.h src/core/libraries/kernel/event_queue.h

View File

@ -10,6 +10,7 @@
#include "core/libraries/kernel/event_queues.h" #include "core/libraries/kernel/event_queues.h"
#include "core/libraries/kernel/file_system.h" #include "core/libraries/kernel/file_system.h"
#include "core/libraries/kernel/libkernel.h" #include "core/libraries/kernel/libkernel.h"
#include "core/libraries/kernel/memory/kernel_memory.h"
#include "core/libraries/kernel/memory_management.h" #include "core/libraries/kernel/memory_management.h"
#include "core/libraries/kernel/thread_management.h" #include "core/libraries/kernel/thread_management.h"
#include "core/libraries/kernel/time_management.h" #include "core/libraries/kernel/time_management.h"
@ -180,6 +181,7 @@ void LibKernel_Register(Core::Loader::SymbolsResolver* sym) {
Libraries::Kernel::fileSystemSymbolsRegister(sym); Libraries::Kernel::fileSystemSymbolsRegister(sym);
Libraries::Kernel::timeSymbolsRegister(sym); Libraries::Kernel::timeSymbolsRegister(sym);
Libraries::Kernel::pthreadSymbolsRegister(sym); Libraries::Kernel::pthreadSymbolsRegister(sym);
Libraries::Kernel::RegisterKernelMemory(sym);
// temp // temp
LIB_FUNCTION("NWtTN10cJzE", "libSceLibcInternalExt", 1, "libSceLibcInternal", 1, 1, LIB_FUNCTION("NWtTN10cJzE", "libSceLibcInternalExt", 1, "libSceLibcInternal", 1, 1,

View File

@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "flexible_memory.h"
namespace Libraries::Kernel {
bool FlexibleMemory::Map(u64 virtual_addr, std::size_t len, int prot,
VirtualMemory::MemoryMode cpu_mode) {
std::scoped_lock lock{mutex};
AllocatedBlock block{};
block.map_virtual_addr = virtual_addr;
block.map_size = len;
block.prot = prot;
block.cpu_mode = cpu_mode;
allocated_blocks.push_back(block);
allocated_total += len;
return true;
}
} // namespace Libraries::Kernel

View File

@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <mutex>
#include <vector>
#include "common/types.h"
#include "core/virtual_memory.h"
namespace Libraries::Kernel {
class FlexibleMemory {
public:
struct AllocatedBlock {
u64 map_virtual_addr;
u64 map_size;
int prot;
VirtualMemory::MemoryMode cpu_mode;
};
FlexibleMemory(){};
virtual ~FlexibleMemory(){};
public:
bool Map(u64 virtual_addr, std::size_t len, int prot, VirtualMemory::MemoryMode cpu_mode);
private:
std::vector<AllocatedBlock> allocated_blocks;
u64 allocated_total = 0;
std::mutex mutex;
};
} // namespace Libraries::Kernel

View File

@ -0,0 +1,78 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <common/assert.h>
#include <common/singleton.h>
#include <core/libraries/error_codes.h>
#include <core/libraries/libs.h>
#include <core/virtual_memory.h>
#include "flexible_memory.h"
#include "kernel_memory.h"
namespace Libraries::Kernel {
bool Is16KBMultiple(u64 n) {
return ((n % (16ull * 1024) == 0));
}
s32 PS4_SYSV_ABI sceKernelMapNamedFlexibleMemory(void** addr_in_out, std::size_t len, int prot,
int flags, const char* name) {
LOG_INFO(Kernel_Vmm, "len = {:#x}, prot = {:#x}, flags = {:#x}, name = {}", len, prot, flags,
name);
if (len == 0 || !Is16KBMultiple(len)) {
LOG_ERROR(Kernel_Vmm, "len is 0 or not 16kb multiple");
return ORBIS_KERNEL_ERROR_EINVAL;
}
static constexpr size_t MaxNameSize = 32;
if (std::strlen(name) > MaxNameSize) {
LOG_ERROR(Kernel_Vmm, "name exceeds 32 bytes!");
return ORBIS_KERNEL_ERROR_ENAMETOOLONG;
}
if (name == nullptr) {
LOG_ERROR(Kernel_Vmm, "name is invalid!");
return ORBIS_KERNEL_ERROR_EFAULT;
}
VirtualMemory::MemoryMode cpu_mode = VirtualMemory::MemoryMode::NoAccess;
switch (prot) {
case 0x3:
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
break;
default:
UNREACHABLE();
}
auto in_addr = reinterpret_cast<u64>(*addr_in_out);
auto out_addr = VirtualMemory::memory_alloc(in_addr, len, cpu_mode);
*addr_in_out = reinterpret_cast<void*>(out_addr);
auto* flexible_memory = Common::Singleton<FlexibleMemory>::Instance();
if (!flexible_memory->Map(out_addr, len, prot, cpu_mode)) {
UNREACHABLE();
}
if (out_addr == 0) {
LOG_ERROR(Kernel_Vmm, "Can't allocate address");
return ORBIS_KERNEL_ERROR_ENOMEM;
}
LOG_INFO(Kernel_Vmm, "in_addr = {:#x} out_addr = {:#x}", in_addr, out_addr);
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceKernelMapFlexibleMemory(void** addr_in_out, std::size_t len, int prot,
int flags) {
return sceKernelMapNamedFlexibleMemory(addr_in_out, len, prot, flags, "");
}
void RegisterKernelMemory(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("mL8NDH86iQI", "libkernel", 1, "libkernel", 1, 1, sceKernelMapNamedFlexibleMemory);
LIB_FUNCTION("IWIBBdTHit4", "libkernel", 1, "libkernel", 1, 1, sceKernelMapFlexibleMemory);
}
} // namespace Libraries::Kernel

View File

@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/types.h"
namespace Core::Loader {
class SymbolsResolver;
}
namespace Libraries::Kernel {
s32 PS4_SYSV_ABI sceKernelMapNamedFlexibleMemory(void** addrInOut, std::size_t len, int prot,
int flags, const char* name);
s32 PS4_SYSV_ABI sceKernelMapFlexibleMemory(void** addr_in_out, std::size_t len, int prot,
int flags);
void RegisterKernelMemory(Core::Loader::SymbolsResolver* sym);
} // namespace Libraries::Kernel

View File

@ -827,7 +827,11 @@ int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr
int result = pthread_copy_attributes(&(*thread)->attr, attr); int result = pthread_copy_attributes(&(*thread)->attr, attr);
if (result == 0) { if (result == 0) {
if (name != NULL) {
(*thread)->name = name; (*thread)->name = name;
} else {
(*thread)->name = "no-name";
}
(*thread)->entry = start_routine; (*thread)->entry = start_routine;
(*thread)->arg = arg; (*thread)->arg = arg;
(*thread)->is_almost_done = false; (*thread)->is_almost_done = false;

View File

@ -103,11 +103,21 @@ int PS4_SYSV_ABI sceUserServiceGetDiscPlayerFlag() {
return ORBIS_OK; return ORBIS_OK;
} }
int PS4_SYSV_ABI sceUserServiceGetEvent() { s32 PS4_SYSV_ABI sceUserServiceGetEvent(OrbisUserServiceEvent* event) {
LOG_ERROR(Lib_UserService, "(STUBBED) called"); LOG_INFO(Lib_UserService, "(DUMMY) called");
// fake a loggin event
static bool logged_in = false;
if (!logged_in) {
logged_in = true;
event->event = SCE_USER_SERVICE_EVENT_TYPE_LOGIN;
event->userId = 1;
return ORBIS_OK; return ORBIS_OK;
} }
return ORBIS_USER_SERVICE_ERROR_NO_EVENT;
}
int PS4_SYSV_ABI sceUserServiceGetEventCalendarType() { int PS4_SYSV_ABI sceUserServiceGetEventCalendarType() {
LOG_ERROR(Lib_UserService, "(STUBBED) called"); LOG_ERROR(Lib_UserService, "(STUBBED) called");
return ORBIS_OK; return ORBIS_OK;

View File

@ -76,7 +76,7 @@ int PS4_SYSV_ABI sceUserServiceGetCurrentUserGroupIndex();
int PS4_SYSV_ABI sceUserServiceGetDefaultNewUserGroupName(); int PS4_SYSV_ABI sceUserServiceGetDefaultNewUserGroupName();
int PS4_SYSV_ABI sceUserServiceGetDeletedUserInfo(); int PS4_SYSV_ABI sceUserServiceGetDeletedUserInfo();
int PS4_SYSV_ABI sceUserServiceGetDiscPlayerFlag(); int PS4_SYSV_ABI sceUserServiceGetDiscPlayerFlag();
int PS4_SYSV_ABI sceUserServiceGetEvent(); int PS4_SYSV_ABI sceUserServiceGetEvent(OrbisUserServiceEvent* event);
int PS4_SYSV_ABI sceUserServiceGetEventCalendarType(); int PS4_SYSV_ABI sceUserServiceGetEventCalendarType();
int PS4_SYSV_ABI sceUserServiceGetEventFilterTeamEvent(); int PS4_SYSV_ABI sceUserServiceGetEventFilterTeamEvent();
int PS4_SYSV_ABI sceUserServiceGetEventSortEvent(); int PS4_SYSV_ABI sceUserServiceGetEventSortEvent();