summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-08-21 18:54:53 -0700
committerOri Bernstein <ori@eigenstate.org>2015-08-21 19:08:40 -0700
commit14aeadb41737f1765b6f3489f3b8da330aeccf39 (patch)
tree58eeceec013d79b26e024f47a065896e5a44a21d /libstd
parent0bd2678722f5f70a063190d54d12e62420f02b05 (diff)
downloadmc-14aeadb41737f1765b6f3489f3b8da330aeccf39.tar.gz
Get closer to the C ABI
Diffstat (limited to 'libstd')
-rw-r--r--libstd/syscall+freebsd-x64.s32
-rw-r--r--libstd/syscall+linux-x64.s35
-rw-r--r--libstd/syscall+osx-x64.s115
-rw-r--r--libstd/util+posixy-x64.s3
-rw-r--r--libstd/varargs.myr4
5 files changed, 29 insertions, 160 deletions
diff --git a/libstd/syscall+freebsd-x64.s b/libstd/syscall+freebsd-x64.s
index 680971e..8002099 100644
--- a/libstd/syscall+freebsd-x64.s
+++ b/libstd/syscall+freebsd-x64.s
@@ -1,14 +1,5 @@
.globl sys$syscall
sys$syscall:
- pushq %rbp
- pushq %rdi
- pushq %rsi
- pushq %rdx
- pushq %r10
- pushq %r8
- pushq %r9
- pushq %rcx
- pushq %r11
/*
hack: We load 6 args regardless of
how many we actually have. This may
@@ -16,24 +7,15 @@ sys$syscall:
doesn't use them, it's going to be
harmless.
*/
- movq 80 (%rsp),%rax
- movq 88 (%rsp),%rdi
- movq 96 (%rsp),%rsi
- movq 104(%rsp),%rdx
- movq 112(%rsp),%r10
- movq 120(%rsp),%r8
- movq 128(%rsp),%r9
+ movq %rdi,%rax
+ movq %rsi,%rdi
+ movq %rdx,%rsi
+ movq %rcx,%rdx
+ movq %r8,%r10
+ movq %r9,%r8
+ movq 8(%rsp),%r9
syscall
- popq %r11
- popq %rcx
- popq %r9
- popq %r8
- popq %r10
- popq %rdx
- popq %rsi
- popq %rdi
- popq %rbp
ret
diff --git a/libstd/syscall+linux-x64.s b/libstd/syscall+linux-x64.s
index 0393497..f7c020d 100644
--- a/libstd/syscall+linux-x64.s
+++ b/libstd/syscall+linux-x64.s
@@ -1,15 +1,5 @@
.globl sys$syscall
sys$syscall:
- pushq %rbp
- pushq %rdi
- pushq %rsi
- pushq %rdx
- pushq %r10
- pushq %r8
- pushq %r9
- pushq %rcx
- pushq %r11
-
/*
hack: We load 6 args regardless of
how many we actually have. This may
@@ -17,25 +7,16 @@ sys$syscall:
doesn't use them, it's going to be
harmless.
*/
- movq 80 (%rsp),%rax
- /* 88: hidden type arg */
- movq 96 (%rsp),%rdi
- movq 104(%rsp),%rsi
- movq 112(%rsp),%rdx
- movq 120(%rsp),%r10
- movq 128(%rsp),%r8
- movq 136(%rsp),%r9
+ movq %rdi,%rax
+ /* 8(%rsp): hidden type arg */
+ movq 16(%rsp),%rdi
+ movq 24(%rsp),%rsi
+ movq 32(%rsp),%rdx
+ movq 40(%rsp),%r10
+ movq 48(%rsp),%r8
+ movq 56(%rsp),%r9
syscall
- popq %r11
- popq %rcx
- popq %r9
- popq %r8
- popq %r10
- popq %rdx
- popq %rsi
- popq %rdi
- popq %rbp
ret
diff --git a/libstd/syscall+osx-x64.s b/libstd/syscall+osx-x64.s
index 18968e6..8fc1d4c 100644
--- a/libstd/syscall+osx-x64.s
+++ b/libstd/syscall+osx-x64.s
@@ -1,14 +1,6 @@
.globl _sys$syscall
_sys$syscall:
- pushq %rbp
- pushq %rdi
- pushq %rsi
- pushq %rdx
- pushq %r10
- pushq %r8
- pushq %r9
- pushq %rcx
- pushq %r11
+
/*
hack: We load 6 args regardless of
how many we actually have. This may
@@ -16,29 +8,20 @@ _sys$syscall:
doesn't use them, it's going to be
harmless.
*/
- movq 80 (%rsp),%rax
- /* 88: hidden type arg */
- movq 96 (%rsp),%rdi
- movq 104(%rsp),%rsi
- movq 112(%rsp),%rdx
- movq 120(%rsp),%r10
- movq 128(%rsp),%r8
- movq 136(%rsp),%r9
+ movq %rdi,%rax
+ /* 8(%rsp): hidden type arg */
+ movq 16(%rsp),%rdi
+ movq 24(%rsp),%rsi
+ movq 32(%rsp),%rdx
+ movq 40(%rsp),%r10
+ movq 48(%rsp),%r8
+ movq 56(%rsp),%r9
syscall
jae .success
negq %rax
.success:
- popq %r11
- popq %rcx
- popq %r9
- popq %r8
- popq %r10
- popq %rdx
- popq %rsi
- popq %rdi
- popq %rbp
ret
/*
@@ -51,16 +34,6 @@ _sys$syscall:
*/
.globl _sys$__osx_fork
_sys$__osx_fork:
- pushq %rbp
- pushq %rdi
- pushq %rsi
- pushq %rdx
- pushq %r10
- pushq %r8
- pushq %r9
- pushq %rcx
- pushq %r11
-
movq $0x2000002,%rax
syscall
@@ -72,16 +45,6 @@ _sys$__osx_fork:
jz .isparent
xorq %rax,%rax
.isparent:
-
- popq %r11
- popq %rcx
- popq %r9
- popq %r8
- popq %r10
- popq %rdx
- popq %rsi
- popq %rdi
- popq %rbp
ret
/*
@@ -91,16 +54,6 @@ _sys$__osx_fork:
*/
.globl _sys$__osx_pipe
_sys$__osx_pipe:
- pushq %rbp
- pushq %rdi
- pushq %rsi
- pushq %rdx
- pushq %r10
- pushq %r8
- pushq %r9
- pushq %rcx
- pushq %r11
-
movq $0x200002a,%rax
syscall
@@ -112,30 +65,10 @@ _sys$__osx_pipe:
movl %eax,(%rdi)
movl %edx,4(%rdi)
xorq %rax,%rax
-
- popq %r11
- popq %rcx
- popq %r9
- popq %r8
- popq %r10
- popq %rdx
- popq %rsi
- popq %rdi
- popq %rbp
ret
.globl _sys$__osx_lseek
_sys$__osx_lseek:
- pushq %rbp
- pushq %rdi
- pushq %rsi
- pushq %rdx
- pushq %r10
- pushq %r8
- pushq %r9
- pushq %rcx
- pushq %r11
-
movq $0x20000C7,%rax
syscall
@@ -146,31 +79,11 @@ _sys$__osx_lseek:
movq 80(%rsp),%rdi
shlq $32,%rdx
orq %rdx,%rax
-
- popq %r11
- popq %rcx
- popq %r9
- popq %r8
- popq %r10
- popq %rdx
- popq %rsi
- popq %rdi
- popq %rbp
ret
.globl _sys$__osx_gettimeofday
_sys$__osx_gettimeofday:
- pushq %rbp
- pushq %rdi
- pushq %rsi
- pushq %rdx
- pushq %r10
- pushq %r8
- pushq %r9
- pushq %rcx
- pushq %r11
-
movq $0x2000074,%rax
syscall
@@ -182,15 +95,5 @@ _sys$__osx_gettimeofday:
movq %rax, (%rdi)
movl %edx,8(%rdi)
xorq %rax,%rax
-
- popq %r11
- popq %rcx
- popq %r9
- popq %r8
- popq %r10
- popq %rdx
- popq %rsi
- popq %rdi
- popq %rbp
ret
diff --git a/libstd/util+posixy-x64.s b/libstd/util+posixy-x64.s
index b6a9b85..d44ab79 100644
--- a/libstd/util+posixy-x64.s
+++ b/libstd/util+posixy-x64.s
@@ -56,10 +56,9 @@ sys$alloca:
pushq %rbx
movq 8(%rbp),%r15 /* ret addr */
- movq 16(%rbp),%rbx /* len */
/* get stack space */
- subq %rbx,%rsp /* get stack space */
+ subq %rdi,%rsp /* get stack space */
movq %rsp,%rax /* top of stack (return value) */
subq $31,%rsp /* "unpop" the args for return */
andq $(~15),%rsp /* align */
diff --git a/libstd/varargs.myr b/libstd/varargs.myr
index e0948a6..c2ed1b2 100644
--- a/libstd/varargs.myr
+++ b/libstd/varargs.myr
@@ -77,6 +77,9 @@ const vabytes = {ap
-> sl
}
+const inspectarg = {x
+}
+
generic vanext = {ap -> @a
var v : @a
var ti
@@ -87,6 +90,7 @@ generic vanext = {ap -> @a
/* apply the alignment to the arg pointer */
align = ti.align castto(intptr)
+ inspectarg(align)
p = ap.args castto(intptr)
p = (p + align - 1) & ~(align - 1)
ap.args = p castto(byte#)