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]
86 push eax ; Push as argument
93 add esp, 4 ; Remove Argument
101 out 0x20, al ; ACK IRQ
106 mov eax, DWORD [gpMP_LocalAPIC]
107 mov DWORD [eax+0x0B0], 0
117 ; No Error code / int num
121 [extern Threads_Exit]
124 ; Call Proc_Clone with Flags=0
129 add esp, 8 ; Remove arguments from stack
134 ; In child, so now set up stack frame
135 mov ebx, [esp+4] ; Child Function
136 mov edx, [esp+8] ; Argument
141 push 0 ; Kill this thread
142 call Threads_Exit ; Kill Thread
148 ; Calls a user fault handler
150 [global Proc_ReturnToUser]
151 [extern Proc_GetCurThread]
153 ; EBP is the handler to use
155 call Proc_GetCurThread
157 ; EAX is the current thread
159 mov eax, [ebx+40] ; Get Kernel Stack
160 sub eax, KSTACK_USERSTATE_SIZE
163 ; NOTE: This can cause corruption if the signal happens while the user
164 ; has called a kernel operation.
165 ; Good thing this can only be called on a user fault.
170 mov edx, [eax+KSTACK_USERSTATE_SIZE-12] ; User ESP is at top of kstack - 3*4
176 test BYTE [0xFC3F0000+ecx*4], 1
182 test BYTE [0xFC000000+ecx*4], 1
191 test BYTE [0xFC3F0000+ecx*4], 1
197 test BYTE [0xFC000000+ecx*4], 1
200 ; Get and alter User SP
202 mov edx, [ebx+60] ; Get Signal Number from TCB
203 mov [ecx+4], edx ; Parameter (Signal/Error Number)
204 mov [ecx], DWORD User_Syscall_RetAndExit ; Return Address
206 ; Restore Segment Registers
215 push 0x202 ; EFLAGS (IP and Rsvd)
221 ; Just kill the bleeding thing
222 ; (I know it calls int 0xAC in kernel mode, but meh)
237 ; Usermode code exported by the kernel
239 ; Export a place for the user to jump to to call a syscall
240 ; - Allows the kernel to change the method easily
245 ; A place to return to and exit
246 User_Syscall_RetAndExit:
248 call User_Syscall_Exit