/* * ARM specific functions for TCC assembler * * Copyright (c) 2001, 2002 Fabrice Bellard * Copyright (c) 2020 Danny Milosavljevic * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef TARGET_DEFS_ONLY #define CONFIG_TCC_ASM #define NB_ASM_REGS 16 ST_FUNC void g(int c); ST_FUNC void gen_le16(int c); ST_FUNC void gen_le32(int c); /*************************************************************/ #else /*************************************************************/ #define USING_GLOBALS #include "tcc.h" static void asm_error(void) { tcc_error("ARM asm not implemented."); } /* XXX: make it faster ? */ ST_FUNC void g(int c) { int ind1; if (nocode_wanted) return; ind1 = ind + 1; if (ind1 > cur_text_section->data_allocated) section_realloc(cur_text_section, ind1); cur_text_section->data[ind] = c; ind = ind1; } ST_FUNC void gen_le16 (int i) { g(i); g(i>>8); } ST_FUNC void gen_le32 (int i) { gen_le16(i); gen_le16(i>>16); } ST_FUNC void gen_expr32(ExprValue *pe) { gen_le32(pe->v); } ST_FUNC void asm_opcode(TCCState *s1, int opcode) { asm_error(); } ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier) { asm_error(); } /* generate prolog and epilog code for asm statement */ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg) { } ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg) { } ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) { int reg; TokenSym *ts; if (!strcmp(str, "memory") || !strcmp(str, "cc") || !strcmp(str, "flags")) return; ts = tok_alloc(str, strlen(str)); reg = asm_parse_regvar(ts->tok); if (reg == -1) { tcc_error("invalid clobber register '%s'", str); } clobber_regs[reg] = 1; } /* If T refers to a register then return the register number and type. Otherwise return -1. */ ST_FUNC int asm_parse_regvar (int t) { if (t >= TOK_ASM_r0 && t <= TOK_ASM_pc) { /* register name */ switch (t) { case TOK_ASM_fp: return TOK_ASM_r11 - TOK_ASM_r0; case TOK_ASM_ip: return TOK_ASM_r12 - TOK_ASM_r0; case TOK_ASM_sp: return TOK_ASM_r13 - TOK_ASM_r0; case TOK_ASM_lr: return TOK_ASM_r14 - TOK_ASM_r0; case TOK_ASM_pc: return TOK_ASM_r15 - TOK_ASM_r0; default: return t - TOK_ASM_r0; } } else return -1; } /*************************************************************/ #endif /* ndef TARGET_DEFS_ONLY */