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
107 mov eax, DWORD [gpMP_LocalAPIC]
108 mov DWORD [eax+0x0B0], 1
118 ; No Error code / int num
122 [extern Threads_Exit]
125 ; Call Proc_Clone with Flags=0
130 add esp, 8 ; Remove arguments from stack
135 ; In child, so now set up stack frame
136 mov ebx, [esp+4] ; Child Function
137 mov edx, [esp+8] ; Argument
142 push 0 ; Kill this thread
143 call Threads_Exit ; Kill Thread
149 ; Calls a user fault handler
151 [global Proc_ReturnToUser]
152 [extern Proc_GetCurThread]
154 ; EBP is the handler to use
156 call Proc_GetCurThread
158 ; EAX is the current thread
160 mov eax, [ebx+40] ; Get Kernel Stack
161 sub eax, KSTACK_USERSTATE_SIZE
164 ; NOTE: This can cause corruption if the signal happens while the user
165 ; has called a kernel operation.
166 ; Good thing this can only be called on a user fault.
171 mov edx, [eax+KSTACK_USERSTATE_SIZE-12] ; User ESP is at top of kstack - 3*4
177 test BYTE [0xFC3F0000+ecx*4], 1
183 test BYTE [0xFC000000+ecx*4], 1
192 test BYTE [0xFC3F0000+ecx*4], 1
198 test BYTE [0xFC000000+ecx*4], 1
201 ; Get and alter User SP
203 mov edx, [ebx+60] ; Get Signal Number from TCB
204 mov [ecx+4], edx ; Parameter (Signal/Error Number)
205 mov [ecx], DWORD User_Syscall_RetAndExit ; Return Address
207 ; Restore Segment Registers
216 push 0x202 ; EFLAGS (IP and Rsvd)
222 ; Just kill the bleeding thing
223 ; (I know it calls int 0xAC in kernel mode, but meh)
238 ; Usermode code exported by the kernel
240 User_Syscall_RetAndExit:
242 call User_Syscall_Exit