1
0
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:
Adrien Bourmault 2021-03-09 11:24:52 +01:00
parent 9abb67a194
commit f1231af040
Signed by: neox
GPG Key ID: 6EB408FE0ACEC664
5 changed files with 73 additions and 74 deletions

View File

@ -39,8 +39,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, void *arg0, void *arg1, void *arg2, error_t _KeSyscallHandler(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs);
ISRFrame_t *regs );
void KeEnableSyscalls(); void KeEnableSyscalls();

View File

@ -25,39 +25,39 @@
[BITS 64] [BITS 64]
%macro pushAll 0 %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 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 %endmacro
%macro popAll 0 %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 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 %endmacro
%macro IsrWithoutErrCode 1 %macro IsrWithoutErrCode 1

View File

@ -36,21 +36,21 @@ extern _KeSyscallHandler
;; System call pre-handler ;; System call pre-handler
;; ;;
syscallPreHandler: syscallPreHandler:
push r15 push rax ; rax
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 rbx 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 mov rax, cr8
push rax push rax
mov rax, cr4 mov rax, cr4
@ -67,7 +67,7 @@ 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 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 mov rbp, 0 ; Terminate stack traces here
call _KeSyscallHandler call _KeSyscallHandler
@ -75,22 +75,23 @@ syscallPreHandler:
; pop the control registers ; pop the control registers
add rsp, 48 add rsp, 48
; pop registers except return value ; 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 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 add rsp, 16
iretq iretq

View File

@ -29,49 +29,48 @@
#include <io/vga.h> #include <io/vga.h>
#include <sh/shell.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 // Syscall handler that dispatches calls depending of code value
// //
error_t _KeSyscallHandler( ulong code, void *rdi, void *rsi, void *rdx, error_t _KeSyscallHandler(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs)
ISRFrame_t *regs )
{ {
if ((ulong)regs->cs >= (ulong)BtLoaderInfo.codeSegment) { if ((ulong)regs->cs >= (ulong)BtLoaderInfo.codeSegment) {
DebugLog("System call code %ld from userspace (cs %#x)\n", DebugLog("System call code %ld from userspace (cs %#x)\n",
code, regs->cs); regs->rax, regs->cs);
} else { } else {
DebugLog("System call call code %ld from kernel (cs %#x)\n", 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 ENOSYS;
} }
return syscallTable[(uchar)code](rdi, rsi, rdx, regs); return syscallTable[(uchar)regs->rax](rdi, rsi, rdx, rcx, regs);
} }
// //
// Syscalls // 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; 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; 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; 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 /* TODO
- lock the zone - lock the zone
@ -82,7 +81,7 @@ static error_t syscallOpen(void *descriptor, void *address, void *size, ISRFrame
return ENOSYS; 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 /* TODO
- lock the zone - lock the zone
@ -93,7 +92,7 @@ static error_t syscallClose(void *descriptor, void *address, void *flags, ISRFra
return ENOSYS; 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(); KeEnableIRQs();
ShStartShell(); //TODO : return from Shell ShStartShell(); //TODO : return from Shell

View File

@ -28,7 +28,7 @@ global UserTest
global EndOfUser global EndOfUser
UserTest: UserTest:
mov rdi, 4 mov rax, 4
int 0x80 int 0x80
.clone: .clone: