+(define (initialize-heap)
+ (let ((mmap
+ (case target
+ ('darwin "0x20000c5")
+ ('linux "9"))))
+ ; allocate some heap memory
+ (emit "mov $~a, %rax" mmap) ; mmap
+ (emit "xor %rdi, %rdi") ; addr = null
+ (emit "movq $1024, %rsi") ; length = 1kb
+ (emit "movq $0x3, %rdx") ; prot = read | write = 0x2 | 0x1
+ ; flags = anonymous | private
+ (case target
+ ('darwin (emit "movq $0x1002, %r10")) ; anon = 0x1000, priv = 0x02
+ ('linux (emit "movq $0x22, %r10"))) ; anon = 0x20, priv = 0x02
+ (emit "movq $-1, %r8") ; fd = -1
+ (emit "xor %r9, %r9") ; offset = 0
+ (emit "syscall")
+ ; %rax now contains pointer to the start of the heap
+ ; keep track of it
+
+ (emit "movq heap_start@GOTPCREL(%rip), %rsi")
+ (emit "movq %rax, (%rsi)")))
+