Skip to content

Commit

Permalink
i#1569 AArch64: Implement dr_app_start and dr_app_running_under_dynam…
Browse files Browse the repository at this point in the history
…orio.

Tests api.static_{startstop,noclient,noinit} still fail for other reasons.

Review-URL: https://codereview.appspot.com/307250043
  • Loading branch information
egrimley-arm committed Sep 12, 2016
1 parent a4d1705 commit 82dadac
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 31 deletions.
86 changes: 55 additions & 31 deletions core/arch/aarch64/aarch64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,59 @@ GLOBAL_LABEL(dr_call_on_clean_stack:)
#ifndef NOT_DYNAMORIO_CORE_PROPER

#ifdef DR_APP_EXPORTS

/* Save priv_mcontext_t, except for X0, X1, X30, SP and PC, to the address in X0.
* Typically the caller will save those five registers itself before calling this.
* Clobbers X1-X4.
*/
save_priv_mcontext_helper:
stp x2, x3, [x0, #(1 * ARG_SZ*2)]
stp x4, x5, [x0, #(2 * ARG_SZ*2)]
stp x6, x7, [x0, #(3 * ARG_SZ*2)]
stp x8, x9, [x0, #(4 * ARG_SZ*2)]
stp x10, x11, [x0, #(5 * ARG_SZ*2)]
stp x12, x13, [x0, #(6 * ARG_SZ*2)]
stp x14, x15, [x0, #(7 * ARG_SZ*2)]
stp x16, x17, [x0, #(8 * ARG_SZ*2)]
stp x18, x19, [x0, #(9 * ARG_SZ*2)]
stp x20, x21, [x0, #(10 * ARG_SZ*2)]
stp x22, x23, [x0, #(11 * ARG_SZ*2)]
stp x24, x25, [x0, #(12 * ARG_SZ*2)]
stp x26, x27, [x0, #(13 * ARG_SZ*2)]
stp x28, x29, [x0, #(14 * ARG_SZ*2)]
mrs x1, nzcv
mrs x2, fpcr
mrs x3, fpsr
str w1, [x0, #(16 * ARG_SZ*2 + 8)]
str w2, [x0, #(16 * ARG_SZ*2 + 12)]
str w3, [x0, #(16 * ARG_SZ*2 + 16)]
add x4, x0, #simd_OFFSET
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
ret

DECLARE_EXPORTED_FUNC(dr_app_start)
GLOBAL_LABEL(dr_app_start:)
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)]
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 */
CALLC1(save_priv_mcontext_helper, sp)
CALLC1(GLOBAL_REF(dr_app_start_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(dr_app_start)

DECLARE_EXPORTED_FUNC(dr_app_take_over)
Expand All @@ -161,8 +211,10 @@ GLOBAL_LABEL(dr_app_take_over:)

DECLARE_EXPORTED_FUNC(dr_app_running_under_dynamorio)
GLOBAL_LABEL(dr_app_running_under_dynamorio:)
bl GLOBAL_REF(unexpected_return) /* FIXME i#1569: NYI */
movz w0, #0 /* This instruction is manged by mangle_pre_client. */
ret
END_FUNC(dr_app_running_under_dynamorio)

#endif /* DR_APP_EXPORTS */

DECLARE_EXPORTED_FUNC(dynamorio_app_take_over)
Expand All @@ -172,38 +224,10 @@ GLOBAL_LABEL(dynamorio_app_take_over:)
/* 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, #simd_OFFSET
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(save_priv_mcontext_helper, sp)
CALLC1(GLOBAL_REF(dynamorio_app_take_over_helper), sp)
/* If we get here, DR is not taking over. */
add sp, sp, #PRIV_MCONTEXT_SIZE
Expand Down
1 change: 1 addition & 0 deletions core/arch/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3144,6 +3144,7 @@ mangle_pre_client(dcontext_t *dcontext, build_bb_t *bb)
IF_X86(instr_get_opcode(mov) == OP_mov_imm &&)
IF_ARM(instr_get_opcode(mov) == OP_mov &&
OPND_IS_IMMED_INT(instr_get_src(mov, 0)) &&)
IF_AARCH64(instr_get_opcode(mov) == OP_movz &&)
(bb->start_pc == instr_get_raw_bits(mov) ||
/* the translation field might be NULL */
bb->start_pc == instr_get_translation(mov)));
Expand Down

0 comments on commit 82dadac

Please sign in to comment.