Unified · Split
| @@ -56,6 +56,7 @@ static void asm_emit_u(int token, uint32_t opcode, const Operand *rd, const Oper · 55 unmodified lines | |||
| 56 | static void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg); | 56 | static void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg); |
| 57 | static void asm_nullary_opcode(TCCState *s1, int token); | 57 | static void asm_nullary_opcode(TCCState *s1, int token); |
| 58 | static void asm_opcode(TCCState *s1, int token); | 58 | static void asm_opcode(TCCState *s1, int token); |
| 59 | static int asm_parse_csrvar(int t); | ||
| 59 | static int asm_parse_regvar(int t); | 60 | static int asm_parse_regvar(int t); |
| 60 | static void asm_ternary_opcode(TCCState *s1, int token); | 61 | static void asm_ternary_opcode(TCCState *s1, int token); |
| 61 | static void asm_unary_opcode(TCCState *s1, int token); | 62 | static void asm_unary_opcode(TCCState *s1, int token); |
| @@ -165,7 +166,7 @@ static void asm_nullary_opcode(TCCState *s1, int token) · 103 unmodified lines | |||
| 165 | /* Parse a text containing operand and store the result in OP */ | 166 | /* Parse a text containing operand and store the result in OP */ |
| 166 | static void parse_operand(TCCState *s1, Operand *op) | 167 | static void parse_operand(TCCState *s1, Operand *op) |
| 167 | { | 168 | { |
| 168 | ExprValue e; | 169 | ExprValue e = {0}; |
| 169 | int8_t reg; | 170 | int8_t reg; |
| 170 | 171 | ||
| 171 | op->type = 0; | 172 | op->type = 0; |
| @@ -178,16 +179,20 @@ static void parse_operand(TCCState *s1, Operand *op) · 6 unmodified lines | |||
| 178 | } else if (tok == '$') { | 179 | } else if (tok == '$') { |
| 179 | /* constant value */ | 180 | /* constant value */ |
| 180 | next(); // skip '#' or '$' | 181 | next(); // skip '#' or '$' |
| 182 | } else if ((e.v = asm_parse_csrvar(tok)) != -1) { | ||
| 183 | next(); | ||
| 184 | } else { | ||
| 185 | asm_expr(s1, &e); | ||
| 181 | } | 186 | } |
| 182 | asm_expr(s1, &e); | ||
| 183 | op->type = OP_IM32; | 187 | op->type = OP_IM32; |
| 184 | op->e = e; | 188 | op->e = e; |
| 185 | /* compare against unsigned 12-bit maximum */ | 189 | /* compare against unsigned 12-bit maximum */ |
| 186 | if (!op->e.sym) { | 190 | if (!op->e.sym) { |
| 187 | if (op->e.v < 0x1000) | 191 | if (op->e.v < 0x1000) |
| 188 | op->type = OP_IM12S; | 192 | op->type = OP_IM12S; |
| 189 | } else | 193 | } else { |
| 190 | expect("operand"); | 194 | expect("operand"); |
| 195 | } | ||
| 191 | } | 196 | } |
| 192 | 197 | ||
| 193 | static void asm_unary_opcode(TCCState *s1, int token) | 198 | static void asm_unary_opcode(TCCState *s1, int token) |
| @@ -952,6 +957,32 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 758 unmodified lines | |||
| 952 | } | 957 | } |
| 953 | } | 958 | } |
| 954 | 959 | ||
| 960 | static int asm_parse_csrvar(int t) | ||
| 961 | { | ||
| 962 | switch (t) { | ||
| 963 | case TOK_ASM_cycle: | ||
| 964 | return 0xc00; | ||
| 965 | case TOK_ASM_fcsr: | ||
| 966 | return 3; | ||
| 967 | case TOK_ASM_fflags: | ||
| 968 | return 1; | ||
| 969 | case TOK_ASM_frm: | ||
| 970 | return 2; | ||
| 971 | case TOK_ASM_instret: | ||
| 972 | return 0xc02; | ||
| 973 | case TOK_ASM_time: | ||
| 974 | return 0xc01; | ||
| 975 | case TOK_ASM_cycleh: | ||
| 976 | return 0xc80; | ||
| 977 | case TOK_ASM_instreth: | ||
| 978 | return 0xc82; | ||
| 979 | case TOK_ASM_timeh: | ||
| 980 | return 0xc81; | ||
| 981 | default: | ||
| 982 | return -1; | ||
| 983 | } | ||
| 984 | } | ||
| 985 | |||
| 955 | ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier) | 986 | ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier) |
| 956 | { | 987 | { |
| 957 | tcc_error("RISCV64 asm not implemented."); | 988 | tcc_error("RISCV64 asm not implemented."); |