summaryrefslogtreecommitdiff
path: root/libstd/util+posixy-x64.s
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-12-23 16:41:38 -0800
committerOri Bernstein <ori@eigenstate.org>2014-12-23 16:41:38 -0800
commitfc5368fb01485128fbead0818c0136cc83e750be (patch)
tree7d0e5931d586502f76cf8300e5a6b37cb810da20 /libstd/util+posixy-x64.s
parentad1e9d7670685b9fffcdcacc9515b5919afa4c97 (diff)
downloadmc-fc5368fb01485128fbead0818c0136cc83e750be.tar.gz
Assembly is system specific.
Name it as such.
Diffstat (limited to 'libstd/util+posixy-x64.s')
-rw-r--r--libstd/util+posixy-x64.s73
1 files changed, 73 insertions, 0 deletions
diff --git a/libstd/util+posixy-x64.s b/libstd/util+posixy-x64.s
new file mode 100644
index 0000000..2166ecc
--- /dev/null
+++ b/libstd/util+posixy-x64.s
@@ -0,0 +1,73 @@
+/*
+ * Allocates a C string on the stack, for
+ * use within system calls, which is the only
+ * place the Myrddin stack should need nul-terminated
+ * strings.
+ *
+ * This is in assembly, because for efficiency we
+ * allocate the C strings on the stack, and don't adjust
+ * %rsp when returning.
+ */
+.globl sys$cstring
+.globl _sys$cstring
+_sys$cstring:
+sys$cstring:
+ /* save registers */
+ pushq %rbp
+ movq %rsp,%rbp
+ pushq %r15
+ pushq %rsi
+ pushq %rdi
+ pushq %rcx
+
+ movq 8(%rbp),%r15 /* ret addr */
+ movq 16(%rbp),%rsi /* src */
+ movq 24(%rbp),%rcx /* len */
+
+ subq %rcx,%rsp /* get stack */
+ subq $1,%rsp /* +1 for nul */
+ movq %rsp,%rdi /* dest */
+ movq %rsp,%rax /* ret val */
+ subq $16,%rsp /* "unpop" the args */
+ andq $(~15),%rsp /* align */
+
+ cld
+ rep movsb
+ movb $0,(%rdi) /* terminate */
+
+ pushq %r15 /* ret addr */
+
+ /* restore registers */
+ movq -32(%rbp),%rcx
+ movq -24(%rbp),%rdi
+ movq -16(%rbp),%rsi
+ movq -8(%rbp),%r15
+ movq (%rbp),%rbp
+ ret
+
+.globl sys$alloca
+.globl _sys$alloca
+_sys$alloca:
+sys$alloca:
+ /* save registers */
+ pushq %rbp
+ movq %rsp,%rbp
+ pushq %r15
+ pushq %rbx
+
+ movq 8(%rbp),%r15 /* ret addr */
+ movq 16(%rbp),%rbx /* len */
+
+ /* get stack space */
+ subq %rbx,%rsp /* get stack space */
+ movq %rsp,%rax /* top of stack (return value) */
+ subq $16,%rsp /* "unpop" the args for return */
+ andq $(~15),%rsp /* align */
+
+ pushq %r15 /* ret addr */
+
+ /* restore registers */
+ movq -16(%rbp),%rbx
+ movq -8(%rbp),%r15
+ movq (%rbp),%rbp
+ ret