History

riscv64-asm.c: add Zicsr registers

noneofyourbusiness committed 2 years ago

Commit b390fee1 parent 5dc241f1 file · +34 −3Browse files

Unified · Split

riscv64-asm.c+34−3
@@ -56,6 +56,7 @@ static void asm_emit_u(int token, uint32_t opcode, const Operand *rd, const Oper · 55 unmodified lines
5656 static void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
5757 static void asm_nullary_opcode(TCCState *s1, int token);
5858 static void asm_opcode(TCCState *s1, int token);
59+static int asm_parse_csrvar(int t);
5960 static int asm_parse_regvar(int t);
6061 static void asm_ternary_opcode(TCCState *s1, int token);
6162 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
165166 /* Parse a text containing operand and store the result in OP */
166167 static void parse_operand(TCCState *s1, Operand *op)
167168 {
168− ExprValue e;
169+ ExprValue e = {0};
169170 int8_t reg;
170171
171172 op->type = 0;
@@ -178,16 +179,20 @@ static void parse_operand(TCCState *s1, Operand *op) · 6 unmodified lines
178179 } else if (tok == '$') {
179180 /* constant value */
180181 next(); // skip '#' or '$'
182+ } else if ((e.v = asm_parse_csrvar(tok)) != -1) {
183+ next();
184+ } else {
185+ asm_expr(s1, &e);
181186 }
182− asm_expr(s1, &e);
183187 op->type = OP_IM32;
184188 op->e = e;
185189 /* compare against unsigned 12-bit maximum */
186190 if (!op->e.sym) {
187191 if (op->e.v < 0x1000)
188192 op->type = OP_IM12S;
189− } else
193+ } else {
190194 expect("operand");
195+ }
191196 }
192197
193198 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
952957 }
953958 }
954959
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+
955986 ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier)
956987 {
957988 tcc_error("RISCV64 asm not implemented.");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t