sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

osCreateThread.c (1064B)


      1 #include "libultra_internal.h"
      2 #include <PR/R4300.h>
      3 
      4 void __osCleanupThread(void);
      5 
      6 // Don't warn about pointer->u64 cast
      7 #pragma GCC diagnostic push
      8 #pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
      9 
     10 void osCreateThread(OSThread *thread, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri pri) {
     11     register u32 saveMask;
     12     OSIntMask mask;
     13 
     14     thread->id = id;
     15     thread->priority = pri;
     16     thread->next = NULL;
     17     thread->queue = NULL;
     18     thread->context.pc = (u32) entry;
     19     thread->context.a0 = (u64) arg;
     20     thread->context.sp = (u64) sp - 16;
     21     thread->context.ra = (u64) __osCleanupThread;
     22 
     23     mask = OS_IM_ALL;
     24     thread->context.sr = (mask & OS_IM_CPU) | SR_EXL;
     25     thread->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT;
     26     thread->context.fpcsr = (u32) (FPCSR_FS | FPCSR_EV);
     27     thread->fp = 0;
     28     thread->state = OS_STATE_STOPPED;
     29     thread->flags = 0;
     30     saveMask = __osDisableInt();
     31     thread->tlnext = __osActiveQueue;
     32 
     33     __osActiveQueue = thread;
     34     __osRestoreInt(saveMask);
     35 }
     36 
     37 #pragma GCC diagnostic pop