summaryrefslogtreecommitdiff
path: root/mm/include/PR/os_thread.h
blob: 2746e47e6dc12ccdc60eeeafececb38200e9c7fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef PR_OS_THREAD_H
#define PR_OS_THREAD_H

#include "ultratypes.h"
#include <libultraship/libultra/thread.h>
#if 0
#define OS_FLAG_CPU_BREAK 1
#define OS_FLAG_FAULT 2

typedef s32 OSPri;
typedef s32 OSId;

typedef union {
    struct {
        /* 0x00 */ f32 f_odd;
        /* 0x04 */ f32 f_even;
    } f;
} __OSfp; // size = 0x08

typedef struct {
    /* 0x000 */ u64 at, v0, v1, a0, a1, a2, a3;
    /* 0x038 */ u64 t0, t1, t2, t3, t4, t5, t6, t7;
    /* 0x078 */ u64 s0, s1, s2, s3, s4, s5, s6, s7;
    /* 0x0B8 */ u64 t8, t9, gp, sp, s8, ra;
    /* 0x0E8 */ u64 lo, hi;
    /* 0x0F8 */ u32 sr, pc, cause, badvaddr, rcp;
    /* 0x10C */ u32 fpcsr;
    /* 0x110 */ __OSfp  fp0,  fp2,  fp4,  fp6,  fp8, fp10, fp12, fp14;
    /* 0x150 */ __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30;
} __OSThreadContext; // size = 0x190

typedef struct {
    /* 0x00 */ u32 flag;
    /* 0x04 */ u32 count;
    /* 0x08 */ u64 time;
} __OSThreadprofile; // size = 0x10

typedef struct OSThread {
    /* 0x00 */ struct OSThread* next;
    /* 0x04 */ OSPri priority;
    /* 0x08 */ struct OSThread** queue;
    /* 0x0C */ struct OSThread* tlnext;
    /* 0x10 */ u16 state;
    /* 0x12 */ u16 flags;
    /* 0x14 */ OSId id;
    /* 0x18 */ s32 fp;
    /* 0x1C */ __OSThreadprofile* thprof;
    /* 0x20 */ __OSThreadContext context;
} OSThread; // size = 0x1B0

#define OS_STATE_STOPPED (1 << 0)
#define OS_STATE_RUNNABLE (1 << 1)
#define OS_STATE_RUNNING (1 << 2)
#define OS_STATE_WAITING (1 << 3)

#define OS_PRIORITY_IDLE 0
#define OS_PRIORITY_MAIN 10
#define OS_PRIORITY_GRAPH 11
#define OS_PRIORITY_AUDIOMGR 12
#define OS_PRIORITY_PADMGR 14
#define OS_PRIORITY_SCHED 15
#define OS_PRIORITY_DMAMGR 16
#define OS_PRIORITY_IRQMGR 17
#define OS_PRIORITY_PIMGR 150
#define OS_PRIORITY_FAULTCLIENT 126
#define OS_PRIORITY_FAULT 127
#define OS_PRIORITY_APPMAX 127
#define OS_PRIORITY_RMONSPIN 200
#define OS_PRIORITY_RMON 250
#define OS_PRIORITY_VIMGR 254
#define OS_PRIORITY_MAX 255

#define OS_PRIORITY_THREADTAIL -1


void osCreateThread(OSThread* thread, OSId id, void* entry, void* arg, void* sp, OSPri p);
void osDestroyThread(OSThread* t);
void osYieldThread(void);
void osStartThread(OSThread* t);
void osStopThread(OSThread* t);
OSId osGetThreadId(OSThread* t);
void osSetThreadPri(OSThread* thread, OSPri p);
OSPri osGetThreadPri(OSThread* t);

// internal
OSThread* __osGetActiveQueue(void);
#endif
#endif