Files
nt-lite/code/syscall/syscall_stubs.asm
T

148 lines
6.1 KiB
NASM

; syscall_stubs.asm - user-mode INT 0x40 stubs exported by syscall.dll (MASM64)
;
; Calling convention (kernel side):
; RAX = syscall number
; RCX = arg 0
; RDX = arg 1
; R8 = arg 2
; R9 = arg 3
; R10 = arg 4 (our extension - loaded from the stack by SYSCALL_STUB6)
; R11 = arg 5 (our extension - loaded from the stack by SYSCALL_STUB6)
;
; User-mode callers follow standard MS x64: args 1-4 in RCX/RDX/R8/R9,
; args 5+ on the stack above the home area ([rsp+28h], [rsp+30h], ...).
;
; SYSCALL_STUB2 - 4 or fewer args: pure register passing, no stack read.
; SYSCALL_STUB6 - 5 or 6 args: loads [rsp+28h] -> R10 and [rsp+30h] -> R11.
;
; Handle lifecycle:
; SysCloseHandle is the single close stub for every object type.
; There is no SysCloseFile - files are closed through the unified path,
; exactly like mutexes, semaphores, events, and queues.
INCLUDE syscall_nr.inc
.CODE
; ---------------------------------------------------------------------------
SYSCALL_STUB2 MACRO name, nr
PUBLIC Sys&name
Sys&name PROC EXPORT
mov rax, nr
int 40h
ret
Sys&name ENDP
ENDM
; ---------------------------------------------------------------------------
SYSCALL_STUB6 MACRO name, nr
PUBLIC Sys&name
Sys&name PROC EXPORT
mov r10, [rsp+28h] ; 5th argument
mov r11, [rsp+30h] ; 6th argument
mov rax, nr
int 40h
ret
Sys&name ENDP
ENDM
; ---------------------------------------------------------------------------
; Process & Thread
; ---------------------------------------------------------------------------
SYSCALL_STUB2 ExitProcess, SYS_EXIT_PROCESS
SYSCALL_STUB2 ExitThread, SYS_EXIT_THREAD
SYSCALL_STUB2 CreateThread, SYS_CREATE_THREAD
SYSCALL_STUB2 GetCurrentTid, SYS_GET_CURRENT_TID
SYSCALL_STUB2 GetCurrentPid, SYS_GET_CURRENT_PID
SYSCALL_STUB2 Yield, SYS_YIELD
SYSCALL_STUB2 Sleep, SYS_SLEEP
SYSCALL_STUB2 SetThreadPriority, SYS_SET_THREAD_PRIORITY
; ---------------------------------------------------------------------------
; Memory
; ---------------------------------------------------------------------------
SYSCALL_STUB2 Alloc, SYS_ALLOC
SYSCALL_STUB2 Free, SYS_FREE
SYSCALL_STUB2 Realloc, SYS_REALLOC
; ---------------------------------------------------------------------------
; Mutex
; ---------------------------------------------------------------------------
SYSCALL_STUB2 MutexCreate, SYS_MUTEX_CREATE
SYSCALL_STUB2 MutexAcquire, SYS_MUTEX_ACQUIRE
SYSCALL_STUB2 MutexTryAcquire, SYS_MUTEX_TRY_ACQUIRE
SYSCALL_STUB2 MutexRelease, SYS_MUTEX_RELEASE
; ---------------------------------------------------------------------------
; Semaphore
; ---------------------------------------------------------------------------
SYSCALL_STUB2 SemCreate, SYS_SEM_CREATE
SYSCALL_STUB2 SemWait, SYS_SEM_WAIT
SYSCALL_STUB2 SemTryWait, SYS_SEM_TRY_WAIT
SYSCALL_STUB2 SemSignal, SYS_SEM_SIGNAL
; ---------------------------------------------------------------------------
; Event
; ---------------------------------------------------------------------------
SYSCALL_STUB2 EventCreate, SYS_EVENT_CREATE
SYSCALL_STUB2 EventSignal, SYS_EVENT_SIGNAL
SYSCALL_STUB2 EventClear, SYS_EVENT_CLEAR
SYSCALL_STUB2 EventWait, SYS_EVENT_WAIT
; ---------------------------------------------------------------------------
; Queue
; ---------------------------------------------------------------------------
SYSCALL_STUB2 QueueCreate, SYS_QUEUE_CREATE
SYSCALL_STUB2 QueueSend, SYS_QUEUE_SEND
SYSCALL_STUB2 QueueRecv, SYS_QUEUE_RECV
; ---------------------------------------------------------------------------
; Handle (unified - use for files, mutexes, semaphores, events, queues)
; ---------------------------------------------------------------------------
SYSCALL_STUB2 CloseHandle, SYS_CLOSE_HANDLE
; ---------------------------------------------------------------------------
; File I/O
; (To close: SysCloseHandle(handle) - no dedicated SysCloseFile)
; ---------------------------------------------------------------------------
SYSCALL_STUB2 OpenFile, SYS_OPEN_FILE
SYSCALL_STUB2 ReadFile, SYS_READ_FILE
SYSCALL_STUB2 SeekFile, SYS_SEEK_FILE
SYSCALL_STUB2 GetFileSize, SYS_GET_FILE_SIZE
; ---------------------------------------------------------------------------
; Screen
; SysScreenBlit has 5 args (x, y, w, h, pixels) - needs SYSCALL_STUB6.
; SysScreenPutChar has 5 args (c, x, y, fg, bg) - needs SYSCALL_STUB6.
; ---------------------------------------------------------------------------
SYSCALL_STUB6 ScreenBlit, SYS_SCREEN_BLIT
SYSCALL_STUB2 ScreenClear, SYS_SCREEN_CLEAR
SYSCALL_STUB2 ScreenGetSize, SYS_SCREEN_GET_SIZE
SYSCALL_STUB6 ScreenPutChar, SYS_SCREEN_PUT_CHAR
; ---------------------------------------------------------------------------
; Keyboard
; ---------------------------------------------------------------------------
SYSCALL_STUB2 KbPoll, SYS_KB_POLL
SYSCALL_STUB2 KbReadChar, SYS_KB_READ_CHAR
SYSCALL_STUB2 KbReadScancode, SYS_KB_READ_SCANCODE
; ---------------------------------------------------------------------------
; Timer
; ---------------------------------------------------------------------------
SYSCALL_STUB2 GetTick, SYS_GET_TICK
; ---------------------------------------------------------------------------
; Debug
; ---------------------------------------------------------------------------
SYSCALL_STUB2 DebugPrint, SYS_DEBUG_PRINT
; ---------------------------------------------------------------------------
; Process launch & lifecycle
; ---------------------------------------------------------------------------
SYSCALL_STUB2 CreateProcess, SYS_CREATE_PROCESS
SYSCALL_STUB2 WaitForProcess, SYS_WAIT_FOR_PROCESS
SYSCALL_STUB2 GetProcessExitCode, SYS_GET_PROCESS_EXIT_CODE
END