122 lines
4.5 KiB
Text
122 lines
4.5 KiB
Text
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
~ ~~ System calls for the FreeBSD kernel ~~
|
|
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
~
|
|
~ The syscall ABI on FreeBSD is mostly similar to Linux (see
|
|
~ syscall-abi-linux.e for details). However, errors are returned differently;
|
|
~ Linux returns the errno value negated, while FreeBSD returns the value as-is
|
|
~ and sets the carry flag. Evocation assumes the Linux convention, so we convert
|
|
~ as part of the syscall wrappers.
|
|
|
|
~ (call number -- return value)
|
|
: syscall-0
|
|
[ here @
|
|
:rax pop-reg64 ~ syscall number
|
|
syscall
|
|
3 ~ REX + opcode byte + ModR/M
|
|
:cc-above-equal jmp-cc-rel-imm8
|
|
:rax neg-reg64 ~ negate error value
|
|
:rax push-reg64 ~ return value
|
|
here ! ] ;asm
|
|
|
|
~ (first param, call number -- return value)
|
|
: syscall-1
|
|
[ here @
|
|
:rax pop-reg64 ~ syscall number
|
|
:rdi pop-reg64 ~ first param
|
|
syscall
|
|
3 ~ REX + opcode byte + ModR/M
|
|
:cc-above-equal jmp-cc-rel-imm8
|
|
:rax neg-reg64 ~ negate error value
|
|
:rax push-reg64 ~ return value
|
|
here ! ] ;asm
|
|
|
|
~ (first param, second param, call number -- return value)
|
|
: syscall-2
|
|
[ here @
|
|
:rsi :rbx mov-reg64-reg64 ~ save rsi
|
|
:rax pop-reg64 ~ syscall number
|
|
:rsi pop-reg64 ~ second param
|
|
:rdi pop-reg64 ~ first param
|
|
syscall
|
|
3 ~ REX + opcode byte + ModR/M
|
|
:cc-above-equal jmp-cc-rel-imm8
|
|
:rax neg-reg64 ~ negate error value
|
|
:rbx :rsi mov-reg64-reg64 ~ restore rsi
|
|
:rax push-reg64 ~ return value
|
|
here ! ] ;asm
|
|
|
|
~ (first param, second param, third param, call number -- return value)
|
|
: syscall-3
|
|
[ here @
|
|
:rsi :rbx mov-reg64-reg64 ~ save rsi
|
|
:rax pop-reg64 ~ syscall number
|
|
:rdx pop-reg64 ~ third param
|
|
:rsi pop-reg64 ~ second param
|
|
:rdi pop-reg64 ~ first param
|
|
syscall
|
|
3 ~ REX + opcode byte + ModR/M
|
|
:cc-above-equal jmp-cc-rel-imm8
|
|
:rax neg-reg64 ~ negate error value
|
|
:rbx :rsi mov-reg64-reg64 ~ restore rsi
|
|
:rax push-reg64 ~ return value
|
|
here ! ] ;asm
|
|
|
|
~ (first param, second param, third param, fourth param, call number
|
|
~ -- return value)
|
|
: syscall-4
|
|
[ here @
|
|
:rsi :rbx mov-reg64-reg64 ~ save rsi
|
|
:rax pop-reg64 ~ syscall number
|
|
:r10 pop-extrareg64 ~ fourth param
|
|
:rdx pop-reg64 ~ third param
|
|
:rsi pop-reg64 ~ second param
|
|
:rdi pop-reg64 ~ first param
|
|
syscall
|
|
3 ~ REX + opcode byte + ModR/M
|
|
:cc-above-equal jmp-cc-rel-imm8
|
|
:rax neg-reg64 ~ negate error value
|
|
:rbx :rsi mov-reg64-reg64 ~ restore rsi
|
|
:rax push-reg64 ~ return value
|
|
here ! ] ;asm
|
|
|
|
|
|
~ (first param, second param, third param, fourth param, fifth param,
|
|
~ call number -- return value)
|
|
: syscall-5
|
|
[ here @
|
|
:rsi :rbx mov-reg64-reg64 ~ save rsi
|
|
:rax pop-reg64 ~ syscall number
|
|
:r8 pop-extrareg64 ~ fifth param
|
|
:r10 pop-extrareg64 ~ fourth param
|
|
:rdx pop-reg64 ~ third param
|
|
:rsi pop-reg64 ~ second param
|
|
:rdi pop-reg64 ~ first param
|
|
syscall
|
|
3 ~ REX + opcode byte + ModR/M
|
|
:cc-above-equal jmp-cc-rel-imm8
|
|
:rax neg-reg64 ~ negate error value
|
|
:rbx :rsi mov-reg64-reg64 ~ restore rsi
|
|
:rax push-reg64 ~ return value
|
|
here ! ] ;asm
|
|
|
|
|
|
~ (first param, second param, third param, fourth param, fifth param,
|
|
~ sixth param, call number -- return value)
|
|
: syscall-6
|
|
[ here @
|
|
:rsi :rbx mov-reg64-reg64 ~ save rsi
|
|
:rax pop-reg64 ~ syscall number
|
|
:r9 pop-extrareg64 ~ sixth param
|
|
:r8 pop-extrareg64 ~ fifth param
|
|
:r10 pop-extrareg64 ~ fourth param
|
|
:rdx pop-reg64 ~ third param
|
|
:rsi pop-reg64 ~ second param
|
|
:rdi pop-reg64 ~ first param
|
|
syscall
|
|
3 ~ REX + opcode byte + ModR/M
|
|
:cc-above-equal jmp-cc-rel-imm8
|
|
:rax neg-reg64 ~ negate error value
|
|
:rbx :rsi mov-reg64-reg64 ~ restore rsi
|
|
:rax push-reg64 ~ return value
|
|
here ! ] ;asm
|