12 #define DEBUG_FLAGS (8)
14 #define TAG_THREAD 0x7f01
15 #define TAG_SEMA 0x7f02
16 #define TAG_EVF 0x7f03
17 #define TAG_MBX 0x7f04
18 #define TAG_VPL 0x7f05
19 #define TAG_FPL 0x7f06
21 #define MAKE_HANDLE(ptr) (((u32)(ptr) << 5) | ((((struct heaptag *)(ptr))->id & 0x3f) << 1) | 1)
22 #define HANDLE_PTR(handle) ((void *)((((u32)handle) >> 7) << 2))
23 #define HANDLE_ID(handle) (((handle) >> 1) & 0x3f)
24 #define HANDLE_VERIFY(handle, t) (((struct heaptag *)(HANDLE_PTR(handle)))->tag == (t) && \
25 HANDLE_ID(handle) == ((struct heaptag *)(HANDLE_PTR(handle)))->id)
30 #define ALIGN(i) (((i) + 3) & (~3))
31 #define ALIGN_256(i) (((i) + 0xff) & (~0xff))
33 #define UNIMPLEMENTED() \
35 Kprintf("UNIMPLEMENTED FUNCTION %s\n", __PRETTY_FUNCTION__); \
42 Kprintf("TRACE %s\n", __PRETTY_FUNCTION__); \
45 #define TRACE_ERROR() \
47 Kprintf("TRACE %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
50 #define RESERVED_REGCTX_SIZE 0xb8
55 u32 unk, at, v0, v1, a0,
61 sp, fp, ra, hi, lo, sr,
139 unsigned int (*cb)(
void *userdata);
149 struct regctx *saved_regs;
156 struct event *wait_event;
178 u32 irq_preemption_count;
179 u32 thread_preemption_count;
185 struct thread *current_thread;
198 struct thread *idle_thread;
210 u32 unused_or_padding;
220 s32 sytem_status_flag;
221 u32 thread_switch_count;
222 u32 thread_resume_count;
231 static inline u64 add64(u32 hi1, u32 lo1, u32 hi2, u32 lo2)
235 u32 hi = hi1 + hi2 + (lo1 > (lo1 + lo2));
236 return lo | ((u64)hi << 32);
239 static inline u64 as_u64(u32 a1, u32 a2)
241 return (u64)a1 << 32 | a2;
249 static inline void readyq_insert_back(
struct thread *
thread)
251 u32 prio =
thread->priority;
252 thctx.queue_map[prio >> 5] |= 1 << (prio & 0x1f);
253 list_insert(&thctx.ready_queue[prio], &
thread->queue);
259 static inline void readyq_insert_front(
struct thread *
thread)
261 u32 prio =
thread->priority;
262 thctx.queue_map[prio >> 5] |= 1 << (prio & 0x1f);
263 list_insert(thctx.ready_queue[prio].next, &
thread->queue);
269 static inline void readyq_remove(
struct thread *
thread, u32 prio)
271 if (list_node_is_last(&
thread->queue)) {
272 thctx.queue_map[prio >> 5] &= ~(1 << (prio & 0x1f));
275 list_remove(&
thread->queue);
278 extern u32 readyq_highest();
280 extern struct alarm *alarm_alloc();
284 extern void update_timer_compare(
int timid, u64 time,
struct list_head *alarm_list);
286 extern void *heap_alloc(u16 tag, u32 bytes);
287 extern int heap_free(
struct heaptag *tag);
289 extern int thread_start(
struct thread *
thread,
int intr_state);
290 extern int thread_init_and_start(
struct thread *
thread,
int intr_state);
291 extern int thread_leave(
int unk,
int unk2,
int intr_state,
int release);
293 extern unsigned int thread_delay_cb(
void *user);
299 extern int check_thread_stack();
301 #endif // THCOMMON_H_