blob: 4e6e55e77f736127199a9bb6a5b1ebbd28ee5b6b [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
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27#define ASM_ARM_PASS_COMPUTE (1)
28#define ASM_ARM_PASS_EMIT (2)
29
30#define REG_R0 (0)
31#define REG_R1 (1)
32#define REG_R2 (2)
33#define REG_R3 (3)
34#define REG_R4 (4)
35#define REG_R5 (5)
36#define REG_R6 (6)
37#define REG_R7 (7)
38#define REG_R8 (8)
39#define REG_R9 (9)
40#define REG_R10 (10)
41#define REG_R11 (11)
42#define REG_R12 (12)
43#define REG_R13 (13)
44#define REG_R14 (14)
45#define REG_R15 (15)
46#define REG_SP (REG_R13)
47#define REG_LR (REG_R14)
48#define REG_PC (REG_R15)
49
50#define REG_RET REG_R0
51#define REG_ARG_1 REG_R0
52#define REG_ARG_2 REG_R1
53#define REG_ARG_3 REG_R2
54#define REG_ARG_4 REG_R3
55
56#define ARM_CC_EQ (0x0 << 28)
57#define ARM_CC_NE (0x1 << 28)
58#define ARM_CC_CS (0x2 << 28)
59#define ARM_CC_CC (0x3 << 28)
60#define ARM_CC_MI (0x4 << 28)
61#define ARM_CC_PL (0x5 << 28)
62#define ARM_CC_VS (0x6 << 28)
63#define ARM_CC_VC (0x7 << 28)
64#define ARM_CC_HI (0x8 << 28)
65#define ARM_CC_LS (0x9 << 28)
66#define ARM_CC_GE (0xa << 28)
67#define ARM_CC_LT (0xb << 28)
68#define ARM_CC_GT (0xc << 28)
69#define ARM_CC_LE (0xd << 28)
70#define ARM_CC_AL (0xe << 28)
71
72typedef struct _asm_arm_t asm_arm_t;
73
74asm_arm_t *asm_arm_new(uint max_num_labels);
75void asm_arm_free(asm_arm_t *as, bool free_code);
76void asm_arm_start_pass(asm_arm_t *as, uint pass);
77void asm_arm_end_pass(asm_arm_t *as);
78uint 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);
89void asm_arm_mov_reg_reg(asm_arm_t *as, uint reg_dest, uint reg_src);
90void asm_arm_mov_reg_i32(asm_arm_t *as, uint rd, int imm);
91void asm_arm_mov_local_reg(asm_arm_t *as, int local_num, uint rd);
92void asm_arm_mov_reg_local(asm_arm_t *as, uint rd, int local_num);
93
94void asm_arm_cmp_reg_i8(asm_arm_t *as, uint rd, int imm);
95void asm_arm_cmp_reg_reg(asm_arm_t *as, uint rd, uint rn);
96void asm_arm_less_op(asm_arm_t *as, uint rd, uint rn);
97void asm_arm_add_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
98void asm_arm_mov_reg_local_addr(asm_arm_t *as, uint rd, int local_num);
99
100void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label);
101void asm_arm_b_label(asm_arm_t *as, uint label);
102void asm_arm_bl_ind(asm_arm_t *as, void *fun_ptr, uint fun_id, uint reg_temp);
103