35 lines
1.1 KiB
NASM
35 lines
1.1 KiB
NASM
BITS 64
|
|
CPU X64
|
|
|
|
section .text
|
|
global _start
|
|
|
|
extern sterling_runtime_init;runtime setup
|
|
extern sterling_main;user entrypoint
|
|
|
|
_start:
|
|
;Clear RBP (Recommended by the ABI to mark the outermost frame)
|
|
xor rbp, rbp
|
|
|
|
;Extract argc and argv from the stack
|
|
;[rsp] is argc, [rsp + 8] is argv[0] on 64bit
|
|
pop rdi ; rdi = argc
|
|
mov rsi, rsp ; rsi = argv (pointer to the current top of stack)
|
|
|
|
;The System V ABI requires the stack to be 16-byte aligned before a 'call'.
|
|
;The kernel starts us aligned, but our 'pop' just moved rsp by 8 bytes.
|
|
and rsp, -16
|
|
|
|
call sterling_runtime_init ;elf loader hook for the exokernel ?
|
|
|
|
;Call to the 'main' function
|
|
;Assuming signature like C: int sterling_main(int argc, char **argv)
|
|
;May change it to reflect the object file implementation
|
|
call sterling_main
|
|
|
|
; 5. Exit System Call
|
|
; sterling_main return its status in RAX. Move it to RDI for exit.
|
|
mov rdi, rax ; exit status
|
|
mov rax, 60 ; sys_exit (60 for x86_64)
|
|
syscall
|