ref: 979a0dd6fec80a4fe66ced0b5e2ba30cd574abc1
parent: 5778299b7291336a05a50d7387d99c9f28013937
author: Ori Bernstein <[email protected]>
date: Mon Oct 1 21:19:03 EDT 2012
Add missing file for last commit.
--- /dev/null
+++ b/libstd/util.s
@@ -1,0 +1,29 @@
+/*
+ * 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 std$cstring
+std$cstring:
+ movq (%rsp),%r15 /* ret addr */
+ movq 8(%rsp),%rsi /* src */
+ movq %rsp,%rdi /* dest */
+ movq %rsp,%rax /* ret val */
+ movq 16(%rsp),%rcx /* len */
+
+ subq %rcx,%rsp /* get stack */
+ subq $1,%rsp /* nul */
+ andq $(~15),%rsp /* align */
+
+ cld
+ rep movsb
+ movb $0,(%rdi) /* terminate */
+
+ pushq %r15 /* ret addr */
+ ret
+