Add syscalls to x86-64 linux
This commit is contained in:
parent
edc3296083
commit
3705cf387e
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,3 +12,6 @@ __test__*__.core
|
||||
/docs.json
|
||||
|
||||
/*.lst
|
||||
|
||||
# Ninja build
|
||||
.ninja_*
|
||||
|
9
arch/build.ninja
Normal file
9
arch/build.ninja
Normal file
@ -0,0 +1,9 @@
|
||||
rule gas
|
||||
command = gcc -c $in -o $out
|
||||
|
||||
rule archive
|
||||
command = ar rcs $out $in
|
||||
|
||||
build syscall.o: gas x64/linux/syscall.S
|
||||
|
||||
build tanya.a: archive syscall.o
|
65
arch/x64/linux/syscall.S
Normal file
65
arch/x64/linux/syscall.S
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
The kernel uses the following registers:
|
||||
%rdi, %rsi, %rdx, %r8, %r9, %r10
|
||||
|
||||
The number of the syscall is passed in %rax.
|
||||
|
||||
A syscall clobbers:
|
||||
%rax, %rcx, %r11
|
||||
|
||||
The returned value is placed in %rax.
|
||||
*/
|
||||
.text
|
||||
|
||||
.globl syscall1
|
||||
.type syscall1, @function
|
||||
|
||||
syscall1:
|
||||
movq %rsi, %rax // Syscall number.
|
||||
|
||||
syscall
|
||||
|
||||
ret
|
||||
|
||||
|
||||
.globl syscall2
|
||||
.type syscall2, @function
|
||||
|
||||
syscall2:
|
||||
// Store registers.
|
||||
movq %rdi, %r8
|
||||
|
||||
movq %rdx, %rax // Syscall number.
|
||||
|
||||
// Syscall arguments.
|
||||
movq %rsi, %rdi
|
||||
movq %r8, %rsi
|
||||
|
||||
syscall
|
||||
|
||||
// Restore registers.
|
||||
movq %rdi, %rsi
|
||||
movq %r8, %rdi
|
||||
|
||||
ret
|
||||
|
||||
|
||||
.globl syscall3
|
||||
.type syscall3, @function
|
||||
|
||||
syscall3:
|
||||
// Store registers.
|
||||
movq %rdi, %r8
|
||||
|
||||
movq %rcx, %rax // Syscall number.
|
||||
|
||||
// Syscall arguments.
|
||||
movq %rdx, %rdi
|
||||
movq %r8, %rdx
|
||||
|
||||
syscall
|
||||
|
||||
// Restore registers.
|
||||
movq %r8, %rdi
|
||||
|
||||
ret
|
Loading…
Reference in New Issue
Block a user