[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] [PATCH 15/16] arm-asm: Add b, bl, bx, blx
From: |
Danny Milosavljevic |
Subject: |
[Tinycc-devel] [PATCH 15/16] arm-asm: Add b, bl, bx, blx |
Date: |
Sat, 26 Dec 2020 22:58:16 +0100 |
---
arm-asm.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
arm-tok.h | 7 +++++++
2 files changed, 67 insertions(+)
diff --git a/arm-asm.c b/arm-asm.c
index 58853f6..8c8a464 100644
--- a/arm-asm.c
+++ b/arm-asm.c
@@ -754,6 +754,61 @@ static void asm_single_data_transfer_opcode(TCCState *s1,
int token)
}
}
+/* Note: almost dupe of encbranch in arm-gen.c */
+static uint32_t encbranchoffset(int pos, int addr, int fail)
+{
+ addr-=pos+8;
+ addr/=4;
+ if(addr>=0x1000000 || addr<-0x1000000) { // FIXME: Is that correct?
+ if(fail)
+ tcc_error("function bigger than 32MB");
+ return 0;
+ }
+ return /*not 0x0A000000|*/(addr&0xffffff);
+}
+
+static void asm_branch_opcode(TCCState *s1, int token)
+{
+ int jmp_disp = 0;
+ Operand op;
+ parse_operand(s1, &op);
+ if (op.type == OP_IM32 || op.type == OP_IM8 || op.type == OP_IM8N) {
+ jmp_disp = encbranchoffset(ind, op.e.v, 0);
+ if (jmp_disp < -0x800000 || jmp_disp > 0x7fffff) {
+ tcc_error("branch is too far");
+ return;
+ }
+ }
+ switch (ARM_INSTRUCTION_GROUP(token)) {
+ case TOK_ASM_beq:
+ if (op.type == OP_IM32 || op.type == OP_IM8 || op.type == OP_IM8N)
+ asm_emit_opcode(token, (0xa << 24) | (jmp_disp & 0xffffff));
+ else
+ expect("branch target");
+ break;
+ case TOK_ASM_bleq:
+ if (op.type == OP_IM32 || op.type == OP_IM8 || op.type == OP_IM8N)
+ asm_emit_opcode(token, (0xb << 24) | (jmp_disp & 0xffffff));
+ else
+ expect("branch target");
+ break;
+ case TOK_ASM_bxeq:
+ if (op.type != OP_REG32)
+ expect("register");
+ else
+ asm_emit_opcode(token, (0x12fff1 << 4) | op.reg);
+ break;
+ case TOK_ASM_blxeq:
+ if (op.type != OP_REG32)
+ expect("register");
+ else
+ asm_emit_opcode(token, (0x12fff3 << 4) | op.reg);
+ break;
+ default:
+ expect("branch instruction");
+ }
+}
+
ST_FUNC void asm_opcode(TCCState *s1, int token)
{
while (token == TOK_LINEFEED) {
@@ -787,6 +842,11 @@ ST_FUNC void asm_opcode(TCCState *s1, int token)
return asm_nullary_opcode(token);
case TOK_ASM_swieq:
return asm_unary_opcode(s1, token);
+ case TOK_ASM_beq:
+ case TOK_ASM_bleq:
+ case TOK_ASM_bxeq:
+ case TOK_ASM_blxeq:
+ return asm_branch_opcode(s1, token);
case TOK_ASM_clzeq:
case TOK_ASM_sxtbeq:
case TOK_ASM_sxtheq:
diff --git a/arm-tok.h b/arm-tok.h
index 023b01a..2f1798b 100644
--- a/arm-tok.h
+++ b/arm-tok.h
@@ -104,6 +104,13 @@
DEF_ASM_CONDED(push)
DEF_ASM_CONDED(pop)
+ /* branches */
+
+ DEF_ASM_CONDED(b)
+ DEF_ASM_CONDED(bl)
+ DEF_ASM_CONDED(bx)
+ DEF_ASM_CONDED(blx)
+
/* data processing instructions; order is important */
DEF_ASM_CONDED(and)
- [Tinycc-devel] [PATCH 05/16] arm-asm: Add nop, (continued)
- [Tinycc-devel] [PATCH 05/16] arm-asm: Add nop, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 08/16] arm-asm: Add push, pop, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 01/16] arm-asm: Publish g, gen_le16, gen_le32 in tcc.h, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 09/16] arm-asm: Add swi, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 07/16] arm-asm: Add parse_operand, Operand, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 10/16] arm-asm: Add clz, sxtb, sxth, uxtb, uxth, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 12/16] arm-asm: Add stmda, ldmda, stm, ldm, stmia, ldmia, stmdb, ldmdb, stmib, ldmib, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 11/16] arm-asm: Add mul, mla, smull, umull, smlal, umlal, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 13/16] arm-asm: Add ldr, ldrb, str, strb, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 16/16] arm-asm: Optimize gen_le32, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 15/16] arm-asm: Add b, bl, bx, blx,
Danny Milosavljevic <=
- [Tinycc-devel] [PATCH 14/16] arm-asm: Add and, eor, sub, rsb, add, adc, sbc, rsc, tst, teq, cmp, cmn, orr, mov, bic, mvn, Danny Milosavljevic, 2020/12/26
- Re: [Tinycc-devel] [PATCH 00/16] Add ARM inline assembler, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 02/16] arm-asm: Implement asm_parse_regvar and asm_clobber, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 04/16] arm-asm: Remove asm_error, Danny Milosavljevic, 2020/12/26
- Re: [Tinycc-devel] [PATCH 00/16] Add ARM inline assembler, Jan Nieuwenhuizen, 2020/12/27
- Re: [Tinycc-devel] [PATCH 00/16] Add ARM inline assembler, Michael Matz, 2020/12/27
- Prev by Date:
[Tinycc-devel] [PATCH 16/16] arm-asm: Optimize gen_le32
- Next by Date:
[Tinycc-devel] [PATCH 14/16] arm-asm: Add and, eor, sub, rsb, add, adc, sbc, rsc, tst, teq, cmp, cmn, orr, mov, bic, mvn
- Previous by thread:
[Tinycc-devel] [PATCH 16/16] arm-asm: Optimize gen_le32
- Next by thread:
[Tinycc-devel] [PATCH 14/16] arm-asm: Add and, eor, sub, rsb, add, adc, sbc, rsc, tst, teq, cmp, cmn, orr, mov, bic, mvn
- Index(es):