1 ; AcessOS Microkernel Version
6 KERNEL_BASE equ 0xC0000000
8 KSTACK_USERSTATE_SIZE equ (4+8+1+5)*4 ; SRegs, GPRegs, CPU, IRET
12 [extern giMP_TimerCount]
13 [extern gpMP_LocalAPIC]
15 [global SetAPICTimerCount]
29 mov eax, [gpMP_LocalAPIC]
33 mov DWORD [eax+0x380], 0xFFFFFFFF ; Set Initial Count
34 mov DWORD [eax+0x320], 0x000000F0 ; Enable the timer on IVT#0xEF (One Shot)
41 mov DWORD [giMP_TimerCount], ecx
43 mov DWORD [eax+0x320], 0x000100EF
44 mov DWORD [eax+0x380], 0
46 ; Update Timer IRQ to the IRQ code
47 mov eax, SchedulerBase
49 mov DWORD [Isr240.jmp+1], eax
51 ;xchg bx, bx ; MAGIC BREAK
62 ; No Error code / int num
68 [extern Proc_Scheduler]
69 [global SchedulerBase]
78 and BYTE [esp+1], 0xFE ; Clear Trap Flag
82 push eax ; Debug Register 0, Current Thread
93 push eax ; Push as argument
99 [global scheduler_return]
100 scheduler_return: ; Used by some hackery in Proc_DumpThreadCPUState
102 add esp, 4 ; Remove CPU Number (thread is poped later)
110 out 0x20, al ; ACK IRQ
115 mov eax, DWORD [gpMP_LocalAPIC]
116 mov DWORD [eax+0x0B0], 0
119 pop eax ; Debug Register 0, Current Thread
128 add esp, 4*2 ; CPU ID + Dummy error code
129 ; No Error code / int num
133 [extern Threads_Exit]
136 ; Call Proc_Clone with Flags=0
141 add esp, 8 ; Remove arguments from stack
146 ; In child, so now set up stack frame
147 mov ebx, [esp+4] ; Child Function
148 mov edx, [esp+8] ; Argument
152 ; Kill thread once done
154 push 0 ; Kill this thread
155 call Threads_Exit ; Kill Thread
160 ; void Proc_ReturnToUser(void *Method, Uint Parameter)
161 ; Calls a user fault handler
163 [global Proc_ReturnToUser]
164 [extern Proc_GetCurThread]
168 ; [EBP+8]: handler to use
169 ; [EBP+12]: parameter
170 ; [EBP+16]: kernel stack top
172 ;call Proc_GetCurThread
174 ; EAX is the current thread
176 ;mov eax, [ebx+12*4] ; Get Kernel Stack
177 mov eax, [ebp+16] ; Get Kernel Stack
178 sub eax, KSTACK_USERSTATE_SIZE
181 ; NOTE: This can cause corruption if the signal happens while the user
182 ; has called a kernel operation.
183 ; Good thing this can only be called on a user fault.
188 mov edx, [eax+KSTACK_USERSTATE_SIZE-12] ; User ESP is at top of kstack - 3*4
191 test BYTE [0xFC3F0000+ecx*4], 1
196 test BYTE [0xFC000000+ecx*4], 1
203 test BYTE [0xFC3F0000+ecx*4], 1
208 test BYTE [0xFC000000+ecx*4], 1
211 ; Get and alter User SP
213 mov edx, [ebp+12] ; Get parameter
214 mov [edi+4], edx ; save to user stack
215 mov [edi], DWORD User_Syscall_RetAndExit ; Return Address
217 ; Restore Segment Registers
226 push 0x202 ; EFLAGS (IP and Rsvd)
228 mov eax, [ebp+8] ; Method to call
233 ; Just kill the bleeding thing
234 ; (I know it calls int 0xAC in kernel mode, but meh)
242 GetCPUNum: ; TODO: Store in debug registers
246 ; shr ax, 3 ; ax /= 8
251 [global GetEIP_Sched]
252 [global GetEIP_Sched_ret]
253 GetEIP_Sched_ret equ GetEIP_Sched.ret
259 ; Usermode code exported by the kernel
261 ; Export a place for the user to jump to to call a syscall
262 ; - Allows the kernel to change the method easily
264 xchg bx, bx ; MAGIC BREAKPOINT
267 ; A place to return to and exit
268 User_Syscall_RetAndExit:
270 call User_Syscall_Exit