lama_byterun/runtime/gc_runtime.s

204 lines
3 KiB
ArmAsm
Raw Normal View History

2018-11-21 14:23:35 +03:00
.data
printf_format: .string "Stack root: %lx\n"
printf_format2: .string "BOT: %lx\n"
printf_format3: .string "TOP: %lx\n"
printf_format4: .string "EAX: %lx\n"
printf_format5: .string "LOL\n"
__gc_stack_bottom: .long 0
__gc_stack_top: .long 0
2018-12-05 18:31:12 +03:00
2018-12-11 10:22:23 +03:00
.globl __set_w2
.globl __alloc_w1
.globl __alloc_w2
2018-12-05 18:31:12 +03:00
.globl __pre_gc
2018-11-29 18:27:59 +03:00
.globl L__gc_init
.globl __gc_root_scan_stack
.extern init_pool
.extern __gc_test_and_copy_root
2018-11-21 14:23:35 +03:00
.text
2018-12-11 10:22:23 +03:00
__set_w2:
pushl %ebp
movl %esp, %ebp
pushl %ecx
pushl %edx
movl 8(%ebp), %ecx
movl 12(%ebp), %edx
subl $8, %ecx
movl %edx, (%ecx)
movl $0, %eax
pushl %ecx
pushl %edx
movl %ebp, %esp
popl %ebp
ret
__alloc_w2:
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
movl 8(%ebp), %edx
pushl %edx
call alloc
addl $4, %esp
pushl $1
pushl $1
pushl $1
pushl $1
pushl $1
addl $20, %esp
movl 12(%ebp), %ecx
addl $4, %eax
movl %ecx, (%eax)
addl $4, %eax
popl %ebx
popl %ecx
popl %edx
popl %esi
popl %edi
movl %ebp, %esp
popl %ebp
ret
__alloc_w1:
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
movl 4(%ebp), %edx
pushl %edx
call alloc
pushl $1
pushl $1
pushl $1
pushl $1
pushl $1
addl $20, %esp
movl 8(%ebp), %ecx
movl %ecx, (%eax)
addl $4, %eax
popl %ebx
popl %ecx
popl %edx
popl %esi
popl %edi
movl %ebp, %esp
popl %ebp
ret
2018-11-21 14:23:35 +03:00
L__gc_init: movl %esp, __gc_stack_bottom
addl $4, __gc_stack_bottom
2018-11-29 18:27:59 +03:00
call init_pool
2018-11-21 14:23:35 +03:00
ret
2018-12-05 18:31:12 +03:00
__pre_gc:
2018-12-11 10:22:23 +03:00
// movl %ebp, __gc_stack_top
// ret
// pushl %eax
// movl (%ebp), %eax
// movl %eax, __gc_stack_top
// popl %eax
pushl %eax
movl (%ebp), %eax
addl $4, %eax
movl %eax, __gc_stack_top
popl %eax
2018-12-05 18:31:12 +03:00
ret
2018-11-21 14:23:35 +03:00
__gc_root_scan_stack:
2018-11-29 18:27:59 +03:00
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %edx
2018-12-05 18:31:12 +03:00
// pushl __gc_stack_top
// call Lwrite2
// addl $4, %esp
// pushl __gc_stack_bottom
// call Lwrite2
// addl $4, %esp
// movl %esp, __gc_stack_top
// movl %esp, %eax
movl __gc_stack_top, %eax
2018-11-29 18:27:59 +03:00
jmp next
2018-11-21 14:23:35 +03:00
loop:
movl (%eax), %ebx
// check that it is not a pointer to code section
// i.e. the following is not true:
// __executable_start <= (%eax) <= __etext
check11:
leal __executable_start, %edx
cmpl %ebx, %edx
jna check12
jmp check21
check12:
leal __etext, %edx
cmpl %ebx, %edx
jnb next
// check that it is not a pointer into the program stack
// i.e. the following is not true:
// __gc_stack_bottom <= (%eax) <= __gc_stack_top
check21:
cmpl %ebx, __gc_stack_top
jna check22
jmp loop2
check22:
cmpl %ebx, __gc_stack_bottom
jnb next
// check if it a valid pointer
// i.e. the lastest bit is set to zero
loop2:
andl $0x00000001, %ebx
jnz next
2018-11-29 18:27:59 +03:00
gc_run_t:
2018-11-21 14:23:35 +03:00
pushl %eax
2018-11-29 18:27:59 +03:00
// pushl (%eax)
pushl %eax
call __gc_test_and_copy_root
addl $4, %esp
2018-11-21 14:23:35 +03:00
popl %eax
next:
addl $4, %eax
cmpl %eax, __gc_stack_bottom
jne loop
2018-11-29 18:27:59 +03:00
returnn:
movl $0, %eax
popl %edx
popl %ebx
movl %ebp, %esp
popl %ebp
2018-11-21 14:23:35 +03:00
ret