pru.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Copyright 2016-2022 Free Software Foundation, Inc.
  2. Contributed by Dimitar Dimitrov <dimitar@dinux.eu>
  3. This file is part of the PRU simulator.
  4. This library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef PRU_H
  15. #define PRU_H
  16. #include "opcode/pru.h"
  17. /* Needed for handling the dual PRU address space. */
  18. #define IMEM_ADDR_MASK ((1u << 23) - 1)
  19. #define IMEM_ADDR_DEFAULT 0x20000000
  20. /* Define memory sizes to allocate for simulated target. Sizes are
  21. artificially large to accommodate execution of compiler test suite.
  22. Please synchronize with the linker script for prusim target. */
  23. #define DMEM_DEFAULT_SIZE (64 * 1024 * 1024)
  24. /* 16-bit word addressable space. */
  25. #define IMEM_DEFAULT_SIZE (64 * 4 * 1024)
  26. /* For AM335x SoCs. */
  27. #define XFRID_SCRATCH_BANK_0 10
  28. #define XFRID_SCRATCH_BANK_1 11
  29. #define XFRID_SCRATCH_BANK_2 12
  30. #define XFRID_SCRATCH_BANK_PEER 14
  31. #define XFRID_MAX 255
  32. #define CPU (cpu->pru_cpu)
  33. #define PC (CPU.pc)
  34. #define PC_byteaddr ((PC << 2) | PC_ADDR_SPACE_MARKER)
  35. /* Various opcode fields. */
  36. #define RS1 extract_regval (CPU.regs[GET_INSN_FIELD (RS1, inst)], \
  37. GET_INSN_FIELD (RS1SEL, inst))
  38. #define RS2 extract_regval (CPU.regs[GET_INSN_FIELD (RS2, inst)], \
  39. GET_INSN_FIELD (RS2SEL, inst))
  40. #define RS2_w0 extract_regval (CPU.regs[GET_INSN_FIELD (RS2, inst)], \
  41. RSEL_15_0)
  42. #define XBBO_BASEREG (CPU.regs[GET_INSN_FIELD (RS1, inst)])
  43. #define RS1SEL GET_INSN_FIELD (RS1SEL, inst)
  44. #define RS1_WIDTH regsel_width (RS1SEL)
  45. #define RDSEL GET_INSN_FIELD (RDSEL, inst)
  46. #define RD_WIDTH regsel_width (RDSEL)
  47. #define RD_REGN GET_INSN_FIELD (RD, inst)
  48. #define IO GET_INSN_FIELD (IO, inst)
  49. #define IMM8 GET_INSN_FIELD (IMM8, inst)
  50. #define IMM16 GET_INSN_FIELD (IMM16, inst)
  51. #define WAKEONSTATUS GET_INSN_FIELD (WAKEONSTATUS, inst)
  52. #define CB GET_INSN_FIELD (CB, inst)
  53. #define RDB GET_INSN_FIELD (RDB, inst)
  54. #define XFR_WBA GET_INSN_FIELD (XFR_WBA, inst)
  55. #define LOOP_JMPOFFS GET_INSN_FIELD (LOOP_JMPOFFS, inst)
  56. #define BROFF ((uint32_t) GET_BROFF_SIGNED (inst))
  57. #define _BURSTLEN_CALCULATE(BITFIELD) \
  58. ((BITFIELD) >= LSSBBO_BYTECOUNT_R0_BITS7_0 ? \
  59. (CPU.regs[0] >> ((BITFIELD) - LSSBBO_BYTECOUNT_R0_BITS7_0) * 8) & 0xff \
  60. : (BITFIELD) + 1)
  61. #define BURSTLEN _BURSTLEN_CALCULATE (GET_BURSTLEN (inst))
  62. #define XFR_LENGTH _BURSTLEN_CALCULATE (GET_INSN_FIELD (XFR_LENGTH, inst))
  63. #define DO_XIN(wba,regn,rdb,l) \
  64. pru_sim_xin (sd, cpu, (wba), (regn), (rdb), (l))
  65. #define DO_XOUT(wba,regn,rdb,l) \
  66. pru_sim_xout (sd, cpu, (wba), (regn), (rdb), (l))
  67. #define DO_XCHG(wba,regn,rdb,l) \
  68. pru_sim_xchg (sd, cpu, (wba), (regn), (rdb), (l))
  69. #define RAISE_SIGILL(sd) sim_engine_halt ((sd), NULL, NULL, PC_byteaddr, \
  70. sim_stopped, SIM_SIGILL)
  71. #define RAISE_SIGINT(sd) sim_engine_halt ((sd), NULL, NULL, PC_byteaddr, \
  72. sim_stopped, SIM_SIGINT)
  73. #define MAC_R25_MAC_MODE_MASK (1u << 0)
  74. #define MAC_R25_ACC_CARRY_MASK (1u << 1)
  75. #define CARRY CPU.carry
  76. #define CTABLE CPU.ctable
  77. #define PC_ADDR_SPACE_MARKER CPU.pc_addr_space_marker
  78. #define LOOPTOP CPU.loop.looptop
  79. #define LOOPEND CPU.loop.loopend
  80. #define LOOP_IN_PROGRESS CPU.loop.loop_in_progress
  81. #define LOOPCNT CPU.loop.loop_counter
  82. /* 32 GP registers plus PC. */
  83. #define NUM_REGS 33
  84. #endif /* PRU_H */