From 1ac9417d509807e2646a5fe1f7ce2f88658c3294 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Tue, 20 Sep 2022 01:50:32 +0300 Subject: [PATCH] [Kernel] More threading work --- include/kernel/kernel_types.hpp | 6 +++++- src/core/kernel/address_arbiter.cpp | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/kernel/kernel_types.hpp b/include/kernel/kernel_types.hpp index 26d6a7a5..b7e81fcf 100644 --- a/include/kernel/kernel_types.hpp +++ b/include/kernel/kernel_types.hpp @@ -8,12 +8,16 @@ namespace SVCResult { Success = 0, Failure = 0xFFFFFFFF, ObjectNotFound = 0xD88007FA, - // Different calls return a different value + + // Different calls return a different value for these ones + InvalidEnumValue = 0xD8E007ED, + InvalidEnumValueAlt = 0xD8E093ED, BadHandle = 0xD8E007F7, BadHandleAlt = 0xD9001BF7, BadThreadPriority = 0xE0E01BFD, PortNameTooLong = 0xE0E0181E, + }; } diff --git a/src/core/kernel/address_arbiter.cpp b/src/core/kernel/address_arbiter.cpp index a89d31c3..8421a035 100644 --- a/src/core/kernel/address_arbiter.cpp +++ b/src/core/kernel/address_arbiter.cpp @@ -34,7 +34,7 @@ void Kernel::arbitrateAddress() { const Handle handle = regs[0]; const u32 address = regs[1]; const u32 type = regs[2]; - const u32 value = regs[3]; + const s32 value = regs[3]; const s64 ns = s64(u64(regs[4]) | (u64(regs[5]) << 32)); printf("ArbitrateAddress(Handle = %X, address = %08X, type = %s, value = %d, ns = %lld)\n", handle, address, @@ -46,13 +46,25 @@ void Kernel::arbitrateAddress() { return; } - if (value > 4) { - Helpers::panic("ArbitrateAddress: invalid arbitration type"); + if (address & 3) { + Helpers::panic("ArbitrateAddres:: Unaligned address"); + } + + if (value > 4) [[unlikely]] { + regs[0] = SVCResult::InvalidEnumValueAlt; + return; } switch (static_cast(type)) { - case ArbitrationType::WaitIfLess: - Helpers::panic("Uwu"); + // Puts this thread to sleep if word < value until another thread signals the address with the type SIGNAL + case ArbitrationType::WaitIfLess: { + s32 word = static_cast(mem.read32(address)); // Yes this is meant to be signed + if (word < value) { + Helpers::panic("Needa sleep"); + } + break; + } + default: Helpers::panic("ArbitrateAddress: Unimplemented type %s", arbitrationTypeToString(type)); }