1 ; AcessOS Microkernel Version
6 KERNEL_BASE equ 0xC0000000
8 KSTACK_USERSTATE_SIZE equ (4+8+1+5)*4 ; SRegs, GPRegs, CPU, IRET
11 [extern giMP_TimerCount]
12 [extern gpMP_LocalAPIC]
14 [global SetAPICTimerCount]
28 mov eax, [gpMP_LocalAPIC]
32 mov DWORD [eax+0x380], 0xFFFFFFFF ; Set Initial Count
33 mov DWORD [eax+0x320], 0x000000F0 ; Enable the timer on IVT#0xEF (One Shot)
40 mov DWORD [giMP_TimerCount], ecx
42 mov DWORD [eax+0x320], 0x00010000
44 ; Update Timer IRQ to the IRQ code
45 mov eax, SchedulerBase
47 mov DWORD [Isr240+5+5+1], eax
55 ; No Error code / int num
61 [extern Proc_Scheduler]
62 [global SchedulerBase]
77 push eax ; Push as argument
81 add esp, 4 ; Remove Argument
93 ; No Error code / int num
100 ; Call Proc_Clone with Flags=0
105 add esp, 8 ; Remove arguments from stack
110 ; In child, so now set up stack frame
111 mov ebx, [esp+4] ; Child Function
112 mov edx, [esp+8] ; Argument
117 push 0 ; Kill this thread
118 call Threads_Exit ; Kill Thread
124 ; Calls a user fault handler
126 [global Proc_ReturnToUser]
127 [extern Proc_GetCurThread]
129 ; EBP is the handler to use
131 call Proc_GetCurThread
133 ; EAX is the current thread
135 mov eax, [ebx+40] ; Get Kernel Stack
136 sub eax, KSTACK_USERSTATE_SIZE
139 ; NOTE: This can cause corruption if the signal happens while the user
140 ; has called a kernel operation.
141 ; Good thing this can only be called on a user fault.
146 mov edx, [eax+KSTACK_USERSTATE_SIZE-12] ; User ESP is at top of kstack - 3*4
152 test BYTE [0xFC3F0000+ecx*4], 1
158 test BYTE [0xFC000000+ecx*4], 1
167 test BYTE [0xFC3F0000+ecx*4], 1
173 test BYTE [0xFC000000+ecx*4], 1
176 ; Get and alter User SP
178 mov edx, [ebx+60] ; Get Signal Number from TCB
179 mov [ecx+4], edx ; Parameter (Signal/Error Number)
180 mov [ecx], DWORD User_Syscall_RetAndExit ; Return Address
182 ; Restore Segment Registers
191 push 0x202 ; EFLAGS (IP and Rsvd)
197 ; Just kill the bleeding thing
198 ; (I know it calls int 0xAC in kernel mode, but meh)
213 ; Usermode code exported by the kernel
215 User_Syscall_RetAndExit:
217 call User_Syscall_Exit