mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
syscalls use rax for code
This commit is contained in:
parent
9abb67a194
commit
f1231af040
@ -39,8 +39,7 @@ extern error_t KeSyscall(ulong code);
|
||||
|
||||
extern void KeJumpToUserspace(ulong args, void *entryPoint, void *stackAddr);
|
||||
|
||||
error_t _KeSyscallHandler( ulong code, void *arg0, void *arg1, void *arg2,
|
||||
ISRFrame_t *regs );
|
||||
error_t _KeSyscallHandler(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs);
|
||||
|
||||
void KeEnableSyscalls();
|
||||
|
||||
|
@ -25,39 +25,39 @@
|
||||
[BITS 64]
|
||||
|
||||
%macro pushAll 0
|
||||
push r15
|
||||
push r14
|
||||
push r13
|
||||
push r12
|
||||
push r11
|
||||
push r10
|
||||
push r9
|
||||
push r8
|
||||
push rbp
|
||||
push rdi
|
||||
push rsi
|
||||
push rdx
|
||||
push rcx
|
||||
push rbx
|
||||
push rax
|
||||
push rbx
|
||||
push rcx
|
||||
push rdx
|
||||
push rsi
|
||||
push rdi
|
||||
push rbp
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r11
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
push r15
|
||||
%endmacro
|
||||
|
||||
%macro popAll 0
|
||||
pop rax
|
||||
pop rbx
|
||||
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 r14
|
||||
pop r13
|
||||
pop r12
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
pop rbp
|
||||
pop rdi
|
||||
pop rsi
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rbx
|
||||
pop rax
|
||||
%endmacro
|
||||
|
||||
%macro IsrWithoutErrCode 1
|
||||
|
@ -36,21 +36,21 @@ extern _KeSyscallHandler
|
||||
;; System call pre-handler
|
||||
;;
|
||||
syscallPreHandler:
|
||||
push r15
|
||||
push r14
|
||||
push r13
|
||||
push r12
|
||||
push r11
|
||||
push 0 ; r10
|
||||
push r9
|
||||
push r8
|
||||
push rbp
|
||||
push 0 ; rdi
|
||||
push 0 ; rsi
|
||||
push 0 ; rdx
|
||||
push rcx
|
||||
push rax ; rax
|
||||
push rbx
|
||||
push rax
|
||||
push rcx
|
||||
push 0 ; rdx
|
||||
push 0 ; rsi
|
||||
push 0 ; rdi
|
||||
push rbp
|
||||
push r8
|
||||
push r9
|
||||
push 0 ; r10
|
||||
push r11
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
push r15
|
||||
mov rax, cr8
|
||||
push rax
|
||||
mov rax, cr4
|
||||
@ -67,7 +67,7 @@ syscallPreHandler:
|
||||
|
||||
; Call the C routine to dispatch interrupts
|
||||
cld ; DF must be cleared by the caller
|
||||
mov rsi, rsp ; First argument points to the processor state
|
||||
mov r8, rsp ; First argument points to the processor state
|
||||
mov rbp, 0 ; Terminate stack traces here
|
||||
|
||||
call _KeSyscallHandler
|
||||
@ -75,22 +75,23 @@ syscallPreHandler:
|
||||
; pop the control registers
|
||||
add rsp, 48
|
||||
; pop registers except return value
|
||||
pop rbx
|
||||
pop rbx ; 2x rbx to discard old rax
|
||||
pop rcx
|
||||
pop rdx ; 0
|
||||
pop rsi ; 0
|
||||
pop rdi ; 0
|
||||
pop rbp
|
||||
pop r8
|
||||
pop r9
|
||||
pop r10 ; 0
|
||||
pop r11
|
||||
pop r12
|
||||
pop r13
|
||||
pop r14
|
||||
pop r15
|
||||
; pop the error code, interrupt id + crx
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
pop rbp
|
||||
pop rdi
|
||||
pop rsi
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rbx
|
||||
; pop rax without overwriting
|
||||
add rsp, 8
|
||||
; pop the error code, interrupt id
|
||||
add rsp, 16
|
||||
|
||||
iretq
|
||||
|
@ -29,49 +29,48 @@
|
||||
#include <io/vga.h>
|
||||
#include <sh/shell.h>
|
||||
|
||||
static error_t (*syscallTable[255])(void*, void*, void*, ISRFrame_t*) = {NULL};
|
||||
static error_t (*syscallTable[255])(void*, void*, void*, void*, ISRFrame_t*) = {NULL};
|
||||
|
||||
|
||||
//
|
||||
// Syscall handler that dispatches calls depending of code value
|
||||
//
|
||||
error_t _KeSyscallHandler( ulong code, void *rdi, void *rsi, void *rdx,
|
||||
ISRFrame_t *regs )
|
||||
error_t _KeSyscallHandler(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs)
|
||||
{
|
||||
if ((ulong)regs->cs >= (ulong)BtLoaderInfo.codeSegment) {
|
||||
DebugLog("System call code %ld from userspace (cs %#x)\n",
|
||||
code, regs->cs);
|
||||
regs->rax, regs->cs);
|
||||
} else {
|
||||
DebugLog("System call call code %ld from kernel (cs %#x)\n",
|
||||
code, regs->cs);
|
||||
regs->rax, regs->cs);
|
||||
}
|
||||
|
||||
if (code > LATEST_SYSCALL_CODE) {
|
||||
if (regs->rax > LATEST_SYSCALL_CODE) {
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
return syscallTable[(uchar)code](rdi, rsi, rdx, regs);
|
||||
return syscallTable[(uchar)regs->rax](rdi, rsi, rdx, rcx, regs);
|
||||
}
|
||||
|
||||
//
|
||||
// Syscalls
|
||||
//
|
||||
static error_t syscallStub(void *rdi, void *rsi, void *rdx, ISRFrame_t *regs)
|
||||
static error_t syscallStub(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs)
|
||||
{
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static error_t syscallRead(void *descriptor, void *address, void *flags, ISRFrame_t *regs)
|
||||
static error_t syscallRead(void *descriptor, void *address, void *flags, void *rcx, ISRFrame_t *regs)
|
||||
{
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static error_t syscallWrite(void *descriptor, void *address, void *flags, ISRFrame_t *regs)
|
||||
static error_t syscallWrite(void *descriptor, void *address, void *flags, void *rcx, ISRFrame_t *regs)
|
||||
{
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static error_t syscallOpen(void *descriptor, void *address, void *size, ISRFrame_t *regs)
|
||||
static error_t syscallOpen(void *descriptor, void *address, void *size, void *rcx, ISRFrame_t *regs)
|
||||
{
|
||||
/* TODO
|
||||
- lock the zone
|
||||
@ -82,7 +81,7 @@ static error_t syscallOpen(void *descriptor, void *address, void *size, ISRFrame
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static error_t syscallClose(void *descriptor, void *address, void *flags, ISRFrame_t *regs)
|
||||
static error_t syscallClose(void *descriptor, void *address, void *flags, void *rcx, ISRFrame_t *regs)
|
||||
{
|
||||
/* TODO
|
||||
- lock the zone
|
||||
@ -93,7 +92,7 @@ static error_t syscallClose(void *descriptor, void *address, void *flags, ISRFra
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static error_t syscallKernelShell(void *rdi, void *rsi, void *rdx, ISRFrame_t *regs)
|
||||
static error_t syscallKernelShell(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs)
|
||||
{
|
||||
KeEnableIRQs();
|
||||
ShStartShell(); //TODO : return from Shell
|
||||
|
@ -28,7 +28,7 @@ global UserTest
|
||||
global EndOfUser
|
||||
|
||||
UserTest:
|
||||
mov rdi, 4
|
||||
mov rax, 4
|
||||
int 0x80
|
||||
|
||||
.clone:
|
||||
|
Loading…
Reference in New Issue
Block a user