|
| 1 | +#define DW_CFA_register 0x9 |
| 2 | +#define ehframe_x22 22 |
| 3 | +#define ehframe_x23 23 |
| 4 | +#define ehframe_pc 32 |
| 5 | + |
| 6 | + .section __TEXT,__text,regular,pure_instructions |
| 7 | + |
| 8 | +//-------------------------------------- |
| 9 | +// to_be_interrupted() a frameless function that does a non-ABI |
| 10 | +// function call ("is interrupted/traps" simulated) to trap(). |
| 11 | +// Before it branches to trap(), it puts its return address in |
| 12 | +// x23. trap() knows to branch back to $x23 when it has finished. |
| 13 | +//-------------------------------------- |
| 14 | + .globl _to_be_interrupted |
| 15 | + .p2align 2 |
| 16 | +_to_be_interrupted: |
| 17 | + .cfi_startproc |
| 18 | + |
| 19 | + // This is a garbage entry to ensure that eh_frame is emitted, |
| 20 | + // it isn't used for anything. If there's no eh_frame, lldb |
| 21 | + // can do an assembly emulation scan and add a rule for $lr |
| 22 | + // which won't expose the issue at hand. |
| 23 | + .cfi_escape DW_CFA_register, ehframe_x22, ehframe_x23 |
| 24 | + mov x24, x0 |
| 25 | + add x24, x24, #1 |
| 26 | + |
| 27 | + adrp x23, L_.return@PAGE ; put return address in x4 |
| 28 | + add x23, x23, L_.return@PAGEOFF |
| 29 | + |
| 30 | + b _trap ; branch to trap handler, fake async interrupt |
| 31 | + |
| 32 | +L_.return: |
| 33 | + mov x0, x24 |
| 34 | + ret |
| 35 | + .cfi_endproc |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +//-------------------------------------- |
| 40 | +// trap() trap handler function, sets up stack frame |
| 41 | +// with special unwind rule for the pc value of the |
| 42 | +// "interrupted" stack frame (it's in x23), then calls |
| 43 | +// break_to_debugger(). |
| 44 | +//-------------------------------------- |
| 45 | + .globl _trap |
| 46 | + .p2align 2 |
| 47 | +_trap: |
| 48 | + .cfi_startproc |
| 49 | + .cfi_signal_frame |
| 50 | + |
| 51 | + // The pc value when we were interrupted is in x23 |
| 52 | + .cfi_escape DW_CFA_register, ehframe_pc, ehframe_x23 |
| 53 | + |
| 54 | + // standard prologue save of fp & lr so we can call puts() |
| 55 | + sub sp, sp, #32 |
| 56 | + stp x29, x30, [sp, #16] |
| 57 | + add x29, sp, #16 |
| 58 | + .cfi_def_cfa w29, 16 |
| 59 | + .cfi_offset w30, -8 |
| 60 | + .cfi_offset w29, -16 |
| 61 | + |
| 62 | + bl _break_to_debugger |
| 63 | + |
| 64 | + ldp x29, x30, [sp, #16] |
| 65 | + add sp, sp, #32 |
| 66 | + |
| 67 | + // jump back to $x23 to resume execution of to_be_interrupted |
| 68 | + br x23 |
| 69 | + .cfi_endproc |
| 70 | + |
| 71 | +//-------------------------------------- |
| 72 | +// break_to_debugger() executes a BRK instruction |
| 73 | +//-------------------------------------- |
| 74 | + .globl _break_to_debugger |
| 75 | + .p2align 2 |
| 76 | +_break_to_debugger: |
| 77 | + .cfi_startproc |
| 78 | + |
| 79 | + // standard prologue save of fp & lr so we can call puts() |
| 80 | + sub sp, sp, #32 |
| 81 | + stp x29, x30, [sp, #16] |
| 82 | + add x29, sp, #16 |
| 83 | + .cfi_def_cfa w29, 16 |
| 84 | + .cfi_offset w30, -8 |
| 85 | + .cfi_offset w29, -16 |
| 86 | + |
| 87 | + brk #0xf000 ;; __builtin_debugtrap aarch64 instruction |
| 88 | + |
| 89 | + ldp x29, x30, [sp, #16] |
| 90 | + add sp, sp, #32 |
| 91 | + ret |
| 92 | + .cfi_endproc |
0 commit comments