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