libk  Artifact [ceb93a428c]

Artifact ceb93a428c52efcbca9d005b17762028589f167d0564c609be25d61bf73b3053:


bits 64
%include "../arch/x86.lin.64.s"
%include "../arch/x86.cdecl.64.s"
; vim: ft=nasm

global kmem_platform_mmap
kmem_platform_mmap:
	; to call mmap, we need to translate the cdecl64
	; register arguments to their appropriate syscall64
	; registers. these are mostly the same, with one
	; obnoxious exception. the NOPs have been written
	; in as comments to aid in understanding.

	  mov sys.reg.1, ccall.reg.0 ;nop - rdi → rdi
	  mov sys.reg.2, ccall.reg.1 ;nop - rsi → rsi
	  mov sys.reg.3, ccall.reg.2 ;nop - rdx → rdx
	  mov sys.reg.4, ccall.reg.3 ; OP - rcx → r10
	  mov sys.reg.5, ccall.reg.4 ;nop - r8 → r8
	  mov sys.reg.6, ccall.reg.5 ;nop - r9 → r9

	mov sys.reg.0, sys.mmap
	sys.call

	mov ccall.reg.ret, sys.reg.ret ; rax → rdi
	ret