MIO: First tests of (Access through Unified Memory) being conducted

This commit is contained in:
Correia 2024-04-29 22:40:28 -03:00
parent ad902629ac
commit bf94036ade
7 changed files with 56 additions and 15 deletions

View File

@ -20,7 +20,8 @@ namespace cosmic::console {
}
}
void IntCInfra::trapIrq(IntControllers in, u8 id) {
if (in == EeInt)
if (in == EeInt) {
eeInt.raiseIrq(id);
}
}
}

View File

@ -8,8 +8,10 @@ namespace cosmic::engine {
scheduler(solver), intc(inte) {
}
void EeTimers::resetTimers() {
for (u8 tt = {}; tt != timers.size(); tt++) {
timers.at(tt) = {};
for (u8 chronos = {}; chronos != timers.size(); chronos++) {
timers.at(chronos) = {};
// Not necessary perhaps, it will depend on the implementation
timers[chronos].count = {};
}
raiseEvent = scheduler->createSchedTick(false,[this](u8 position, bool ov) {
timerReached(position, ov);
@ -25,16 +27,16 @@ namespace cosmic::engine {
static u8 base{};
base = engine::T0 + raised;
auto timer{std::addressof(timers.at(raised))};
const auto timer{std::addressof(timers.at(raised))};
if (!overflow) {
bool compare{timer->ctrl.trap.compare};
const bool compare{timer->ctrl.trap.compare};
if (compare) {
timer->ctrl.trap.compare = true;
intc->trapIrq(console::EeInt, base);
}
}
bool woutOverflow{!timer->ctrl.trap.overflow};
bool shouldTrap{woutOverflow && overflow};
const bool woutOverflow{!timer->ctrl.trap.overflow};
const bool shouldTrap{woutOverflow && overflow};
if (shouldTrap) {
timer->ctrl.trap.overflow = true;
intc->trapIrq(console::EeInt, base);

View File

@ -7,7 +7,7 @@ namespace cosmic::vm {
class Scheduler;
}
namespace cosmic::engine {
struct EeHwTimer {
struct HwTimer {
u32 clocks;
bool isEnabled;
u16 count;
@ -39,6 +39,6 @@ namespace cosmic::engine {
void timerReached(u8 raised, bool overflow);
vm::CallBackId raiseEvent{};
std::array<EeHwTimer, 4> timers;
std::array<HwTimer, 4> timers;
};
}

View File

@ -44,4 +44,26 @@ namespace cosmic::mio {
return &soundBlock[address];
}
}
constexpr u64 megaByte = 1024 * 1024;
constexpr u64 soundMemory = megaByte * 2;
constexpr u64 iopMemory = megaByte * 2;
// Allocating 32 megabytes of RAM to the primary CPU
constexpr u64 mainMemory = megaByte * 32;
GlobalMemory::GlobalMemory() {
constexpr std::array<uintptr_t, 3> finalChunk{
0, soundMemory, soundMemory + iopMemory
};
const u64 amountOfBtcRequired{soundMemory + iopMemory + mainMemory};
u8* transaction = static_cast<u8*>(
mmap(nullptr, amountOfBtcRequired,
PROT_READ | PROT_WRITE, MAP_ANONYMOUS, 0, -1));
umm = os::MappedMemory<u8>{transaction, amountOfBtcRequired};
if (!umm) {
}
soundBlock = os::MappedMemory<u8>{*umm + finalChunk[0], soundMemory};
iopBlock = os::MappedMemory<u8>{*umm + finalChunk[1], iopMemory};
ramBlock = os::MappedMemory<u8>{*umm + finalChunk[2], mainMemory};
}
}

View File

@ -11,18 +11,25 @@ namespace cosmic::mio {
class GlobalMemory {
public:
GlobalMemory();
u8* mapVirtAddress(u32 address, RealAddressFrom mkFrom = MainMemory);
u64 biosSize() {
return static_cast<u64>(&ramBlock[0x3fffff] - &ramBlock[0]) + 1;
}
u8* iopUnaligned(u32 address);
u8* spu2Unaligned(u32 address);
void iopSoftClean() {
memset(*iopBlock, 0, iopBlock.getBlockSize());
}
private:
u8* access(u32 address, RealAddressFrom from);
os::MappedMemory<u8> iopBlock{static_cast<uint64_t>(1024 * 1024 * 2)};
os::MappedMemory<u8> soundBlock{static_cast<uint64_t>(1024 * 1024 * 2)};
// Allocating 32 megabytes of RAM to the primary CPU
os::MappedMemory<u8> ramBlock{static_cast<uint64_t>(1024 * 1024 * 32)};
// Our unified memory strategy pointer
os::MappedMemory<u8> umm;
// Below, all unified memory regions related to console activities
os::MappedMemory<u8> iopBlock;
os::MappedMemory<u8> soundBlock;
os::MappedMemory<u8> ramBlock;
};
}

View File

@ -6,7 +6,11 @@ namespace cosmic::os {
template<typename T>
struct MappedMemory {
MappedMemory() = default;
MappedMemory<T>(T* address) : managedBlock(address) {}
explicit MappedMemory<T>(T* address, u64 sz) :
blockSize(sz),
managedBlock(address) {
}
MappedMemory(MappedMemory&) = delete;
MappedMemory<T>(u64 mSize) :
blockSize(mSize * sizeof(T)),
@ -33,6 +37,9 @@ namespace cosmic::os {
void enableDump() {
madvise(reinterpret_cast<void*>(managedBlock), blockSize, MADV_DODUMP);
}
operator bool() const {
return managedBlock != nullptr;
}
private:
u64 blockSize{};
T* managedBlock{};

View File

@ -87,6 +87,8 @@ namespace cosmic::vm {
iop->resetIop();
ioDma->resetIoDma();
sound->resetSound();
iop->iopMem->controller->mapped->iopSoftClean();
}
void EmuVm::dealWithSyscalls() {
hle::SyscallOrigin origin{};