mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
Userspace can trigger syscalls
This commit is contained in:
parent
b3d83fac11
commit
59318483f9
8
Makefile
8
Makefile
@ -344,7 +344,7 @@ run: test
|
|||||||
|
|
||||||
testnokvm: all installonimage
|
testnokvm: all installonimage
|
||||||
@qemu-system-x86_64 -vga std -machine type=q35 \
|
@qemu-system-x86_64 -vga std -machine type=q35 \
|
||||||
-cpu host -rtc base=localtime -m $(ram) \
|
-cpu qemu64 -rtc base=localtime -m $(ram) \
|
||||||
-drive file=$(installdisk),index=0,media=disk,format=raw \
|
-drive file=$(installdisk),index=0,media=disk,format=raw \
|
||||||
-net nic,model=rtl8139 -audiodev id=pa,driver=pa \
|
-net nic,model=rtl8139 -audiodev id=pa,driver=pa \
|
||||||
-machine pcspk-audiodev=pa \
|
-machine pcspk-audiodev=pa \
|
||||||
@ -359,7 +359,7 @@ testnosnd: all installonimage
|
|||||||
|
|
||||||
test32: all installonimage
|
test32: all installonimage
|
||||||
@qemu-system-i386 -vga std -enable-kvm -machine type=q35 \
|
@qemu-system-i386 -vga std -enable-kvm -machine type=q35 \
|
||||||
-cpu host -rtc base=localtime -m $(ram) \
|
-cpu qemu32 -rtc base=localtime -m $(ram) \
|
||||||
-drive file=$(installdisk),index=0,media=disk,format=raw \
|
-drive file=$(installdisk),index=0,media=disk,format=raw \
|
||||||
-net nic,model=rtl8139 -audiodev id=pa,driver=pa \
|
-net nic,model=rtl8139 -audiodev id=pa,driver=pa \
|
||||||
-machine pcspk-audiodev=pa \
|
-machine pcspk-audiodev=pa \
|
||||||
@ -390,7 +390,7 @@ ddd: all installonimage
|
|||||||
|
|
||||||
gdbnokvm: all installonimage
|
gdbnokvm: all installonimage
|
||||||
@setsid qemu-system-x86_64 -vga std -machine type=q35 \
|
@setsid qemu-system-x86_64 -vga std -machine type=q35 \
|
||||||
-cpu host -rtc base=localtime -m $(ram) \
|
-cpu qemu64 -rtc base=localtime -m $(ram) \
|
||||||
-drive file=$(installdisk),index=0,media=disk,format=raw \
|
-drive file=$(installdisk),index=0,media=disk,format=raw \
|
||||||
-net nic,model=rtl8139 -audiodev id=pa,driver=pa \
|
-net nic,model=rtl8139 -audiodev id=pa,driver=pa \
|
||||||
-machine pcspk-audiodev=pa -no-reboot -no-shutdown\
|
-machine pcspk-audiodev=pa -no-reboot -no-shutdown\
|
||||||
@ -403,7 +403,7 @@ gdbnokvm: all installonimage
|
|||||||
|
|
||||||
dddnokvm: all installonimage
|
dddnokvm: all installonimage
|
||||||
@setsid qemu-system-x86_64 -vga std -machine type=q35 \
|
@setsid qemu-system-x86_64 -vga std -machine type=q35 \
|
||||||
-cpu host -rtc base=localtime -m $(ram) \
|
-cpu qemu64 -rtc base=localtime -m $(ram) \
|
||||||
-drive file=$(installdisk),index=0,media=disk,format=raw \
|
-drive file=$(installdisk),index=0,media=disk,format=raw \
|
||||||
-net nic,model=rtl8139 -audiodev id=pa,driver=pa \
|
-net nic,model=rtl8139 -audiodev id=pa,driver=pa \
|
||||||
-machine pcspk-audiodev=pa -no-reboot -no-shutdown\
|
-machine pcspk-audiodev=pa -no-reboot -no-shutdown\
|
||||||
|
@ -35,7 +35,7 @@ extern error_t KeSyscall(ulong code);
|
|||||||
|
|
||||||
extern void KeJumpToUserspace(ulong args, void *entryPoint, void *stackAddr);
|
extern void KeJumpToUserspace(ulong args, void *entryPoint, void *stackAddr);
|
||||||
|
|
||||||
error_t _KeSyscallHandler(ulong code);
|
error_t _KeSyscallHandler(ulong code, ISRFrame_t *regs);
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
@ -122,12 +122,24 @@ void KeSetupIDT(void)
|
|||||||
// Set IDT ptr
|
// Set IDT ptr
|
||||||
_KeIdtPtr.limit = (sizeof(IdtEntry_t) * 256) - 1;
|
_KeIdtPtr.limit = (sizeof(IdtEntry_t) * 256) - 1;
|
||||||
_KeIdtPtr.base = &idt;
|
_KeIdtPtr.base = &idt;
|
||||||
|
|
||||||
|
/* ISR flags :
|
||||||
|
0x8E = 1 0 0 0 1 1 1 0
|
||||||
|
| | | | '-'-'-'------ Gate type : 0xE is interrupt gate
|
||||||
|
| | | '-------------- S (must be 0)
|
||||||
|
| '-'---------------- DPL : 0 is Supervisor
|
||||||
|
'-------------------- P : 1 is present
|
||||||
|
0xEE = 1 1 1 0 1 1 1 0
|
||||||
|
| | | | '-'-'-'------ Gate type : 0xE is interrupt gate
|
||||||
|
| | | '-------------- S (must be 0)
|
||||||
|
| '-'---------------- DPL : 3 is user
|
||||||
|
'-------------------- P : 1 is present */
|
||||||
|
|
||||||
// Set IDT Exception Gates
|
// Set IDT Exception Gates
|
||||||
KeSetIDTGate(0x00, (ulong)isr0, codeSeg, 0x8E, 2);
|
KeSetIDTGate(0x00, (ulong)isr0, codeSeg, 0x8E, 2);
|
||||||
KeSetIDTGate(0x01, (ulong)isr1, codeSeg, 0x8E, 2);
|
KeSetIDTGate(0x01, (ulong)isr1, codeSeg, 0x8E, 2);
|
||||||
KeSetIDTGate(0x02, (ulong)isr2, codeSeg, 0x8E, 2);
|
KeSetIDTGate(0x02, (ulong)isr2, codeSeg, 0x8E, 2);
|
||||||
KeSetIDTGate(0x03, (ulong)isr3, codeSeg, 0x8E, 2);
|
KeSetIDTGate(0x03, (ulong)isr3, codeSeg, 0xEE, 2);
|
||||||
KeSetIDTGate(0x04, (ulong)isr4, codeSeg, 0x8E, 2);
|
KeSetIDTGate(0x04, (ulong)isr4, codeSeg, 0x8E, 2);
|
||||||
KeSetIDTGate(0x05, (ulong)isr5, codeSeg, 0x8E, 2);
|
KeSetIDTGate(0x05, (ulong)isr5, codeSeg, 0x8E, 2);
|
||||||
KeSetIDTGate(0x06, (ulong)isr6, codeSeg, 0x8E, 2);
|
KeSetIDTGate(0x06, (ulong)isr6, codeSeg, 0x8E, 2);
|
||||||
@ -176,7 +188,7 @@ void KeSetupIDT(void)
|
|||||||
KeSetIDTGate(0x2F, (ulong)isr47, codeSeg, 0x8E, 3);
|
KeSetIDTGate(0x2F, (ulong)isr47, codeSeg, 0x8E, 3);
|
||||||
|
|
||||||
// SYSCALL
|
// SYSCALL
|
||||||
KeSetIDTGate(0x80, (ulong)isr128, codeSeg, 0x8E, 3); // Directly handled by _KeSyscallHandler, without registration
|
KeSetIDTGate(0x80, (ulong)isr128, codeSeg, 0xEE, 3); // Directly handled by _KeSyscallHandler, without registration
|
||||||
|
|
||||||
KeIdtIsInitialized++;
|
KeIdtIsInitialized++;
|
||||||
|
|
||||||
@ -328,7 +340,7 @@ void _KeHandleISR(ISRFrame_t *regs)
|
|||||||
if (regs->intNo >= 0x20 && regs->intNo <= 0x2F && !(KeGetIrqRegister(0x0b) & (1<<(regs->intNo - 0x20)))) {
|
if (regs->intNo >= 0x20 && regs->intNo <= 0x2F && !(KeGetIrqRegister(0x0b) & (1<<(regs->intNo - 0x20)))) {
|
||||||
KeSpuriousCount++;
|
KeSpuriousCount++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < isrList.n; i++) {
|
for (int i = 0; i < isrList.n; i++) {
|
||||||
if (regs->intNo == isrList.entry[i].isrNo) {
|
if (regs->intNo == isrList.entry[i].isrNo) {
|
||||||
|
@ -82,7 +82,21 @@ Die:
|
|||||||
;; System call pre-handler
|
;; System call pre-handler
|
||||||
;;
|
;;
|
||||||
syscallPreHandler:
|
syscallPreHandler:
|
||||||
pushAll
|
push r15
|
||||||
|
push r14
|
||||||
|
push r13
|
||||||
|
push r12
|
||||||
|
push r11
|
||||||
|
push r10
|
||||||
|
push r9
|
||||||
|
push r8
|
||||||
|
push rbp
|
||||||
|
push 0
|
||||||
|
push rsi
|
||||||
|
push rdx
|
||||||
|
push rcx
|
||||||
|
push rbx
|
||||||
|
push rax
|
||||||
mov rax, cr8
|
mov rax, cr8
|
||||||
push rax
|
push rax
|
||||||
mov rax, cr4
|
mov rax, cr4
|
||||||
@ -99,17 +113,33 @@ syscallPreHandler:
|
|||||||
|
|
||||||
; Call the C routine to dispatch interrupts
|
; Call the C routine to dispatch interrupts
|
||||||
cld ; DF must be cleared by the caller
|
cld ; DF must be cleared by the caller
|
||||||
mov rdi, rsp ; First argument points to the processor state
|
mov rsi, rsp ; First argument points to the processor state
|
||||||
mov rbp, 0 ; Terminate stack traces here
|
mov rbp, 0 ; Terminate stack traces here
|
||||||
|
|
||||||
call _KeSyscallHandler
|
call _KeSyscallHandler
|
||||||
|
|
||||||
; pop the control registers
|
; pop the control registers
|
||||||
add rsp, 48
|
add rsp, 48
|
||||||
; pop registers
|
; pop registers except return value
|
||||||
popAll
|
pop rbx
|
||||||
|
pop rbx ; 2x rbx to discard rax
|
||||||
|
pop rcx
|
||||||
|
pop rdx
|
||||||
|
pop rsi
|
||||||
|
pop rdi
|
||||||
|
pop rbp
|
||||||
|
pop r8
|
||||||
|
pop r9
|
||||||
|
pop r10
|
||||||
|
pop r11
|
||||||
|
pop r12
|
||||||
|
pop r13
|
||||||
|
pop r14
|
||||||
|
pop r15
|
||||||
; pop the error code and interrupt id
|
; pop the error code and interrupt id
|
||||||
add rsp, 16
|
add rsp, 16
|
||||||
|
|
||||||
|
iretq
|
||||||
|
|
||||||
Die2:
|
Die2:
|
||||||
hlt
|
hlt
|
||||||
|
@ -27,9 +27,14 @@
|
|||||||
#include <ke/idt.h>
|
#include <ke/idt.h>
|
||||||
#include <io/vga.h>
|
#include <io/vga.h>
|
||||||
|
|
||||||
error_t _KeSyscallHandler(ulong code)
|
error_t _KeSyscallHandler(ulong code, ISRFrame_t *regs)
|
||||||
{
|
{
|
||||||
DebugLog("Got a system call code %ld !\n", code);
|
DebugLog("Got a system call code %ld from cs %#x\n", code, regs->cs);
|
||||||
|
|
||||||
|
if ((ulong)regs->cs != (ulong)BtLoaderInfo.codeSegment) {
|
||||||
|
bprintf(BStdOut, "Got a system call from userspace code %d\n", code);
|
||||||
|
BStdOut->flusher(BStdOut);
|
||||||
|
}
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ global UserTest
|
|||||||
global EndOfUser
|
global EndOfUser
|
||||||
|
|
||||||
UserTest:
|
UserTest:
|
||||||
mov rdi, 13
|
mov rdi, 45
|
||||||
;int 0x80
|
int 0x80
|
||||||
|
|
||||||
.clone:
|
.clone:
|
||||||
nop
|
nop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user