[Kernel] Implement ArbitrationType::DecrementAndWaitIfLess

This commit is contained in:
wheremyfoodat 2022-10-10 16:57:33 +03:00
parent 81b0f3dde0
commit 6c3acda34e
3 changed files with 16 additions and 6 deletions

View file

@ -58,7 +58,7 @@ void Kernel::arbitrateAddress() {
regs[0] = SVCResult::Success; regs[0] = SVCResult::Success;
switch (static_cast<ArbitrationType>(type)) { switch (static_cast<ArbitrationType>(type)) {
// Puts this thread to sleep if word < value until another thread signals the address with the type SIGNAL // Puts this thread to sleep if word < value until another thread arbitrates the address using SIGNAL
case ArbitrationType::WaitIfLess: { case ArbitrationType::WaitIfLess: {
s32 word = static_cast<s32>(mem.read32(address)); // Yes this is meant to be signed s32 word = static_cast<s32>(mem.read32(address)); // Yes this is meant to be signed
if (word < value) { if (word < value) {
@ -67,6 +67,17 @@ void Kernel::arbitrateAddress() {
break; break;
} }
// Puts this thread to sleep if word < value until another thread arbitrates the address using SIGNAL
// If the thread is put to sleep, the arbiter address is decremented
case ArbitrationType::DecrementAndWaitIfLess: {
s32 word = static_cast<s32>(mem.read32(address)); // Yes this is meant to be signed
if (word < value) {
mem.write32(address, word - 1);
sleepThreadOnArbiter(address);
}
break;
}
case ArbitrationType::Signal: case ArbitrationType::Signal:
signalArbiter(address, value); signalArbiter(address, value);
break; break;

View file

@ -73,8 +73,7 @@ void Kernel::waitSynchronizationN() {
logSVC("WaitSynchronizationN (STUBBED)\n"); logSVC("WaitSynchronizationN (STUBBED)\n");
regs[0] = SVCResult::Success; regs[0] = SVCResult::Success;
if (currentThreadIndex == 1) { printf("Hacky WaitSync stuff for OoT triggered!!!\n");
printf("WaitSynchN OoT hack triggered\n"); threads[currentThreadIndex].status = ThreadStatus::Ready;
switchThread(0); switchThread(rand() % threadCount);
}
} }

View file

@ -9,7 +9,7 @@ int main (int argc, char *argv[]) {
emu.initGraphicsContext(); emu.initGraphicsContext();
auto romPath = std::filesystem::current_path() / (argc > 1 ? argv[1] : "SimplerTri.elf"); auto romPath = std::filesystem::current_path() / (argc > 1 ? argv[1] : "OoT.3ds");
if (!emu.loadROM(romPath)) { if (!emu.loadROM(romPath)) {
// For some reason just .c_str() doesn't show the proper path // For some reason just .c_str() doesn't show the proper path
Helpers::panic("Failed to load ROM file: %s", romPath.string().c_str()); Helpers::panic("Failed to load ROM file: %s", romPath.string().c_str());