asm.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2015 Regents of the University of California
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  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. */
  13. #ifndef _ASM_RISCV_ASM_H
  14. #define _ASM_RISCV_ASM_H
  15. #ifdef __ASSEMBLY__
  16. #define __ASM_STR(x) x
  17. #else
  18. #define __ASM_STR(x) #x
  19. #endif
  20. #if __riscv_xlen == 64
  21. #define __REG_SEL(a, b) __ASM_STR(a)
  22. #elif __riscv_xlen == 32
  23. #define __REG_SEL(a, b) __ASM_STR(b)
  24. #else
  25. #error "Unexpected __riscv_xlen"
  26. #endif
  27. #define REG_L __REG_SEL(ld, lw)
  28. #define REG_S __REG_SEL(sd, sw)
  29. #define SZREG __REG_SEL(8, 4)
  30. #define LGREG __REG_SEL(3, 2)
  31. #if __SIZEOF_POINTER__ == 8
  32. #ifdef __ASSEMBLY__
  33. #define RISCV_PTR .dword
  34. #define RISCV_SZPTR 8
  35. #define RISCV_LGPTR 3
  36. #else
  37. #define RISCV_PTR ".dword"
  38. #define RISCV_SZPTR "8"
  39. #define RISCV_LGPTR "3"
  40. #endif
  41. #elif __SIZEOF_POINTER__ == 4
  42. #ifdef __ASSEMBLY__
  43. #define RISCV_PTR .word
  44. #define RISCV_SZPTR 4
  45. #define RISCV_LGPTR 2
  46. #else
  47. #define RISCV_PTR ".word"
  48. #define RISCV_SZPTR "4"
  49. #define RISCV_LGPTR "2"
  50. #endif
  51. #else
  52. #error "Unexpected __SIZEOF_POINTER__"
  53. #endif
  54. #if (__SIZEOF_INT__ == 4)
  55. #define RISCV_INT __ASM_STR(.word)
  56. #define RISCV_SZINT __ASM_STR(4)
  57. #define RISCV_LGINT __ASM_STR(2)
  58. #else
  59. #error "Unexpected __SIZEOF_INT__"
  60. #endif
  61. #if (__SIZEOF_SHORT__ == 2)
  62. #define RISCV_SHORT __ASM_STR(.half)
  63. #define RISCV_SZSHORT __ASM_STR(2)
  64. #define RISCV_LGSHORT __ASM_STR(1)
  65. #else
  66. #error "Unexpected __SIZEOF_SHORT__"
  67. #endif
  68. #endif /* _ASM_RISCV_ASM_H */