IOP OS

From WiiBrew
Jump to navigation Jump to search

IOP OS is a set of functions in the NET module (as well as SSL in IOS9, although SSL does not actually use it) in IOS that convert DS ARM9 OS calls to IOS syscalls.

Toggling interrupts

Disabling interrupts is simulated by locking a mutex (but not an OSMutex) implemented as a message queue and changing the current thread priority to 0x38 (higher than other threads in the process). While this does not completely prevent concurrent execution within the module, it is enough for most uses of OSDisableInterrupts. Despite this, the design used may be a mistake when porting the code to IOS, since lower priority ARM9 OS threads can starve from being blocked by higher priority threads, which would achieve this goal.

Threads

Threads are implemented as a proxy to IOS threads. Because of this, OSThreadQueue is only used for suspended queues.

struct OSThread {
	int threadId;
	int priority;
	void *threadSpecific;
	struct OSThread *next;
}

struct OSThreadQueue {
	struct OSThread *head;
	struct OSThread *tail;
}

Mutexes

Mutexes are implemented as message queues that are read from to lock the mutex and sent to to unlock the mutex.

struct OSMutex {
	int mqid;
	int mq;
	int count;
	int owner; // thread id
}

Alarms

Alarms have two components: an event handler component and a user component. The event handler component is stored in a global variable, while the user component is stored at a pointer provided by the code.

struct OSAlarm {
	void (*handler)(struct OSAlarm *alarm, u32 unknown); // 0x0
	u64 time; // 0x4
	u64 repeatInterval; // 0xc
	u64 unknown; // 0x14 - another time value
	u32 timerId; // 0x1c
}

struct AlarmEventInfo {
	u32 msg;
	OSAlarm *alarm;
	struct AlarmEventInfo *next;
}