Skip to content

Commit

Permalink
WIP add update_base_pointer macro
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgilchrist committed Aug 11, 2024
1 parent 102a2a2 commit 104ff0e
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions runtime/arm64.S
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,30 @@ END_FUNCTION(caml_callback3_asm)
LEAVE_FUNCTION
.endm

/* Updates the oldest saved frame pointer in the target fiber.
A fiber stack may need to grow, causing the reallocation of the entire fiber,
including stack_info and stack_handler structures.
caml_try_realloc_stack will not be able to update the linked list of
frame-pointers if it has been split (ie, in a continuation).
caml_resume and caml_reperform use this macro to update the oldest saved fp (x29)
(highest one in the stack) in case the fiber was reallocated to reattach the
frame-pointer linked list.
REG: Stack_handler(target_fiber)
The frame pointer will be pushed into the stack immediately after these
instructions. The offset of the oldest saved fp in a fiber from the stack
handler is 48 = 4 words (caml_runstack) + 2 words (lr (x30) and fp (x29)).
*/
#ifdef WITH_FRAME_POINTERS
#define UPDATE_BASE_POINTER(REG) \
;; ldr TMP, [sp, -8]; \
;; str TMP, [REG, -48]
#else
#define UPDATE_BASE_POINTER(REG)
#endif


/*
* A continuation is a one word object that points to a fiber. A fiber [f] will
Expand Down Expand Up @@ -1070,7 +1094,7 @@ FUNCTION(caml_reperform)
add x3, x2, 1 /* x3 (last_fiber) := Val_ptr(old stack) */
/* Need to update the oldest saved frame pointer here as the execution of
the handler may have caused the current fiber stack to reallocate. */
/* TODO */
/* TODO call UPDATE_BASE_POINTERS (x2) */
b L(do_perform)
CFI_ENDPROC
END_FUNCTION(caml_reperform)
Expand Down Expand Up @@ -1121,7 +1145,10 @@ FUNCTION(caml_resume)
/* Need to update the oldest saved frame pointer here as the current fiber
stack may have been reallocated or we may be resuming a computation
that was not originally run here. */
/* TODO */
/* TODO UPDATE_BASE_POINTER(x8)
When we switch stacks to x9, then we loose the placeholder for
where we were resumed from?
*/
SWITCH_OCAML_STACKS x9, x0
mov x0, x2
br x4
Expand Down

0 comments on commit 104ff0e

Please sign in to comment.