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 | } Operand; | 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 | /* Parse a text containing operand and store the result in OP */ | 116 | /* Parse a text containing operand and store the result in OP */ |
| 115 | static void parse_operand(TCCState *s1, Operand *op) | 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 | case TOK_ASM_auipc: | 217 | case TOK_ASM_auipc: |
| 216 | asm_emit_u(token, (0x05 << 2) | 3, &ops[0], &ops[1]); | 218 | asm_emit_u(token, (0x05 << 2) | 3, &ops[0], &ops[1]); |
| 217 | return; | 219 | return; |
| 220 | case TOK_ASM_jal: | ||
| 221 | asm_emit_u(token, 0x6f, ops, ops + 1); | ||
| 222 | return; | ||
| 218 | default: | 223 | default: |
| 219 | expect("binary instruction"); | 224 | expect("binary instruction"); |
| 220 | } | 225 | } |
| @@ -399,6 +404,12 @@ static void asm_data_processing_opcode(TCCState* s1, int token) · 178 unmodified lines | |||
| 399 | case TOK_ASM_sltiu: | 404 | case TOK_ASM_sltiu: |
| 400 | asm_emit_i(token, (0x4 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]); | 405 | asm_emit_i(token, (0x4 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]); |
| 401 | return; | 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 | default: | 413 | default: |
| 403 | expect("known data processing instruction"); | 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 | case TOK_ASM_lui: | 600 | case TOK_ASM_lui: |
| 590 | case TOK_ASM_auipc: | 601 | case TOK_ASM_auipc: |
| 602 | case TOK_ASM_jal: | ||
| 591 | asm_binary_opcode(s1, token); | 603 | asm_binary_opcode(s1, token); |
| 592 | return; | 604 | return; |
| 593 | 605 | ||
| @@ -628,6 +640,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 34 unmodified lines | |||
| 628 | case TOK_ASM_slti: | 640 | case TOK_ASM_slti: |
| 629 | case TOK_ASM_sltu: | 641 | case TOK_ASM_sltu: |
| 630 | case TOK_ASM_sltiu: | 642 | case TOK_ASM_sltiu: |
| 643 | case TOK_ASM_jalr: | ||
| 631 | asm_data_processing_opcode(s1, token); | 644 | asm_data_processing_opcode(s1, token); |
| 632 | return; | 645 | return; |
| 633 | 646 | ||