target_arch_reg.h 3.0 KB

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