+;
+; Returns after an interrupt, restoring the user state
+; - Also handles signal handlers
+;
+[global ReturnFromInterrupt]
+[extern Threads_GetPendingSignal]
+[extern Threads_GetSignalHandler]
+[extern Proc_CallUser]
+ReturnFromInterrupt:
+ ; Check that we're returning to userland
+ test DWORD [esp+(4+8+2+1)*4], 0x07
+ jz .ret ; Kernel interrupted, return
+
+ call Threads_GetPendingSignal
+ ; eax: signal number
+ test eax, eax
+ jz .ret
+
+ ; There's a signal pending, funtime
+ push eax
+ call Threads_GetSignalHandler
+ ; eax: signal handler
+ pop ecx
+ test eax, eax
+ jz .ret
+ cmp eax, -1
+ jz .default
+
+ ; (some stack abuse)
+ push User_RestoreState
+ push ecx
+ mov ecx, esp
+
+ push (2+4+8+2+2)*4 ; Up to and incl. CS
+ push ecx ; User stack data base
+ push DWORD [ecx+(2+4+8+2+3)*4] ; User SP
+ push eax ; handler
+ call Proc_CallUser
+ ; Oh, ... it failed. Default time?
+ add esp, (4+2)*4
+.default:
+
+
+ ; Fall through to return
+.ret: