blob: 15e7a047b54ac0a157e13261bd10af46cfe51a25 [file] [log] [blame]
Fabian Vogtfe3d16e2014-08-16 22:55:53 +02001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2014 Fabian Vogt
Fabian Vogt16ee30c2014-08-28 01:18:56 +02007 * Copyright (c) 2013, 2014 Damien P. George
Fabian Vogtfe3d16e2014-08-16 22:55:53 +02008 *
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 */
Damien Georgeebde3c62015-01-01 18:07:43 +000027#ifndef __MICROPY_INCLUDED_PY_ASMARM_H__
28#define __MICROPY_INCLUDED_PY_ASMARM_H__
29
30#include "py/misc.h"
Fabian Vogtfe3d16e2014-08-16 22:55:53 +020031
32#define ASM_ARM_PASS_COMPUTE (1)
33#define ASM_ARM_PASS_EMIT (2)
34
Damien George0b610de2014-09-29 16:25:04 +010035#define ASM_ARM_REG_R0 (0)
36#define ASM_ARM_REG_R1 (1)
37#define ASM_ARM_REG_R2 (2)
38#define ASM_ARM_REG_R3 (3)
39#define ASM_ARM_REG_R4 (4)
40#define ASM_ARM_REG_R5 (5)
41#define ASM_ARM_REG_R6 (6)
42#define ASM_ARM_REG_R7 (7)
43#define ASM_ARM_REG_R8 (8)
44#define ASM_ARM_REG_R9 (9)
45#define ASM_ARM_REG_R10 (10)
46#define ASM_ARM_REG_R11 (11)
47#define ASM_ARM_REG_R12 (12)
48#define ASM_ARM_REG_R13 (13)
49#define ASM_ARM_REG_R14 (14)
50#define ASM_ARM_REG_R15 (15)
51#define ASM_ARM_REG_SP (ASM_ARM_REG_R13)
52#define ASM_ARM_REG_LR (ASM_ARM_REG_R14)
53#define ASM_ARM_REG_PC (ASM_ARM_REG_R15)
Fabian Vogtfe3d16e2014-08-16 22:55:53 +020054
Damien George0b610de2014-09-29 16:25:04 +010055#define ASM_ARM_CC_EQ (0x0 << 28)
56#define ASM_ARM_CC_NE (0x1 << 28)
57#define ASM_ARM_CC_CS (0x2 << 28)
58#define ASM_ARM_CC_CC (0x3 << 28)
59#define ASM_ARM_CC_MI (0x4 << 28)
60#define ASM_ARM_CC_PL (0x5 << 28)
61#define ASM_ARM_CC_VS (0x6 << 28)
62#define ASM_ARM_CC_VC (0x7 << 28)
63#define ASM_ARM_CC_HI (0x8 << 28)
64#define ASM_ARM_CC_LS (0x9 << 28)
65#define ASM_ARM_CC_GE (0xa << 28)
66#define ASM_ARM_CC_LT (0xb << 28)
67#define ASM_ARM_CC_GT (0xc << 28)
68#define ASM_ARM_CC_LE (0xd << 28)
69#define ASM_ARM_CC_AL (0xe << 28)
Fabian Vogtfe3d16e2014-08-16 22:55:53 +020070
71typedef struct _asm_arm_t asm_arm_t;
72
73asm_arm_t *asm_arm_new(uint max_num_labels);
74void asm_arm_free(asm_arm_t *as, bool free_code);
75void asm_arm_start_pass(asm_arm_t *as, uint pass);
76void asm_arm_end_pass(asm_arm_t *as);
Paul Sokolovsky351424e2015-05-07 23:08:09 +030077uint asm_arm_get_code_pos(asm_arm_t *as);
Fabian Vogtfe3d16e2014-08-16 22:55:53 +020078uint asm_arm_get_code_size(asm_arm_t *as);
79void *asm_arm_get_code(asm_arm_t *as);
80
81void asm_arm_entry(asm_arm_t *as, int num_locals);
82void asm_arm_exit(asm_arm_t *as);
83void asm_arm_label_assign(asm_arm_t *as, uint label);
84
85void asm_arm_align(asm_arm_t* as, uint align);
86void asm_arm_data(asm_arm_t* as, uint bytesize, uint val);
87
88void asm_arm_bkpt(asm_arm_t *as);
Fabian Vogte5268962014-10-04 00:53:46 +020089
90// mov
Fabian Vogtfe3d16e2014-08-16 22:55:53 +020091void asm_arm_mov_reg_reg(asm_arm_t *as, uint reg_dest, uint reg_src);
92void asm_arm_mov_reg_i32(asm_arm_t *as, uint rd, int imm);
93void asm_arm_mov_local_reg(asm_arm_t *as, int local_num, uint rd);
94void asm_arm_mov_reg_local(asm_arm_t *as, uint rd, int local_num);
Fabian Vogte5268962014-10-04 00:53:46 +020095void asm_arm_setcc_reg(asm_arm_t *as, uint rd, uint cond);
Fabian Vogtfe3d16e2014-08-16 22:55:53 +020096
Fabian Vogte5268962014-10-04 00:53:46 +020097// compare
Fabian Vogtfe3d16e2014-08-16 22:55:53 +020098void asm_arm_cmp_reg_i8(asm_arm_t *as, uint rd, int imm);
99void asm_arm_cmp_reg_reg(asm_arm_t *as, uint rd, uint rn);
Fabian Vogte5268962014-10-04 00:53:46 +0200100
101// arithmetic
Damien George3112cde2014-09-29 18:45:42 +0100102void asm_arm_add_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
103void asm_arm_sub_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
Damien George567b3492015-06-04 14:00:29 +0000104void asm_arm_mul_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
Damien George1ef23482014-10-12 14:21:06 +0100105void asm_arm_and_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
106void asm_arm_eor_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
107void asm_arm_orr_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
Fabian Vogtfe3d16e2014-08-16 22:55:53 +0200108void asm_arm_mov_reg_local_addr(asm_arm_t *as, uint rd, int local_num);
Fabian Vogte5268962014-10-04 00:53:46 +0200109void asm_arm_lsl_reg_reg(asm_arm_t *as, uint rd, uint rs);
110void asm_arm_asr_reg_reg(asm_arm_t *as, uint rd, uint rs);
Fabian Vogtfe3d16e2014-08-16 22:55:53 +0200111
Fabian Vogte5268962014-10-04 00:53:46 +0200112// memory
Paul Sokolovsky351424e2015-05-07 23:08:09 +0300113void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn, uint byte_offset);
Damien George91cfd412014-10-12 16:59:29 +0100114void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn);
115void asm_arm_ldrb_reg_reg(asm_arm_t *as, uint rd, uint rn);
Paul Sokolovsky351424e2015-05-07 23:08:09 +0300116void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm, uint byte_offset);
Fabian Vogte5268962014-10-04 00:53:46 +0200117void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm);
118void asm_arm_strb_reg_reg(asm_arm_t *as, uint rd, uint rm);
119// store to array
120void asm_arm_str_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
121void asm_arm_strh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
122void asm_arm_strb_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
123
Paul Sokolovsky351424e2015-05-07 23:08:09 +0300124// stack
125void asm_arm_push(asm_arm_t *as, uint reglist);
126void asm_arm_pop(asm_arm_t *as, uint reglist);
127
Fabian Vogte5268962014-10-04 00:53:46 +0200128// control flow
Fabian Vogtfe3d16e2014-08-16 22:55:53 +0200129void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label);
130void asm_arm_b_label(asm_arm_t *as, uint label);
131void asm_arm_bl_ind(asm_arm_t *as, void *fun_ptr, uint fun_id, uint reg_temp);
132
Damien Georgeebde3c62015-01-01 18:07:43 +0000133#endif // __MICROPY_INCLUDED_PY_ASMARM_H__