mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-04 17:53:17 +00:00
core: Reorganize
This commit is contained in:
parent
89cf4dbfcb
commit
369d92fa56
73 changed files with 724 additions and 572 deletions
33
src/core/aerolib/aerolib.cpp
Normal file
33
src/core/aerolib/aerolib.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <cstring>
|
||||
#include "common/types.h"
|
||||
#include "core/aerolib/aerolib.h"
|
||||
|
||||
namespace Core::AeroLib {
|
||||
|
||||
// Use a direct table here + binary search as contents are static
|
||||
static constexpr NidEntry NIDS[] = {
|
||||
#define STUB(nid, name) \
|
||||
{ nid, #name },
|
||||
#include "aerolib.inl"
|
||||
#undef STUB
|
||||
};
|
||||
|
||||
const NidEntry* FindByNid(const char* nid) {
|
||||
s64 l = 0;
|
||||
s64 r = sizeof(NIDS) / sizeof(NIDS[0]) - 1;
|
||||
|
||||
while (l <= r) {
|
||||
const size_t m = l + (r - l) / 2;
|
||||
const int cmp = std::strcmp(NIDS[m].nid, nid);
|
||||
if (cmp == 0) {
|
||||
return &NIDS[m];
|
||||
} else if (cmp < 0) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
r = m - 1;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace Core::AeroLib
|
14
src/core/aerolib/aerolib.h
Normal file
14
src/core/aerolib/aerolib.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Core::AeroLib {
|
||||
|
||||
struct NidEntry {
|
||||
const char* nid;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
const NidEntry* FindByNid(const char* nid);
|
||||
|
||||
} // namespace Core::AeroLib
|
11225
src/core/aerolib/aerolib.inl
Normal file
11225
src/core/aerolib/aerolib.inl
Normal file
File diff suppressed because it is too large
Load diff
82
src/core/aerolib/stubs.cpp
Normal file
82
src/core/aerolib/stubs.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include "common/log.h"
|
||||
#include "core/aerolib/aerolib.h"
|
||||
#include "core/aerolib/stubs.h"
|
||||
|
||||
namespace Core::AeroLib {
|
||||
|
||||
// Helper to provide stub implementations for missing functions
|
||||
//
|
||||
// This works by pre-compiling generic stub functions ("slots"), and then
|
||||
// on lookup, setting up the nid_entry they are matched with
|
||||
//
|
||||
// If it runs out of stubs with name information, it will return
|
||||
// a default implemetnation without function name details
|
||||
|
||||
// Up to 512, larger values lead to more resolve stub slots
|
||||
// and to longer compile / CI times
|
||||
//
|
||||
// Must match STUBS_LIST define
|
||||
constexpr u32 MAX_STUBS = 128;
|
||||
|
||||
u64 UnresolvedStub() {
|
||||
LOG_ERROR("Unresolved Stub: called, returning zero to {}\n", __builtin_return_address(0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u64 UnknownStub() {
|
||||
LOG_ERROR("Stub: Unknown (nid: Unknown) called, returning zero to {}\n", __builtin_return_address(0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const NidEntry* stub_nids[MAX_STUBS];
|
||||
static std::string stub_nids_unknown[MAX_STUBS];
|
||||
|
||||
template <int stub_index>
|
||||
static u64 CommonStub() {
|
||||
auto entry = stub_nids[stub_index];
|
||||
if (entry) {
|
||||
LOG_ERROR("Stub: {} (nid: {}) called, returning zero to {}\n", entry->name, entry->nid, __builtin_return_address(0));
|
||||
} else {
|
||||
LOG_ERROR("Stub: Unknown (nid: {}) called, returning zero to {}\n", stub_nids_unknown[stub_index], __builtin_return_address(0));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 UsedStubEntries;
|
||||
|
||||
#define XREP_1(x) \
|
||||
&CommonStub<x>,
|
||||
|
||||
#define XREP_2(x) XREP_1(x) XREP_1(x + 1)
|
||||
#define XREP_4(x) XREP_2(x) XREP_2(x + 2)
|
||||
#define XREP_8(x) XREP_4(x) XREP_4(x + 4)
|
||||
#define XREP_16(x) XREP_8(x) XREP_8(x + 8)
|
||||
#define XREP_32(x) XREP_16(x) XREP_16(x + 16)
|
||||
#define XREP_64(x) XREP_32(x) XREP_32(x + 32)
|
||||
#define XREP_128(x) XREP_64(x) XREP_64(x + 64)
|
||||
#define XREP_256(x) XREP_128(x) XREP_128(x + 128)
|
||||
#define XREP_512(x) XREP_256(x) XREP_256(x + 256)
|
||||
|
||||
#define STUBS_LIST XREP_128(0)
|
||||
|
||||
static u64 (*stub_handlers[MAX_STUBS])() = {
|
||||
STUBS_LIST
|
||||
};
|
||||
|
||||
u64 GetStub(const char* nid) {
|
||||
if (UsedStubEntries >= MAX_STUBS) {
|
||||
return (u64)&UnknownStub;
|
||||
}
|
||||
|
||||
const auto entry = FindByNid(nid);
|
||||
if (!entry) {
|
||||
stub_nids_unknown[UsedStubEntries] = nid;
|
||||
} else {
|
||||
stub_nids[UsedStubEntries] = entry;
|
||||
}
|
||||
|
||||
return (u64)stub_handlers[UsedStubEntries++];
|
||||
}
|
||||
|
||||
} // namespace Core::AeroLib
|
11
src/core/aerolib/stubs.h
Normal file
11
src/core/aerolib/stubs.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::AeroLib {
|
||||
|
||||
u64 UnresolvedStub();
|
||||
|
||||
u64 GetStub(const char* nid);
|
||||
|
||||
} // namespace Core::AeroLib
|
Loading…
Add table
Add a link
Reference in a new issue