opcode.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-11-09 WangXiaoyao Add portable asm support
  9. * 2022-03-16 WangXiaoyao Porting to xtheadsync & xtheadcmo ISA extension
  10. */
  11. #ifndef __OPCODE_H__
  12. #define __OPCODE_H__
  13. /**
  14. * @brief binary opcode pseudo operations
  15. * Used to bypass toolchain restriction on extension ISA
  16. *
  17. * WARNING: Xuantie ISAs are not compatible to each other in opcode.
  18. * It's painful to port this file, and should be really careful.
  19. */
  20. /**
  21. * @brief RISC-V instruction formats
  22. */
  23. /**
  24. * R type: .insn r opcode6, func3, func7, rd, rs1, rs2
  25. *
  26. * +-------+-----+-----+-------+----+---------+
  27. * | func7 | rs2 | rs1 | func3 | rd | opcode6 |
  28. * +-------+-----+-----+-------+----+---------+
  29. * 31 25 20 15 12 7 0
  30. */
  31. #define __OPC_INSN_FORMAT_R(opcode, func3, func7, rd, rs1, rs2) \
  32. ".insn r "RT_STRINGIFY(opcode)","RT_STRINGIFY(func3)","RT_STRINGIFY(func7)","RT_STRINGIFY(rd)","RT_STRINGIFY(rs1)","RT_STRINGIFY(rs2)
  33. /**
  34. * @brief Xuantie T-HEAD extension ISA format
  35. * Compatible to Xuantie C908 user manual v03
  36. */
  37. #define __OPC_INSN_FORMAT_CACHE(func7, rs2, rs1) \
  38. __OPC_INSN_FORMAT_R(0x0b, 0x0, func7, x0, rs1, rs2)
  39. #ifdef _TOOLCHAIN_SUPP_XTHEADE_ISA_
  40. #define OPC_SYNC "sync"
  41. #define OPC_SYNC_S "sync.s"
  42. #define OPC_SYNC_I "sync.i"
  43. #define OPC_SYNC_IS "sync.is"
  44. #define OPC_DCACHE_CALL "dcache.call"
  45. #define OPC_DCACHE_IALL "dcache.iall"
  46. #define OPC_DCACHE_CIALL "dcache.ciall"
  47. #define OPC_DCACHE_CVAL1(rs1) "dcache.cval1 "_TOSTR(rs1)
  48. #define OPC_ICACHE_IALL "icache.iall"
  49. #define OPC_DCACHE_CVA(rs1) "dcache.cva "RT_STRINGIFY(rs1)
  50. #define OPC_DCACHE_IVA(rs1) "dcache.iva "RT_STRINGIFY(rs1)
  51. #define OPC_DCACHE_CIVA(rs1) "dcache.civa "RT_STRINGIFY(rs1)
  52. #define OPC_ICACHE_IVA(rs1) "icache.iva "RT_STRINGIFY(rs1)
  53. #else /* !_TOOLCHAIN_NOT_SUPP_THEAD_ISA_ */
  54. #define OPC_SYNC ".long 0x0180000B"
  55. #define OPC_SYNC_S ".long 0x0190000B"
  56. #define OPC_SYNC_I ".long 0x01A0000B"
  57. #define OPC_SYNC_IS ".long 0x01B0000B"
  58. #define OPC_DCACHE_CALL ".long 0x0010000B"
  59. #define OPC_DCACHE_IALL ".long 0x0020000B"
  60. #define OPC_DCACHE_CIALL ".long 0x0030000B"
  61. #define OPC_DCACHE_CVAL1(rs1) __OPC_INSN_FORMAT_CACHE(0x1, x4, rs1)
  62. #define OPC_ICACHE_IALL ".long 0x0100000B"
  63. #define OPC_DCACHE_CVA(rs1) __OPC_INSN_FORMAT_CACHE(0x1, x5, rs1)
  64. #define OPC_DCACHE_IVA(rs1) __OPC_INSN_FORMAT_CACHE(0x1, x6, rs1)
  65. #define OPC_DCACHE_CIVA(rs1) __OPC_INSN_FORMAT_CACHE(0x1, x7, rs1)
  66. #define OPC_ICACHE_IVA(rs1) __OPC_INSN_FORMAT_CACHE(0x1, x16, rs1)
  67. #endif /* _TOOLCHAIN_NOT_SUPP_THEAD_ISA_ */
  68. /**
  69. * @brief RISC-V zifencei ISA
  70. */
  71. #ifdef _TOOLCHAIN_SUPP_ZIFENCEI_ISA_
  72. #define OPC_FENCE_I "fence.i"
  73. #else /* !_TOOLCHAIN_SUPP_ZIFENCEI_ISA_ */
  74. #define OPC_FENCE_I ".long 0x0000100F"
  75. #endif /* _TOOLCHAIN_SUPP_ZIFENCEI_ISA_ */
  76. #endif /* __OPCODE_H__ */