aboutsummaryrefslogtreecommitdiff
path: root/system/x86_64
diff options
context:
space:
mode:
authorKlaatu <[email protected]>2015-05-17 15:33:21 +1200
committerKlaatu <[email protected]>2015-05-17 15:33:21 +1200
commitb0de699679e8f1e39af847ed172d1ba605b4370c (patch)
tree01dac00471d61f727394e508c613b29cff0ceae5 /system/x86_64
bulk upload of source
Diffstat (limited to 'system/x86_64')
-rw-r--r--system/x86_64/Flags1
-rw-r--r--system/x86_64/Makefile5
-rw-r--r--system/x86_64/__restore_rt.S8
-rw-r--r--system/x86_64/gettimeofday.S18
-rw-r--r--system/x86_64/start.S17
-rw-r--r--system/x86_64/syscalls.h20
-rw-r--r--system/x86_64/unified.S27
-rw-r--r--system/x86_64/waitpid.S10
8 files changed, 106 insertions, 0 deletions
diff --git a/system/x86_64/Flags b/system/x86_64/Flags
new file mode 100644
index 0000000..af36a53
--- /dev/null
+++ b/system/x86_64/Flags
@@ -0,0 +1 @@
+OPTIMIZATION =
diff --git a/system/x86_64/Makefile b/system/x86_64/Makefile
new file mode 100644
index 0000000..6b11a00
--- /dev/null
+++ b/system/x86_64/Makefile
@@ -0,0 +1,5 @@
+include Flags
+include ../Files
+
+system.a: unified.o $(ALL) __restore_rt.o
+ ar cr $@ $^
diff --git a/system/x86_64/__restore_rt.S b/system/x86_64/__restore_rt.S
new file mode 100644
index 0000000..34a5d3f
--- /dev/null
+++ b/system/x86_64/__restore_rt.S
@@ -0,0 +1,8 @@
+.text
+.align 16
+.global __restore_rt
+.type __restore_rt,@function
+__restore_rt:
+ movq $15, %rax
+ syscall
+ hlt
diff --git a/system/x86_64/gettimeofday.S b/system/x86_64/gettimeofday.S
new file mode 100644
index 0000000..8c2f83b
--- /dev/null
+++ b/system/x86_64/gettimeofday.S
@@ -0,0 +1,18 @@
+.text
+.global gettimeofday
+.type gettimeofday,@function
+gettimeofday:
+ mov $0xffffffffff600000,%rax
+ callq *%rax
+ cmpq $-128, %rax
+ jbe 1f
+ negl %eax
+ pushq %rax
+ call __errno_location
+ popq %rcx
+ movl %ecx,(%rax)
+ orq $-1, %rax
+1:
+ ret
+.Lhere:
+ .size gettimeofday,.Lhere-gettimeofday
diff --git a/system/x86_64/start.S b/system/x86_64/start.S
new file mode 100644
index 0000000..b31b9b1
--- /dev/null
+++ b/system/x86_64/start.S
@@ -0,0 +1,17 @@
+.text
+.global _start
+_start:
+ popq %rdi /* %rdi = argc */
+ movq %rsp,%rsi /* %rsi = argv */
+ pushq %rdi
+
+ leaq 8(%rsi,%rdi,8),%rdx /* %rdx = envp = (8*rdi)+%rsi+8 */
+
+ movq %rdx, environ(%rip)
+ call main
+ movq %rax, %rdi /* return value */
+ call exit
+ hlt
+.Lstart:
+ .size _start,.Lstart-_start
+
diff --git a/system/x86_64/syscalls.h b/system/x86_64/syscalls.h
new file mode 100644
index 0000000..b4f1476
--- /dev/null
+++ b/system/x86_64/syscalls.h
@@ -0,0 +1,20 @@
+#include <asm/unistd.h>
+
+#define syscall_weak(name,wsym,sym) \
+.text; \
+.type wsym,@function; \
+.weak wsym; \
+wsym: ; \
+.type sym,@function; \
+.global sym; \
+sym: \
+ mov $__NR_##name,%al; \
+ jmp __unified_syscall
+
+#define syscall(name,sym) \
+.text; \
+.type sym,@function; \
+.global sym; \
+sym: \
+ mov $__NR_##name,%al; \
+ jmp __unified_syscall
diff --git a/system/x86_64/unified.S b/system/x86_64/unified.S
new file mode 100644
index 0000000..c4dff7d
--- /dev/null
+++ b/system/x86_64/unified.S
@@ -0,0 +1,27 @@
+#define SYS_exit 0x3c
+
+.text
+.weak exit
+exit:
+.global _exit
+_exit:
+ mov $SYS_exit,%al
+
+.global __unified_syscall
+__unified_syscall:
+ movzbl %al, %eax
+ mov %rcx, %r10
+ syscall
+ cmpq $-128, %rax
+ jbe .Lnoerror
+ negl %eax
+ pushq %rax
+ call __errno_location
+ popq %rcx
+ movl %ecx,(%rax)
+ orq $-1, %rax
+.Lnoerror:
+
+ ret
+.Lhere:
+ .size __unified_syscall,.Lhere-__unified_syscall
diff --git a/system/x86_64/waitpid.S b/system/x86_64/waitpid.S
new file mode 100644
index 0000000..2a85491
--- /dev/null
+++ b/system/x86_64/waitpid.S
@@ -0,0 +1,10 @@
+.text
+.type waitpid,@function
+.weak waitpid
+waitpid:
+.type __libc_waitpid,@function
+.global __libc_waitpid
+__libc_waitpid:
+ xor %rcx,%rcx
+ mov $__NR_wait4,%al
+ jmp __unified_syscall