14static void clock_mul(iop_sys_clock_t *dst, iop_sys_clock_t *src, u32 mul);
15static void clock_div(iop_sys_clock_t *dst, iop_sys_clock_t *src, u32 d, u32 *r);
17static struct thread *refer_thread(
int thid,
int current);
19static void thread_get_run_stats(
struct thread *
thread, iop_thread_run_status_t *stat);
20static void thread_get_status(
struct thread *
thread, iop_thread_info_t *info);
27int CreateThread(iop_thread_t *thparam)
34 return KE_ILLEGAL_CONTEXT;
37 if (thparam->attr & ~(TH_ASM | TH_C | TH_UMODE | TH_NO_FILLSTACK | TH_CLEAR_STACK)) {
38 return KE_ILLEGAL_ATTR;
41 if (thparam->priority > 126) {
42 return KE_ILLEGAL_PRIORITY;
45 if ((u32)thparam->thread & 3) {
46 return KE_ILLEGAL_ENTRY;
49 if (thparam->stacksize < 0x130) {
50 return KE_ILLEGAL_STACK_SIZE;
61 thparam->stacksize = ALIGN_256(thparam->stacksize);
62 stack = AllocSysMemory(1, thparam->stacksize, 0);
69 thread->tag.id = ++thctx.thread_id;
70 thread->entry = thparam->thread;
71 thread->stack_size = thparam->stacksize;
73 thread->init_priority = thparam->priority;
74 thread->attr = thparam->attr;
75 thread->option = thparam->option;
76 thread->status = THS_DORMANT;
79 list_insert(&thctx.thread_list, &
thread->thread_list);
81 if ((
thread->attr & TH_NO_FILLSTACK) == 0) {
83 memset(
thread->stack_top, 0xff,
thread->stack_size - 0x30);
88 return MAKE_HANDLE(
thread);
91int DeleteThread(
int thid)
97 return KE_ILLEGAL_CONTEXT;
101 return KE_ILLEGAL_THID;
106 thread = HANDLE_PTR(thid);
107 if (!HANDLE_VERIFY(thid, TAG_THREAD) ||
thread == thctx.idle_thread) {
109 return KE_UNKNOWN_THID;
112 if (
thread->status != THS_DORMANT) {
114 return KE_NOT_DORMANT;
117 if (
thread->attr & TH_CLEAR_STACK) {
121 FreeSysMemory(
thread->stack_top);
122 list_remove(&
thread->queue);
123 list_remove(&
thread->thread_list);
131int StartThread(
int thid,
void *arg)
138 return KE_ILLEGAL_CONTEXT;
142 return KE_ILLEGAL_THID;
147 thread = HANDLE_PTR(thid);
148 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
150 return KE_UNKNOWN_THID;
153 if (
thread->status != THS_DORMANT) {
155 return KE_NOT_DORMANT;
159 reg_offset = ALIGN(
thread->stack_size) - RESERVED_REGCTX_SIZE;
161 memset(
thread->saved_regs, 0, RESERVED_REGCTX_SIZE);
163 thread->saved_regs->a0 = (u32)arg;
165 return thread_init_and_start(
thread, state);
168int StartThreadArgs(
int thid,
int args,
void *argp)
171 u32 arg_offset, reg_offset;
175 return KE_ILLEGAL_CONTEXT;
179 return KE_ILLEGAL_THID;
184 thread = HANDLE_PTR(thid);
185 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
187 return KE_UNKNOWN_THID;
190 if (
thread->status != THS_DORMANT) {
192 return KE_NOT_DORMANT;
196 arg_offset = ALIGN(
thread->stack_size) - ALIGN(args);
197 if (args > 0 && argp) {
198 memcpy(
thread->stack_top + arg_offset, argp, args);
205 reg_offset = arg_offset - RESERVED_REGCTX_SIZE;
208 memset(
thread->saved_regs, 0, RESERVED_REGCTX_SIZE);
210 thread->saved_regs->a0 = args;
211 thread->saved_regs->a1 = (u32)
thread->stack_top + arg_offset;
213 return thread_init_and_start(
thread, state);
221 return KE_ILLEGAL_CONTEXT;
225 thctx.current_thread->status = THS_DORMANT;
226 list_insert(&thctx.dormant_queue, &thctx.current_thread->queue);
227 thctx.run_next = NULL;
230 Kprintf(
"panic ! Thread DORMANT !\n");
236int ExitDeleteThread()
241 return KE_ILLEGAL_CONTEXT;
245 thctx.current_thread->status = THS_DORMANT;
246 list_insert(&thctx.delete_queue, &thctx.current_thread->queue);
247 thctx.run_next = NULL;
250 Kprintf(
"panic ! Thread ExitDeleted !\n");
256int TerminateThread(
int thid)
262 return KE_ILLEGAL_CONTEXT;
267 thread = HANDLE_PTR(thid);
268 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
270 return KE_UNKNOWN_THID;
273 if (
thread->status == THS_DORMANT) {
278 if (
thread->status == THS_READY) {
281 list_remove(&
thread->queue);
282 if (
thread->wait_type == TSW_DELAY) {
283 CancelAlarm(thread_delay_cb,
thread);
284 }
else if (
thread->wait_type >= TSW_DELAY &&
thread->wait_type <= TSW_FPL) {
285 thread->wait_event->waiter_count--;
289 thread->status = THS_DORMANT;
290 list_insert(&thctx.dormant_queue, &
thread->queue);
296int iTerminateThread(
int thid)
301 return KE_ILLEGAL_CONTEXT;
305 return KE_ILLEGAL_THID;
308 thread = HANDLE_PTR(thid);
309 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
310 return KE_UNKNOWN_THID;
313 if (
thread->status == THS_DORMANT) {
317 if (
thread == thctx.current_thread) {
318 thctx.run_next = NULL;
320 if (
thread->status == THS_READY) {
323 list_remove(&
thread->queue);
325 if (
thread->status == THS_WAIT) {
326 if (
thread->wait_type == TSW_DELAY) {
327 iCancelAlarm(thread_delay_cb,
thread);
329 thread->wait_event->waiter_count--;
335 thread->status = THS_DORMANT;
336 list_insert(&thctx.dormant_queue, &
thread->queue);
341int DisableDispatchThread(
void)
346int EnableDispatchThread(
void)
351int ChangeThreadPriority(
int thid,
int priority)
357 return KE_ILLEGAL_CONTEXT;
363 thread = thctx.current_thread;
365 thread = HANDLE_PTR(thid);
366 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
368 return KE_UNKNOWN_THID;
371 if (
thread->status == THS_DORMANT) {
378 if (priority - 1 >= 126) {
380 return KE_ILLEGAL_PRIORITY;
383 priority = thctx.current_thread->priority;
386 if (
thread == thctx.current_thread) {
387 if (priority >= readyq_highest()) {
388 thread->status = THS_READY;
389 thread->priority = priority;
390 readyq_insert_back(
thread);
391 thctx.run_next = NULL;
396 thread->priority = priority;
398 if (
thread->status == THS_READY) {
400 thread->priority = priority;
402 return thread_start(
thread, state);
410 if (
thread->status == THS_WAIT &&
thread->wait_type != TSW_DELAY) {
411 if (
thread->wait_event->attr & SA_THPRI) {
421int iChangeThreadPriority(
int thid,
int priority)
426 return KE_ILLEGAL_CONTEXT;
430 return KE_ILLEGAL_THID;
433 thread = HANDLE_PTR(thid);
434 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
435 return KE_UNKNOWN_THID;
438 if (
thread->status == THS_DORMANT) {
443 priority = thctx.current_thread->priority;
446 if (priority - 1 >= 126) {
447 return KE_ILLEGAL_PRIORITY;
450 if (
thread == thctx.current_thread) {
451 thread->status = THS_READY;
453 if (
thread->status != THS_READY) {
454 thread->priority = priority;
455 if (
thread->status != THS_WAIT ||
thread->wait_type == TSW_DELAY) {
459 if ((
thread->wait_event->attr & 1) == 0) {
467 thread->priority = priority;
468 readyq_insert_back(
thread);
469 thctx.run_next = NULL;
474int RotateThreadReadyQueue(
int priority)
480 return KE_ILLEGAL_CONTEXT;
483 if (priority >= 127) {
484 return KE_ILLEGAL_PRIORITY;
489 thread = thctx.current_thread;
492 priority =
thread->priority;
495 if (list_empty(&thctx.ready_queue[priority])) {
500 if (priority !=
thread->priority) {
501 thread = list_first_entry(&thctx.ready_queue[priority],
struct thread, queue);
502 list_remove(&
thread->queue);
503 list_insert(&thctx.ready_queue[priority], &
thread->queue);
509 thread->status = THS_READY;
510 readyq_insert_back(
thread);
515int iRotateThreadReadyQueue(
int priority)
520 return KE_ILLEGAL_CONTEXT;
523 thread = thctx.current_thread;
526 if (priority >= 126) {
527 return KE_ILLEGAL_PRIORITY;
530 priority = readyq_highest();
531 if (
thread->priority < priority) {
532 priority =
thread->priority;
536 if (list_empty(&thctx.ready_queue[priority])) {
540 if (priority ==
thread->priority) {
541 thread->status = THS_READY;
542 readyq_insert_back(
thread);
543 thctx.run_next = NULL;
545 thread = list_first_entry(&thctx.ready_queue[priority],
struct thread, queue);
546 list_remove(&
thread->queue);
547 list_insert(&thctx.ready_queue[priority], &
thread->queue);
553int ReleaseWaitThread(
int thid)
559 return KE_ILLEGAL_CONTEXT;
563 return KE_ILLEGAL_THID;
568 thread = HANDLE_PTR(thid);
569 if (
thread == thctx.current_thread) {
571 return KE_ILLEGAL_THID;
574 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
576 return KE_UNKNOWN_THID;
579 if (
thread->status != THS_WAIT) {
584 thread->saved_regs->v0 = KE_RELEASE_WAIT;
585 list_remove(&
thread->queue);
586 thread->status = THS_READY;
588 if (
thread->wait_type == TSW_DELAY) {
589 CancelAlarm(thread_delay_cb,
thread);
591 thread->wait_event->waiter_count--;
594 return thread_start(
thread, state);
597int iReleaseWaitThread(
int thid)
602 return KE_ILLEGAL_CONTEXT;
606 return KE_ILLEGAL_THID;
609 thread = HANDLE_PTR(thid);
611 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
612 return KE_UNKNOWN_THID;
615 if (
thread->status != THS_WAIT) {
619 thread->saved_regs->v0 = KE_RELEASE_WAIT;
620 list_remove(&
thread->queue);
621 thread->status = THS_READY;
623 if (
thread->wait_type == TSW_DELAY) {
624 iCancelAlarm(thread_delay_cb,
thread);
626 thread->wait_event->waiter_count--;
629 readyq_insert_back(
thread);
630 thctx.run_next = NULL;
638 return KE_ILLEGAL_CONTEXT;
641 return MAKE_HANDLE(thctx.current_thread);
644int CheckThreadStack(
void)
650 return check_thread_stack();
653int ReferThreadStatus(
int thid, iop_thread_info_t *info)
659 return KE_ILLEGAL_CONTEXT;
664 thread = refer_thread(thid, 1);
670 thread_get_status(
thread, info);
677int iReferThreadStatus(
int thid, iop_thread_info_t *info)
682 return KE_ILLEGAL_THID;
685 thread = HANDLE_PTR(thid);
687 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
688 return KE_UNKNOWN_THID;
691 thread_get_status(
thread, info);
702 return KE_ILLEGAL_CONTEXT;
705 if (
CpuSuspendIntr(&state) == KE_CPUDI && (thctx.debug_flags & 8)) {
706 Kprintf(
"WARNING: SleepThread KE_CAN_NOT_WAIT\n");
708 check_thread_stack();
710 thread = thctx.current_thread;
712 if (
thread->wakeup_count != 0) {
718 thread->status = THS_WAIT;
719 thread->wait_type = TSW_SLEEP;
720 thread->wait_event = NULL;
722 thctx.run_next = NULL;
724 list_insert(&thctx.sleep_queue, &
thread->queue);
729int WakeupThread(
int thid)
735 return KE_ILLEGAL_CONTEXT;
739 return KE_ILLEGAL_THID;
744 thread = HANDLE_PTR(thid);
745 if (
thread == thctx.current_thread) {
746 return KE_ILLEGAL_THID;
749 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
750 return KE_UNKNOWN_THID;
753 if (
thread->status == THS_DORMANT) {
758 if (
thread->status == THS_WAIT &&
thread->wait_type == TSW_SLEEP) {
759 list_remove(&
thread->queue);
760 thread->status = THS_READY;
762 return thread_start(
thread, state);
772int iWakeupThread(
int thid)
777 return KE_ILLEGAL_CONTEXT;
781 return KE_ILLEGAL_THID;
784 thread = HANDLE_PTR(thid);
785 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
786 return KE_UNKNOWN_THID;
789 if (
thread->status == THS_DORMANT) {
793 if (
thread->status == THS_WAIT &&
thread->wait_type == TSW_SLEEP) {
794 list_remove(&
thread->queue);
795 thread->status = THS_READY;
796 readyq_insert_back(
thread);
797 thctx.run_next = NULL;
805int CancelWakeupThread(
int thid)
808 int state, wakeup_count;
811 return KE_ILLEGAL_CONTEXT;
816 thread = HANDLE_PTR(thid);
817 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
819 return KE_UNKNOWN_THID;
822 thread = thctx.current_thread;
825 wakeup_count =
thread->wakeup_count;
832int iCancelWakeupThread(
int thid)
838 return KE_ILLEGAL_CONTEXT;
842 return KE_ILLEGAL_THID;
845 thread = HANDLE_PTR(thid);
846 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
847 return KE_UNKNOWN_THID;
850 wakeup_count =
thread->wakeup_count;
856int SuspendThread(
int thid)
861int iSuspendThread(
int thid)
866int ResumeThread(
int thid)
871int iResumeThread(
int thid)
876int DelayThread(
int usec)
878 iop_sys_clock_t clock;
883 return KE_ILLEGAL_CONTEXT;
886 USec2SysClock(usec, &clock);
887 if (
CpuSuspendIntr(&state) == KE_CPUDI && (thctx.debug_flags & 8)) {
888 Kprintf(
"WARNING: DelayThread KE_CAN_NOT_WAIT\n");
890 check_thread_stack();
892 thread = thctx.current_thread;
894 ret = SetAlarm(&clock, thread_delay_cb,
thread);
900 thread->status = THS_WAIT;
901 thread->wait_type = TSW_DELAY;
902 thread->wait_usecs = usec;
905 thctx.run_next = NULL;
906 list_insert(&thctx.delay_queue, &
thread->queue);
912int GetSystemTime(iop_sys_clock_t *sys_clock)
917int SetAlarm(iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *userdata),
void *arg)
919 iop_sys_clock_t systime;
925 return KE_ILLEGAL_CONTEXT;
930 if (!list_empty(&thctx.alarm)) {
931 list_for_each (
alarm, &thctx.alarm, alarm_list) {
932 if (
alarm->cb == alarm_cb &&
alarm->userptr == arg) {
934 return KE_FOUND_HANDLER;
939 alarm = alarm_alloc();
945 if (sys_clock->hi == 0 && sys_clock->lo < thctx.min_wait) {
946 sys_clock->lo = thctx.min_wait;
949 GetSystemTime(&systime);
952 alarm->target = add64(sys_clock->hi, sys_clock->lo, systime.hi, systime.lo);
953 alarm->cb = alarm_cb;
954 alarm->userptr = arg;
956 alarm_insert(&thctx.alarm,
alarm);
958 GetSystemTime(&systime);
959 time = as_u64(systime.hi, systime.lo);
960 update_timer_compare(thctx.timer_id, time, &thctx.alarm);
967int iSetAlarm(iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *userdata),
void *arg)
970 iop_sys_clock_t systime;
974 return KE_ILLEGAL_CONTEXT;
977 list_for_each (
alarm, &thctx.alarm, alarm_list) {
978 if (
alarm->cb == alarm_cb &&
alarm->userptr == arg) {
979 return KE_FOUND_HANDLER;
983 alarm = alarm_alloc();
988 if (sys_clock->hi == 0 && sys_clock->lo < thctx.min_wait) {
989 sys_clock->lo = thctx.min_wait;
992 read_sys_time(&systime);
994 alarm->target = add64(sys_clock->hi, sys_clock->lo, systime.hi, systime.lo);
995 alarm->cb = alarm_cb;
996 alarm->userptr = arg;
998 alarm_insert(&thctx.alarm,
alarm);
999 read_sys_time(&systime);
1000 time = as_u64(systime.hi, systime.lo);
1001 update_timer_compare(thctx.timer_id, time, &thctx.alarm);
1006int CancelAlarm(
unsigned int (*alarm_cb)(
void *userdata),
void *arg)
1012 return KE_ILLEGAL_CONTEXT;
1017 if (list_empty(&thctx.alarm)) {
1019 return KE_NOTFOUND_HANDLER;
1022 list_for_each (
alarm, &thctx.alarm, alarm_list) {
1023 if (
alarm->cb == alarm_cb &&
alarm->userptr == arg) {
1024 list_remove(&
alarm->alarm_list);
1026 thctx.alarm_count--;
1035 return KE_NOTFOUND_HANDLER;
1038int iCancelAlarm(
unsigned int (*alarm_cb)(
void *userdata),
void *arg)
1043 return KE_ILLEGAL_CONTEXT;
1046 if (list_empty(&thctx.alarm)) {
1047 return KE_NOTFOUND_HANDLER;
1050 list_for_each (
alarm, &thctx.alarm, alarm_list) {
1051 if (
alarm->cb == alarm_cb &&
alarm->userptr == arg) {
1052 list_remove(&
alarm->alarm_list);
1054 thctx.alarm_count--;
1060 return KE_NOTFOUND_HANDLER;
1063void USec2SysClock(u32 usec, iop_sys_clock_t *sys_clock)
1066 sys_clock->lo = usec;
1067 clock_mul(sys_clock, sys_clock, thctx.unk_clock_mult);
1068 clock_div(sys_clock, sys_clock, thctx.unk_clock_div, NULL);
1071void SysClock2USec(iop_sys_clock_t *sys_clock, u32 *sec, u32 *usec)
1073 iop_sys_clock_t clock;
1074 clock_mul(&clock, sys_clock, thctx.unk_clock_div);
1075 clock_div(&clock, &clock, thctx.unk_clock_mult, NULL);
1076 clock_div(&clock, &clock, 1000000, usec);
1080int GetSystemStatusFlag()
1082 return thctx.sytem_status_flag;
1085int GetThreadCurrentPriority(
void)
1088 return KE_ILLEGAL_CONTEXT;
1091 return thctx.current_thread->priority;
1094unsigned int GetSystemTimeLow(
void)
1096 return GetTimerCounter(thctx.timer_id);
1099int ReferSystemStatus(iop_sys_status_t *info,
size_t size)
1102 if (size <
sizeof(*info)) {
1106 memset(info, 0, size);
1111 info->status = TSS_NOTHREAD;
1112 }
else if (ret == KE_CPUDI) {
1113 info->status = TSS_DISABLEINTR;
1115 info->status = TSS_THREAD;
1118 info->systemLowTimerWidth = 32;
1119 info->idleClocks.hi = thctx.idle_thread->run_clocks_hi;
1120 info->idleClocks.lo = thctx.idle_thread->run_clocks_lo;
1121 info->threadSwitchCount = thctx.thread_switch_count;
1122 info->comesOutOfIdleCount = thctx.idle_thread->irq_preemption_count;
1129int ReferThreadRunStatus(
int thid, iop_thread_run_status_t *stat,
size_t size)
1135 return KE_ILLEGAL_CONTEXT;
1140 thread = refer_thread(thid, 1);
1146 if (size <
sizeof(*stat)) {
1148 return KE_ILLEGAL_SIZE;
1151 memset(stat, 0, size);
1152 thread_get_run_stats(
thread, stat);
1162int GetThreadStackFreeSize(
int thid)
1170 return KE_ILLEGAL_CONTEXT;
1175 thread = refer_thread(thid, 1);
1181 stack =
thread->stack_top;
1182 stack_size =
thread->stack_size / 4;
1185 for (i = 0; i < stack_size; i++) {
1186 if (stack[i] != -1) {
1195int GetThreadmanIdList(
int type,
int *readbuf,
int readbufsize,
int *objectcount)
1197 int state, write_count, obj_count;
1200 return KE_ILLEGAL_CONTEXT;
1211 list_for_each (
thread, &thctx.thread_list, thread_list) {
1212 if (
thread != thctx.idle_thread) {
1213 if (write_count < readbufsize) {
1214 *readbuf++ = MAKE_HANDLE(
thread);
1221 case TMID_Semaphore: {
1223 list_for_each (sema, &thctx.semaphore, sema_list) {
1224 if (write_count < readbufsize) {
1225 *readbuf++ = MAKE_HANDLE(sema);
1231 case TMID_EventFlag: {
1233 list_for_each (evf, &thctx.event_flag, evf_list) {
1234 if (write_count < readbufsize) {
1235 *readbuf++ = MAKE_HANDLE(evf);
1243 list_for_each (mbx, &thctx.mbox, mbox_list) {
1244 if (write_count < readbufsize) {
1245 *readbuf++ = MAKE_HANDLE(mbx);
1253 list_for_each (vpl, &thctx.vpool, vpl_list) {
1254 if (write_count < readbufsize) {
1255 *readbuf++ = MAKE_HANDLE(vpl);
1263 list_for_each (fpl, &thctx.fpool, fpl_list) {
1264 if (write_count < readbufsize) {
1265 *readbuf++ = MAKE_HANDLE(fpl);
1271 case TMID_SleepThread: {
1273 list_for_each (
thread, &thctx.sleep_queue, queue) {
1274 if (write_count < readbufsize) {
1275 *readbuf++ = MAKE_HANDLE(
thread);
1281 case TMID_DelayThread: {
1283 list_for_each (
thread, &thctx.delay_queue, queue) {
1284 if (write_count < readbufsize) {
1285 *readbuf++ = MAKE_HANDLE(
thread);
1291 case TMID_DormantThread: {
1293 list_for_each (
thread, &thctx.dormant_queue, queue) {
1294 if (write_count < readbufsize) {
1295 *readbuf++ = MAKE_HANDLE(
thread);
1302 struct heaptag *tag = HANDLE_PTR(type);
1306 if (type < 0 || tag->tag < TAG_SEMA || tag->tag > TAG_FPL || tag->id != HANDLE_ID(type)) {
1308 return KE_ILLEGAL_TYPE;
1330 if (write_count < readbufsize) {
1331 *readbuf++ = MAKE_HANDLE(
thread);
1342 *objectcount = obj_count;
1348static void clock_mul(iop_sys_clock_t *dst, iop_sys_clock_t *src, u32 mul)
1351 res = (u64)src->hi << 32 | src->lo;
1354 dst->hi = res >> 32;
1360static void clock_div(iop_sys_clock_t *dst, iop_sys_clock_t *src, u32 d, u32 *r)
1379 for (i = 0; i < 4; ++i) {
1380 v11 = (v8 << 8) | (lo >> 24);
1383 v4 = (v4 << 8) | (v9 >> 24);
1386 v9 = (v9 << 8) + v12;
1398static struct thread *refer_thread(
int thid,
int current)
1402 if (!thid && current) {
1403 return thctx.current_thread;
1406 thread = HANDLE_PTR(thid);
1407 if (!HANDLE_VERIFY(thid, TAG_THREAD)) {
1408 return (
struct thread *)KE_UNKNOWN_THID;
1414static void thread_get_status(
struct thread *
thread, iop_thread_info_t *info)
1416 memset(info, 0,
sizeof(*info));
1417 info->status =
thread->status;
1418 info->currentPriority =
thread->priority;
1419 info->initPriority =
thread->init_priority;
1420 info->entry =
thread->entry;
1421 info->stack =
thread->stack_top;
1422 info->stackSize =
thread->stack_size;
1423 info->gpReg = (
void *)
thread->gp;
1424 info->attr =
thread->attr;
1425 info->option =
thread->option;
1427 if (
thread->status == THS_WAIT) {
1428 info->waitType =
thread->wait_type;
1429 if (
thread->wait_type == TSW_DELAY) {
1430 info->waitId =
thread->wait_usecs;
1432 switch (
thread->wait_type) {
1440 info->waitId = MAKE_HANDLE(container_of(
thread->wait_event,
struct mbox,
event));
1443 info->waitId = MAKE_HANDLE(container_of(
thread->wait_event,
struct fpool,
event));
1446 info->waitId = MAKE_HANDLE(container_of(
thread->wait_event,
struct vpool,
event));
1455 info->wakeupCount =
thread->wakeup_count;
1457 info->regContext = 0;
1459 info->regContext = (
long *)
thread->saved_regs;
1463static void thread_get_run_stats(
struct thread *
thread, iop_thread_run_status_t *stat)
1465 stat->status =
thread->status;
1466 stat->currentPriority =
thread->priority;
1468 if (
thread->status == THS_WAIT) {
1469 stat->waitType =
thread->wait_type;
1470 if (
thread->wait_type == TSW_DELAY) {
1471 stat->waitId =
thread->wait_usecs;
1473 switch (
thread->wait_type) {
1481 stat->waitId = MAKE_HANDLE(container_of(
thread->wait_event,
struct mbox,
event));
1484 stat->waitId = MAKE_HANDLE(container_of(
thread->wait_event,
struct fpool,
event));
1487 stat->waitId = MAKE_HANDLE(container_of(
thread->wait_event,
struct vpool,
event));
1496 stat->wakeupCount =
thread->wakeup_count;
1498 stat->regContext = (
long *)
thread->saved_regs;
1501 stat->runClocks.hi =
thread->run_clocks_hi;
1502 stat->runClocks.lo =
thread->run_clocks_lo;
1503 stat->intrPreemptCount =
thread->irq_preemption_count;
1504 stat->threadPreemptCount =
thread->thread_preemption_count;
1505 stat->releaseCount =
thread->release_count;
int CpuResumeIntr(int state)
int CpuInvokeInKmode(void *function,...)
int QueryIntrContext(void)
int CpuSuspendIntr(int *state)
int thread_leave(int unk, int unk2, int intr_state, int release)