ref: 3e35cbe5f783ddfb57747e53ee3b70454b71001e
parent: 86406b0c185d4121a41aa7484702e0e6d158540c
author: Ori Bernstein <[email protected]>
date: Tue Dec 23 11:41:38 EST 2014
Assembly is system specific. Name it as such.
--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -73,6 +73,9 @@
all: lib$(STDLIB).a $(MYRBIN)
+%.myr: %+$(SYSCLASS)-$(ARCH).myr
+ cp $< $@
+
%.myr: %+$(SYSCLASS).myr
cp $< $@
@@ -85,7 +88,7 @@
%.myr: %+$(ARCH).myr
cp $< $@
-%.s: %+$(SYSCLASS).s
+%.s: %+$(SYSCLASS)-$(ARCH).s
cp $< $@
%.s: %+$(SYS)-$(ARCH).s
--- /dev/null
+++ b/libstd/util+plan9-x64.s
@@ -1,0 +1,71 @@
+/*
+ * 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
+ * SP when returning.
+ */
+TEXT sys$cstring+0(SB),$0
+ /* save registers */
+ PUSHQ BP
+ MOVQ SP,BP
+ PUSHQ R15
+ PUSHQ SI
+ PUSHQ DI
+ PUSHQ CX
+
+ MOVQ 8(BP),R15 /* ret addr */
+ MOVQ 16(BP),SI /* src */
+ MOVQ 24(BP),CX /* len */
+
+ SUBQ CX,SP /* get stack */
+ SUBQ $1,SP /* +1 for nul */
+ MOVQ SP,DI /* dest */
+ MOVQ SP,AX /* ret val */
+ SUBQ $16,SP /* "unpop" the args */
+ ANDQ $(~15),SP /* align */
+
+ CLD
+ REP; MOVSB
+ MOVB $0,(DI) /* terminate */
+
+ PUSHQ R15 /* ret addr */
+
+ /* Restore registers */
+ MOVQ -32(BP),CX
+ MOVQ -24(BP),DI
+ MOVQ -16(BP),SI
+ MOVQ -8(BP),R15
+ MOVQ (BP),BP
+ RET
+
+TEXT sys$alloca+0(SB),$0
+ /* save registers */
+ PUSHQ BP
+ MOVQ SP,BP
+ PUSHQ R15
+ PUSHQ BX
+
+ MOVQ 8(BP),R15 /* ret addr */
+ MOVQ 16(BP),BX /* len */
+
+ /* get stack space */
+ SUBQ BX,SP /* get stack space */
+ MOVQ SP,AX /* top of stack (return value) */
+ SUBQ $16,SP /* "unpop" the args for return */
+ ANDQ $(~15),SP /* align */
+
+ PUSHQ R15 /* ret addr */
+
+ /* restore registers */
+ MOVQ -16(BP),BX
+ MOVQ -8(BP),R15
+ MOVQ (BP),BP
+ RET
+
+TEXT sys$gettos+0(SB),$0
+ LEAQ _tos+0(SB),AX
+ RET
--- a/libstd/util+plan9.s
+++ /dev/null
@@ -1,71 +1,0 @@
-/*
- * 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
- * SP when returning.
- */
-TEXT sys$cstring+0(SB),$0
- /* save registers */
- PUSHQ BP
- MOVQ SP,BP
- PUSHQ R15
- PUSHQ SI
- PUSHQ DI
- PUSHQ CX
-
- MOVQ 8(BP),R15 /* ret addr */
- MOVQ 16(BP),SI /* src */
- MOVQ 24(BP),CX /* len */
-
- SUBQ CX,SP /* get stack */
- SUBQ $1,SP /* +1 for nul */
- MOVQ SP,DI /* dest */
- MOVQ SP,AX /* ret val */
- SUBQ $16,SP /* "unpop" the args */
- ANDQ $(~15),SP /* align */
-
- CLD
- REP; MOVSB
- MOVB $0,(DI) /* terminate */
-
- PUSHQ R15 /* ret addr */
-
- /* Restore registers */
- MOVQ -32(BP),CX
- MOVQ -24(BP),DI
- MOVQ -16(BP),SI
- MOVQ -8(BP),R15
- MOVQ (BP),BP
- RET
-
-TEXT sys$alloca+0(SB),$0
- /* save registers */
- PUSHQ BP
- MOVQ SP,BP
- PUSHQ R15
- PUSHQ BX
-
- MOVQ 8(BP),R15 /* ret addr */
- MOVQ 16(BP),BX /* len */
-
- /* get stack space */
- SUBQ BX,SP /* get stack space */
- MOVQ SP,AX /* top of stack (return value) */
- SUBQ $16,SP /* "unpop" the args for return */
- ANDQ $(~15),SP /* align */
-
- PUSHQ R15 /* ret addr */
-
- /* restore registers */
- MOVQ -16(BP),BX
- MOVQ -8(BP),R15
- MOVQ (BP),BP
- RET
-
-TEXT sys$gettos+0(SB),$0
- LEAQ _tos+0(SB),AX
- RET
--- /dev/null
+++ b/libstd/util+posixy-x64.s
@@ -1,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