int MM_int_AllocateCoarse(tVAddr VAddr, int Domain);
int MM_int_SetPageInfo(tVAddr VAddr, tMM_PageInfo *pi);
int MM_int_GetPageInfo(tVAddr VAddr, tMM_PageInfo *pi);
+tVAddr MM_NewKStack(int bGlobal);
// === GLOBALS ===
// TODO: Implement FreeTemp
}
+tVAddr MM_NewKStack(int bGlobal)
+{
+ // TODO: Implement NewKStack
+ // TODO: Should I support global stacks? if only for the idle thread
+ return 0;
+}
+
void MM_DumpTables(tVAddr Start, tVAddr End)
{
// === IMPORTS ===
extern tThread gThreadZero;
extern void SwitchTask(Uint32 NewSP, Uint32 *OldSP, Uint32 NewIP, Uint32 *OldIP, Uint32 MemPtr);
+extern void KernelThreadHeader(void); // Actually takes args
+extern tVAddr MM_NewKStack(int bGlobal); // TODO: Move out into a header
// === PROTOTYPES ===
void Proc_IdleThread(void *unused);
tTID Proc_NewKThread( void (*Fnc)(void*), void *Ptr )
{
- // TODO: Implement
- return -1;
+ tThread *new;
+ Uint32 sp;
+
+ new = Threads_CloneTCB(NULL, 0);
+ if(!new) return -1;
+
+ new->KernelStack = MM_NewKStack(0);
+ if(!new) {
+ // TODO: Delete thread
+ return -1;
+ }
+
+ sp = new->KernelStack;
+
+ *(Uint32*)(sp -= 4) = (Uint)new;
+ *(Uint32*)(sp -= 4) = (Uint)Fnc;
+ *(Uint32*)(sp -= 4) = 1;
+ *(Uint32*)(sp -= 4) = (Uint)Ptr;
+
+ new->SavedState.SP = sp;
+ new->SavedState.IP = (Uint)KernelThreadHeader;
+
+ Threads_AddActive(new);
+
+ return new->TID;
}
void Proc_CallFaultHandler(tThread *Thread)