From: John Hodge Date: Mon, 26 Sep 2011 14:30:43 +0000 (+0800) Subject: Kernel/arm7 - NewKThread (partially) implemented X-Git-Tag: rel0.11~48 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=bcde7ddae4eb57329312e7dbe4bfd3a9a7d6832b;p=tpg%2Facess2.git Kernel/arm7 - NewKThread (partially) implemented --- diff --git a/Kernel/arch/arm7/include/proc.h b/Kernel/arch/arm7/include/proc.h index e2063597..1dd9b0f4 100644 --- a/Kernel/arch/arm7/include/proc.h +++ b/Kernel/arch/arm7/include/proc.h @@ -11,7 +11,7 @@ // === STRUCTURES === typedef struct { - Uint32 IP, LR, SP; + Uint32 IP, SP; Uint32 UserIP, UserSP; } tTaskState; diff --git a/Kernel/arch/arm7/mm_virt.c b/Kernel/arch/arm7/mm_virt.c index 7abf4e74..c191c683 100644 --- a/Kernel/arch/arm7/mm_virt.c +++ b/Kernel/arch/arm7/mm_virt.c @@ -38,6 +38,7 @@ void MM_int_GetTables(tVAddr VAddr, Uint32 **Table0, Uint32 **Table1); 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 === @@ -394,6 +395,13 @@ void MM_FreeTemp(tVAddr VAddr) // 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) { diff --git a/Kernel/arch/arm7/proc.c b/Kernel/arch/arm7/proc.c index 30279cc1..2ab7d466 100644 --- a/Kernel/arch/arm7/proc.c +++ b/Kernel/arch/arm7/proc.c @@ -12,6 +12,8 @@ // === 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); @@ -66,8 +68,31 @@ tTID Proc_SpawnWorker( void (*Fnc)(void*), void *Ptr ) 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)