fix the return value of LdrLoadImage, make use of __declspec(dllexport), speed up blitting, add dummy TEB, redesign the syscall interface, fix stack alignent so movaps doesn't crash, implement a shitload of win32, implement a simple shell, add bink as video.exe 😎, minor kmain.c cleanup, HAL now supports power-off events, implemented \b in hal_screen.c, fix many deadlocks, add wait for exit event for processes, completely new error codes, small readme changes.
This commit is contained in:
1 parent
c13dd99150
commit
7f4052f41c
33 files changed
+6396
-735
No files matched your search
+73
-31
@@ -1,32 +1,74 @@
|
||||
; syscall_nr.inc - assembled from syscall_nr.h for use in .asm files
|
||||
SYS_EXIT_THREAD EQU 0
|
||||
SYS_EXIT_PROCESS EQU 1
|
||||
SYS_SPAWN EQU 2
|
||||
SYS_SLEEP EQU 3
|
||||
SYS_YIELD EQU 4
|
||||
SYS_ALLOC EQU 5
|
||||
SYS_FREE EQU 6
|
||||
SYS_CREATE_THREAD EQU 7
|
||||
SYS_OPEN_HANDLE EQU 8
|
||||
SYS_CLOSE_HANDLE EQU 9
|
||||
SYS_DBG_PRINT EQU 10
|
||||
SYS_MUTEX_CREATE EQU 11
|
||||
SYS_MUTEX_ACQUIRE EQU 12
|
||||
SYS_MUTEX_RELEASE EQU 13
|
||||
SYS_SEM_CREATE EQU 14
|
||||
SYS_SEM_WAIT EQU 15
|
||||
SYS_SEM_SIGNAL EQU 16
|
||||
SYS_EVENT_CREATE EQU 17
|
||||
SYS_EVENT_SET EQU 18
|
||||
SYS_EVENT_WAIT EQU 19
|
||||
SYS_QUEUE_CREATE EQU 20
|
||||
SYS_QUEUE_SEND EQU 21
|
||||
SYS_QUEUE_RECV EQU 22
|
||||
SYS_SCREEN_BLIT EQU 23
|
||||
SYS_GET_TICK EQU 24
|
||||
SYS_OPEN EQU 25
|
||||
SYS_READ EQU 26
|
||||
SYS_FCLOSE EQU 27
|
||||
SYS_FSEEK EQU 28
|
||||
SYS_FSIZE EQU 29
|
||||
SYS_MAX EQU 30
|
||||
; Keep in sync with syscall_nr.h and ke_syscall.c.
|
||||
|
||||
; Process & Thread
|
||||
SYS_EXIT_PROCESS EQU 0
|
||||
SYS_EXIT_THREAD EQU 1
|
||||
SYS_CREATE_THREAD EQU 2
|
||||
SYS_GET_CURRENT_TID EQU 3
|
||||
SYS_GET_CURRENT_PID EQU 4
|
||||
SYS_YIELD EQU 5
|
||||
SYS_SLEEP EQU 6
|
||||
SYS_SET_THREAD_PRIORITY EQU 7
|
||||
|
||||
; Memory
|
||||
SYS_ALLOC EQU 8
|
||||
SYS_FREE EQU 9
|
||||
SYS_REALLOC EQU 10
|
||||
|
||||
; Mutex
|
||||
SYS_MUTEX_CREATE EQU 11
|
||||
SYS_MUTEX_ACQUIRE EQU 12
|
||||
SYS_MUTEX_TRY_ACQUIRE EQU 13
|
||||
SYS_MUTEX_RELEASE EQU 14
|
||||
|
||||
; Semaphore
|
||||
SYS_SEM_CREATE EQU 15
|
||||
SYS_SEM_WAIT EQU 16
|
||||
SYS_SEM_TRY_WAIT EQU 17
|
||||
SYS_SEM_SIGNAL EQU 18
|
||||
|
||||
; Event
|
||||
SYS_EVENT_CREATE EQU 19
|
||||
SYS_EVENT_SIGNAL EQU 20
|
||||
SYS_EVENT_CLEAR EQU 21
|
||||
SYS_EVENT_WAIT EQU 22
|
||||
|
||||
; Queue
|
||||
SYS_QUEUE_CREATE EQU 23
|
||||
SYS_QUEUE_SEND EQU 24
|
||||
SYS_QUEUE_RECV EQU 25
|
||||
|
||||
; Handle (unified - one close for every object type)
|
||||
SYS_CLOSE_HANDLE EQU 26
|
||||
|
||||
; File I/O
|
||||
SYS_OPEN_FILE EQU 27
|
||||
SYS_READ_FILE EQU 28
|
||||
SYS_SEEK_FILE EQU 29
|
||||
SYS_GET_FILE_SIZE EQU 30
|
||||
|
||||
; Screen
|
||||
SYS_SCREEN_BLIT EQU 31
|
||||
SYS_SCREEN_CLEAR EQU 32
|
||||
SYS_SCREEN_GET_SIZE EQU 33
|
||||
SYS_SCREEN_PUT_CHAR EQU 34
|
||||
|
||||
; Keyboard
|
||||
SYS_KB_POLL EQU 35
|
||||
SYS_KB_READ_CHAR EQU 36
|
||||
SYS_KB_READ_SCANCODE EQU 37
|
||||
|
||||
; Timer
|
||||
SYS_GET_TICK EQU 38
|
||||
|
||||
; Debug
|
||||
SYS_DEBUG_PRINT EQU 39
|
||||
|
||||
; Process launch & lifecycle
|
||||
SYS_CREATE_PROCESS EQU 40
|
||||
SYS_WAIT_FOR_PROCESS EQU 41
|
||||
SYS_GET_PROCESS_EXIT_CODE EQU 42
|
||||
|
||||
; Sentinel
|
||||
SYS_MAX EQU 43
|
||||
+125
-158
@@ -1,180 +1,147 @@
|
||||
; syscall_stubs.asm - user-mode INT 0x2E stubs exported by syscall.dll (MASM64)
|
||||
; Microsoft x64 ABI: args in RCX, RDX, R8, R9; args 5+6 in R10, R11.
|
||||
; 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 ; SYS_* constants
|
||||
INCLUDE syscall_nr.inc
|
||||
|
||||
.CODE
|
||||
|
||||
SysExitThread PROC
|
||||
mov rax, SYS_EXIT_THREAD
|
||||
int 40h
|
||||
; ---------------------------------------------------------------------------
|
||||
SYSCALL_STUB2 MACRO name, nr
|
||||
PUBLIC Sys&name
|
||||
Sys&name PROC EXPORT
|
||||
mov rax, nr
|
||||
int 40h
|
||||
ret
|
||||
SysExitThread ENDP
|
||||
Sys&name ENDP
|
||||
ENDM
|
||||
|
||||
SysExitProcess PROC
|
||||
mov rax, SYS_EXIT_PROCESS
|
||||
int 40h
|
||||
; ---------------------------------------------------------------------------
|
||||
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
|
||||
SysExitProcess ENDP
|
||||
Sys&name ENDP
|
||||
ENDM
|
||||
|
||||
SysYield PROC
|
||||
mov rax, SYS_YIELD
|
||||
int 40h
|
||||
ret
|
||||
SysYield ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
SysSleep PROC ; RCX = milliseconds
|
||||
mov rax, SYS_SLEEP
|
||||
int 40h
|
||||
ret
|
||||
SysSleep ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; Memory
|
||||
; ---------------------------------------------------------------------------
|
||||
SYSCALL_STUB2 Alloc, SYS_ALLOC
|
||||
SYSCALL_STUB2 Free, SYS_FREE
|
||||
SYSCALL_STUB2 Realloc, SYS_REALLOC
|
||||
|
||||
SysAlloc PROC ; RCX = size -> RAX = ptr
|
||||
mov rax, SYS_ALLOC
|
||||
int 40h
|
||||
ret
|
||||
SysAlloc ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
SysFree PROC ; RCX = ptr, RDX = size
|
||||
mov rax, SYS_FREE
|
||||
int 40h
|
||||
ret
|
||||
SysFree ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
SysCreateThread PROC ; RCX=entry, RDX=arg, R8=priority -> RAX=handle
|
||||
mov rax, SYS_CREATE_THREAD
|
||||
int 40h
|
||||
ret
|
||||
SysCreateThread ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
SysCloseHandle PROC ; RCX = handle
|
||||
mov rax, SYS_CLOSE_HANDLE
|
||||
int 40h
|
||||
ret
|
||||
SysCloseHandle ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; Queue
|
||||
; ---------------------------------------------------------------------------
|
||||
SYSCALL_STUB2 QueueCreate, SYS_QUEUE_CREATE
|
||||
SYSCALL_STUB2 QueueSend, SYS_QUEUE_SEND
|
||||
SYSCALL_STUB2 QueueRecv, SYS_QUEUE_RECV
|
||||
|
||||
SysDbgPrint PROC ; RCX = string ptr
|
||||
mov rax, SYS_DBG_PRINT
|
||||
int 40h
|
||||
ret
|
||||
SysDbgPrint ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; Handle (unified - use for files, mutexes, semaphores, events, queues)
|
||||
; ---------------------------------------------------------------------------
|
||||
SYSCALL_STUB2 CloseHandle, SYS_CLOSE_HANDLE
|
||||
|
||||
SysMutexCreate PROC ; -> RAX = handle
|
||||
mov rax, SYS_MUTEX_CREATE
|
||||
int 40h
|
||||
ret
|
||||
SysMutexCreate ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
SysMutexAcquire PROC ; RCX = handle
|
||||
mov rax, SYS_MUTEX_ACQUIRE
|
||||
int 40h
|
||||
ret
|
||||
SysMutexAcquire ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
SysMutexRelease PROC ; RCX = handle
|
||||
mov rax, SYS_MUTEX_RELEASE
|
||||
int 40h
|
||||
ret
|
||||
SysMutexRelease ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; Keyboard
|
||||
; ---------------------------------------------------------------------------
|
||||
SYSCALL_STUB2 KbPoll, SYS_KB_POLL
|
||||
SYSCALL_STUB2 KbReadChar, SYS_KB_READ_CHAR
|
||||
SYSCALL_STUB2 KbReadScancode, SYS_KB_READ_SCANCODE
|
||||
|
||||
SysSemCreate PROC ; RCX=initial, RDX=max -> RAX=handle
|
||||
mov rax, SYS_SEM_CREATE
|
||||
int 40h
|
||||
ret
|
||||
SysSemCreate ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; Timer
|
||||
; ---------------------------------------------------------------------------
|
||||
SYSCALL_STUB2 GetTick, SYS_GET_TICK
|
||||
|
||||
SysSemWait PROC ; RCX = handle
|
||||
mov rax, SYS_SEM_WAIT
|
||||
int 40h
|
||||
ret
|
||||
SysSemWait ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; Debug
|
||||
; ---------------------------------------------------------------------------
|
||||
SYSCALL_STUB2 DebugPrint, SYS_DEBUG_PRINT
|
||||
|
||||
SysSemSignal PROC ; RCX = handle
|
||||
mov rax, SYS_SEM_SIGNAL
|
||||
int 40h
|
||||
ret
|
||||
SysSemSignal ENDP
|
||||
|
||||
SysEventCreate PROC ; RCX=manualReset, RDX=initialState -> RAX=handle
|
||||
mov rax, SYS_EVENT_CREATE
|
||||
int 40h
|
||||
ret
|
||||
SysEventCreate ENDP
|
||||
|
||||
SysEventSet PROC ; RCX = handle
|
||||
mov rax, SYS_EVENT_SET
|
||||
int 40h
|
||||
ret
|
||||
SysEventSet ENDP
|
||||
|
||||
SysEventWait PROC ; RCX = handle
|
||||
mov rax, SYS_EVENT_WAIT
|
||||
int 40h
|
||||
ret
|
||||
SysEventWait ENDP
|
||||
|
||||
SysQueueCreate PROC ; -> RAX = handle
|
||||
mov rax, SYS_QUEUE_CREATE
|
||||
int 40h
|
||||
ret
|
||||
SysQueueCreate ENDP
|
||||
|
||||
SysQueueSend PROC ; RCX=handle, RDX=*msg, R8=blocking
|
||||
mov rax, SYS_QUEUE_SEND
|
||||
int 40h
|
||||
ret
|
||||
SysQueueSend ENDP
|
||||
|
||||
SysQueueRecv PROC ; RCX=handle, RDX=*msg, R8=blocking
|
||||
mov rax, SYS_QUEUE_RECV
|
||||
int 40h
|
||||
ret
|
||||
SysQueueRecv ENDP
|
||||
|
||||
SysScreenBlit PROC
|
||||
; RCX=x, RDX=y, R8=w, R9=h
|
||||
; The 5th arg (pixels) is on the stack above the 32-byte shadow space and return address.
|
||||
mov r10, [rsp + 40]
|
||||
|
||||
mov rax, SYS_SCREEN_BLIT
|
||||
int 40h
|
||||
ret
|
||||
SysScreenBlit ENDP
|
||||
|
||||
SysGetTick PROC ; -> RAX = milliseconds
|
||||
mov rax, SYS_GET_TICK
|
||||
int 40h
|
||||
ret
|
||||
SysGetTick ENDP
|
||||
|
||||
SysOpen PROC ; RCX = *path -> RAX = handle (0 = failure)
|
||||
mov rax, SYS_OPEN
|
||||
int 40h
|
||||
ret
|
||||
SysOpen ENDP
|
||||
|
||||
SysRead PROC ; RCX = handle, RDX = *buf, R8 = size -> RAX = bytes read
|
||||
mov rax, SYS_READ
|
||||
int 40h
|
||||
ret
|
||||
SysRead ENDP
|
||||
|
||||
SysFClose PROC ; RCX = handle
|
||||
mov rax, SYS_FCLOSE
|
||||
int 40h
|
||||
ret
|
||||
SysFClose ENDP
|
||||
|
||||
SysFSeek PROC ; RCX = handle, RDX = offset
|
||||
mov rax, SYS_FSEEK
|
||||
int 40h
|
||||
ret
|
||||
SysFSeek ENDP
|
||||
|
||||
SysFSize PROC ; RCX = handle -> RAX = size in bytes
|
||||
mov rax, SYS_FSIZE
|
||||
int 40h
|
||||
ret
|
||||
SysFSize ENDP
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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
|
||||
Reference in new issue
Block a user