Numworks Epsilon  1.4.1
Graphing Calculator Operating System
asmarm.h
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2014 Fabian Vogt
7  * Copyright (c) 2013, 2014 Damien P. George
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  */
27 #ifndef MICROPY_INCLUDED_PY_ASMARM_H
28 #define MICROPY_INCLUDED_PY_ASMARM_H
29 
30 #include "py/misc.h"
31 #include "py/asmbase.h"
32 
33 #define ASM_ARM_REG_R0 (0)
34 #define ASM_ARM_REG_R1 (1)
35 #define ASM_ARM_REG_R2 (2)
36 #define ASM_ARM_REG_R3 (3)
37 #define ASM_ARM_REG_R4 (4)
38 #define ASM_ARM_REG_R5 (5)
39 #define ASM_ARM_REG_R6 (6)
40 #define ASM_ARM_REG_R7 (7)
41 #define ASM_ARM_REG_R8 (8)
42 #define ASM_ARM_REG_R9 (9)
43 #define ASM_ARM_REG_R10 (10)
44 #define ASM_ARM_REG_R11 (11)
45 #define ASM_ARM_REG_R12 (12)
46 #define ASM_ARM_REG_R13 (13)
47 #define ASM_ARM_REG_R14 (14)
48 #define ASM_ARM_REG_R15 (15)
49 #define ASM_ARM_REG_SP (ASM_ARM_REG_R13)
50 #define ASM_ARM_REG_LR (ASM_ARM_REG_R14)
51 #define ASM_ARM_REG_PC (ASM_ARM_REG_R15)
52 
53 #define ASM_ARM_CC_EQ (0x0 << 28)
54 #define ASM_ARM_CC_NE (0x1 << 28)
55 #define ASM_ARM_CC_CS (0x2 << 28)
56 #define ASM_ARM_CC_CC (0x3 << 28)
57 #define ASM_ARM_CC_MI (0x4 << 28)
58 #define ASM_ARM_CC_PL (0x5 << 28)
59 #define ASM_ARM_CC_VS (0x6 << 28)
60 #define ASM_ARM_CC_VC (0x7 << 28)
61 #define ASM_ARM_CC_HI (0x8 << 28)
62 #define ASM_ARM_CC_LS (0x9 << 28)
63 #define ASM_ARM_CC_GE (0xa << 28)
64 #define ASM_ARM_CC_LT (0xb << 28)
65 #define ASM_ARM_CC_GT (0xc << 28)
66 #define ASM_ARM_CC_LE (0xd << 28)
67 #define ASM_ARM_CC_AL (0xe << 28)
68 
69 typedef struct _asm_arm_t {
73 } asm_arm_t;
74 
75 void asm_arm_end_pass(asm_arm_t *as);
76 
77 void asm_arm_entry(asm_arm_t *as, int num_locals);
78 void asm_arm_exit(asm_arm_t *as);
79 
80 void asm_arm_bkpt(asm_arm_t *as);
81 
82 // mov
83 void asm_arm_mov_reg_reg(asm_arm_t *as, uint reg_dest, uint reg_src);
84 void asm_arm_mov_reg_i32(asm_arm_t *as, uint rd, int imm);
85 void asm_arm_mov_local_reg(asm_arm_t *as, int local_num, uint rd);
86 void asm_arm_mov_reg_local(asm_arm_t *as, uint rd, int local_num);
87 void asm_arm_setcc_reg(asm_arm_t *as, uint rd, uint cond);
88 
89 // compare
90 void asm_arm_cmp_reg_i8(asm_arm_t *as, uint rd, int imm);
91 void asm_arm_cmp_reg_reg(asm_arm_t *as, uint rd, uint rn);
92 
93 // arithmetic
94 void asm_arm_add_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
95 void asm_arm_sub_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
96 void asm_arm_mul_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
97 void asm_arm_and_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
98 void asm_arm_eor_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
99 void asm_arm_orr_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
100 void asm_arm_mov_reg_local_addr(asm_arm_t *as, uint rd, int local_num);
101 void asm_arm_lsl_reg_reg(asm_arm_t *as, uint rd, uint rs);
102 void asm_arm_asr_reg_reg(asm_arm_t *as, uint rd, uint rs);
103 
104 // memory
105 void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn, uint byte_offset);
106 void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn);
107 void asm_arm_ldrb_reg_reg(asm_arm_t *as, uint rd, uint rn);
108 void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm, uint byte_offset);
109 void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm);
110 void asm_arm_strb_reg_reg(asm_arm_t *as, uint rd, uint rm);
111 // store to array
112 void asm_arm_str_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
113 void asm_arm_strh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
114 void asm_arm_strb_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
115 
116 // stack
117 void asm_arm_push(asm_arm_t *as, uint reglist);
118 void asm_arm_pop(asm_arm_t *as, uint reglist);
119 
120 // control flow
121 void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label);
122 void asm_arm_b_label(asm_arm_t *as, uint label);
123 void asm_arm_bl_ind(asm_arm_t *as, void *fun_ptr, uint fun_id, uint reg_temp);
124 
125 #if GENERIC_ASM_API
126 
127 // The following macros provide a (mostly) arch-independent API to
128 // generate native code, and are used by the native emitter.
129 
130 #define ASM_WORD_SIZE (4)
131 
132 #define REG_RET ASM_ARM_REG_R0
133 #define REG_ARG_1 ASM_ARM_REG_R0
134 #define REG_ARG_2 ASM_ARM_REG_R1
135 #define REG_ARG_3 ASM_ARM_REG_R2
136 #define REG_ARG_4 ASM_ARM_REG_R3
137 
138 #define REG_TEMP0 ASM_ARM_REG_R0
139 #define REG_TEMP1 ASM_ARM_REG_R1
140 #define REG_TEMP2 ASM_ARM_REG_R2
141 
142 #define REG_LOCAL_1 ASM_ARM_REG_R4
143 #define REG_LOCAL_2 ASM_ARM_REG_R5
144 #define REG_LOCAL_3 ASM_ARM_REG_R6
145 #define REG_LOCAL_NUM (3)
146 
147 #define ASM_T asm_arm_t
148 #define ASM_END_PASS asm_arm_end_pass
149 #define ASM_ENTRY asm_arm_entry
150 #define ASM_EXIT asm_arm_exit
151 
152 #define ASM_JUMP asm_arm_b_label
153 #define ASM_JUMP_IF_REG_ZERO(as, reg, label) \
154  do { \
155  asm_arm_cmp_reg_i8(as, reg, 0); \
156  asm_arm_bcc_label(as, ASM_ARM_CC_EQ, label); \
157  } while (0)
158 #define ASM_JUMP_IF_REG_NONZERO(as, reg, label) \
159  do { \
160  asm_arm_cmp_reg_i8(as, reg, 0); \
161  asm_arm_bcc_label(as, ASM_ARM_CC_NE, label); \
162  } while (0)
163 #define ASM_JUMP_IF_REG_EQ(as, reg1, reg2, label) \
164  do { \
165  asm_arm_cmp_reg_reg(as, reg1, reg2); \
166  asm_arm_bcc_label(as, ASM_ARM_CC_EQ, label); \
167  } while (0)
168 #define ASM_CALL_IND(as, ptr, idx) asm_arm_bl_ind(as, ptr, idx, ASM_ARM_REG_R3)
169 
170 #define ASM_MOV_REG_TO_LOCAL(as, reg, local_num) asm_arm_mov_local_reg(as, (local_num), (reg))
171 #define ASM_MOV_IMM_TO_REG(as, imm, reg) asm_arm_mov_reg_i32(as, (reg), (imm))
172 #define ASM_MOV_ALIGNED_IMM_TO_REG(as, imm, reg) asm_arm_mov_reg_i32(as, (reg), (imm))
173 #define ASM_MOV_IMM_TO_LOCAL_USING(as, imm, local_num, reg_temp) \
174  do { \
175  asm_arm_mov_reg_i32(as, (reg_temp), (imm)); \
176  asm_arm_mov_local_reg(as, (local_num), (reg_temp)); \
177  } while (false)
178 #define ASM_MOV_LOCAL_TO_REG(as, local_num, reg) asm_arm_mov_reg_local(as, (reg), (local_num))
179 #define ASM_MOV_REG_REG(as, reg_dest, reg_src) asm_arm_mov_reg_reg((as), (reg_dest), (reg_src))
180 #define ASM_MOV_LOCAL_ADDR_TO_REG(as, local_num, reg) asm_arm_mov_reg_local_addr(as, (reg), (local_num))
181 
182 #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) asm_arm_lsl_reg_reg((as), (reg_dest), (reg_shift))
183 #define ASM_ASR_REG_REG(as, reg_dest, reg_shift) asm_arm_asr_reg_reg((as), (reg_dest), (reg_shift))
184 #define ASM_OR_REG_REG(as, reg_dest, reg_src) asm_arm_orr_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
185 #define ASM_XOR_REG_REG(as, reg_dest, reg_src) asm_arm_eor_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
186 #define ASM_AND_REG_REG(as, reg_dest, reg_src) asm_arm_and_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
187 #define ASM_ADD_REG_REG(as, reg_dest, reg_src) asm_arm_add_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
188 #define ASM_SUB_REG_REG(as, reg_dest, reg_src) asm_arm_sub_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
189 #define ASM_MUL_REG_REG(as, reg_dest, reg_src) asm_arm_mul_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
190 
191 #define ASM_LOAD_REG_REG(as, reg_dest, reg_base) asm_arm_ldr_reg_reg((as), (reg_dest), (reg_base), 0)
192 #define ASM_LOAD_REG_REG_OFFSET(as, reg_dest, reg_base, word_offset) asm_arm_ldr_reg_reg((as), (reg_dest), (reg_base), 4 * (word_offset))
193 #define ASM_LOAD8_REG_REG(as, reg_dest, reg_base) asm_arm_ldrb_reg_reg((as), (reg_dest), (reg_base))
194 #define ASM_LOAD16_REG_REG(as, reg_dest, reg_base) asm_arm_ldrh_reg_reg((as), (reg_dest), (reg_base))
195 #define ASM_LOAD32_REG_REG(as, reg_dest, reg_base) asm_arm_ldr_reg_reg((as), (reg_dest), (reg_base), 0)
196 
197 #define ASM_STORE_REG_REG(as, reg_value, reg_base) asm_arm_str_reg_reg((as), (reg_value), (reg_base), 0)
198 #define ASM_STORE_REG_REG_OFFSET(as, reg_dest, reg_base, word_offset) asm_arm_str_reg_reg((as), (reg_dest), (reg_base), 4 * (word_offset))
199 #define ASM_STORE8_REG_REG(as, reg_value, reg_base) asm_arm_strb_reg_reg((as), (reg_value), (reg_base))
200 #define ASM_STORE16_REG_REG(as, reg_value, reg_base) asm_arm_strh_reg_reg((as), (reg_value), (reg_base))
201 #define ASM_STORE32_REG_REG(as, reg_value, reg_base) asm_arm_str_reg_reg((as), (reg_value), (reg_base), 0)
202 
203 #endif // GENERIC_ASM_API
204 
205 #endif // MICROPY_INCLUDED_PY_ASMARM_H
void asm_arm_cmp_reg_reg(asm_arm_t *as, uint rd, uint rn)
void asm_arm_mov_reg_i32(asm_arm_t *as, uint rd, int imm)
void asm_arm_mov_reg_reg(asm_arm_t *as, uint reg_dest, uint reg_src)
void asm_arm_end_pass(asm_arm_t *as)
void asm_arm_strb_reg_reg(asm_arm_t *as, uint rd, uint rm)
uint push_reglist
Definition: asmarm.h:71
void asm_arm_cmp_reg_i8(asm_arm_t *as, uint rd, int imm)
void asm_arm_entry(asm_arm_t *as, int num_locals)
void asm_arm_eor_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm)
void asm_arm_lsl_reg_reg(asm_arm_t *as, uint rd, uint rs)
void asm_arm_add_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm)
struct _asm_arm_t asm_arm_t
void asm_arm_setcc_reg(asm_arm_t *as, uint rd, uint cond)
void asm_arm_sub_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm)
void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label)
uint stack_adjust
Definition: asmarm.h:72
void asm_arm_ldrb_reg_reg(asm_arm_t *as, uint rd, uint rn)
void asm_arm_bkpt(asm_arm_t *as)
void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn, uint byte_offset)
void asm_arm_b_label(asm_arm_t *as, uint label)
void asm_arm_str_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn)
void asm_arm_exit(asm_arm_t *as)
void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn)
void asm_arm_mov_reg_local(asm_arm_t *as, uint rd, int local_num)
void asm_arm_mul_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm)
void asm_arm_bl_ind(asm_arm_t *as, void *fun_ptr, uint fun_id, uint reg_temp)
void asm_arm_mov_reg_local_addr(asm_arm_t *as, uint rd, int local_num)
void asm_arm_asr_reg_reg(asm_arm_t *as, uint rd, uint rs)
void asm_arm_strb_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn)
void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm, uint byte_offset)
void asm_arm_push(asm_arm_t *as, uint reglist)
void asm_arm_orr_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm)
void asm_arm_pop(asm_arm_t *as, uint reglist)
void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm)
void asm_arm_mov_local_reg(asm_arm_t *as, int local_num, uint rd)
void asm_arm_strh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn)
void asm_arm_and_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm)
mp_asm_base_t base
Definition: asmarm.h:70
unsigned int uint
Definition: misc.h:38