lama_byterun/runtime/gc_runtime.s

114 lines
1.9 KiB
ArmAsm
Raw Normal View History

2023-05-31 11:01:11 +02:00
.data
2018-11-21 14:23:35 +03:00
__gc_stack_bottom: .long 0
2023-05-31 11:01:11 +02:00
__gc_stack_top: .long 0
2018-12-05 18:31:12 +03:00
2023-05-31 11:01:11 +02:00
.globl __pre_gc
.globl __post_gc
.globl __gc_init
.globl __gc_root_scan_stack
.globl __gc_stack_top
.globl __gc_stack_bottom
.extern __init
.extern gc_test_and_mark_root
.text
2018-12-11 10:22:23 +03:00
__gc_init:
2023-05-31 11:01:11 +02:00
movl %ebp, __gc_stack_bottom
addl $4, __gc_stack_bottom
call __init
ret
2018-11-21 14:23:35 +03:00
// if __gc_stack_top is equal to 0
// then set __gc_stack_top to %ebp
// else return
2018-12-05 18:31:12 +03:00
__pre_gc:
2023-05-31 11:01:11 +02:00
pushl %eax
movl __gc_stack_top, %eax
cmpl $0, %eax
jne __pre_gc_2
movl %ebp, %eax
// addl $8, %eax
movl %eax, __gc_stack_top
__pre_gc_2:
2023-05-31 11:01:11 +02:00
popl %eax
ret
2018-12-11 10:22:23 +03:00
// if __gc_stack_top has been set by the caller
// (i.e. it is equal to its %ebp)
// then set __gc_stack_top to 0
// else return
__post_gc:
2023-05-31 11:01:11 +02:00
pushl %eax
movl __gc_stack_top, %eax
cmpl %eax, %ebp
jnz __post_gc2
movl $0, __gc_stack_top
__post_gc2:
2023-05-31 11:01:11 +02:00
popl %eax
ret
// Scan stack for roots
// strting from __gc_stack_top
// till __gc_stack_bottom
2018-11-21 14:23:35 +03:00
__gc_root_scan_stack:
2023-05-31 11:01:11 +02:00
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %edx
movl __gc_stack_top, %eax
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:
2023-05-31 11:01:11 +02:00
leal __executable_start, %edx
cmpl %ebx, %edx
jna check12
jmp check21
2018-11-21 14:23:35 +03:00
check12:
2023-05-31 11:01:11 +02:00
leal __etext, %edx
cmpl %ebx, %edx
jnb next
2018-11-21 14:23:35 +03:00
// 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:
2023-05-31 11:01:11 +02:00
cmpl %ebx, __gc_stack_top
jna check22
jmp loop2
2018-11-21 14:23:35 +03:00
check22:
2023-05-31 11:01:11 +02:00
cmpl %ebx, __gc_stack_bottom
jnb next
2018-11-21 14:23:35 +03:00
// check if it a valid pointer
// i.e. the lastest bit is set to zero
loop2:
2023-05-31 11:01:11 +02:00
andl $0x00000001, %ebx
jnz next
2018-11-29 18:27:59 +03:00
gc_run_t:
2023-05-31 11:01:11 +02:00
pushl %eax
pushl %eax
call gc_test_and_mark_root
addl $4, %esp
popl %eax
2018-11-21 14:23:35 +03:00
next:
2023-05-31 11:01:11 +02:00
addl $4, %eax
cmpl %eax, __gc_stack_bottom
jne loop
2018-11-29 18:27:59 +03:00
returnn:
2023-05-31 11:01:11 +02:00
movl $0, %eax
popl %edx
popl %ebx
movl %ebp, %esp
popl %ebp
ret