From DSiBrew
Revision as of 00:07, 2 July 2022 by Hallowizer (talk | contribs) (added a stub section on memory allocation)
Jump to navigation Jump to search

The ARM9 SDK contains an OS library that handles various functions. It does not have many debugging strings, so most names listed on this page are taken from the Wii.


struct OSFpContext {
	f64 REG_DIV_NUMER; // 0x0
	f64 REG_DIV_DENOM; // 0x8
	f64 SQRT_PARAM; // 0x10
	u16 REG_DIVCNT; // 0x18
	u16 REG_SQRTCNT; // 0x1a

struct OSContext {
	u32 psr; // 0x0
	u32 r0; // 0x4
	u32 r1; // 0x8
	u32 r2; // 0xc
	u32 r3; // 0x10
	u32 r4; // 0x14
	u32 r5; // 0x18
	u32 r6; // 0x1c
	u32 r7; // 0x20
	u32 r8; // 0x24
	u32 r9; // 0x28
	u32 r10; // 0x2c
	u32 r11; // 0x30
	u32 r12; // 0x34
	void *sp; // 0x38
	void *lr; // 0x3c
	void *pc; // 0x40
	void *kernelSp; // 0x44
	struct OSFpContext fp; // 0x48

struct OSThread {
	struct OSContext ctx; // 0x0
	u32 state; // 0x64
	struct OSThread *nextRunning; // 0x68
	u32 threadId; // 0x6c
	u32 priority; // 0x70
	u32 unknown; // 0x74
	struct OSThreadQueue *queue; // 0x78
	struct OSThreadLink linkQueue; // 0x7c
	u32 unknown2; // 0x80
	struct OSMutexQueue *queueMutex; // 0x84
	// more unknown fields - the total length is not known

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

struct OSThreadLink {
	struct OSThread *prev;
	struct OSThread *next;

struct OSMutex {
	struct OSThreadQueue waitingQueue;
	struct OSThread *holder;
	u32 timesLocked;
	struct OSMutex *next;
	struct OSMutex *prev;

struct OSMutexQueue {
	struct OSMutex *waiting;
	struct OSMutex *head;
	struct OSMutex *tail;

Message queues

struct OSMessageQueue {
	struct OSThreadQueue waitForReceive;
	struct OSThreadQueue waitForSend;
	u32 *buf;
	u32 capacity;
	u32 rotation;
	u32 messagesEnqueued;

Memory allocation

3 types of heaps exist: EXPH (exponential heap), FRMH (frame heap), and UNTH (unit heap).