Experiments with x86_64 syscalls from assembler on OS X 10.6.
--- a/.hgignore Tue Feb 07 11:34:20 2012 -0500
+++ b/.hgignore Sun Oct 07 22:29:10 2012 -0400
@@ -7,6 +7,9 @@
*.Plo
syntax: regexp
+
+^experiments/assembly/tiny_osx\.macho$
+
^experiments/codegen/tinyscheme[^/]*/scheme$
^experiments/codegen/shell$
--- a/experiments/assembly/Makefile Tue Feb 07 11:34:20 2012 -0500
+++ b/experiments/assembly/Makefile Sun Oct 07 22:29:10 2012 -0400
@@ -15,5 +15,8 @@
tiny.elf: tiny.S elfheader.S
gcc -nostdlib -o tiny.elf tiny.S
+tiny_osx.macho: tiny_osx.S machoheader.S
+ gcc -nostdlib -o tiny_osx.macho tiny_osx.S
+
clean:
rm -f $(TARGETS)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/experiments/assembly/machoheader.S Sun Oct 07 22:29:10 2012 -0400
@@ -0,0 +1,8 @@
+# Based on the teachings of http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
+# and the content of https://developer.apple.com/library/mac/#documentation/developertools/conceptual/MachORuntime/Reference/reference.html
+
+origin:
+machoheader:
+ .long 0xfeedfacf # MH_MAGIC_64
+
+ // Totally unfinished, so far. See tiny_osx.S.
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/experiments/assembly/tiny_osx.S Sun Oct 07 22:29:10 2012 -0400
@@ -0,0 +1,29 @@
+#include <sys/syscall.h>
+ .text
+ .code64
+
+//#include "machoheader.S"
+origin:
+
+ .globl start
+start:
+ // 16-byte stack alignment for system calls??
+ andq $0xfffffffffffffff0, %rsp
+
+ movq $1, %rdi
+ leaq hello(%rip), %rsi
+ movl hellolen(%rip), %edx
+ movq $(0x2000000 | SYS_write), %rax
+ syscall
+
+ movq $0, %rdi
+ movq $(0x2000000 | SYS_exit), %rax
+ syscall
+
+hello:
+ .ascii "Hello, world!\n"
+hellolen:
+ .long . - hello
+
+fileend:
+ .set memsize, fileend - origin