-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcall_scheme.s
72 lines (66 loc) · 1.91 KB
/
call_scheme.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
.data
.globl _stack_bottom, _gc_free, _heap_end, _global_refs, context_fp
.align 4
_stack_bottom:
.long 0
_gc_free:
.long 0
_heap_end:
.long 0
_global_refs:
.long 0
context_fp:
.long 0
.text
.code32
.globl _call_scheme
_call_scheme:
pushl %ebx
pushl %esi
pushl %edi
pushl %ebp
subl $12, %esp # balance the c-stack onto a 16-byte boundary for OS X
# 1 return addr + 4 regs + 3 paddings = 8 words
movl $0, %esi # cp=0
movl _gc_free, %edi # ap
movl _stack_bottom, %ebp # fp
addl $4, %ebp
movl $0, -4(%ebp) # fp[-1]=size of the frame (indeterminate)
movl $return_from_scheme, (%ebp) # fp[0]=return address
movl $0, %ebx # t1=0 (number of arguments)
jmp _scheme_entry
return_from_scheme:
addl $12, %esp
popl %ebp
popl %edi
popl %esi
popl %ebx
ret
.globl _call_closure
_call_closure:
pushl %ebx
pushl %esi
pushl %edi
pushl %ebp
subl $12, %esp # 16-byte alignment
movl _global_refs, %eax # ac=contents of vector
addl $-1, %eax # -vector-tag+ws = -1
movl 4(%eax), %esi # cp=global_refs[1]
subl $6, %esi # remove closure-tag
movl _gc_free, %edi # ap
movl context_fp, %ebp # fp
movl $return_from_closure, (%ebp) # fp[0]=return address
movl (%eax), %eax # ac=global_refs[0]
movl %eax, 4(%ebp) # fp[1]=ac
movl $1, %ebx # t1=1
jmp *4(%esi)
return_from_closure:
sarl $3, %eax # fixnum->int
movl %ebp, context_fp
movl %edi, _gc_free
addl $12, %esp
popl %ebp
popl %edi
popl %esi
popl %ebx
ret