miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
syscall.c File Reference
#include <miniOS/syscall.h>
#include <miniOS/sched/sched.h>
#include <miniOS/arch/x86_64/irq.h>
#include <miniOS/io.h>
#include <miniOS/types.h>
#include <stddef.h>
#include "syscall_internal.h"
Include dependency graph for syscall.c:

Macros

#define IA32_EFER   0xC0000080UL
#define IA32_STAR   0xC0000081UL
#define IA32_LSTAR   0xC0000082UL
#define IA32_SFMASK   0xC0000084UL
#define SYSCALL_DISPATCH_UNHANDLED   ((int64_t)0x7fffffffffffffffLL)

Functions

static void wrmsr (uint32_t msr, uint64_t val)
static uint64_t rdmsr (uint32_t msr)
void syscall_entry (void)
void int80_entry (void)
void syscall_save_user_regs (uint64_t user_rip, uint64_t user_rflags, uint64_t user_rsp)
void syscall_save_user_callee_regs (uint64_t user_rbp, uint64_t user_rbx, uint64_t user_r12, uint64_t user_r13, uint64_t user_r14, uint64_t user_r15)
void syscall_get_saved_user_callee_regs (uint64_t *out_rbp, uint64_t *out_rbx, uint64_t *out_r12, uint64_t *out_r13, uint64_t *out_r14, uint64_t *out_r15)
void syscall_get_saved_user_ctx (uint64_t *out_rip, uint64_t *out_rfl, uint64_t *out_rsp)
void syscall_get_saved_user_rdi_rsi_rdx (uint64_t *out_rdi, uint64_t *out_rsi, uint64_t *out_rdx)
 The SYSCALL instruction clobbers RCX and R11; arguments in RDI/RSI/RDX are preserved by the syscall.asm stub in per-CPU scratch space. This helper exposes them to kernel C code (e.g., SYS_execve handler) that needs all three argument registers.
void syscall_save_restart_state (uint64_t nr, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6)
void syscall_init (void)
 Writes IA32_LSTAR MSR to the address of syscall_entry (the NASM entry stub in syscall.asm), writes IA32_STAR MSR with kernel CS (0x08) and user CS (0x1B) selectors, writes IA32_FMASK to mask IF during syscall entry (interrupts disabled at syscall boundary), and sets SCE bit in IA32_EFER. Called once by the BSP during boot.
int64_t syscall_dispatch (uint64_t nr, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6)

Variables

uint64_t syscall_kernel_rsp_storage

Macro Definition Documentation

◆ IA32_EFER

#define IA32_EFER   0xC0000080UL

◆ IA32_LSTAR

#define IA32_LSTAR   0xC0000082UL

◆ IA32_SFMASK

#define IA32_SFMASK   0xC0000084UL

◆ IA32_STAR

#define IA32_STAR   0xC0000081UL

◆ SYSCALL_DISPATCH_UNHANDLED

#define SYSCALL_DISPATCH_UNHANDLED   ((int64_t)0x7fffffffffffffffLL)

Function Documentation

◆ int80_entry()

void int80_entry ( void )
extern
Here is the caller graph for this function:

◆ rdmsr()

uint64_t rdmsr ( uint32_t msr)
inlinestatic
Here is the caller graph for this function:

◆ syscall_dispatch()

int64_t syscall_dispatch ( uint64_t nr,
uint64_t arg1,
uint64_t arg2,
uint64_t arg3,
uint64_t arg4,
uint64_t arg5,
uint64_t arg6 )

syscall_dispatch() - Dispatch a syscall number to grouped subsystem handlers.

src/kernel/syscall.c owns the stable public entrypoints and delegates the large implementation bodies to subsystem-specific pieces:

  • syscall_mm.inc : brk/mmap/munmap/clock_gettime
  • syscall_fs.inc : VFS, pipes, polling, stat and mount operations
  • syscall_proc.inc : fork/exec/wait/signal/session/process helpers
  • syscall_net.inc : socket syscalls and lwIP callbacks
Here is the call graph for this function:
Here is the caller graph for this function:

◆ syscall_entry()

void syscall_entry ( void )
extern
Here is the caller graph for this function:

◆ syscall_get_saved_user_callee_regs()

void syscall_get_saved_user_callee_regs ( uint64_t * out_rbp,
uint64_t * out_rbx,
uint64_t * out_r12,
uint64_t * out_r13,
uint64_t * out_r14,
uint64_t * out_r15 )
Here is the call graph for this function:

◆ syscall_get_saved_user_ctx()

void syscall_get_saved_user_ctx ( uint64_t * out_rip,
uint64_t * out_rfl,
uint64_t * out_rsp )
Here is the call graph for this function:

◆ syscall_save_user_callee_regs()

void syscall_save_user_callee_regs ( uint64_t user_rbp,
uint64_t user_rbx,
uint64_t user_r12,
uint64_t user_r13,
uint64_t user_r14,
uint64_t user_r15 )
Here is the call graph for this function:

◆ syscall_save_user_regs()

void syscall_save_user_regs ( uint64_t user_rip,
uint64_t user_rflags,
uint64_t user_rsp )
Here is the call graph for this function:

◆ wrmsr()

void wrmsr ( uint32_t msr,
uint64_t val )
inlinestatic
Here is the caller graph for this function:

Variable Documentation

◆ syscall_kernel_rsp_storage

uint64_t syscall_kernel_rsp_storage
extern