From: John Hodge Date: Tue, 24 Aug 2010 01:18:25 +0000 (+0800) Subject: Fixed Proc_ReturnToUser's dependence on the structure of tThread X-Git-Tag: rel0.06~46 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=de2ae10743172075f2d527780bdfd890ccddb8e7;p=tpg%2Facess2.git Fixed Proc_ReturnToUser's dependence on the structure of tThread --- diff --git a/Kernel/arch/x86/include/arch.h b/Kernel/arch/x86/include/arch.h index 0fec144e..eff85fc2 100644 --- a/Kernel/arch/x86/include/arch.h +++ b/Kernel/arch/x86/include/arch.h @@ -58,7 +58,7 @@ static inline int IS_LOCKED(struct sShortSpinlock *Lock) { static inline void SHORTLOCK(struct sShortSpinlock *Lock) { int v = 1; int IF; - // int val = GetCPUNum() + 1; + // int cpu = GetCPUNum() + 1; // Save interrupt state and clear interrupts __ASM__ ("pushf;\n\tcli;\n\tpop %%eax" : "=a"(IF)); @@ -66,7 +66,7 @@ static inline void SHORTLOCK(struct sShortSpinlock *Lock) { // Wait for another CPU to release while(v) - __ASM__("xchgl %%ecx, (%%edi)":"=c"(v):"a"(1),"D"(&Lock->Lock)); + __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(&Lock->Lock)); Lock->IF = IF; } diff --git a/Kernel/arch/x86/proc.asm b/Kernel/arch/x86/proc.asm index 80cc3cbb..e0598a55 100644 --- a/Kernel/arch/x86/proc.asm +++ b/Kernel/arch/x86/proc.asm @@ -150,13 +150,16 @@ SpawnTask: .parent: ret -; +; void Proc_ReturnToUser(void *Method, Uint Parameter) ; Calls a user fault handler ; [global Proc_ReturnToUser] [extern Proc_GetCurThread] Proc_ReturnToUser: - ; EBP is the handler to use + push ebp + mov ebp, esp + ; [EBP+4]: handler to use + ; [EBP+8]: parameter call Proc_GetCurThread @@ -204,10 +207,10 @@ Proc_ReturnToUser: jnz .justKillIt ; Get and alter User SP - mov ecx, edx - mov edx, [ebx+68] ; Get Signal Number from TCB (TODO: Get this from parameters) - mov [ecx+4], edx ; Parameter (Signal/Error Number) - mov [ecx], DWORD User_Syscall_RetAndExit ; Return Address + mov edi, edx + mov edx, [ebp+8] ; Get parameter + mov [edi+4], edx ; save to user stack + mov [edi], DWORD User_Syscall_RetAndExit ; Return Address ; Restore Segment Registers mov ax, 0x23 @@ -217,10 +220,11 @@ Proc_ReturnToUser: mov gs, ax push 0x23 ; SS - push ecx ; ESP + push edi ; ESP push 0x202 ; EFLAGS (IP and Rsvd) push 0x1B ; CS - push ebp ; EIP + mov eax, [ebp+4] ; Method to call + push eax ; EIP iret @@ -233,7 +237,7 @@ Proc_ReturnToUser: int 0xAC [global GetCPUNum] -GetCPUNum: +GetCPUNum: ; TODO: Store in debug registers xor eax, eax str ax sub ax, 0x30 @@ -245,7 +249,7 @@ GetCPUNum: ; Export a place for the user to jump to to call a syscall ; - Allows the kernel to change the method easily User_Syscall: - xchg bx, bx + xchg bx, bx ; MAGIC BREAKPOINT int 0xAC ; A place to return to and exit diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 16af0da8..bfd0e8f7 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -48,7 +48,7 @@ extern int giNextTID; extern tThread gThreadZero; extern tThread *Threads_CloneTCB(Uint *Err, Uint Flags); extern void Isr8(void); // Double Fault -extern void Proc_ReturnToUser(void); +extern void Proc_ReturnToUser(tVAddr Handler, Uint Argument); // === PROTOTYPES === void ArchThreads_Init(void); @@ -829,7 +829,7 @@ void Proc_CallFaultHandler(tThread *Thread) { // Rewinds the stack and calls the user function // Never returns - __asm__ __volatile__ ("mov %0, %%ebp;\n\tcall Proc_ReturnToUser" :: "r"(Thread->FaultHandler)); + Proc_ReturnToUser( Thread->FaultHandler, Thread->CurFaultNum ); for(;;); }