MCPcopy Create free account
hub / github.com/doldecomp/mkdd / OSCreateThread

Function OSCreateThread

libs/dolphin/os/OSThread.c:340–394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338}
339
340BOOL OSCreateThread(OSThread *thread, OSThreadStartFunction func, void *param, void *stack, u32 stackSize, OSPriority priority, u16 attr)
341{
342 BOOL enable;
343 u32 stackThing;
344 int i;
345 u32 tmp[2]; // DUMB compiler smfh.
346
347 if (priority < OS_PRIORITY_MIN || priority > OS_PRIORITY_MAX)
348 {
349 return FALSE;
350 }
351
352 stackThing = ((u32)stack & 0xFFFFFFF8); // ??
353 thread->state = OS_THREAD_STATE_READY;
354 thread->attr = attr & OS_THREAD_ATTR_DETACH;
355 thread->base = priority;
356 thread->priority = priority;
357 thread->suspend = 1;
358 thread->val = (void *)-1;
359 thread->mutex = nullptr;
360 OSInitThreadQueue(&thread->queueJoin);
361 OSInitMutexQueue(&thread->queueMutex);
362 *(u32 *)(stackThing - 8) = 0;
363 *(u32 *)(stackThing - 4) = 0;
364
365 OSInitContext(&thread->context, (u32)func, (u32)(stackThing - 8));
366
367 thread->context.lr = (u32)&OSExitThread;
368 thread->context.gpr[3] = (u32)param;
369 thread->stackBase = stack;
370 thread->stackEnd = (u32 *)((u32)stack - stackSize);
371 *(thread->stackEnd) = OS_THREAD_STACK_MAGIC;
372 thread->error = 0;
373 thread->specific[0] = nullptr;
374 thread->specific[1] = nullptr;
375
376 enable = OSDisableInterrupts();
377
378 if (__OSErrorTable[OS_ERROR_FPE] != nullptr)
379 {
380 thread->context.srr1 |= 0x900; // ??
381 thread->context.state |= OS_CONTEXT_STATE_FPSAVED;
382 thread->context.fpscr = (__OSFpscrEnableBits & 0xF8) | 0x4; // ??
383
384 for (i = 0; i < 32; i++)
385 {
386 *(u64 *)&thread->context.fpr[i] = -1; // ???????
387 *(u64 *)&thread->context.psf[i] = -1; // ???????
388 }
389 }
390
391 AddTail(&__OSActiveThreadQueue, thread, linkActive);
392 OSRestoreInterrupts(enable);
393 return TRUE;
394}
395
396void OSExitThread(void *val)
397{

Callers 4

CreateReadThreadFunction · 0.85
CreateAudioDecodeThreadFunction · 0.85
CreateVideoDecodeThreadFunction · 0.85

Calls 4

OSInitThreadQueueFunction · 0.85
OSInitMutexQueueFunction · 0.85
OSInitContextFunction · 0.85
OSDisableInterruptsFunction · 0.85

Tested by

no test coverage detected