ref: b43c9855d957cb62e91425cf645a379e44bb883d
parent: bccf793446bc1afadce825b98000c3664544d114
author: Ori Bernstein <[email protected]>
date: Thu Sep 27 15:20:29 EDT 2012
Make CLI args work on OSX.
--- a/libstd/start-osx.s
+++ b/libstd/start-osx.s
@@ -1,11 +1,55 @@
+/*
+ * counts the length of the string pointed to
+ * by %rbx, returning len in %r9
+ */
+cstrlen:
+ xorq %r9,%r9
+ jmp .lentest
+
+ .lenloop:
+ incq %r9
+ .lentest:
+ cmpb $0,(%r8,%r9)
+ jne .lenloop
+ ret
+
.globl start
start:
- /* turn args into a slice */
- /* TODO */
- /* enter the main program */
- call _main
- /* exit */
- movq %rax,%rdi
- movq $0x2000001,%rax
- syscall
+ /* turn args into a slice */
+ movq %rsp,%rbp
+ /* stack allocate sizeof(byte[:])*argc */
+ movq (%rbp),%rax
+ imulq $16,%rax
+ subq %rax,%rsp
+ movq %rsp, %rdx /* saved args[:] */
+
+ /* iterate over the strings for argc, and put
+ * them into the args array. */
+ movq (%rbp), %rax /* argc */
+ leaq 8(%rbp), %rbx /* argv */
+ movq %rsp, %rcx
+ movq (%rbp), %rsi /* saved argc */
+
+ testq %rax,%rax
+ jz .cvtdone
+ .cvtloop:
+ subq $1,%rax
+ movq (%rbx),%r8
+ call cstrlen
+ movq %r8, (%rcx)
+ movq %r9, 8(%rcx)
+ addq $8, %rbx
+ addq $16, %rcx
+ testq %rax,%rax
+ jnz .cvtloop
+ .cvtdone:
+ pushq %rsi
+ pushq %rdx
+
+ /* enter the main program */
+ call _main
+ /* exit */
+ movq %rax,%rdi
+ movq $0x2000001,%rax
+ syscall
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -15,6 +15,7 @@
/* make libparse happy */
Node *file;
+char *filename;
char *libname;
char *binname;
@@ -86,21 +87,7 @@
if (libname && binname)
die("Can't specify both library and binary names");
- switch (regcomp(&usepat, "^[[:space:]]*use[[:space:]]+([^[:space:]]+)", REG_EXTENDED)) {
- case REG_BADBR: die("case REG_BADBR:"); break;
- case REG_BADPAT: die("case REG_BADPAT:"); break;
- case REG_BADRPT: die("case REG_BADRPT:"); break;
- case REG_EBRACE: die("case REG_EBRACE:"); break;
- case REG_EBRACK: die("case REG_EBRACK:"); break;
- case REG_ECOLLATE: die("case REG_ECOLLATE:"); break;
- case REG_EEND: die("case REG_EEND:"); break;
- case REG_EESCAPE: die("case REG_EESCAPE:"); break;
- case REG_EPAREN: die("case REG_EPAREN:"); break;
- case REG_ERANGE: die("case REG_ERANGE:"); break;
- case REG_ESIZE: die("case REG_ESIZE:"); break;
- case REG_ESPACE: die("case REG_ESPACE:"); break;
- case REG_ESUBREG: die("case REG_ESUBREG:"); break;
- }
+ regcomp(&usepat, "^[[:space:]]*use[[:space:]]+([^[:space:]]+)", REG_EXTENDED);
for (i = optind; i < argc; i++)
getdeps(argv[i]);