[Kernel] Implement ClearEvent, stub WaitSynchronization1

This commit is contained in:
wheremyfoodat 2022-09-20 19:02:52 +03:00
parent 6bfe321777
commit d3a2591d19
5 changed files with 37 additions and 1 deletions

View file

@ -82,6 +82,7 @@ class Kernel {
// SVC implementations
void arbitrateAddress();
void clearEvent();
void createAddressArbiter();
void createEvent();
void createThread();
@ -95,6 +96,7 @@ class Kernel {
void svcCloseHandle();
void connectToPort();
void outputDebugString();
void waitSynchronization1();
public:
Kernel(CPU& cpu, Memory& mem);

View file

@ -65,6 +65,7 @@ struct Process {
struct Event {
ResetType resetType = ResetType::OneShot;
bool fired = false;
Event(ResetType resetType) : resetType(resetType) {}
};

View file

@ -27,4 +27,35 @@ void Kernel::createEvent() {
regs[0] = SVCResult::Success;
regs[1] = makeEvent(static_cast<ResetType>(resetType));
}
// Result ClearEvent(Handle event)
void Kernel::clearEvent() {
const Handle handle = regs[0];
const auto event = getObject(handle, KernelObjectType::Event);
printf("ClearEvent(event handle = %d)\n", event);
if (event == nullptr) [[unlikely]] {
regs[0] = SVCResult::BadHandle;
return;
}
event->getData<Event>()->fired = false;
regs[0] = SVCResult::Success;
}
// Result WaitSynchronization1(Handle handle, s64 timeout_nanoseconds)
void Kernel::waitSynchronization1() {
const Handle handle = regs[0];
const s64 ns = s64(u64(regs[1]) | (u64(regs[2]) << 32));
const auto event = getObject(handle, KernelObjectType::Event);
if (event == nullptr) [[unlikely]] {
Helpers::panic("WaitSynchronization1: Bad event handle");
regs[0] = SVCResult::BadHandle;
return;
}
printf("WaitSynchronization1(handle = %X, ns = %lld) (STUBBED)\n", handle, ns);
regs[0] = SVCResult::Success;
}

View file

@ -20,10 +20,12 @@ void Kernel::serviceSVC(u32 svc) {
case 0x02: queryMemory(); break;
case 0x08: createThread(); break;
case 0x17: createEvent(); break;
case 0x19: clearEvent(); break;
case 0x1F: mapMemoryBlock(); break;
case 0x21: createAddressArbiter(); break;
case 0x22: arbitrateAddress(); break;
case 0x23: svcCloseHandle(); break;
case 0x24: waitSynchronization1(); break;
case 0x2D: connectToPort(); break;
case 0x32: sendSyncRequest(); break;
case 0x38: getResourceLimit(); break;

View file

@ -92,5 +92,5 @@ void Kernel::sleepThreadOnArbiter(u32 waitingAddress) {
t.status = ThreadStatus::WaitArbiter;
t.waitingAddress = waitingAddress;
switchThread(1);
switchThread(1); // TODO: Properly change threads
}