26 #ifndef MICROPY_INCLUDED_PY_ASMTHUMB_H 27 #define MICROPY_INCLUDED_PY_ASMTHUMB_H 32 #define ASM_THUMB_REG_R0 (0) 33 #define ASM_THUMB_REG_R1 (1) 34 #define ASM_THUMB_REG_R2 (2) 35 #define ASM_THUMB_REG_R3 (3) 36 #define ASM_THUMB_REG_R4 (4) 37 #define ASM_THUMB_REG_R5 (5) 38 #define ASM_THUMB_REG_R6 (6) 39 #define ASM_THUMB_REG_R7 (7) 40 #define ASM_THUMB_REG_R8 (8) 41 #define ASM_THUMB_REG_R9 (9) 42 #define ASM_THUMB_REG_R10 (10) 43 #define ASM_THUMB_REG_R11 (11) 44 #define ASM_THUMB_REG_R12 (12) 45 #define ASM_THUMB_REG_R13 (13) 46 #define ASM_THUMB_REG_R14 (14) 47 #define ASM_THUMB_REG_R15 (15) 48 #define ASM_THUMB_REG_LR (REG_R14) 50 #define ASM_THUMB_CC_EQ (0x0) 51 #define ASM_THUMB_CC_NE (0x1) 52 #define ASM_THUMB_CC_CS (0x2) 53 #define ASM_THUMB_CC_CC (0x3) 54 #define ASM_THUMB_CC_MI (0x4) 55 #define ASM_THUMB_CC_PL (0x5) 56 #define ASM_THUMB_CC_VS (0x6) 57 #define ASM_THUMB_CC_VC (0x7) 58 #define ASM_THUMB_CC_HI (0x8) 59 #define ASM_THUMB_CC_LS (0x9) 60 #define ASM_THUMB_CC_GE (0xa) 61 #define ASM_THUMB_CC_LT (0xb) 62 #define ASM_THUMB_CC_GT (0xc) 63 #define ASM_THUMB_CC_LE (0xd) 79 #define ASM_THUMB_OP_IT (0xbf00) 80 #define ASM_THUMB_OP_ITE_EQ (0xbf0c) 81 #define ASM_THUMB_OP_ITE_CS (0xbf2c) 82 #define ASM_THUMB_OP_ITE_MI (0xbf4c) 83 #define ASM_THUMB_OP_ITE_VS (0xbf6c) 84 #define ASM_THUMB_OP_ITE_HI (0xbf8c) 85 #define ASM_THUMB_OP_ITE_GE (0xbfac) 86 #define ASM_THUMB_OP_ITE_GT (0xbfcc) 88 #define ASM_THUMB_OP_NOP (0xbf00) 89 #define ASM_THUMB_OP_WFI (0xbf30) 90 #define ASM_THUMB_OP_CPSID_I (0xb672) // cpsid i, disable irq 91 #define ASM_THUMB_OP_CPSIE_I (0xb662) // cpsie i, enable irq 101 #define ASM_THUMB_FORMAT_1_LSL (0x0000) 102 #define ASM_THUMB_FORMAT_1_LSR (0x0800) 103 #define ASM_THUMB_FORMAT_1_ASR (0x1000) 105 #define ASM_THUMB_FORMAT_1_ENCODE(op, rlo_dest, rlo_src, offset) \ 106 ((op) | ((offset) << 6) | ((rlo_src) << 3) | (rlo_dest)) 116 #define ASM_THUMB_FORMAT_2_ADD (0x1800) 117 #define ASM_THUMB_FORMAT_2_SUB (0x1a00) 118 #define ASM_THUMB_FORMAT_2_REG_OPERAND (0x0000) 119 #define ASM_THUMB_FORMAT_2_IMM_OPERAND (0x0400) 121 #define ASM_THUMB_FORMAT_2_ENCODE(op, rlo_dest, rlo_src, src_b) \ 122 ((op) | ((src_b) << 6) | ((rlo_src) << 3) | (rlo_dest)) 132 static inline void asm_thumb_add_rlo_rlo_i3(
asm_thumb_t *as,
uint rlo_dest,
uint rlo_src_a,
int i3_src)
136 static inline void asm_thumb_sub_rlo_rlo_i3(
asm_thumb_t *as,
uint rlo_dest,
uint rlo_src_a,
int i3_src)
142 #define ASM_THUMB_FORMAT_3_MOV (0x2000) 143 #define ASM_THUMB_FORMAT_3_CMP (0x2800) 144 #define ASM_THUMB_FORMAT_3_ADD (0x3000) 145 #define ASM_THUMB_FORMAT_3_SUB (0x3800) 147 #define ASM_THUMB_FORMAT_3_ENCODE(op, rlo, i8) ((op) | ((rlo) << 8) | (i8)) 161 #define ASM_THUMB_FORMAT_4_AND (0x4000) 162 #define ASM_THUMB_FORMAT_4_EOR (0x4040) 163 #define ASM_THUMB_FORMAT_4_LSL (0x4080) 164 #define ASM_THUMB_FORMAT_4_LSR (0x40c0) 165 #define ASM_THUMB_FORMAT_4_ASR (0x4100) 166 #define ASM_THUMB_FORMAT_4_ADC (0x4140) 167 #define ASM_THUMB_FORMAT_4_SBC (0x4180) 168 #define ASM_THUMB_FORMAT_4_ROR (0x41c0) 169 #define ASM_THUMB_FORMAT_4_TST (0x4200) 170 #define ASM_THUMB_FORMAT_4_NEG (0x4240) 171 #define ASM_THUMB_FORMAT_4_CMP (0x4280) 172 #define ASM_THUMB_FORMAT_4_CMN (0x42c0) 173 #define ASM_THUMB_FORMAT_4_ORR (0x4300) 174 #define ASM_THUMB_FORMAT_4_MUL (0x4340) 175 #define ASM_THUMB_FORMAT_4_BIC (0x4380) 176 #define ASM_THUMB_FORMAT_4_MVN (0x43c0) 189 #define ASM_THUMB_FORMAT_9_STR (0x6000) 190 #define ASM_THUMB_FORMAT_9_LDR (0x6800) 191 #define ASM_THUMB_FORMAT_9_WORD_TRANSFER (0x0000) 192 #define ASM_THUMB_FORMAT_9_BYTE_TRANSFER (0x1000) 194 #define ASM_THUMB_FORMAT_10_STRH (0x8000) 195 #define ASM_THUMB_FORMAT_10_LDRH (0x8800) 197 #define ASM_THUMB_FORMAT_9_10_ENCODE(op, rlo_dest, rlo_base, offset) \ 198 ((op) | (((offset) << 6) & 0x07c0) | ((rlo_base) << 3) | (rlo_dest)) 218 #define ASM_THUMB_OP_MOVW (0xf240) 219 #define ASM_THUMB_OP_MOVT (0xf2c0) 245 #define ASM_WORD_SIZE (4) 247 #define REG_RET ASM_THUMB_REG_R0 248 #define REG_ARG_1 ASM_THUMB_REG_R0 249 #define REG_ARG_2 ASM_THUMB_REG_R1 250 #define REG_ARG_3 ASM_THUMB_REG_R2 251 #define REG_ARG_4 ASM_THUMB_REG_R3 254 #define REG_TEMP0 ASM_THUMB_REG_R0 255 #define REG_TEMP1 ASM_THUMB_REG_R1 256 #define REG_TEMP2 ASM_THUMB_REG_R2 258 #define REG_LOCAL_1 ASM_THUMB_REG_R4 259 #define REG_LOCAL_2 ASM_THUMB_REG_R5 260 #define REG_LOCAL_3 ASM_THUMB_REG_R6 261 #define REG_LOCAL_NUM (3) 263 #define ASM_T asm_thumb_t 264 #define ASM_END_PASS asm_thumb_end_pass 265 #define ASM_ENTRY asm_thumb_entry 266 #define ASM_EXIT asm_thumb_exit 268 #define ASM_JUMP asm_thumb_b_label 269 #define ASM_JUMP_IF_REG_ZERO(as, reg, label) \ 271 asm_thumb_cmp_rlo_i8(as, reg, 0); \ 272 asm_thumb_bcc_label(as, ASM_THUMB_CC_EQ, label); \ 274 #define ASM_JUMP_IF_REG_NONZERO(as, reg, label) \ 276 asm_thumb_cmp_rlo_i8(as, reg, 0); \ 277 asm_thumb_bcc_label(as, ASM_THUMB_CC_NE, label); \ 279 #define ASM_JUMP_IF_REG_EQ(as, reg1, reg2, label) \ 281 asm_thumb_cmp_rlo_rlo(as, reg1, reg2); \ 282 asm_thumb_bcc_label(as, ASM_THUMB_CC_EQ, label); \ 284 #define ASM_CALL_IND(as, ptr, idx) asm_thumb_bl_ind(as, ptr, idx, ASM_THUMB_REG_R3) 286 #define ASM_MOV_REG_TO_LOCAL(as, reg, local_num) asm_thumb_mov_local_reg(as, (local_num), (reg)) 287 #define ASM_MOV_IMM_TO_REG(as, imm, reg) asm_thumb_mov_reg_i32_optimised(as, (reg), (imm)) 288 #define ASM_MOV_ALIGNED_IMM_TO_REG(as, imm, reg) asm_thumb_mov_reg_i32_aligned(as, (reg), (imm)) 289 #define ASM_MOV_IMM_TO_LOCAL_USING(as, imm, local_num, reg_temp) \ 291 asm_thumb_mov_reg_i32_optimised(as, (reg_temp), (imm)); \ 292 asm_thumb_mov_local_reg(as, (local_num), (reg_temp)); \ 294 #define ASM_MOV_LOCAL_TO_REG(as, local_num, reg) asm_thumb_mov_reg_local(as, (reg), (local_num)) 295 #define ASM_MOV_REG_REG(as, reg_dest, reg_src) asm_thumb_mov_reg_reg((as), (reg_dest), (reg_src)) 296 #define ASM_MOV_LOCAL_ADDR_TO_REG(as, local_num, reg) asm_thumb_mov_reg_local_addr(as, (reg), (local_num)) 298 #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_LSL, (reg_dest), (reg_shift)) 299 #define ASM_ASR_REG_REG(as, reg_dest, reg_shift) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_ASR, (reg_dest), (reg_shift)) 300 #define ASM_OR_REG_REG(as, reg_dest, reg_src) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_ORR, (reg_dest), (reg_src)) 301 #define ASM_XOR_REG_REG(as, reg_dest, reg_src) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_EOR, (reg_dest), (reg_src)) 302 #define ASM_AND_REG_REG(as, reg_dest, reg_src) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_AND, (reg_dest), (reg_src)) 303 #define ASM_ADD_REG_REG(as, reg_dest, reg_src) asm_thumb_add_rlo_rlo_rlo((as), (reg_dest), (reg_dest), (reg_src)) 304 #define ASM_SUB_REG_REG(as, reg_dest, reg_src) asm_thumb_sub_rlo_rlo_rlo((as), (reg_dest), (reg_dest), (reg_src)) 305 #define ASM_MUL_REG_REG(as, reg_dest, reg_src) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_MUL, (reg_dest), (reg_src)) 307 #define ASM_LOAD_REG_REG(as, reg_dest, reg_base) asm_thumb_ldr_rlo_rlo_i5((as), (reg_dest), (reg_base), 0) 308 #define ASM_LOAD_REG_REG_OFFSET(as, reg_dest, reg_base, word_offset) asm_thumb_ldr_rlo_rlo_i5((as), (reg_dest), (reg_base), (word_offset)) 309 #define ASM_LOAD8_REG_REG(as, reg_dest, reg_base) asm_thumb_ldrb_rlo_rlo_i5((as), (reg_dest), (reg_base), 0) 310 #define ASM_LOAD16_REG_REG(as, reg_dest, reg_base) asm_thumb_ldrh_rlo_rlo_i5((as), (reg_dest), (reg_base), 0) 311 #define ASM_LOAD32_REG_REG(as, reg_dest, reg_base) asm_thumb_ldr_rlo_rlo_i5((as), (reg_dest), (reg_base), 0) 313 #define ASM_STORE_REG_REG(as, reg_src, reg_base) asm_thumb_str_rlo_rlo_i5((as), (reg_src), (reg_base), 0) 314 #define ASM_STORE_REG_REG_OFFSET(as, reg_src, reg_base, word_offset) asm_thumb_str_rlo_rlo_i5((as), (reg_src), (reg_base), (word_offset)) 315 #define ASM_STORE8_REG_REG(as, reg_src, reg_base) asm_thumb_strb_rlo_rlo_i5((as), (reg_src), (reg_base), 0) 316 #define ASM_STORE16_REG_REG(as, reg_src, reg_base) asm_thumb_strh_rlo_rlo_i5((as), (reg_src), (reg_base), 0) 317 #define ASM_STORE32_REG_REG(as, reg_src, reg_base) asm_thumb_str_rlo_rlo_i5((as), (reg_src), (reg_base), 0) 319 #endif // GENERIC_ASM_API 321 #endif // MICROPY_INCLUDED_PY_ASMTHUMB_H #define ASM_THUMB_FORMAT_9_STR
#define ASM_THUMB_FORMAT_3_MOV
void asm_thumb_format_4(asm_thumb_t *as, uint op, uint rlo_dest, uint rlo_src)
#define ASM_THUMB_FORMAT_9_WORD_TRANSFER
#define ASM_THUMB_FORMAT_2_IMM_OPERAND
#define ASM_THUMB_FORMAT_9_LDR
void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num)
#define ASM_THUMB_FORMAT_3_CMP
#define ASM_THUMB_FORMAT_9_10_ENCODE(op, rlo_dest, rlo_base, offset)
void asm_thumb_mov_reg_local(asm_thumb_t *as, uint rlo_dest, int local_num)
bool asm_thumb_b_n_label(asm_thumb_t *as, uint label)
#define ASM_THUMB_FORMAT_10_STRH
void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, mp_uint_t i32_src)
void asm_thumb_mov_reg_i32_optimised(asm_thumb_t *as, uint reg_dest, int i32_src)
#define ASM_THUMB_FORMAT_1_ENCODE(op, rlo_dest, rlo_src, offset)
#define ASM_THUMB_FORMAT_10_LDRH
#define ASM_THUMB_FORMAT_2_ADD
void asm_thumb_mov_reg_reg(asm_thumb_t *as, uint reg_dest, uint reg_src)
bool asm_thumb_bcc_nw_label(asm_thumb_t *as, int cond, uint label, bool wide)
#define ASM_THUMB_FORMAT_2_SUB
#define ASM_THUMB_FORMAT_2_REG_OPERAND
void asm_thumb_mov_reg_i32_aligned(asm_thumb_t *as, uint reg_dest, int i32)
#define ASM_THUMB_FORMAT_4_CMP
void asm_thumb_exit(asm_thumb_t *as)
void asm_thumb_mov_reg_i16(asm_thumb_t *as, uint mov_op, uint reg_dest, int i16_src)
#define ASM_THUMB_FORMAT_3_ADD
bool asm_thumb_bl_label(asm_thumb_t *as, uint label)
#define ASM_THUMB_FORMAT_3_SUB
void asm_thumb_bcc_label(asm_thumb_t *as, int cc, uint label)
void asm_thumb_op16(asm_thumb_t *as, uint op)
#define ASM_THUMB_FORMAT_3_ENCODE(op, rlo, i8)
struct _asm_thumb_t asm_thumb_t
void asm_thumb_mov_local_reg(asm_thumb_t *as, int local_num_dest, uint rlo_src)
void asm_thumb_op32(asm_thumb_t *as, uint op1, uint op2)
#define ASM_THUMB_FORMAT_2_ENCODE(op, rlo_dest, rlo_src, src_b)
void asm_thumb_b_label(asm_thumb_t *as, uint label)
#define ASM_THUMB_FORMAT_9_BYTE_TRANSFER
void asm_thumb_end_pass(asm_thumb_t *as)
void asm_thumb_entry(asm_thumb_t *as, int num_locals)
void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp)