-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.s
60 lines (58 loc) · 923 Bytes
/
mem.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
.text
.globl mymalloc
.globl runGC
.extern _mymalloc
.extern _runGC
mymalloc:
# nuke caller-saved registers except argument(s)
xor %rax, %rax
xor %rcx, %rcx
xor %rdx, %rdx
xor %rsi, %rsi
xor %r8, %r8
xor %r9, %r9
xor %r10, %r10
xor %r11, %r11
push %rbp
mov %rsp, %rbp
# move possible register roots on stack
push %rbx
push %r12
push %r13
push %r14
push %r15
# put marker on stack
push $0x12abcdef
sub $16, %rsp
movabsq $_mymalloc, %rax
call *%rax
mov %rbp, %rsp
pop %rbp
ret
runGC:
# nuke all caller-saved registers
xor %rax, %rax
xor %rcx, %rcx
xor %rdx, %rdx
xor %rsi, %rsi
xor %rdi, %rdi
xor %r8, %r8
xor %r9, %r9
xor %r10, %r10
xor %r11, %r11
push %rbp
mov %rsp, %rbp
# move possible register roots on stack
push %rbx
push %r12
push %r13
push %r14
push %r15
# put marker on stack
push $0x12abcdef
sub $16, %rsp
movabsq $_runGC, %rax
call *%rax
mov %rbp, %rsp
pop %rbp
ret