|
| 1 | +void |
| 2 | +emit_shim( |
| 3 | + unsigned char *code, unsigned char *data, _PyExecutorObject *executor, |
| 4 | + const _PyUOpInstruction *instruction, jit_state *state) |
| 5 | +{ |
| 6 | + // 0: 6db63bef stp d15, d14, [sp, #-0xa0]! |
| 7 | + // 4: 6d0133ed stp d13, d12, [sp, #0x10] |
| 8 | + // 8: 6d022beb stp d11, d10, [sp, #0x20] |
| 9 | + // c: 6d0323e9 stp d9, d8, [sp, #0x30] |
| 10 | + // 10: a9046ffc stp x28, x27, [sp, #0x40] |
| 11 | + // 14: a90567fa stp x26, x25, [sp, #0x50] |
| 12 | + // 18: a9065ff8 stp x24, x23, [sp, #0x60] |
| 13 | + // 1c: a90757f6 stp x22, x21, [sp, #0x70] |
| 14 | + // 20: a9084ff4 stp x20, x19, [sp, #0x80] |
| 15 | + // 24: a9097bfd stp x29, x30, [sp, #0x90] |
| 16 | + // 28: 910243fd add x29, sp, #0x90 |
| 17 | + // 2c: aa0003f4 mov x20, x0 |
| 18 | + // 30: aa0103f5 mov x21, x1 |
| 19 | + // 34: aa0203f6 mov x22, x2 |
| 20 | + // 38: 9400000c bl 0x68 <ltmp0+0x68> |
| 21 | + // 3c: a9497bfd ldp x29, x30, [sp, #0x90] |
| 22 | + // 40: a9484ff4 ldp x20, x19, [sp, #0x80] |
| 23 | + // 44: a94757f6 ldp x22, x21, [sp, #0x70] |
| 24 | + // 48: a9465ff8 ldp x24, x23, [sp, #0x60] |
| 25 | + // 4c: a94567fa ldp x26, x25, [sp, #0x50] |
| 26 | + // 50: a9446ffc ldp x28, x27, [sp, #0x40] |
| 27 | + // 54: 6d4323e9 ldp d9, d8, [sp, #0x30] |
| 28 | + // 58: 6d422beb ldp d11, d10, [sp, #0x20] |
| 29 | + // 5c: 6d4133ed ldp d13, d12, [sp, #0x10] |
| 30 | + // 60: 6cca3bef ldp d15, d14, [sp], #0xa0 |
| 31 | + // 64: d65f03c0 ret |
| 32 | + const unsigned char code_body[104] = { |
| 33 | + 0xef, 0x3b, 0xb6, 0x6d, 0xed, 0x33, 0x01, 0x6d, |
| 34 | + 0xeb, 0x2b, 0x02, 0x6d, 0xe9, 0x23, 0x03, 0x6d, |
| 35 | + 0xfc, 0x6f, 0x04, 0xa9, 0xfa, 0x67, 0x05, 0xa9, |
| 36 | + 0xf8, 0x5f, 0x06, 0xa9, 0xf6, 0x57, 0x07, 0xa9, |
| 37 | + 0xf4, 0x4f, 0x08, 0xa9, 0xfd, 0x7b, 0x09, 0xa9, |
| 38 | + 0xfd, 0x43, 0x02, 0x91, 0xf4, 0x03, 0x00, 0xaa, |
| 39 | + 0xf5, 0x03, 0x01, 0xaa, 0xf6, 0x03, 0x02, 0xaa, |
| 40 | + 0x0c, 0x00, 0x00, 0x94, 0xfd, 0x7b, 0x49, 0xa9, |
| 41 | + 0xf4, 0x4f, 0x48, 0xa9, 0xf6, 0x57, 0x47, 0xa9, |
| 42 | + 0xf8, 0x5f, 0x46, 0xa9, 0xfa, 0x67, 0x45, 0xa9, |
| 43 | + 0xfc, 0x6f, 0x44, 0xa9, 0xe9, 0x23, 0x43, 0x6d, |
| 44 | + 0xeb, 0x2b, 0x42, 0x6d, 0xed, 0x33, 0x41, 0x6d, |
| 45 | + 0xef, 0x3b, 0xca, 0x6c, 0xc0, 0x03, 0x5f, 0xd6, |
| 46 | + }; |
| 47 | + memcpy(code, code_body, sizeof(code_body)); |
| 48 | +} |
| 49 | + |
| 50 | +void |
| 51 | +emit_0( |
| 52 | + unsigned char *code, unsigned char *data, _PyExecutorObject *executor, |
| 53 | + const _PyUOpInstruction *instruction, jit_state *state) |
| 54 | +{ |
| 55 | +} |
| 56 | + |
| 57 | +void |
| 58 | +emit_1( |
| 59 | + unsigned char *code, unsigned char *data, _PyExecutorObject *executor, |
| 60 | + const _PyUOpInstruction *instruction, jit_state *state) |
| 61 | +{ |
| 62 | + // 0: a9bf7bfd stp x29, x30, [sp, #-0x10]! |
| 63 | + // 4: 910003fd mov x29, sp |
| 64 | + // 8: 90000008 adrp x8, 0x0 <ltmp0> |
| 65 | + // 0000000000000008: ARM64_RELOC_GOT_LOAD_PAGE21 _sausage |
| 66 | + // c: f9400108 ldr x8, [x8] |
| 67 | + // 000000000000000c: ARM64_RELOC_GOT_LOAD_PAGEOFF12 _sausage |
| 68 | + // 10: 39400108 ldrb w8, [x8] |
| 69 | + // 14: 36000068 tbz w8, #0x0, 0x20 <ltmp0+0x20> |
| 70 | + // 18: 94000000 bl 0x18 <ltmp0+0x18> |
| 71 | + // 0000000000000018: ARM64_RELOC_BRANCH26 _order_eggs_sausage_and_bacon |
| 72 | + // 1c: 14000002 b 0x24 <ltmp0+0x24> |
| 73 | + // 20: 94000000 bl 0x20 <ltmp0+0x20> |
| 74 | + // 0000000000000020: ARM64_RELOC_BRANCH26 _order_eggs_and_bacon |
| 75 | + // 24: 90000008 adrp x8, 0x0 <ltmp0> |
| 76 | + // 0000000000000024: ARM64_RELOC_GOT_LOAD_PAGE21 _spammed |
| 77 | + // 28: f9400108 ldr x8, [x8] |
| 78 | + // 0000000000000028: ARM64_RELOC_GOT_LOAD_PAGEOFF12 _spammed |
| 79 | + // 2c: 3900011f strb wzr, [x8] |
| 80 | + // 30: a8c17bfd ldp x29, x30, [sp], #0x10 |
| 81 | + const unsigned char code_body[52] = { |
| 82 | + 0xfd, 0x7b, 0xbf, 0xa9, 0xfd, 0x03, 0x00, 0x91, |
| 83 | + 0x08, 0x00, 0x00, 0x90, 0x08, 0x01, 0x40, 0xf9, |
| 84 | + 0x08, 0x01, 0x40, 0x39, 0x68, 0x00, 0x00, 0x36, |
| 85 | + 0x00, 0x00, 0x00, 0x94, 0x02, 0x00, 0x00, 0x14, |
| 86 | + 0x00, 0x00, 0x00, 0x94, 0x08, 0x00, 0x00, 0x90, |
| 87 | + 0x08, 0x01, 0x40, 0xf9, 0x1f, 0x01, 0x00, 0x39, |
| 88 | + 0xfd, 0x7b, 0xc1, 0xa8, |
| 89 | + }; |
| 90 | + // 0: &spammed+0x0 |
| 91 | + // 8: &sausage+0x0 |
| 92 | + patch_64(data + 0x0, (uintptr_t)&spammed); |
| 93 | + patch_64(data + 0x8, (uintptr_t)&sausage); |
| 94 | + memcpy(code, code_body, sizeof(code_body)); |
| 95 | + patch_aarch64_33rx(code + 0x8, (uintptr_t)data + 0x8); |
| 96 | + patch_aarch64_trampoline(code + 0x18, 0x1, state); |
| 97 | + patch_aarch64_trampoline(code + 0x20, 0x0, state); |
| 98 | + patch_aarch64_33rx(code + 0x24, (uintptr_t)data); |
| 99 | +} |
| 100 | + |
| 101 | +void |
| 102 | +emit_2( |
| 103 | + unsigned char *code, unsigned char *data, _PyExecutorObject *executor, |
| 104 | + const _PyUOpInstruction *instruction, jit_state *state) |
| 105 | +{ |
| 106 | + // 0: 90000008 adrp x8, 0x0 <ltmp0> |
| 107 | + // 0000000000000000: ARM64_RELOC_GOT_LOAD_PAGE21 _spam |
| 108 | + // 4: f9400108 ldr x8, [x8] |
| 109 | + // 0000000000000004: ARM64_RELOC_GOT_LOAD_PAGEOFF12 _spam |
| 110 | + // 8: 39400108 ldrb w8, [x8] |
| 111 | + // c: 7100051f cmp w8, #0x1 |
| 112 | + // 10: 54000041 b.ne 0x18 <ltmp0+0x18> |
| 113 | + // 14: 14000000 b 0x14 <ltmp0+0x14> |
| 114 | + // 0000000000000014: ARM64_RELOC_BRANCH26 __JIT_ERROR_TARGET |
| 115 | + const unsigned char code_body[24] = { |
| 116 | + 0x08, 0x00, 0x00, 0x90, 0x08, 0x01, 0x40, 0xf9, |
| 117 | + 0x08, 0x01, 0x40, 0x39, 0x1f, 0x05, 0x00, 0x71, |
| 118 | + 0x41, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x14, |
| 119 | + }; |
| 120 | + // 0: &spam+0x0 |
| 121 | + patch_64(data + 0x0, (uintptr_t)&spam); |
| 122 | + memcpy(code, code_body, sizeof(code_body)); |
| 123 | + patch_aarch64_33rx(code + 0x0, (uintptr_t)data); |
| 124 | + patch_aarch64_26r(code + 0x14, state->instruction_starts[instruction->error_target]); |
| 125 | +} |
| 126 | + |
| 127 | +static_assert(SYMBOL_MASK_WORDS >= 1, "SYMBOL_MASK_WORDS too small"); |
| 128 | + |
| 129 | +typedef struct { |
| 130 | + void (*emit)( |
| 131 | + unsigned char *code, unsigned char *data, _PyExecutorObject *executor, |
| 132 | + const _PyUOpInstruction *instruction, jit_state *state); |
| 133 | + size_t code_size; |
| 134 | + size_t data_size; |
| 135 | + symbol_mask trampoline_mask; |
| 136 | +} StencilGroup; |
| 137 | + |
| 138 | +static const StencilGroup shim = {emit_shim, 104, 0, {0}}; |
| 139 | + |
| 140 | +static const StencilGroup stencil_groups[MAX_UOP_ID + 1] = { |
| 141 | + [0] = {emit_0, 0, 0, {0}}, |
| 142 | + [1] = {emit_1, 52, 16, {0x03}}, |
| 143 | + [2] = {emit_2, 24, 8, {0}}, |
| 144 | +}; |
| 145 | + |
| 146 | +static const void * const symbols_map[2] = { |
| 147 | + [0] = &order_eggs_and_bacon, |
| 148 | + [1] = &order_eggs_sausage_and_bacon, |
| 149 | +}; |
0 commit comments