Fixed the EFLAGS contents to actually enable IF
[tpg/acess2.git] / Kernel / arch / x86 / proc.asm
1 ; AcessOS Microkernel Version
2 ; Start.asm
3
4 [bits 32]
5
6 KERNEL_BASE     equ 0xC0000000
7
8 KSTACK_USERSTATE_SIZE   equ     (4+8+1+5)*4     ; SRegs, GPRegs, CPU, IRET
9
10 [section .text]
11 ; --------------
12 ; Task Scheduler
13 ; --------------
14 [extern Proc_Scheduler]
15 [global SchedulerBase]
16 SchedulerBase:
17         pusha
18         push ds
19         push es
20         push fs
21         push gs
22         
23         mov ax, 0x10
24         mov ds, ax
25         mov es, ax
26         mov fs, ax
27         mov gs, ax
28         
29         mov eax, [esp+12*4]     ; CPU Number
30         push eax        ; Pus as argument
31         
32         call Proc_Scheduler
33         
34         add esp, 4      ; Remove Argument
35         
36         pop gs
37         pop fs
38         pop es
39         pop ds
40
41         mov dx, 0x20
42         mov al, 0x20
43         out dx, al              ; ACK IRQ
44         popa
45         add esp, 4      ; CPU ID
46         ; No Error code / int num
47         iret
48
49 [extern Proc_Clone]
50 [extern Threads_Exit]
51 [global SpawnTask]
52 SpawnTask:
53         ; Call Proc_Clone with Flags=0
54         xor eax, eax
55         push eax
56         push eax
57         call Proc_Clone
58         add esp, 8      ; Remove arguments from stack
59         
60         test eax, eax
61         jnz .parent
62         
63         ; In child, so now set up stack frame
64         mov ebx, [esp+4]        ; Child Function
65         mov edx, [esp+8]        ; Argument
66         ; Child
67         push edx        ; Argument
68         call ebx        ; Function
69         call Threads_Exit       ; Kill Thread
70         
71 .parent:
72         ret
73
74 ;
75 ; Calls a user fault handler
76 ;
77 [global Proc_AlterUserReturnAddr]
78 [extern Proc_GetCurThread]
79 Proc_AlterUserReturnAddr:
80         ; EBP is the handler to use
81         
82         call Proc_GetCurThread
83         xchg bx, bx
84         
85         ; EAX is the current thread
86         mov ebx, eax
87         mov eax, [ebx+40]       ; Get Kernel Stack
88         sub eax, KSTACK_USERSTATE_SIZE  
89         
90         ;
91         ; NOTE: This can cause corruption if the signal happens while the user
92         ;       has called a kernel operation.
93         ; Good thing this can only be called on a user fault.
94         ;
95         
96         ; Get and alter User SP
97         mov ecx, [eax+KSTACK_USERSTATE_SIZE-12]
98         mov edx, [ebx+60]       ; Get Signal Number
99         mov [ecx-4], edx
100         mov [ecx-8], DWORD User_Syscall_RetAndExit
101         sub ecx, 8
102         
103         ; Restore Segment Registers
104         mov ax, 0x23
105         mov ds, ax
106         mov es, ax
107         mov fs, ax
108         mov gs, ax
109         
110         push 0x23       ; SS
111         push ecx        ; ESP
112         push 0x202      ; EFLAGS (IP and Rsvd)
113         push 0x1B       ; CS
114         push ebp        ; EIP
115         
116         iret
117
118
119 [section .usertext]
120 User_Syscall_RetAndExit:
121         push eax
122         call User_Syscall_Exit
123 User_Syscall_Exit:
124         xor eax, eax
125         mov ebx, [esp+4]
126         int 0xAC

UCC git Repository :: git.ucc.asn.au