btfixup.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * asm/btfixup.h: Macros for boot time linking.
  3. *
  4. * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  5. */
  6. #ifndef _SPARC_BTFIXUP_H
  7. #define _SPARC_BTFIXUP_H
  8. #include <linux/init.h>
  9. #ifndef __ASSEMBLY__
  10. #ifdef MODULE
  11. extern unsigned int ___illegal_use_of_BTFIXUP_SIMM13_in_module(void);
  12. extern unsigned int ___illegal_use_of_BTFIXUP_SETHI_in_module(void);
  13. extern unsigned int ___illegal_use_of_BTFIXUP_HALF_in_module(void);
  14. extern unsigned int ___illegal_use_of_BTFIXUP_INT_in_module(void);
  15. #define BTFIXUP_SIMM13(__name) ___illegal_use_of_BTFIXUP_SIMM13_in_module()
  16. #define BTFIXUP_HALF(__name) ___illegal_use_of_BTFIXUP_HALF_in_module()
  17. #define BTFIXUP_SETHI(__name) ___illegal_use_of_BTFIXUP_SETHI_in_module()
  18. #define BTFIXUP_INT(__name) ___illegal_use_of_BTFIXUP_INT_in_module()
  19. #define BTFIXUP_BLACKBOX(__name) ___illegal_use_of_BTFIXUP_BLACKBOX_in_module
  20. #else
  21. #define BTFIXUP_SIMM13(__name) ___sf_##__name()
  22. #define BTFIXUP_HALF(__name) ___af_##__name()
  23. #define BTFIXUP_SETHI(__name) ___hf_##__name()
  24. #define BTFIXUP_INT(__name) ((unsigned int)&___i_##__name)
  25. /* This must be written in assembly and present in a sethi */
  26. #define BTFIXUP_BLACKBOX(__name) ___b_##__name
  27. #endif /* MODULE */
  28. /* Fixup call xx */
  29. #define BTFIXUPDEF_CALL(__type, __name, __args...) \
  30. extern __type ___f_##__name(__args); \
  31. extern unsigned ___fs_##__name[3];
  32. #define BTFIXUPDEF_CALL_CONST(__type, __name, __args...) \
  33. extern __type ___f_##__name(__args) __attribute_const__; \
  34. extern unsigned ___fs_##__name[3];
  35. #define BTFIXUP_CALL(__name) ___f_##__name
  36. #define BTFIXUPDEF_BLACKBOX(__name) \
  37. extern unsigned ___bs_##__name[2];
  38. /* Put bottom 13bits into some register variable */
  39. #define BTFIXUPDEF_SIMM13(__name) \
  40. static inline unsigned int ___sf_##__name(void) __attribute_const__; \
  41. extern unsigned ___ss_##__name[2]; \
  42. static inline unsigned int ___sf_##__name(void) { \
  43. unsigned int ret; \
  44. __asm__ ("or %%g0, ___s_" #__name ", %0" : "=r"(ret)); \
  45. return ret; \
  46. }
  47. #define BTFIXUPDEF_SIMM13_INIT(__name,__val) \
  48. static inline unsigned int ___sf_##__name(void) __attribute_const__; \
  49. extern unsigned ___ss_##__name[2]; \
  50. static inline unsigned int ___sf_##__name(void) { \
  51. unsigned int ret; \
  52. __asm__ ("or %%g0, ___s_" #__name "__btset_" #__val ", %0" : "=r"(ret));\
  53. return ret; \
  54. }
  55. /* Put either bottom 13 bits, or upper 22 bits into some register variable
  56. * (depending on the value, this will lead into sethi FIX, reg; or
  57. * mov FIX, reg; )
  58. */
  59. #define BTFIXUPDEF_HALF(__name) \
  60. static inline unsigned int ___af_##__name(void) __attribute_const__; \
  61. extern unsigned ___as_##__name[2]; \
  62. static inline unsigned int ___af_##__name(void) { \
  63. unsigned int ret; \
  64. __asm__ ("or %%g0, ___a_" #__name ", %0" : "=r"(ret)); \
  65. return ret; \
  66. }
  67. #define BTFIXUPDEF_HALF_INIT(__name,__val) \
  68. static inline unsigned int ___af_##__name(void) __attribute_const__; \
  69. extern unsigned ___as_##__name[2]; \
  70. static inline unsigned int ___af_##__name(void) { \
  71. unsigned int ret; \
  72. __asm__ ("or %%g0, ___a_" #__name "__btset_" #__val ", %0" : "=r"(ret));\
  73. return ret; \
  74. }
  75. /* Put upper 22 bits into some register variable */
  76. #define BTFIXUPDEF_SETHI(__name) \
  77. static inline unsigned int ___hf_##__name(void) __attribute_const__; \
  78. extern unsigned ___hs_##__name[2]; \
  79. static inline unsigned int ___hf_##__name(void) { \
  80. unsigned int ret; \
  81. __asm__ ("sethi %%hi(___h_" #__name "), %0" : "=r"(ret)); \
  82. return ret; \
  83. }
  84. #define BTFIXUPDEF_SETHI_INIT(__name,__val) \
  85. static inline unsigned int ___hf_##__name(void) __attribute_const__; \
  86. extern unsigned ___hs_##__name[2]; \
  87. static inline unsigned int ___hf_##__name(void) { \
  88. unsigned int ret; \
  89. __asm__ ("sethi %%hi(___h_" #__name "__btset_" #__val "), %0" : \
  90. "=r"(ret)); \
  91. return ret; \
  92. }
  93. /* Put a full 32bit integer into some register variable */
  94. #define BTFIXUPDEF_INT(__name) \
  95. extern unsigned char ___i_##__name; \
  96. extern unsigned ___is_##__name[2];
  97. #define BTFIXUPCALL_NORM 0x00000000 /* Always call */
  98. #define BTFIXUPCALL_NOP 0x01000000 /* Possibly optimize to nop */
  99. #define BTFIXUPCALL_RETINT(i) (0x90102000|((i) & 0x1fff)) /* Possibly optimize to mov i, %o0 */
  100. #define BTFIXUPCALL_ORINT(i) (0x90122000|((i) & 0x1fff)) /* Possibly optimize to or %o0, i, %o0 */
  101. #define BTFIXUPCALL_RETO0 0x01000000 /* Return first parameter, actually a nop */
  102. #define BTFIXUPCALL_ANDNINT(i) (0x902a2000|((i) & 0x1fff)) /* Possibly optimize to andn %o0, i, %o0 */
  103. #define BTFIXUPCALL_SWAPO0O1 0xd27a0000 /* Possibly optimize to swap [%o0],%o1 */
  104. #define BTFIXUPCALL_SWAPO0G0 0xc07a0000 /* Possibly optimize to swap [%o0],%g0 */
  105. #define BTFIXUPCALL_SWAPG1G2 0xc4784000 /* Possibly optimize to swap [%g1],%g2 */
  106. #define BTFIXUPCALL_STG0O0 0xc0220000 /* Possibly optimize to st %g0,[%o0] */
  107. #define BTFIXUPCALL_STO1O0 0xd2220000 /* Possibly optimize to st %o1,[%o0] */
  108. #define BTFIXUPSET_CALL(__name, __addr, __insn) \
  109. do { \
  110. ___fs_##__name[0] |= 1; \
  111. ___fs_##__name[1] = (unsigned long)__addr; \
  112. ___fs_##__name[2] = __insn; \
  113. } while (0)
  114. #define BTFIXUPSET_BLACKBOX(__name, __func) \
  115. do { \
  116. ___bs_##__name[0] |= 1; \
  117. ___bs_##__name[1] = (unsigned long)__func; \
  118. } while (0)
  119. #define BTFIXUPCOPY_CALL(__name, __from) \
  120. do { \
  121. ___fs_##__name[0] |= 1; \
  122. ___fs_##__name[1] = ___fs_##__from[1]; \
  123. ___fs_##__name[2] = ___fs_##__from[2]; \
  124. } while (0)
  125. #define BTFIXUPSET_SIMM13(__name, __val) \
  126. do { \
  127. ___ss_##__name[0] |= 1; \
  128. ___ss_##__name[1] = (unsigned)__val; \
  129. } while (0)
  130. #define BTFIXUPCOPY_SIMM13(__name, __from) \
  131. do { \
  132. ___ss_##__name[0] |= 1; \
  133. ___ss_##__name[1] = ___ss_##__from[1]; \
  134. } while (0)
  135. #define BTFIXUPSET_HALF(__name, __val) \
  136. do { \
  137. ___as_##__name[0] |= 1; \
  138. ___as_##__name[1] = (unsigned)__val; \
  139. } while (0)
  140. #define BTFIXUPCOPY_HALF(__name, __from) \
  141. do { \
  142. ___as_##__name[0] |= 1; \
  143. ___as_##__name[1] = ___as_##__from[1]; \
  144. } while (0)
  145. #define BTFIXUPSET_SETHI(__name, __val) \
  146. do { \
  147. ___hs_##__name[0] |= 1; \
  148. ___hs_##__name[1] = (unsigned)__val; \
  149. } while (0)
  150. #define BTFIXUPCOPY_SETHI(__name, __from) \
  151. do { \
  152. ___hs_##__name[0] |= 1; \
  153. ___hs_##__name[1] = ___hs_##__from[1]; \
  154. } while (0)
  155. #define BTFIXUPSET_INT(__name, __val) \
  156. do { \
  157. ___is_##__name[0] |= 1; \
  158. ___is_##__name[1] = (unsigned)__val; \
  159. } while (0)
  160. #define BTFIXUPCOPY_INT(__name, __from) \
  161. do { \
  162. ___is_##__name[0] |= 1; \
  163. ___is_##__name[1] = ___is_##__from[1]; \
  164. } while (0)
  165. #define BTFIXUPVAL_CALL(__name) \
  166. ((unsigned long)___fs_##__name[1])
  167. extern void btfixup(void);
  168. #else /* __ASSEMBLY__ */
  169. #define BTFIXUP_SETHI(__name) %hi(___h_ ## __name)
  170. #define BTFIXUP_SETHI_INIT(__name,__val) %hi(___h_ ## __name ## __btset_ ## __val)
  171. #endif /* __ASSEMBLY__ */
  172. #endif /* !(_SPARC_BTFIXUP_H) */