@@ -45,9 +45,8 @@ struct _asm_arm_t {
4545 byte * code_base ;
4646 byte dummy_data [4 ];
4747
48- uint max_num_labels ;
49- int * label_offsets ;
50- int num_locals ;
48+ mp_uint_t max_num_labels ;
49+ mp_uint_t * label_offsets ;
5150 uint push_reglist ;
5251 uint stack_adjust ;
5352};
@@ -57,7 +56,7 @@ asm_arm_t *asm_arm_new(uint max_num_labels) {
5756
5857 as = m_new0 (asm_arm_t , 1 );
5958 as -> max_num_labels = max_num_labels ;
60- as -> label_offsets = m_new (int , max_num_labels );
59+ as -> label_offsets = m_new (mp_uint_t , max_num_labels );
6160
6261 return as ;
6362}
@@ -66,15 +65,15 @@ void asm_arm_free(asm_arm_t *as, bool free_code) {
6665 if (free_code ) {
6766 MP_PLAT_FREE_EXEC (as -> code_base , as -> code_size );
6867 }
69-
68+ m_del ( mp_uint_t , as -> label_offsets , as -> max_num_labels );
7069 m_del_obj (asm_arm_t , as );
7170}
7271
7372void asm_arm_start_pass (asm_arm_t * as , uint pass ) {
7473 as -> pass = pass ;
7574 as -> code_offset = 0 ;
7675 if (pass == ASM_ARM_PASS_COMPUTE ) {
77- memset (as -> label_offsets , -1 , as -> max_num_labels * sizeof (int ));
76+ memset (as -> label_offsets , -1 , as -> max_num_labels * sizeof (mp_uint_t ));
7877 }
7978}
8079
@@ -127,7 +126,7 @@ STATIC void emit(asm_arm_t *as, uint op) {
127126
128127// Insert word into instruction flow, add "ALWAYS" condition code
129128STATIC void emit_al (asm_arm_t * as , uint op ) {
130- emit (as , op | ARM_CC_AL );
129+ emit (as , op | ASM_ARM_CC_AL );
131130}
132131
133132// Basic instructions without condition code
@@ -178,7 +177,7 @@ void asm_arm_bkpt(asm_arm_t *as) {
178177
179178// locals:
180179// - stored on the stack in ascending order
181- // - numbered 0 through as-> num_locals-1
180+ // - numbered 0 through num_locals-1
182181// - SP points to first local
183182//
184183// | SP
@@ -194,30 +193,36 @@ void asm_arm_entry(asm_arm_t *as, int num_locals) {
194193 }
195194
196195 as -> stack_adjust = 0 ;
197- as -> num_locals = num_locals ;
198- as -> push_reglist = 1 << REG_R1 | 1 << REG_R2 | 1 << REG_R3 | 1 << REG_R4
199- | 1 << REG_R5 | 1 << REG_R6 | 1 << REG_R7 | 1 << REG_R8 ;
196+ as -> push_reglist = 1 << ASM_ARM_REG_R1
197+ | 1 << ASM_ARM_REG_R2
198+ | 1 << ASM_ARM_REG_R3
199+ | 1 << ASM_ARM_REG_R4
200+ | 1 << ASM_ARM_REG_R5
201+ | 1 << ASM_ARM_REG_R6
202+ | 1 << ASM_ARM_REG_R7
203+ | 1 << ASM_ARM_REG_R8 ;
200204
201205 // Only adjust the stack if there are more locals than usable registers
202206 if (num_locals > 3 ) {
203207 as -> stack_adjust = num_locals * 4 ;
204208 // Align stack to 8 bytes
205- if ( as -> num_locals & 1 )
209+ if ( num_locals & 1 ) {
206210 as -> stack_adjust += 4 ;
211+ }
207212 }
208213
209- emit_al (as , asm_arm_op_push (as -> push_reglist | 1 << REG_LR ));
214+ emit_al (as , asm_arm_op_push (as -> push_reglist | 1 << ASM_ARM_REG_LR ));
210215 if (as -> stack_adjust > 0 ) {
211- emit_al (as , asm_arm_op_sub_imm (REG_SP , REG_SP , as -> stack_adjust ));
216+ emit_al (as , asm_arm_op_sub_imm (ASM_ARM_REG_SP , ASM_ARM_REG_SP , as -> stack_adjust ));
212217 }
213218}
214219
215220void asm_arm_exit (asm_arm_t * as ) {
216221 if (as -> stack_adjust > 0 ) {
217- emit_al (as , asm_arm_op_add_imm (REG_SP , REG_SP , as -> stack_adjust ));
222+ emit_al (as , asm_arm_op_add_imm (ASM_ARM_REG_SP , ASM_ARM_REG_SP , as -> stack_adjust ));
218223 }
219224
220- emit_al (as , asm_arm_op_pop (as -> push_reglist | (1 << REG_PC )));
225+ emit_al (as , asm_arm_op_pop (as -> push_reglist | (1 << ASM_ARM_REG_PC )));
221226}
222227
223228void asm_arm_label_assign (asm_arm_t * as , uint label ) {
@@ -289,8 +294,8 @@ void asm_arm_cmp_reg_reg(asm_arm_t *as, uint rd, uint rn) {
289294
290295void asm_arm_less_op (asm_arm_t * as , uint rd , uint rn , uint rm ) {
291296 asm_arm_cmp_reg_reg (as , rn , rm ); // cmp rn, rm
292- emit (as , asm_arm_op_mov_imm (rd , 1 ) | ARM_CC_LT ); // movlt rd, #1
293- emit (as , asm_arm_op_mov_imm (rd , 0 ) | ARM_CC_GE ); // movge rd, #0
297+ emit (as , asm_arm_op_mov_imm (rd , 1 ) | ASM_ARM_CC_LT ); // movlt rd, #1
298+ emit (as , asm_arm_op_mov_imm (rd , 0 ) | ASM_ARM_CC_GE ); // movge rd, #0
294299}
295300
296301void asm_arm_add_reg (asm_arm_t * as , uint rd , uint rn , uint rm ) {
@@ -300,13 +305,13 @@ void asm_arm_add_reg(asm_arm_t *as, uint rd, uint rn, uint rm) {
300305
301306void asm_arm_mov_reg_local_addr (asm_arm_t * as , uint rd , int local_num ) {
302307 // add rd, sp, #local_num*4
303- emit_al (as , asm_arm_op_add_imm (rd , REG_SP , local_num << 2 ));
308+ emit_al (as , asm_arm_op_add_imm (rd , ASM_ARM_REG_SP , local_num << 2 ));
304309}
305310
306311void asm_arm_bcc_label (asm_arm_t * as , int cond , uint label ) {
307312 assert (label < as -> max_num_labels );
308- int dest = as -> label_offsets [label ];
309- int rel = dest - as -> code_offset ;
313+ mp_uint_t dest = as -> label_offsets [label ];
314+ mp_int_t rel = dest - as -> code_offset ;
310315 rel -= 8 ; // account for instruction prefetch, PC is 8 bytes ahead of this instruction
311316 rel >>= 2 ; // in ARM mode the branch target is 32-bit aligned, so the 2 LSB are omitted
312317
@@ -318,21 +323,21 @@ void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label) {
318323}
319324
320325void asm_arm_b_label (asm_arm_t * as , uint label ) {
321- asm_arm_bcc_label (as , ARM_CC_AL , label );
326+ asm_arm_bcc_label (as , ASM_ARM_CC_AL , label );
322327}
323328
324329void asm_arm_bl_ind (asm_arm_t * as , void * fun_ptr , uint fun_id , uint reg_temp ) {
325330 // If the table offset fits into the ldr instruction
326331 if (fun_id < (0x1000 / 4 )) {
327- emit_al (as , asm_arm_op_mov_reg (REG_LR , REG_PC )); // mov lr, pc
332+ emit_al (as , asm_arm_op_mov_reg (ASM_ARM_REG_LR , ASM_ARM_REG_PC )); // mov lr, pc
328333 emit_al (as , 0x597f000 | (fun_id << 2 )); // ldr pc, [r7, #fun_id*4]
329334 return ;
330335 }
331336
332337 emit_al (as , 0x59f0004 | (reg_temp << 12 )); // ldr rd, [pc, #4]
333338 // Set lr after fun_ptr
334- emit_al (as , asm_arm_op_add_imm (REG_LR , REG_PC , 4 )); // add lr, pc, #4
335- emit_al (as , asm_arm_op_mov_reg (REG_PC , reg_temp )); // mov pc, reg_temp
339+ emit_al (as , asm_arm_op_add_imm (ASM_ARM_REG_LR , ASM_ARM_REG_PC , 4 )); // add lr, pc, #4
340+ emit_al (as , asm_arm_op_mov_reg (ASM_ARM_REG_PC , reg_temp )); // mov pc, reg_temp
336341 emit (as , (uint ) fun_ptr );
337342}
338343
0 commit comments