sysdep.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (C) 2017 Hangzhou C-SKY Microsystems co.,ltd.
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB
  5. * in this tarball.
  6. */
  7. #ifndef _LINUX_CSKY_SYSDEP_H
  8. #define _LINUX_CSKY_SYSDEP_H 1
  9. #include <common/sysdep.h>
  10. #include <sys/syscall.h>
  11. #undef SYS_ify
  12. #define SYS_ify(name) (__NR_##name)
  13. #ifdef __ASSEMBLER__
  14. /* ELF uses byte-counts for .align, most others use log2 of count of bytes. */
  15. #define ALIGNARG(log2) log2
  16. /* For ELF we need the `.type' directive to make shared libs work right. */
  17. #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,%##typearg;
  18. #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
  19. #define ENTRY(name) \
  20. .globl C_SYMBOL_NAME(name); \
  21. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),function) \
  22. .align ALIGNARG(4); \
  23. C_LABEL(name)
  24. #undef END
  25. #define END(name) ASM_SIZE_DIRECTIVE(name)
  26. #undef ret_ERRVAL
  27. #define ret_ERRVAL rts
  28. #undef PSEUDO_END
  29. #define PSEUDO_END(name) END(name)
  30. #ifdef __PIC__
  31. #define __GET_GB \
  32. bsr 1f; \
  33. 1: lrw gb, 1b@GOTPC; \
  34. addu gb, lr;
  35. /*
  36. * __JSR must be used with __GET_GB and SAVE_ARGS
  37. */
  38. #define __JSR(symbol) \
  39. lrw a2, symbol@PLT; \
  40. add a2, gb; \
  41. ld.w a2, (a2); \
  42. jsr a2;
  43. #define PSEUDO_ERRJMP \
  44. subi sp, 8; \
  45. st.w lr, (sp); \
  46. st.w gb, (sp, 4); \
  47. __GET_GB \
  48. lrw a2, __syscall_error@PLT; \
  49. addu a2, gb; \
  50. ld.w a2, (a2); \
  51. jsr a2; \
  52. ld.w lr, (sp); \
  53. ld.w gb, (sp, 4); \
  54. addi sp, 8; \
  55. rts;
  56. #else /* __PIC__ */
  57. #define __GET_GB
  58. #define __JSR(symbol) jsri symbol;
  59. #define PSEUDO_ERRJMP \
  60. subi sp, 4; \
  61. stw lr, (sp, 0); \
  62. jsri __syscall_error; \
  63. ldw lr, (sp, 0); \
  64. addi sp, 4; \
  65. rts;
  66. #endif /* __PIC__ */
  67. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  68. .text; \
  69. 99: PSEUDO_ERRJMP; \
  70. ENTRY(name); \
  71. DO_CALL(syscall_name, args); \
  72. btsti a0, 31; \
  73. bt 99b;
  74. #undef PSEUDO_END_ERRVAL
  75. #define PSEUDO_END_ERRVAL(name) \
  76. rts; \
  77. END(name)
  78. /* DO_CALL */
  79. #undef DO_CALL
  80. #ifdef __CSKYABIV2__
  81. #define DO_CALL(syscall_name, args) \
  82. DOARGS_##args \
  83. mov t0, r7; \
  84. lrw r7, SYS_ify (syscall_name); \
  85. trap 0; \
  86. mov r7, t0; \
  87. UNDOARGS_##args
  88. #define DOARGS_0
  89. #define DOARGS_1
  90. #define DOARGS_2
  91. #define DOARGS_3
  92. #define DOARGS_4
  93. #define DOARGS_5 subi sp, 4; st.w r4, (sp, 0); ld.w r4, (sp, 4);
  94. #define DOARGS_6 subi sp, 8; stm r4-r5, (sp); ld.w r4, (sp, 8); ld.w r5, (sp, 12);
  95. #define UNDOARGS_0
  96. #define UNDOARGS_1
  97. #define UNDOARGS_2
  98. #define UNDOARGS_3
  99. #define UNDOARGS_4
  100. #define UNDOARGS_5 ld.w r4, (sp, 0); addi sp, 4;
  101. #define UNDOARGS_6 ldm r4-r5, (sp); addi sp, 8;
  102. #else /* __CSKYABIV2__ */
  103. #define DO_CALL(syscall_name, args) \
  104. lrw r1, SYS_ify (syscall_name); \
  105. trap 0;
  106. #define DOARGS_0
  107. #define DOARGS_1
  108. #define DOARGS_2
  109. #define DOARGS_3
  110. #define DOARGS_4
  111. #define DOARGS_5
  112. #define DOARGS_6
  113. #define UNDOARGS_0
  114. #define UNDOARGS_1
  115. #define UNDOARGS_2
  116. #define UNDOARGS_3
  117. #define UNDOARGS_4
  118. #define UNDOARGS_5
  119. #define UNDOARGS_6
  120. #endif /* __CSKYABIV2__ */
  121. /*
  122. * define DO_CALL_2, only ABIV2 need DO_CALL_2
  123. * to be quite different with DO_CALL, DO_CALL_2 need not save r7.
  124. */
  125. #ifdef __CSKYABIV2__
  126. #undef DO_CALL_2
  127. #define DO_CALL_2(syscall_name, args) \
  128. DOARGS2_##args; \
  129. lrw r7, SYS_ify(syscall_name); \
  130. trap 0; \
  131. UNDOARGS2_##args
  132. #undef DOARGS2_0
  133. #define DOARGS2_0
  134. #undef DOARGS2_1
  135. #define DOARGS2_1 DOARGS2_0
  136. #undef DOARGS2_2
  137. #define DOARGS2_2 DOARGS2_0
  138. #undef DOARGS2_3
  139. #define DOARGS2_3 DOARGS2_0
  140. #undef DOARGS2_4
  141. #define DOARGS2_4 DOARGS2_0
  142. #undef DOARGS2_5
  143. #define DOARGS2_5 \
  144. subi sp, 8; \
  145. cfi_adjust_cfa_offset (8); \
  146. stw r4, (sp, 0); \
  147. ldw r4, (sp, 24)
  148. #undef DOARGS2_6
  149. #define DOARGS2_6 \
  150. subi sp, 8; \
  151. cfi_adjust_cfa_offset (8); \
  152. stw r4, (sp, 0); \
  153. stw r5, (sp, 4); \
  154. ldw r4, (sp, 24); \
  155. ldw r5, (sp, 28)
  156. #undef UNDOARGS2_0
  157. #define UNDOARGS2_0
  158. #undef UNDOARGS2_1
  159. #define UNDOARGS2_1 UNDOARGS2_0
  160. #undef UNDOARGS2_2
  161. #define UNDOARGS2_2 UNDOARGS2_0
  162. #undef UNDOARGS2_3
  163. #define UNDOARGS2_3 UNDOARGS2_0
  164. #undef UNDOARGS2_4
  165. #define UNDOARGS2_4 UNDOARGS2_0
  166. #undef UNDOARGS2_5
  167. #define UNDOARGS2_5 \
  168. ldw r4, (sp, 0); \
  169. addi sp, 8
  170. #undef UNDOARGS2_6
  171. #define UNDOARGS2_6 \
  172. ldw r4, (sp, 0); \
  173. ldw r5, (sp, 4); \
  174. addi sp, 8
  175. #endif /* __CSKYABIV2__ */
  176. #endif /* __ASSEMBLER__ */
  177. #endif /* _LINUX_CSKY_SYSDEP_H */