libk  platform.mmap.fn.x86.lin.64.s at [357c708c52]

File legacy/platform.mmap.fn.x86.lin.64.s artifact a05b3cdd12 part of check-in 357c708c52


bits 64
%include "../arch/posix/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