Skip to content

Commit

Permalink
i#1569 AArch64: Implement dynamorio_app_take_over.
Browse files Browse the repository at this point in the history
  • Loading branch information
egrimley-arm committed Jun 3, 2016
1 parent 9e4b83b commit a64a62e
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions core/arch/aarch64/aarch64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ GLOBAL_LABEL(dr_app_start:)

DECLARE_EXPORTED_FUNC(dr_app_take_over)
GLOBAL_LABEL(dr_app_take_over:)
bl GLOBAL_REF(unexpected_return) /* FIXME i#1569: NYI */
b GLOBAL_REF(dynamorio_app_take_over)
END_FUNC(dr_app_take_over)

DECLARE_EXPORTED_FUNC(dr_app_running_under_dynamorio)
Expand All @@ -139,9 +139,53 @@ GLOBAL_LABEL(dr_app_running_under_dynamorio:)
END_FUNC(dr_app_running_under_dynamorio)
#endif /* DR_APP_EXPORTS */

/* sizeof(priv_mcontext_t) rounded up to a multiple of 16 */
#define PRIV_MCONTEXT_SIZE 800

DECLARE_EXPORTED_FUNC(dynamorio_app_take_over)
GLOBAL_LABEL(dynamorio_app_take_over:)
bl GLOBAL_REF(unexpected_return) /* FIXME i#1569: NYI */
/* Save FP and LR for the case that DR is not taking over. */
stp x29, x30, [sp, #-16]!
/* Build a priv_mcontext_t on the stack. */
sub sp, sp, #PRIV_MCONTEXT_SIZE
stp x0, x1, [sp, #(0 * ARG_SZ*2)]
stp x2, x3, [sp, #(1 * ARG_SZ*2)]
stp x4, x5, [sp, #(2 * ARG_SZ*2)]
stp x6, x7, [sp, #(3 * ARG_SZ*2)]
stp x8, x9, [sp, #(4 * ARG_SZ*2)]
stp x10, x11, [sp, #(5 * ARG_SZ*2)]
stp x12, x13, [sp, #(6 * ARG_SZ*2)]
stp x14, x15, [sp, #(7 * ARG_SZ*2)]
stp x16, x17, [sp, #(8 * ARG_SZ*2)]
stp x18, x19, [sp, #(9 * ARG_SZ*2)]
stp x20, x21, [sp, #(10 * ARG_SZ*2)]
stp x22, x23, [sp, #(11 * ARG_SZ*2)]
stp x24, x25, [sp, #(12 * ARG_SZ*2)]
stp x26, x27, [sp, #(13 * ARG_SZ*2)]
stp x28, x29, [sp, #(14 * ARG_SZ*2)]
add x0, sp, #(PRIV_MCONTEXT_SIZE + 16) /* compute original SP */
stp x30, x0, [sp, #(15 * ARG_SZ*2)]
str x30, [sp, #(16 * ARG_SZ*2)] /* save LR as PC */
mrs x1, nzcv
mrs x2, fpcr
mrs x3, fpsr
str w1, [sp, #(16 * ARG_SZ*2 + 8)]
str w2, [sp, #(16 * ARG_SZ*2 + 12)]
str w3, [sp, #(16 * ARG_SZ*2 + 16)]
add x4, sp, #(16 * ARG_SZ*2 + 20) /* offsetof(priv_mcontext_t, simd) */
st1 {v0.2d-v3.2d}, [x4], #64
st1 {v4.2d-v7.2d}, [x4], #64
st1 {v8.2d-v11.2d}, [x4], #64
st1 {v12.2d-v15.2d}, [x4], #64
st1 {v16.2d-v19.2d}, [x4], #64
st1 {v20.2d-v23.2d}, [x4], #64
st1 {v24.2d-v27.2d}, [x4], #64
st1 {v28.2d-v31.2d}, [x4], #64
CALLC1(GLOBAL_REF(dynamorio_app_take_over_helper), sp)
/* If we get here, DR is not taking over. */
add sp, sp, #PRIV_MCONTEXT_SIZE
ldp x29, x30, [sp], #16
ret
END_FUNC(dynamorio_app_take_over)

/*
Expand Down

0 comments on commit a64a62e

Please sign in to comment.