git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
exported spinlocks
[tpg/acess2.git]
/
Kernel
/
arch
/
x86
/
proc.asm
diff --git
a/Kernel/arch/x86/proc.asm
b/Kernel/arch/x86/proc.asm
index
bcb0f58
..
732d35f
100644
(file)
--- a/
Kernel/arch/x86/proc.asm
+++ b/
Kernel/arch/x86/proc.asm
@@
-8,9
+8,10
@@
KERNEL_BASE equ 0xC0000000
KSTACK_USERSTATE_SIZE equ (4+8+1+5)*4 ; SRegs, GPRegs, CPU, IRET
[section .text]
KSTACK_USERSTATE_SIZE equ (4+8+1+5)*4 ; SRegs, GPRegs, CPU, IRET
[section .text]
+%if USE_MP
[extern giMP_TimerCount]
[extern gpMP_LocalAPIC]
[extern giMP_TimerCount]
[extern gpMP_LocalAPIC]
-[extern Isr240]
+[extern Isr240
.jmp
]
[global SetAPICTimerCount]
SetAPICTimerCount:
pusha
[global SetAPICTimerCount]
SetAPICTimerCount:
pusha
@@
-27,7
+28,7
@@
SetAPICTimerCount:
mov eax, [gpMP_LocalAPIC]
mov ecx, [eax+0x320]
mov eax, [gpMP_LocalAPIC]
mov ecx, [eax+0x320]
- test ecx, 0x0001000
+ test ecx, 0x0001000
0
jz .setTime
mov DWORD [eax+0x380], 0xFFFFFFFF ; Set Initial Count
mov DWORD [eax+0x320], 0x000000F0 ; Enable the timer on IVT#0xEF (One Shot)
jz .setTime
mov DWORD [eax+0x380], 0xFFFFFFFF ; Set Initial Count
mov DWORD [eax+0x320], 0x000000F0 ; Enable the timer on IVT#0xEF (One Shot)
@@
-39,22
+40,28
@@
SetAPICTimerCount:
sub ecx, [eax+0x390]
mov DWORD [giMP_TimerCount], ecx
; Disable APIC Timer
sub ecx, [eax+0x390]
mov DWORD [giMP_TimerCount], ecx
; Disable APIC Timer
- mov DWORD [eax+0x320], 0x00010000
+ mov DWORD [eax+0x320], 0x000100EF
+ mov DWORD [eax+0x380], 0
; Update Timer IRQ to the IRQ code
mov eax, SchedulerBase
; Update Timer IRQ to the IRQ code
mov eax, SchedulerBase
- sub eax, Isr240
+5+5+1
- mov DWORD [Isr240
+5+5
+1], eax
+ sub eax, Isr240
.jmp+5
+ mov DWORD [Isr240
.jmp
+1], eax
+ ;xchg bx, bx ; MAGIC BREAK
.ret:
mov dx, 0x20
mov al, 0x20
out dx, al ; ACK IRQ
.ret:
mov dx, 0x20
mov al, 0x20
out dx, al ; ACK IRQ
+ pop gs
+ pop fs
+ pop es
+ pop ds
popa
add esp, 4 ; CPU ID
; No Error code / int num
iret
popa
add esp, 4 ; CPU ID
; No Error code / int num
iret
-
+%endif
; --------------
; Task Scheduler
; --------------
; --------------
; Task Scheduler
; --------------
@@
-67,27
+74,50
@@
SchedulerBase:
push fs
push gs
push fs
push gs
+ mov eax, dr0
+ push eax ; Debug Register 0, Current Thread
+
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
+ %if USE_MP
call GetCPUNum
call GetCPUNum
+ mov ebx, eax
push eax ; Push as argument
push eax ; Push as argument
+ %else
+ push 0
+ %endif
call Proc_Scheduler
add esp, 4 ; Remove Argument
call Proc_Scheduler
add esp, 4 ; Remove Argument
+
+ %if USE_MP
+ test ebx, ebx
+ jnz .sendEOI
+ %endif
+
+ mov al, 0x20
+ out 0x20, al ; ACK IRQ
+ %if USE_MP
+ jmp .ret
+.sendEOI:
+ mov eax, DWORD [gpMP_LocalAPIC]
+ mov DWORD [eax+0x0B0], 0
+ %endif
+.ret:
+ pop eax ; Debug Register 0, Current Thread
+ mov dr0, eax
+
pop gs
pop fs
pop es
pop ds
pop gs
pop fs
pop es
pop ds
-
- mov dx, 0x20
- mov al, 0x20
- out dx, al ; ACK IRQ
+
popa
add esp, 4 ; CPU ID
; No Error code / int num
popa
add esp, 4 ; CPU ID
; No Error code / int num
@@
-120,19
+150,22
@@
SpawnTask:
.parent:
ret
.parent:
ret
-;
+;
void Proc_ReturnToUser(void *Method, Uint Parameter)
; Calls a user fault handler
;
[global Proc_ReturnToUser]
[extern Proc_GetCurThread]
Proc_ReturnToUser:
; Calls a user fault handler
;
[global Proc_ReturnToUser]
[extern Proc_GetCurThread]
Proc_ReturnToUser:
- ; EBP is the handler to use
+ push ebp
+ mov ebp, esp
+ ; [EBP+4]: handler to use
+ ; [EBP+8]: parameter
call Proc_GetCurThread
; EAX is the current thread
mov ebx, eax
call Proc_GetCurThread
; EAX is the current thread
mov ebx, eax
- mov eax, [ebx+
40]
; Get Kernel Stack
+ mov eax, [ebx+
12*4]
; Get Kernel Stack
sub eax, KSTACK_USERSTATE_SIZE
;
sub eax, KSTACK_USERSTATE_SIZE
;
@@
-174,10
+207,10
@@
Proc_ReturnToUser:
jnz .justKillIt
; Get and alter User SP
jnz .justKillIt
; Get and alter User SP
- mov e
cx
, edx
- mov edx, [eb
x+60] ; Get Signal Number from TCB
- mov [e
cx+4], edx ; Parameter (Signal/Error Number)
- mov [e
cx
], DWORD User_Syscall_RetAndExit ; Return Address
+ mov e
di
, edx
+ mov edx, [eb
p+8] ; Get parameter
+ mov [e
di+4], edx ; save to user stack
+ mov [e
di
], DWORD User_Syscall_RetAndExit ; Return Address
; Restore Segment Registers
mov ax, 0x23
; Restore Segment Registers
mov ax, 0x23
@@
-187,10
+220,11
@@
Proc_ReturnToUser:
mov gs, ax
push 0x23 ; SS
mov gs, ax
push 0x23 ; SS
- push e
cx
; ESP
+ push e
di
; ESP
push 0x202 ; EFLAGS (IP and Rsvd)
push 0x1B ; CS
push 0x202 ; EFLAGS (IP and Rsvd)
push 0x1B ; CS
- push ebp ; EIP
+ mov eax, [ebp+4] ; Method to call
+ push eax ; EIP
iret
iret
@@
-203,7
+237,7
@@
Proc_ReturnToUser:
int 0xAC
[global GetCPUNum]
int 0xAC
[global GetCPUNum]
-GetCPUNum:
+GetCPUNum:
; TODO: Store in debug registers
xor eax, eax
str ax
sub ax, 0x30
xor eax, eax
str ax
sub ax, 0x30
@@
-212,6
+246,13
@@
GetCPUNum:
; Usermode code exported by the kernel
[section .usertext]
; Usermode code exported by the kernel
[section .usertext]
+; Export a place for the user to jump to to call a syscall
+; - Allows the kernel to change the method easily
+User_Syscall:
+ xchg bx, bx ; MAGIC BREAKPOINT
+ int 0xAC
+
+; A place to return to and exit
User_Syscall_RetAndExit:
push eax
call User_Syscall_Exit
User_Syscall_RetAndExit:
push eax
call User_Syscall_Exit
UCC
git Repository :: git.ucc.asn.au