X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fproc.asm;h=a07bdad840809b7e71c24a104b196dbe0cbb7c1d;hb=be6e3ccd05add9ad319a121661c20cb4769f58d7;hp=41623bdd23fc63cacdee6f491cf3f0cc7145df1d;hpb=83612bb37fbd8e84d90ecb9e6a7157aadd1e2175;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/proc.asm b/Kernel/arch/x86/proc.asm index 41623bdd..a07bdad8 100644 --- a/Kernel/arch/x86/proc.asm +++ b/Kernel/arch/x86/proc.asm @@ -74,6 +74,9 @@ SchedulerBase: push fs push gs + mov eax, dr0 + push eax ; Debug Register 0, Current Thread + mov ax, 0x10 mov ds, ax mov es, ax @@ -97,17 +100,19 @@ SchedulerBase: jnz .sendEOI %endif - mov dx, 0x20 mov al, 0x20 - out dx, al ; ACK IRQ + out 0x20, al ; ACK IRQ %if USE_MP jmp .ret .sendEOI: mov eax, DWORD [gpMP_LocalAPIC] - mov DWORD [eax+0x0B0], 1 + mov DWORD [eax+0x0B0], 0 %endif .ret: + pop eax ; Debug Register 0, Current Thread + mov dr0, eax + pop gs pop fs pop es @@ -145,19 +150,24 @@ 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+8]: handler to use + ; [EBP+12]: parameter + ; [EBP+16]: kernel stack top - call Proc_GetCurThread + ;call Proc_GetCurThread ; EAX is the current thread - mov ebx, eax - mov eax, [ebx+40] ; Get Kernel Stack + ;mov ebx, eax + ;mov eax, [ebx+12*4] ; Get Kernel Stack + mov eax, [ebp+16] ; Get Kernel Stack sub eax, KSTACK_USERSTATE_SIZE ; @@ -199,10 +209,10 @@ Proc_ReturnToUser: jnz .justKillIt ; Get and alter User SP - mov ecx, edx - mov edx, [ebx+60] ; Get Signal Number from TCB - mov [ecx+4], edx ; Parameter (Signal/Error Number) - mov [ecx], DWORD User_Syscall_RetAndExit ; Return Address + mov edi, edx + mov edx, [ebp+12] ; Get parameter + mov [edi+4], edx ; save to user stack + mov [edi], DWORD User_Syscall_RetAndExit ; Return Address ; Restore Segment Registers mov ax, 0x23 @@ -212,10 +222,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+8] ; Method to call + push eax ; EIP iret @@ -228,15 +239,23 @@ Proc_ReturnToUser: int 0xAC [global GetCPUNum] -GetCPUNum: - xor eax, eax - str ax - sub ax, 0x30 - shr ax, 3 ; ax /= 8 +GetCPUNum: ; TODO: Store in debug registers +; xor eax, eax +; str ax +; sub ax, 0x30 +; shr ax, 3 ; ax /= 8 + mov eax, dr1 ret ; Usermode code exported by the kernel [section .usertext] +; 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 ; MAGIC BREAKPOINT + int 0xAC + +; A place to return to and exit User_Syscall_RetAndExit: push eax call User_Syscall_Exit