From 2bc3d9a3815a6cd172b3b4f7696c46a006021b13 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 31 Oct 2023 00:12:51 +0100 Subject: gc kinda almost there --- include/data.s | 189 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 135 insertions(+), 54 deletions(-) (limited to 'include/data.s') diff --git a/include/data.s b/include/data.s index 43d2ba8..3ee8213 100644 --- a/include/data.s +++ b/include/data.s @@ -2,40 +2,104 @@ .ifndef _data_s_file _data_s_file: -# Simple values and boxed machine integers -# | ptr | value | -CON_evacuate1: - retq # TODO -CON_scavenge1: - retq - # Format of the info tables: # - code # ----- code pointer # - 8B helper information for eval/apply (generally this is 0, and only gets used for FUN/PAP) # - 8B pointer to scavenge # - 8B pointer to evacuate +# +# Evacuate interface: +# in: %rsi continuation, %rbp what to evacuate +# out: %rbp where the thing is now +# Notes: +# - IND thunks skip themselves on evacuate +# - checking if whether stuff is already in write region are managed by _gc_evacuate prelude +# +# Scavenge interface: +# in: %rsi continuation, %rbp what to scavenge +# out: %rbp next thing to scavenge in memory +# +# Saved registers by evacuate and scavenge +# - _uskel_gc needs to preserve %rdi now; that might increase +# - scavenges use %r12-%r15 +# - %rax-%rdx is scratch and evacuate use + +# Simple values and boxed machine integers +# | ptr | value | +INT_evacuate: + pushq 010(%rbp) + pushq $INT_code + mov %rsp,%rbp + jmp *%rsi +INT_scavenge: + add $020, %rbp + jmp *%rsi INT_info_table: - cell CON_evacuate1 - cell CON_scavenge1 + cell INT_evacuate + cell INT_scavenge cell 0 INT_code: continue +# Indirection +# | ptr | indptr | +IND_evacuate: + mov 010(%rbp), %rbp + jmp _gc_evacuate +IND_scavenge: + jmp 0 # thou shalt not scavenge here + +IND_info: + cell IND_evacuate + cell IND_scavenge + cell 0 +IND_code: + enter 010(%rbp) + # List -# | ptr | 0 | -# | ptr | 1 | a | b | +# | ptr | 0 | # [] case +# | ptr | 1 | a | b | # (a:b) case LIST_evacuate: - # [] | a : b - retq #TODO + cmpq $0, 010(%rbp) + je LIST_evacuate_nil + pushq 030(%rbp) + pushq 020(%rbp) + pushq $1 + pushq $LIST_code + mov %rsp, %rbp + jmp *%rsi + LIST_evacuate_nil: + pushq $0 + pushq $LIST_code + mov %rsp, %rbp + jmp *%rsi LIST_scavenge: - mov 010(%rbp), %rax - shl $1, %rax - add $2, %rax - shl $3, %rax - add %rax, %rsi - retq + cmpq $0, 010(%rbp) + je LIST_scavenge_nil + mov %rbp, %r15 + mov %rsi, %r14 + + mov $LIST_scavenge1, %rsi + mov 020(%r15), %rbp + jmp _gc_evacuate + LIST_scavenge1: + mov %rbp, 020(%r15) + + mov $LIST_scavenge2, %rsi + mov 030(%r15), %rbp + jmp _gc_evacuate + LIST_scavenge2: + mov %rbp, 030(%r15) + + mov %r15, %rbp + add $040, %rbp + jmp *%r14 + LIST_scavenge_nil: + add $020, %rbp + jmp *%rsi + LIST_info_table: cell LIST_evacuate cell LIST_scavenge @@ -46,13 +110,14 @@ LIST_code: # FUN objects # | ptr | thunkptr | args | arg[0] | arg[1] | ... | arg[args] | FUN_evacuate: - retq #TODO + #TODO FUN_scavenge: - mov 020(%rbp), %rax - add $3, %rax - shl $3, %rax - add %rax, %rsi - retq + #TODO + #mov 020(%rbp), %rax + #add $3, %rax + #shl $3, %rax + #add %rax, %rsi + #retq # Info tables for FUN objects. FUN0_info_table: @@ -89,39 +154,55 @@ FUN4_info_table: cell 4 FUN4_code: continue +# add more funN here as needed -# TODO: add more funN here as needed - -# indirection (Q: how to recognize IND and THUNK on return?) -# | ptr | indptr | -IND_evacuate: - retq #TODO -IND_scavenge: - add $020,%rsi - retq -IND_info: - cell IND_evacuate - cell IND_scavenge - cell 0 -IND_code: - enter 010(%rbp) - -# THU objects (gc implementation only, actual THUs are defined by functions) +# THU objects (gc implementation only, actual THU data are created by functions) # | ptr | args | arg[0] | arg[1] | ... | arg[args] | # args wouldn't need to be here but let's keep them for gc simplicity THU_evacuate: - retq #TODO + mov 010(%rbp), %rbx + mov %rbx,%rdx + mov %rbx,%rcx + add $2, %rdx + shl $3, %rdx + add %rbp, %rdx + THU_evacuate_one: + dec %rcx + cmp $0, %rcx + jl THU_evacuate_fini + sub $010, %rdx + pushq (%rdx) + jmp THU_evacuate_one + THU_evacuate_fini: + pushq %rbx + pushq 000(%rbp) + mov %rsp, %rbp + jmp *%rsi THU_scavenge: - mov 010(%rbp), %rax - add $2,%rax - shl $3,%rax - add %rax,%rsi - retq + mov 010(%rbp), %r12 + mov %rbp, %r15 + mov %rsi, %r14 + mov %r12,%r13 + add $2, %r13 + shl $3, %r13 + add %r15, %r13 + THU_scavenge_one: + sub $010, %r13 + sub $1, %r12 + jl THU_scavenge_fini + mov (%r13), %rbp + mov $THU_scavenge_one_cont, %rsi + jmp _gc_evacuate + THU_scavenge_one_cont: + mov %rbp, (%r13) + jmp THU_scavenge_one + + THU_scavenge_fini: + mov %r15, %rbp + mov 010(%rbp), %r13 + add $2, %r13 + shl $3, %r13 + add %r13, %rbp + jmp *%r14 .endif # _data_s_file - -# evacuate and scavenge: -# - evacuate just copies the object -# - scavenge evacuates all children (to the new location IF they are in the old -# location), changes the pointer, and moves the scavenge pointer to the next -# object (because everything needs to be scavenged) -- cgit v1.2.3