|
59 | 59 | #endif |
60 | 60 |
|
61 | 61 | // wrapper around everything in this file |
62 | | -#if N_X64 || N_X86 || N_THUMB || N_ARM || N_XTENSA || N_XTENSAWIN || N_RV32 || N_DEBUG |
| 62 | +#if N_X64 || N_X86 || N_THUMB || N_ARM || N_XTENSA || N_XTENSAWIN || N_RV32 || N_68K || N_DEBUG |
63 | 63 |
|
64 | 64 | // C stack layout for native functions: |
65 | 65 | // 0: nlr_buf_t [optional] |
|
147 | 147 | #define LOCAL_IDX_GEN_PC(emit) ((emit)->code_state_start + OFFSETOF_CODE_STATE_IP) |
148 | 148 | #define LOCAL_IDX_LOCAL_VAR(emit, local_num) ((emit)->stack_start + (emit)->n_state - 1 - (local_num)) |
149 | 149 |
|
| 150 | +#if N_68K |
| 151 | + |
| 152 | +// 68k: REG_LOCAL_1=D7 is the only data register safe for cached locals. |
| 153 | +// REG_LOCAL_2=A2 and REG_LOCAL_3=A3 are address registers; emitnative.c |
| 154 | +// may apply arithmetic to local-variable registers, which is invalid on An. |
150 | 155 | #if MICROPY_PERSISTENT_CODE_SAVE |
| 156 | +#define REG_GENERATOR_STATE (REG_LOCAL_2) |
| 157 | +#define REG_QSTR_TABLE (REG_LOCAL_3) |
| 158 | +#else |
| 159 | +#define REG_GENERATOR_STATE (REG_LOCAL_2) |
| 160 | +#endif |
| 161 | +#define MAX_REGS_FOR_LOCAL_VARS (1) |
| 162 | +static const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1}; |
| 163 | + |
| 164 | +#elif MICROPY_PERSISTENT_CODE_SAVE |
151 | 165 |
|
152 | 166 | // When building with the ability to save native code to .mpy files: |
153 | 167 | // - Qstrs are indirect via qstr_table, and REG_LOCAL_3 always points to qstr_table. |
@@ -625,8 +639,16 @@ static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop |
625 | 639 | // Set code_state.fun_bc |
626 | 640 | ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_FUN_OBJ(emit), REG_PARENT_ARG_1); |
627 | 641 |
|
628 | | - // Set code_state.n_state (only works on little endian targets due to n_state being uint16_t) |
| 642 | + // Set code_state.n_state. |
| 643 | + // n_state is a uint16_t, but the emitter writes a full uintptr_t-sized slot. |
| 644 | + // On little-endian the value naturally lands in the correct bytes. |
| 645 | + // On big-endian (N_68K) the uint16_t occupies the upper half of the word, |
| 646 | + // so shift the value left by 16 to place it in the correct byte positions. |
| 647 | + #if N_68K |
| 648 | + emit_native_mov_state_imm_via(emit, emit->code_state_start + OFFSETOF_CODE_STATE_N_STATE, (mp_uint_t)emit->n_state << 16, REG_ARG_1); |
| 649 | + #else |
629 | 650 | emit_native_mov_state_imm_via(emit, emit->code_state_start + OFFSETOF_CODE_STATE_N_STATE, emit->n_state, REG_ARG_1); |
| 651 | + #endif |
630 | 652 |
|
631 | 653 | // Put address of code_state into first arg |
632 | 654 | ASM_MOV_REG_LOCAL_ADDR(emit->as, REG_ARG_1, emit->code_state_start); |
@@ -2624,6 +2646,31 @@ static void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { |
2624 | 2646 | default: |
2625 | 2647 | break; |
2626 | 2648 | } |
| 2649 | + #elif N_68K |
| 2650 | + // CMP.L reg_rhs, REG_ARG_2 → sets flags for REG_ARG_2 - reg_rhs. |
| 2651 | + // Scc REG_RET sets byte to 0xFF (true) or 0x00 (false). |
| 2652 | + // ANDI.L #1 extracts the boolean into bits 31:0 of REG_RET. |
| 2653 | + { |
| 2654 | + static const uint8_t ops[6 + 6] = { |
| 2655 | + // unsigned (CMP: REG_ARG_2 - reg_rhs) |
| 2656 | + ASM_68K_CC_CS, // LESS (carry set = below) |
| 2657 | + ASM_68K_CC_HI, // MORE (above) |
| 2658 | + ASM_68K_CC_EQ, // EQUAL |
| 2659 | + ASM_68K_CC_LS, // LESS_EQUAL (below or same) |
| 2660 | + ASM_68K_CC_CC, // MORE_EQUAL (carry clear = above or same) |
| 2661 | + ASM_68K_CC_NE, // NOT_EQUAL |
| 2662 | + // signed |
| 2663 | + ASM_68K_CC_LT, // LESS |
| 2664 | + ASM_68K_CC_GT, // MORE |
| 2665 | + ASM_68K_CC_EQ, // EQUAL |
| 2666 | + ASM_68K_CC_LE, // LESS_EQUAL |
| 2667 | + ASM_68K_CC_GE, // MORE_EQUAL |
| 2668 | + ASM_68K_CC_NE, // NOT_EQUAL |
| 2669 | + }; |
| 2670 | + asm_68k_cmp_reg_reg(emit->as, REG_ARG_2, reg_rhs); |
| 2671 | + asm_68k_scc_dreg(emit->as, ops[op_idx], REG_RET); |
| 2672 | + asm_68k_andi_l(emit->as, REG_RET, 1); |
| 2673 | + } |
2627 | 2674 | #elif N_DEBUG |
2628 | 2675 | asm_debug_setcc_reg_reg_reg(emit->as, op_idx, REG_RET, REG_ARG_2, reg_rhs); |
2629 | 2676 | #else |
|
0 commit comments