xref: /openbmc/qemu/target/riscv/translate.c (revision 89c88309)
1 /*
2  * RISC-V emulation for qemu: main translation routines.
3  *
4  * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2 or later, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "qemu/osdep.h"
20 #include "qemu/log.h"
21 #include "cpu.h"
22 #include "tcg/tcg-op.h"
23 #include "disas/disas.h"
24 #include "exec/cpu_ldst.h"
25 #include "exec/exec-all.h"
26 #include "exec/helper-proto.h"
27 #include "exec/helper-gen.h"
28 
29 #include "exec/translator.h"
30 #include "exec/log.h"
31 
32 #include "instmap.h"
33 
34 /* global register indices */
35 static TCGv cpu_gpr[32], cpu_pc, cpu_vl;
36 static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */
37 static TCGv load_res;
38 static TCGv load_val;
39 
40 #include "exec/gen-icount.h"
41 
42 /*
43  * If an operation is being performed on less than TARGET_LONG_BITS,
44  * it may require the inputs to be sign- or zero-extended; which will
45  * depend on the exact operation being performed.
46  */
47 typedef enum {
48     EXT_NONE,
49     EXT_SIGN,
50     EXT_ZERO,
51 } DisasExtend;
52 
53 typedef struct DisasContext {
54     DisasContextBase base;
55     /* pc_succ_insn points to the instruction following base.pc_next */
56     target_ulong pc_succ_insn;
57     target_ulong priv_ver;
58     target_ulong misa;
59     uint32_t opcode;
60     uint32_t mstatus_fs;
61     uint32_t mem_idx;
62     /* Remember the rounding mode encoded in the previous fp instruction,
63        which we have already installed into env->fp_status.  Or -1 for
64        no previous fp instruction.  Note that we exit the TB when writing
65        to any system register, which includes CSR_FRM, so we do not have
66        to reset this known value.  */
67     int frm;
68     bool w;
69     bool virt_enabled;
70     bool ext_ifencei;
71     bool hlsx;
72     /* vector extension */
73     bool vill;
74     uint8_t lmul;
75     uint8_t sew;
76     uint16_t vlen;
77     uint16_t mlen;
78     bool vl_eq_vlmax;
79     uint8_t ntemp;
80     CPUState *cs;
81     TCGv zero;
82     /* Space for 3 operands plus 1 extra for address computation. */
83     TCGv temp[4];
84 } DisasContext;
85 
86 static inline bool has_ext(DisasContext *ctx, uint32_t ext)
87 {
88     return ctx->misa & ext;
89 }
90 
91 #ifdef TARGET_RISCV32
92 # define is_32bit(ctx)  true
93 #elif defined(CONFIG_USER_ONLY)
94 # define is_32bit(ctx)  false
95 #else
96 static inline bool is_32bit(DisasContext *ctx)
97 {
98     return (ctx->misa & RV32) == RV32;
99 }
100 #endif
101 
102 /* The word size for this operation. */
103 static inline int oper_len(DisasContext *ctx)
104 {
105     return ctx->w ? 32 : TARGET_LONG_BITS;
106 }
107 
108 
109 /*
110  * RISC-V requires NaN-boxing of narrower width floating point values.
111  * This applies when a 32-bit value is assigned to a 64-bit FP register.
112  * For consistency and simplicity, we nanbox results even when the RVD
113  * extension is not present.
114  */
115 static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)
116 {
117     tcg_gen_ori_i64(out, in, MAKE_64BIT_MASK(32, 32));
118 }
119 
120 /*
121  * A narrow n-bit operation, where n < FLEN, checks that input operands
122  * are correctly Nan-boxed, i.e., all upper FLEN - n bits are 1.
123  * If so, the least-significant bits of the input are used, otherwise the
124  * input value is treated as an n-bit canonical NaN (v2.2 section 9.2).
125  *
126  * Here, the result is always nan-boxed, even the canonical nan.
127  */
128 static void gen_check_nanbox_s(TCGv_i64 out, TCGv_i64 in)
129 {
130     TCGv_i64 t_max = tcg_constant_i64(0xffffffff00000000ull);
131     TCGv_i64 t_nan = tcg_constant_i64(0xffffffff7fc00000ull);
132 
133     tcg_gen_movcond_i64(TCG_COND_GEU, out, in, t_max, in, t_nan);
134 }
135 
136 static void generate_exception(DisasContext *ctx, int excp)
137 {
138     tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
139     gen_helper_raise_exception(cpu_env, tcg_constant_i32(excp));
140     ctx->base.is_jmp = DISAS_NORETURN;
141 }
142 
143 static void generate_exception_mtval(DisasContext *ctx, int excp)
144 {
145     tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
146     tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr));
147     gen_helper_raise_exception(cpu_env, tcg_constant_i32(excp));
148     ctx->base.is_jmp = DISAS_NORETURN;
149 }
150 
151 static void gen_exception_debug(void)
152 {
153     gen_helper_raise_exception(cpu_env, tcg_constant_i32(EXCP_DEBUG));
154 }
155 
156 /* Wrapper around tcg_gen_exit_tb that handles single stepping */
157 static void exit_tb(DisasContext *ctx)
158 {
159     if (ctx->base.singlestep_enabled) {
160         gen_exception_debug();
161     } else {
162         tcg_gen_exit_tb(NULL, 0);
163     }
164 }
165 
166 /* Wrapper around tcg_gen_lookup_and_goto_ptr that handles single stepping */
167 static void lookup_and_goto_ptr(DisasContext *ctx)
168 {
169     if (ctx->base.singlestep_enabled) {
170         gen_exception_debug();
171     } else {
172         tcg_gen_lookup_and_goto_ptr();
173     }
174 }
175 
176 static void gen_exception_illegal(DisasContext *ctx)
177 {
178     generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST);
179 }
180 
181 static void gen_exception_inst_addr_mis(DisasContext *ctx)
182 {
183     generate_exception_mtval(ctx, RISCV_EXCP_INST_ADDR_MIS);
184 }
185 
186 static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
187 {
188     if (translator_use_goto_tb(&ctx->base, dest)) {
189         tcg_gen_goto_tb(n);
190         tcg_gen_movi_tl(cpu_pc, dest);
191         tcg_gen_exit_tb(ctx->base.tb, n);
192     } else {
193         tcg_gen_movi_tl(cpu_pc, dest);
194         lookup_and_goto_ptr(ctx);
195     }
196 }
197 
198 /*
199  * Wrappers for getting reg values.
200  *
201  * The $zero register does not have cpu_gpr[0] allocated -- we supply the
202  * constant zero as a source, and an uninitialized sink as destination.
203  *
204  * Further, we may provide an extension for word operations.
205  */
206 static TCGv temp_new(DisasContext *ctx)
207 {
208     assert(ctx->ntemp < ARRAY_SIZE(ctx->temp));
209     return ctx->temp[ctx->ntemp++] = tcg_temp_new();
210 }
211 
212 static TCGv get_gpr(DisasContext *ctx, int reg_num, DisasExtend ext)
213 {
214     TCGv t;
215 
216     if (reg_num == 0) {
217         return ctx->zero;
218     }
219 
220     switch (ctx->w ? ext : EXT_NONE) {
221     case EXT_NONE:
222         return cpu_gpr[reg_num];
223     case EXT_SIGN:
224         t = temp_new(ctx);
225         tcg_gen_ext32s_tl(t, cpu_gpr[reg_num]);
226         return t;
227     case EXT_ZERO:
228         t = temp_new(ctx);
229         tcg_gen_ext32u_tl(t, cpu_gpr[reg_num]);
230         return t;
231     }
232     g_assert_not_reached();
233 }
234 
235 static void gen_get_gpr(DisasContext *ctx, TCGv t, int reg_num)
236 {
237     tcg_gen_mov_tl(t, get_gpr(ctx, reg_num, EXT_NONE));
238 }
239 
240 static TCGv dest_gpr(DisasContext *ctx, int reg_num)
241 {
242     if (reg_num == 0 || ctx->w) {
243         return temp_new(ctx);
244     }
245     return cpu_gpr[reg_num];
246 }
247 
248 static void gen_set_gpr(DisasContext *ctx, int reg_num, TCGv t)
249 {
250     if (reg_num != 0) {
251         if (ctx->w) {
252             tcg_gen_ext32s_tl(cpu_gpr[reg_num], t);
253         } else {
254             tcg_gen_mov_tl(cpu_gpr[reg_num], t);
255         }
256     }
257 }
258 
259 static void gen_jal(DisasContext *ctx, int rd, target_ulong imm)
260 {
261     target_ulong next_pc;
262 
263     /* check misaligned: */
264     next_pc = ctx->base.pc_next + imm;
265     if (!has_ext(ctx, RVC)) {
266         if ((next_pc & 0x3) != 0) {
267             gen_exception_inst_addr_mis(ctx);
268             return;
269         }
270     }
271     if (rd != 0) {
272         tcg_gen_movi_tl(cpu_gpr[rd], ctx->pc_succ_insn);
273     }
274 
275     gen_goto_tb(ctx, 0, ctx->base.pc_next + imm); /* must use this for safety */
276     ctx->base.is_jmp = DISAS_NORETURN;
277 }
278 
279 #ifndef CONFIG_USER_ONLY
280 /* The states of mstatus_fs are:
281  * 0 = disabled, 1 = initial, 2 = clean, 3 = dirty
282  * We will have already diagnosed disabled state,
283  * and need to turn initial/clean into dirty.
284  */
285 static void mark_fs_dirty(DisasContext *ctx)
286 {
287     TCGv tmp;
288     target_ulong sd;
289 
290     if (ctx->mstatus_fs == MSTATUS_FS) {
291         return;
292     }
293     /* Remember the state change for the rest of the TB.  */
294     ctx->mstatus_fs = MSTATUS_FS;
295 
296     tmp = tcg_temp_new();
297     sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD;
298 
299     tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
300     tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd);
301     tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
302 
303     if (ctx->virt_enabled) {
304         tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs));
305         tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd);
306         tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs));
307     }
308     tcg_temp_free(tmp);
309 }
310 #else
311 static inline void mark_fs_dirty(DisasContext *ctx) { }
312 #endif
313 
314 static void gen_set_rm(DisasContext *ctx, int rm)
315 {
316     if (ctx->frm == rm) {
317         return;
318     }
319     ctx->frm = rm;
320     gen_helper_set_rounding_mode(cpu_env, tcg_constant_i32(rm));
321 }
322 
323 static int ex_plus_1(DisasContext *ctx, int nf)
324 {
325     return nf + 1;
326 }
327 
328 #define EX_SH(amount) \
329     static int ex_shift_##amount(DisasContext *ctx, int imm) \
330     {                                         \
331         return imm << amount;                 \
332     }
333 EX_SH(1)
334 EX_SH(2)
335 EX_SH(3)
336 EX_SH(4)
337 EX_SH(12)
338 
339 #define REQUIRE_EXT(ctx, ext) do { \
340     if (!has_ext(ctx, ext)) {      \
341         return false;              \
342     }                              \
343 } while (0)
344 
345 #define REQUIRE_64BIT(ctx) do { \
346     if (is_32bit(ctx)) {        \
347         return false;           \
348     }                           \
349 } while (0)
350 
351 static int ex_rvc_register(DisasContext *ctx, int reg)
352 {
353     return 8 + reg;
354 }
355 
356 static int ex_rvc_shifti(DisasContext *ctx, int imm)
357 {
358     /* For RV128 a shamt of 0 means a shift by 64. */
359     return imm ? imm : 64;
360 }
361 
362 /* Include the auto-generated decoder for 32 bit insn */
363 #include "decode-insn32.c.inc"
364 
365 static bool gen_arith_imm_fn(DisasContext *ctx, arg_i *a, DisasExtend ext,
366                              void (*func)(TCGv, TCGv, target_long))
367 {
368     TCGv dest = dest_gpr(ctx, a->rd);
369     TCGv src1 = get_gpr(ctx, a->rs1, ext);
370 
371     func(dest, src1, a->imm);
372 
373     gen_set_gpr(ctx, a->rd, dest);
374     return true;
375 }
376 
377 static bool gen_arith_imm_tl(DisasContext *ctx, arg_i *a, DisasExtend ext,
378                              void (*func)(TCGv, TCGv, TCGv))
379 {
380     TCGv dest = dest_gpr(ctx, a->rd);
381     TCGv src1 = get_gpr(ctx, a->rs1, ext);
382     TCGv src2 = tcg_constant_tl(a->imm);
383 
384     func(dest, src1, src2);
385 
386     gen_set_gpr(ctx, a->rd, dest);
387     return true;
388 }
389 
390 static bool gen_arith(DisasContext *ctx, arg_r *a, DisasExtend ext,
391                       void (*func)(TCGv, TCGv, TCGv))
392 {
393     TCGv dest = dest_gpr(ctx, a->rd);
394     TCGv src1 = get_gpr(ctx, a->rs1, ext);
395     TCGv src2 = get_gpr(ctx, a->rs2, ext);
396 
397     func(dest, src1, src2);
398 
399     gen_set_gpr(ctx, a->rd, dest);
400     return true;
401 }
402 
403 static bool gen_shift_imm_fn(DisasContext *ctx, arg_shift *a, DisasExtend ext,
404                              void (*func)(TCGv, TCGv, target_long))
405 {
406     TCGv dest, src1;
407     int max_len = oper_len(ctx);
408 
409     if (a->shamt >= max_len) {
410         return false;
411     }
412 
413     dest = dest_gpr(ctx, a->rd);
414     src1 = get_gpr(ctx, a->rs1, ext);
415 
416     func(dest, src1, a->shamt);
417 
418     gen_set_gpr(ctx, a->rd, dest);
419     return true;
420 }
421 
422 static bool gen_shift_imm_tl(DisasContext *ctx, arg_shift *a, DisasExtend ext,
423                              void (*func)(TCGv, TCGv, TCGv))
424 {
425     TCGv dest, src1, src2;
426     int max_len = oper_len(ctx);
427 
428     if (a->shamt >= max_len) {
429         return false;
430     }
431 
432     dest = dest_gpr(ctx, a->rd);
433     src1 = get_gpr(ctx, a->rs1, ext);
434     src2 = tcg_constant_tl(a->shamt);
435 
436     func(dest, src1, src2);
437 
438     gen_set_gpr(ctx, a->rd, dest);
439     return true;
440 }
441 
442 static bool gen_shift(DisasContext *ctx, arg_r *a, DisasExtend ext,
443                       void (*func)(TCGv, TCGv, TCGv))
444 {
445     TCGv dest = dest_gpr(ctx, a->rd);
446     TCGv src1 = get_gpr(ctx, a->rs1, ext);
447     TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE);
448     TCGv ext2 = tcg_temp_new();
449 
450     tcg_gen_andi_tl(ext2, src2, oper_len(ctx) - 1);
451     func(dest, src1, ext2);
452 
453     gen_set_gpr(ctx, a->rd, dest);
454     tcg_temp_free(ext2);
455     return true;
456 }
457 
458 static bool gen_unary(DisasContext *ctx, arg_r2 *a, DisasExtend ext,
459                       void (*func)(TCGv, TCGv))
460 {
461     TCGv dest = dest_gpr(ctx, a->rd);
462     TCGv src1 = get_gpr(ctx, a->rs1, ext);
463 
464     func(dest, src1);
465 
466     gen_set_gpr(ctx, a->rd, dest);
467     return true;
468 }
469 
470 static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
471 {
472     DisasContext *ctx = container_of(dcbase, DisasContext, base);
473     CPUState *cpu = ctx->cs;
474     CPURISCVState *env = cpu->env_ptr;
475 
476     return cpu_ldl_code(env, pc);
477 }
478 
479 /* Include insn module translation function */
480 #include "insn_trans/trans_rvi.c.inc"
481 #include "insn_trans/trans_rvm.c.inc"
482 #include "insn_trans/trans_rva.c.inc"
483 #include "insn_trans/trans_rvf.c.inc"
484 #include "insn_trans/trans_rvd.c.inc"
485 #include "insn_trans/trans_rvh.c.inc"
486 #include "insn_trans/trans_rvv.c.inc"
487 #include "insn_trans/trans_rvb.c.inc"
488 #include "insn_trans/trans_privileged.c.inc"
489 
490 /* Include the auto-generated decoder for 16 bit insn */
491 #include "decode-insn16.c.inc"
492 
493 static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
494 {
495     /* check for compressed insn */
496     if (extract16(opcode, 0, 2) != 3) {
497         if (!has_ext(ctx, RVC)) {
498             gen_exception_illegal(ctx);
499         } else {
500             ctx->pc_succ_insn = ctx->base.pc_next + 2;
501             if (!decode_insn16(ctx, opcode)) {
502                 gen_exception_illegal(ctx);
503             }
504         }
505     } else {
506         uint32_t opcode32 = opcode;
507         opcode32 = deposit32(opcode32, 16, 16,
508                              translator_lduw(env, ctx->base.pc_next + 2));
509         ctx->pc_succ_insn = ctx->base.pc_next + 4;
510         if (!decode_insn32(ctx, opcode32)) {
511             gen_exception_illegal(ctx);
512         }
513     }
514 }
515 
516 static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
517 {
518     DisasContext *ctx = container_of(dcbase, DisasContext, base);
519     CPURISCVState *env = cs->env_ptr;
520     RISCVCPU *cpu = RISCV_CPU(cs);
521     uint32_t tb_flags = ctx->base.tb->flags;
522 
523     ctx->pc_succ_insn = ctx->base.pc_first;
524     ctx->mem_idx = tb_flags & TB_FLAGS_MMU_MASK;
525     ctx->mstatus_fs = tb_flags & TB_FLAGS_MSTATUS_FS;
526     ctx->priv_ver = env->priv_ver;
527 #if !defined(CONFIG_USER_ONLY)
528     if (riscv_has_ext(env, RVH)) {
529         ctx->virt_enabled = riscv_cpu_virt_enabled(env);
530     } else {
531         ctx->virt_enabled = false;
532     }
533 #else
534     ctx->virt_enabled = false;
535 #endif
536     ctx->misa = env->misa;
537     ctx->frm = -1;  /* unknown rounding mode */
538     ctx->ext_ifencei = cpu->cfg.ext_ifencei;
539     ctx->vlen = cpu->cfg.vlen;
540     ctx->hlsx = FIELD_EX32(tb_flags, TB_FLAGS, HLSX);
541     ctx->vill = FIELD_EX32(tb_flags, TB_FLAGS, VILL);
542     ctx->sew = FIELD_EX32(tb_flags, TB_FLAGS, SEW);
543     ctx->lmul = FIELD_EX32(tb_flags, TB_FLAGS, LMUL);
544     ctx->mlen = 1 << (ctx->sew  + 3 - ctx->lmul);
545     ctx->vl_eq_vlmax = FIELD_EX32(tb_flags, TB_FLAGS, VL_EQ_VLMAX);
546     ctx->cs = cs;
547     ctx->w = false;
548     ctx->ntemp = 0;
549     memset(ctx->temp, 0, sizeof(ctx->temp));
550 
551     ctx->zero = tcg_constant_tl(0);
552 }
553 
554 static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu)
555 {
556 }
557 
558 static void riscv_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
559 {
560     DisasContext *ctx = container_of(dcbase, DisasContext, base);
561 
562     tcg_gen_insn_start(ctx->base.pc_next);
563 }
564 
565 static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
566 {
567     DisasContext *ctx = container_of(dcbase, DisasContext, base);
568     CPURISCVState *env = cpu->env_ptr;
569     uint16_t opcode16 = translator_lduw(env, ctx->base.pc_next);
570 
571     decode_opc(env, ctx, opcode16);
572     ctx->base.pc_next = ctx->pc_succ_insn;
573     ctx->w = false;
574 
575     for (int i = ctx->ntemp - 1; i >= 0; --i) {
576         tcg_temp_free(ctx->temp[i]);
577         ctx->temp[i] = NULL;
578     }
579     ctx->ntemp = 0;
580 
581     if (ctx->base.is_jmp == DISAS_NEXT) {
582         target_ulong page_start;
583 
584         page_start = ctx->base.pc_first & TARGET_PAGE_MASK;
585         if (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE) {
586             ctx->base.is_jmp = DISAS_TOO_MANY;
587         }
588     }
589 }
590 
591 static void riscv_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
592 {
593     DisasContext *ctx = container_of(dcbase, DisasContext, base);
594 
595     switch (ctx->base.is_jmp) {
596     case DISAS_TOO_MANY:
597         gen_goto_tb(ctx, 0, ctx->base.pc_next);
598         break;
599     case DISAS_NORETURN:
600         break;
601     default:
602         g_assert_not_reached();
603     }
604 }
605 
606 static void riscv_tr_disas_log(const DisasContextBase *dcbase, CPUState *cpu)
607 {
608 #ifndef CONFIG_USER_ONLY
609     RISCVCPU *rvcpu = RISCV_CPU(cpu);
610     CPURISCVState *env = &rvcpu->env;
611 #endif
612 
613     qemu_log("IN: %s\n", lookup_symbol(dcbase->pc_first));
614 #ifndef CONFIG_USER_ONLY
615     qemu_log("Priv: "TARGET_FMT_ld"; Virt: "TARGET_FMT_ld"\n", env->priv, env->virt);
616 #endif
617     log_target_disas(cpu, dcbase->pc_first, dcbase->tb->size);
618 }
619 
620 static const TranslatorOps riscv_tr_ops = {
621     .init_disas_context = riscv_tr_init_disas_context,
622     .tb_start           = riscv_tr_tb_start,
623     .insn_start         = riscv_tr_insn_start,
624     .translate_insn     = riscv_tr_translate_insn,
625     .tb_stop            = riscv_tr_tb_stop,
626     .disas_log          = riscv_tr_disas_log,
627 };
628 
629 void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
630 {
631     DisasContext ctx;
632 
633     translator_loop(&riscv_tr_ops, &ctx.base, cs, tb, max_insns);
634 }
635 
636 void riscv_translate_init(void)
637 {
638     int i;
639 
640     /* cpu_gpr[0] is a placeholder for the zero register. Do not use it. */
641     /* Use the gen_set_gpr and gen_get_gpr helper functions when accessing */
642     /* registers, unless you specifically block reads/writes to reg 0 */
643     cpu_gpr[0] = NULL;
644 
645     for (i = 1; i < 32; i++) {
646         cpu_gpr[i] = tcg_global_mem_new(cpu_env,
647             offsetof(CPURISCVState, gpr[i]), riscv_int_regnames[i]);
648     }
649 
650     for (i = 0; i < 32; i++) {
651         cpu_fpr[i] = tcg_global_mem_new_i64(cpu_env,
652             offsetof(CPURISCVState, fpr[i]), riscv_fpr_regnames[i]);
653     }
654 
655     cpu_pc = tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, pc), "pc");
656     cpu_vl = tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, vl), "vl");
657     load_res = tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, load_res),
658                              "load_res");
659     load_val = tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, load_val),
660                              "load_val");
661 }
662