2013-01-12 13:48:27 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
2013-01-12 13:48:27 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
This file is part of the Sortix C Library.
|
2013-01-12 13:48:27 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
The Sortix C Library is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
2013-01-12 13:48:27 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
The Sortix C Library is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2013-01-12 13:48:27 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
2013-01-12 13:48:27 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
x64/syscall.s
|
|
|
|
Function for performing system calls.
|
2013-01-12 13:48:27 -05:00
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
# x86_64 system call conventions:
|
|
|
|
# interrupt 128
|
|
|
|
# system call number: %rax
|
|
|
|
# parameters: %rdi, %rsi, %rdx, %rcx, %r8, %r9
|
|
|
|
# return value: %rax, %rdx
|
|
|
|
# return errno: %rcx
|
|
|
|
# clobbered: %rdi, %rsi, %r8, %r9, %r10, %r11
|
|
|
|
# preserved: %rbx, %rsp, %rbp, %r12, %r13, %r14, %r15
|
|
|
|
|
|
|
|
.global asm_syscall
|
|
|
|
asm_syscall: /* syscall num in %rax. */
|
|
|
|
push %rbp
|
|
|
|
mov %rsp, %rbp
|
|
|
|
int $0x80
|
|
|
|
test %ecx, %ecx
|
|
|
|
jnz 1f
|
|
|
|
pop %rbp
|
|
|
|
ret
|
|
|
|
1:
|
|
|
|
push %rbx
|
|
|
|
push %r12
|
|
|
|
push %r13
|
|
|
|
mov %ecx, %ebx # preserve: ret_errno
|
|
|
|
mov %rax, %r12 # preserve: ret_low
|
|
|
|
mov %rdx, %r13 # preserve: ret_high
|
|
|
|
call get_errno_location # get_errno_location()
|
|
|
|
mov %ebx, (%rax) # *get_errno_location() = ret_errno
|
|
|
|
mov %r12, %rax # restore: ret_low
|
|
|
|
mov %r13, %rdx # restore: ret_high
|
|
|
|
pop %r13
|
|
|
|
pop %r12
|
|
|
|
pop %rbx
|
|
|
|
pop %rbp
|
|
|
|
ret
|
2013-05-22 16:06:18 -04:00
|
|
|
.size asm_syscall, .-asm_syscall
|