sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
thbase.h
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
16
17#ifndef __THBASE_H__
18#define __THBASE_H__
19
20#include <types.h>
21#include <irx.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27// Thread attribute definitions
28#define TH_ASM 0x01000000
29#define TH_C 0x02000000
30#define TH_UMODE 0x00000008
31#define TH_NO_FILLSTACK 0x00100000
32#define TH_CLEAR_STACK 0x00200000
33
34// Thread priority definitions
35#define HIGHEST_PRIORITY 1
36#define USER_HIGHEST_PRIORITY 9
37#define USER_LOWEST_PRIORITY 123
38#define LOWEST_PRIORITY 126
39
40typedef struct _iop_thread
41{
42 u32 attr;
43 u32 option;
44 void (*thread)(void *userdata);
45 u32 stacksize;
46 u32 priority;
47} iop_thread_t;
48
50#define TH_SELF 0
51
52// Thread status definitions
53#define THS_RUN 0x01
54#define THS_READY 0x02
55#define THS_WAIT 0x04
56#define THS_SUSPEND 0x08
57#define THS_WAITSUSPEND 0x0C
58#define THS_DORMANT 0x10
59
60// Thread wait status definitions
61#define TSW_SLEEP 1
62#define TSW_DELAY 2
63#define TSW_SEMA 3
64#define TSW_EVENTFLAG 4
65#define TSW_MBX 5
66#define TSW_VPL 6
67#define TSW_FPL 7
68
69typedef struct _iop_thread_status
70{
71 unsigned int attr;
72 unsigned int option;
73 int status;
74 void *entry;
75 void *stack;
76 int stackSize;
77 void *gpReg;
78 int initPriority;
79 int currentPriority;
80 int waitType;
81 int waitId;
82 int wakeupCount;
84 long int *regContext; //
85 unsigned int reserved[4];
86} iop_thread_info_t;
87
88typedef struct _iop_sys_clock
89{
90 u32 lo, hi;
91} iop_sys_clock_t;
92
94{
95 int status;
96 int currentPriority;
97 int waitType;
98 int waitId;
99 int wakeupCount;
100 long int *regContext;
101 iop_sys_clock_t runClocks;
102 unsigned int intrPreemptCount;
103 unsigned int threadPreemptCount;
104 unsigned int releaseCount;
105} iop_thread_run_status_t;
106
107typedef struct _iop_sys_status
108{
109 unsigned int status;
110 int systemLowTimerWidth;
111 iop_sys_clock_t idleClocks;
112 iop_sys_clock_t kernelClocks;
113 unsigned int comesOutOfIdleCount;
114 unsigned int threadSwitchCount;
115 unsigned int reserved[8];
116} iop_sys_status_t;
117
118extern void *GetThreadmanData(void);
119
120extern int CreateThread(iop_thread_t *thread);
121extern int DeleteThread(int thid);
122
123extern int StartThread(int thid, void *arg);
124extern int StartThreadArgs(int thid, int args, void *argp);
125
126extern int ExitThread();
127extern int ExitDeleteThread();
128extern int TerminateThread(int thid);
129extern int iTerminateThread(int thid);
130
131extern int DisableDispatchThread(void);
132extern int EnableDispatchThread(void);
133
134extern int ChangeThreadPriority(int thid, int priority);
135extern int iChangeThreadPriority(int thid, int priority);
136
137extern int RotateThreadReadyQueue(int priority);
138extern int iRotateThreadReadyQueue(int priority);
139
140extern int ReleaseWaitThread(int thid);
141extern int iReleaseWaitThread(int thid);
142
143extern int GetThreadId(void);
144extern int CheckThreadStack(void);
145extern int ReferThreadStatus(int thid, iop_thread_info_t *info);
146extern int iReferThreadStatus(int thid, iop_thread_info_t *info);
147
148extern int SleepThread(void);
149extern int WakeupThread(int thid);
150extern int iWakeupThread(int thid);
151extern int CancelWakeupThread(int thid);
152extern int iCancelWakeupThread(int thid);
153
154extern int SuspendThread(int thid);
155extern int iSuspendThread(int thid);
156extern int ResumeThread(int thid);
157extern int iResumeThread(int thid);
158
159extern int DelayThread(int usec);
160
161extern int GetSystemTime(iop_sys_clock_t *sys_clock);
162extern int SetAlarm(iop_sys_clock_t *sys_clock, unsigned int (*alarm_cb)(void *userdata), void *arg);
163extern int iSetAlarm(iop_sys_clock_t *sys_clock, unsigned int (*alarm_cb)(void *userdata), void *arg);
164extern int CancelAlarm(unsigned int (*alarm_cb)(void *userdata), void *arg);
165extern int iCancelAlarm(unsigned int (*alarm_cb)(void *userdata), void *arg);
166extern void USec2SysClock(u32 usec, iop_sys_clock_t *sys_clock);
167extern void SysClock2USec(iop_sys_clock_t *sys_clock, u32 *sec, u32 *usec);
168
169extern int GetSystemStatusFlag();
170
171// clang-format off
172#define thbase_IMPORTS \
173 thbase_IMPORTS_start \
174 \
175 I_GetThreadmanData \
176 \
177 I_CreateThread \
178 I_DeleteThread \
179 \
180 I_StartThread \
181 I_StartThreadArgs \
182 \
183 I_ExitThread \
184 I_ExitDeleteThread \
185 I_TerminateThread \
186 I_iTerminateThread \
187 \
188 I_DisableDispatchThread \
189 I_EnableDispatchThread \
190 \
191 I_ChangeThreadPriority \
192 I_iChangeThreadPriority \
193 \
194 I_RotateThreadReadyQueue \
195 I_iRotateThreadReadyQueue \
196 \
197 I_ReleaseWaitThread \
198 I_iReleaseWaitThread \
199 \
200 I_GetThreadId \
201 I_ReferThreadStatus \
202 I_iReferThreadStatus \
203 \
204 I_SleepThread \
205 I_WakeupThread \
206 I_iWakeupThread \
207 I_CancelWakeupThread \
208 I_iCancelWakeupThread \
209 \
210 I_SuspendThread \
211 I_iSuspendThread \
212 I_ResumeThread \
213 I_iResumeThread \
214 \
215 I_DelayThread \
216 \
217 I_GetSystemTime \
218 I_SetAlarm \
219 I_iSetAlarm \
220 I_CancelAlarm \
221 I_iCancelAlarm \
222 I_USec2SysClock \
223 I_SysClock2USec \
224 \
225 I_GetSystemStatusFlag \
226 \
227 thbase_IMPORTS_end
228// clang-format on
229
230#define thbase_IMPORTS_start DECLARE_IMPORT_TABLE(thbase, 1, 1)
231#define thbase_IMPORTS_end END_IMPORT_TABLE
232
233#define I_GetThreadmanData DECLARE_IMPORT(3, GetThreadmanData)
234#define I_CreateThread DECLARE_IMPORT(4, CreateThread)
235#define I_DeleteThread DECLARE_IMPORT(5, DeleteThread)
236#define I_StartThread DECLARE_IMPORT(6, StartThread)
237#define I_StartThreadArgs DECLARE_IMPORT(7, StartThreadArgs)
238#define I_ExitThread DECLARE_IMPORT(8, ExitThread)
239#define I_ExitDeleteThread DECLARE_IMPORT(9, ExitDeleteThread)
240#define I_TerminateThread DECLARE_IMPORT(10, TerminateThread)
241#define I_iTerminateThread DECLARE_IMPORT(11, iTerminateThread)
242#define I_DisableDispatchThread DECLARE_IMPORT(12, DisableDispatchThread)
243#define I_EnableDispatchThread DECLARE_IMPORT(13, EnableDispatchThread)
244#define I_ChangeThreadPriority DECLARE_IMPORT(14, ChangeThreadPriority)
245#define I_iChangeThreadPriority DECLARE_IMPORT(15, iChangeThreadPriority)
246#define I_RotateThreadReadyQueue DECLARE_IMPORT(16, RotateThreadReadyQueue)
247#define I_iRotateThreadReadyQueue DECLARE_IMPORT(17, iRotateThreadReadyQueue)
248#define I_ReleaseWaitThread DECLARE_IMPORT(18, ReleaseWaitThread)
249#define I_iReleaseWaitThread DECLARE_IMPORT(19, iReleaseWaitThread)
250#define I_GetThreadId DECLARE_IMPORT(20, GetThreadId)
251#define I_CheckThreadStack DECLARE_IMPORT(21, CheckThreadStack)
252#define I_ReferThreadStatus DECLARE_IMPORT(22, ReferThreadStatus)
253#define I_iReferThreadStatus DECLARE_IMPORT(23, iReferThreadStatus)
254#define I_SleepThread DECLARE_IMPORT(24, SleepThread)
255#define I_WakeupThread DECLARE_IMPORT(25, WakeupThread)
256#define I_iWakeupThread DECLARE_IMPORT(26, iWakeupThread)
257#define I_CancelWakeupThread DECLARE_IMPORT(27, CancelWakeupThread)
258#define I_iCancelWakeupThread DECLARE_IMPORT(28, iCancelWakeupThread)
259#define I_SuspendThread DECLARE_IMPORT(29, SuspendThread)
260#define I_iSuspendThread DECLARE_IMPORT(30, iSuspendThread)
261#define I_ResumeThread DECLARE_IMPORT(31, ResumeThread)
262#define I_iResumeThread DECLARE_IMPORT(32, iResumeThread)
263#define I_DelayThread DECLARE_IMPORT(33, DelayThread)
264#define I_GetSystemTime DECLARE_IMPORT(34, GetSystemTime)
265#define I_SetAlarm DECLARE_IMPORT(35, SetAlarm)
266#define I_iSetAlarm DECLARE_IMPORT(36, iSetAlarm)
267#define I_CancelAlarm DECLARE_IMPORT(37, CancelAlarm)
268#define I_iCancelAlarm DECLARE_IMPORT(38, iCancelAlarm)
269#define I_USec2SysClock DECLARE_IMPORT(39, USec2SysClock)
270#define I_SysClock2USec DECLARE_IMPORT(40, SysClock2USec)
271#define I_GetSystemStatusFlag DECLARE_IMPORT(41, GetSystemStatusFlag)
272
273#ifdef __cplusplus
274}
275#endif
276
277#endif /* __THBASE_H__ */
long int * regContext
Definition thbase.h:84