1*2bf79222SMark Corbin /* 2*2bf79222SMark Corbin * RISC-V register structures 3*2bf79222SMark Corbin * 4*2bf79222SMark Corbin * Copyright (c) 2019 Mark Corbin 5*2bf79222SMark Corbin * 6*2bf79222SMark Corbin * This program is free software; you can redistribute it and/or modify 7*2bf79222SMark Corbin * it under the terms of the GNU General Public License as published by 8*2bf79222SMark Corbin * the Free Software Foundation; either version 2 of the License, or 9*2bf79222SMark Corbin * (at your option) any later version. 10*2bf79222SMark Corbin * 11*2bf79222SMark Corbin * This program is distributed in the hope that it will be useful, 12*2bf79222SMark Corbin * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*2bf79222SMark Corbin * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*2bf79222SMark Corbin * GNU General Public License for more details. 15*2bf79222SMark Corbin * 16*2bf79222SMark Corbin * You should have received a copy of the GNU General Public License 17*2bf79222SMark Corbin * along with this program; if not, see <http://www.gnu.org/licenses/>. 18*2bf79222SMark Corbin */ 19*2bf79222SMark Corbin 20*2bf79222SMark Corbin #ifndef TARGET_ARCH_REG_H 21*2bf79222SMark Corbin #define TARGET_ARCH_REG_H 22*2bf79222SMark Corbin 23*2bf79222SMark Corbin /* Compare with riscv/include/reg.h */ 24*2bf79222SMark Corbin typedef struct target_reg { 25*2bf79222SMark Corbin uint64_t ra; /* return address */ 26*2bf79222SMark Corbin uint64_t sp; /* stack pointer */ 27*2bf79222SMark Corbin uint64_t gp; /* global pointer */ 28*2bf79222SMark Corbin uint64_t tp; /* thread pointer */ 29*2bf79222SMark Corbin uint64_t t[7]; /* temporaries */ 30*2bf79222SMark Corbin uint64_t s[12]; /* saved registers */ 31*2bf79222SMark Corbin uint64_t a[8]; /* function arguments */ 32*2bf79222SMark Corbin uint64_t sepc; /* exception program counter */ 33*2bf79222SMark Corbin uint64_t sstatus; /* status register */ 34*2bf79222SMark Corbin } target_reg_t; 35*2bf79222SMark Corbin 36*2bf79222SMark Corbin typedef struct target_fpreg { 37*2bf79222SMark Corbin uint64_t fp_x[32][2]; /* Floating point registers */ 38*2bf79222SMark Corbin uint64_t fp_fcsr; /* Floating point control reg */ 39*2bf79222SMark Corbin } target_fpreg_t; 40*2bf79222SMark Corbin 41*2bf79222SMark Corbin #define tswapreg(ptr) tswapal(ptr) 42*2bf79222SMark Corbin 43*2bf79222SMark Corbin /* Compare with struct trapframe in riscv/include/frame.h */ target_copy_regs(target_reg_t * regs,const CPURISCVState * env)44*2bf79222SMark Corbinstatic inline void target_copy_regs(target_reg_t *regs, 45*2bf79222SMark Corbin const CPURISCVState *env) 46*2bf79222SMark Corbin { 47*2bf79222SMark Corbin 48*2bf79222SMark Corbin regs->ra = tswapreg(env->gpr[1]); 49*2bf79222SMark Corbin regs->sp = tswapreg(env->gpr[2]); 50*2bf79222SMark Corbin regs->gp = tswapreg(env->gpr[3]); 51*2bf79222SMark Corbin regs->tp = tswapreg(env->gpr[4]); 52*2bf79222SMark Corbin 53*2bf79222SMark Corbin regs->t[0] = tswapreg(env->gpr[5]); 54*2bf79222SMark Corbin regs->t[1] = tswapreg(env->gpr[6]); 55*2bf79222SMark Corbin regs->t[2] = tswapreg(env->gpr[7]); 56*2bf79222SMark Corbin regs->t[3] = tswapreg(env->gpr[28]); 57*2bf79222SMark Corbin regs->t[4] = tswapreg(env->gpr[29]); 58*2bf79222SMark Corbin regs->t[5] = tswapreg(env->gpr[30]); 59*2bf79222SMark Corbin regs->t[6] = tswapreg(env->gpr[31]); 60*2bf79222SMark Corbin 61*2bf79222SMark Corbin regs->s[0] = tswapreg(env->gpr[8]); 62*2bf79222SMark Corbin regs->s[1] = tswapreg(env->gpr[9]); 63*2bf79222SMark Corbin regs->s[2] = tswapreg(env->gpr[18]); 64*2bf79222SMark Corbin regs->s[3] = tswapreg(env->gpr[19]); 65*2bf79222SMark Corbin regs->s[4] = tswapreg(env->gpr[20]); 66*2bf79222SMark Corbin regs->s[5] = tswapreg(env->gpr[21]); 67*2bf79222SMark Corbin regs->s[6] = tswapreg(env->gpr[22]); 68*2bf79222SMark Corbin regs->s[7] = tswapreg(env->gpr[23]); 69*2bf79222SMark Corbin regs->s[8] = tswapreg(env->gpr[24]); 70*2bf79222SMark Corbin regs->s[9] = tswapreg(env->gpr[25]); 71*2bf79222SMark Corbin regs->s[10] = tswapreg(env->gpr[26]); 72*2bf79222SMark Corbin regs->s[11] = tswapreg(env->gpr[27]); 73*2bf79222SMark Corbin 74*2bf79222SMark Corbin regs->a[0] = tswapreg(env->gpr[10]); 75*2bf79222SMark Corbin regs->a[1] = tswapreg(env->gpr[11]); 76*2bf79222SMark Corbin regs->a[2] = tswapreg(env->gpr[12]); 77*2bf79222SMark Corbin regs->a[3] = tswapreg(env->gpr[13]); 78*2bf79222SMark Corbin regs->a[4] = tswapreg(env->gpr[14]); 79*2bf79222SMark Corbin regs->a[5] = tswapreg(env->gpr[15]); 80*2bf79222SMark Corbin regs->a[6] = tswapreg(env->gpr[16]); 81*2bf79222SMark Corbin regs->a[7] = tswapreg(env->gpr[17]); 82*2bf79222SMark Corbin 83*2bf79222SMark Corbin regs->sepc = tswapreg(env->pc); 84*2bf79222SMark Corbin } 85*2bf79222SMark Corbin 86*2bf79222SMark Corbin #undef tswapreg 87*2bf79222SMark Corbin 88*2bf79222SMark Corbin #endif /* TARGET_ARCH_REG_H */ 89