this implements the base instructions, not the pseudoinstructions examples jal ra, 0 jalr x0, ra, 0
Unified · Split
| @@ -111,6 +111,8 @@ typedef struct Operand { · 110 unmodified lines | ||
| 111 | 111 | }; |
| 112 | 112 | } Operand; |
| 113 | 113 | |
| 114 | +static void asm_emit_i(int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2); | |
| 115 | + | |
| 114 | 116 | /* Parse a text containing operand and store the result in OP */ |
| 115 | 117 | static void parse_operand(TCCState *s1, Operand *op) |
| 116 | 118 | { |
| @@ -215,6 +217,9 @@ static void asm_binary_opcode(TCCState* s1, int token) · 98 unmodified lines | ||
| 215 | 217 | case TOK_ASM_auipc: |
| 216 | 218 | asm_emit_u(token, (0x05 << 2) | 3, &ops[0], &ops[1]); |
| 217 | 219 | return; |
| 220 | + case TOK_ASM_jal: | |
| 221 | + asm_emit_u(token, 0x6f, ops, ops + 1); | |
| 222 | + return; | |
| 218 | 223 | default: |
| 219 | 224 | expect("binary instruction"); |
| 220 | 225 | } |
| @@ -399,6 +404,12 @@ static void asm_data_processing_opcode(TCCState* s1, int token) · 178 unmodified lines | ||
| 399 | 404 | case TOK_ASM_sltiu: |
| 400 | 405 | asm_emit_i(token, (0x4 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]); |
| 401 | 406 | return; |
| 407 | + | |
| 408 | + /* indirect jump (RD, RS1, IMM); I-format */ | |
| 409 | + case TOK_ASM_jalr: | |
| 410 | + asm_emit_i(token, 0x67 | (0 << 12), ops, ops + 1, ops + 2); | |
| 411 | + return; | |
| 412 | + | |
| 402 | 413 | default: |
| 403 | 414 | expect("known data processing instruction"); |
| 404 | 415 | } |
| @@ -588,6 +599,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 183 unmodified lines | ||
| 588 | 599 | |
| 589 | 600 | case TOK_ASM_lui: |
| 590 | 601 | case TOK_ASM_auipc: |
| 602 | + case TOK_ASM_jal: | |
| 591 | 603 | asm_binary_opcode(s1, token); |
| 592 | 604 | return; |
| 593 | 605 | |
| @@ -628,6 +640,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 34 unmodified lines | ||
| 628 | 640 | case TOK_ASM_slti: |
| 629 | 641 | case TOK_ASM_sltu: |
| 630 | 642 | case TOK_ASM_sltiu: |
| 643 | + case TOK_ASM_jalr: | |
| 631 | 644 | asm_data_processing_opcode(s1, token); |
| 632 | 645 | return; |
| 633 | 646 | |