head-64.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. #ifndef _ASM_POWERPC_HEAD_64_H
  2. #define _ASM_POWERPC_HEAD_64_H
  3. #include <asm/cache.h>
  4. /*
  5. * We can't do CPP stringification and concatination directly into the section
  6. * name for some reason, so these macros can do it for us.
  7. */
  8. .macro define_ftsec name
  9. .section ".head.text.\name\()","ax",@progbits
  10. .endm
  11. .macro define_data_ftsec name
  12. .section ".head.data.\name\()","a",@progbits
  13. .endm
  14. .macro use_ftsec name
  15. .section ".head.text.\name\()"
  16. .endm
  17. /*
  18. * Fixed (location) sections are used by opening fixed sections and emitting
  19. * fixed section entries into them before closing them. Multiple fixed sections
  20. * can be open at any time.
  21. *
  22. * Each fixed section created in a .S file must have corresponding linkage
  23. * directives including location, added to arch/powerpc/kernel/vmlinux.lds.S
  24. *
  25. * For each fixed section, code is generated into it in the order which it
  26. * appears in the source. Fixed section entries can be placed at a fixed
  27. * location within the section using _LOCATION postifx variants. These must
  28. * be ordered according to their relative placements within the section.
  29. *
  30. * OPEN_FIXED_SECTION(section_name, start_address, end_address)
  31. * FIXED_SECTION_ENTRY_BEGIN(section_name, label1)
  32. *
  33. * USE_FIXED_SECTION(section_name)
  34. * label3:
  35. * li r10,128
  36. * mv r11,r10
  37. * FIXED_SECTION_ENTRY_BEGIN_LOCATION(section_name, label2, start_address)
  38. * FIXED_SECTION_ENTRY_END_LOCATION(section_name, label2, end_address)
  39. * CLOSE_FIXED_SECTION(section_name)
  40. *
  41. * ZERO_FIXED_SECTION can be used to emit zeroed data.
  42. *
  43. * Troubleshooting:
  44. * - If the build dies with "Error: attempt to move .org backwards" at
  45. * CLOSE_FIXED_SECTION() or elsewhere, there may be something
  46. * unexpected being added there. Remove the '. = x_len' line, rebuild, and
  47. * check what is pushing the section down.
  48. * - If the build dies in linking, check arch/powerpc/kernel/vmlinux.lds.S
  49. * for instructions.
  50. * - If the kernel crashes or hangs in very early boot, it could be linker
  51. * stubs at the start of the main text.
  52. */
  53. #define OPEN_FIXED_SECTION(sname, start, end) \
  54. sname##_start = (start); \
  55. sname##_end = (end); \
  56. sname##_len = (end) - (start); \
  57. define_ftsec sname; \
  58. . = 0x0; \
  59. start_##sname:
  60. #define OPEN_TEXT_SECTION(start) \
  61. text_start = (start); \
  62. .section ".text","ax",@progbits; \
  63. . = 0x0; \
  64. start_text:
  65. #define ZERO_FIXED_SECTION(sname, start, end) \
  66. sname##_start = (start); \
  67. sname##_end = (end); \
  68. sname##_len = (end) - (start); \
  69. define_data_ftsec sname; \
  70. . = 0x0; \
  71. . = sname##_len;
  72. #define USE_FIXED_SECTION(sname) \
  73. fs_label = start_##sname; \
  74. fs_start = sname##_start; \
  75. use_ftsec sname;
  76. #define USE_TEXT_SECTION() \
  77. fs_label = start_text; \
  78. fs_start = text_start; \
  79. .text
  80. #define CLOSE_FIXED_SECTION(sname) \
  81. USE_FIXED_SECTION(sname); \
  82. . = sname##_len; \
  83. end_##sname:
  84. #define __FIXED_SECTION_ENTRY_BEGIN(sname, name, __align) \
  85. USE_FIXED_SECTION(sname); \
  86. .align __align; \
  87. .global name; \
  88. name:
  89. #define FIXED_SECTION_ENTRY_BEGIN(sname, name) \
  90. __FIXED_SECTION_ENTRY_BEGIN(sname, name, 0)
  91. #define FIXED_SECTION_ENTRY_BEGIN_LOCATION(sname, name, start) \
  92. USE_FIXED_SECTION(sname); \
  93. name##_start = (start); \
  94. .if (start) < sname##_start; \
  95. .error "Fixed section underflow"; \
  96. .abort; \
  97. .endif; \
  98. . = (start) - sname##_start; \
  99. .global name; \
  100. name:
  101. #define FIXED_SECTION_ENTRY_END_LOCATION(sname, name, end) \
  102. .if (end) > sname##_end; \
  103. .error "Fixed section overflow"; \
  104. .abort; \
  105. .endif; \
  106. .if (. - name > end - name##_start); \
  107. .error "Fixed entry overflow"; \
  108. .abort; \
  109. .endif; \
  110. . = ((end) - sname##_start); \
  111. /*
  112. * These macros are used to change symbols in other fixed sections to be
  113. * absolute or related to our current fixed section.
  114. *
  115. * - DEFINE_FIXED_SYMBOL / FIXED_SYMBOL_ABS_ADDR is used to find the
  116. * absolute address of a symbol within a fixed section, from any section.
  117. *
  118. * - ABS_ADDR is used to find the absolute address of any symbol, from within
  119. * a fixed section.
  120. */
  121. #define DEFINE_FIXED_SYMBOL(label) \
  122. label##_absolute = (label - fs_label + fs_start)
  123. #define FIXED_SYMBOL_ABS_ADDR(label) \
  124. (label##_absolute)
  125. #define ABS_ADDR(label) (label - fs_label + fs_start)
  126. /*
  127. * Following are the BOOK3S exception handler helper macros.
  128. * Handlers come in a number of types, and each type has a number of varieties.
  129. *
  130. * EXC_REAL_* - real, unrelocated exception vectors
  131. * EXC_VIRT_* - virt (AIL), unrelocated exception vectors
  132. * TRAMP_REAL_* - real, unrelocated helpers (virt can call these)
  133. * TRAMP_VIRT_* - virt, unreloc helpers (in practice, real can use)
  134. * TRAMP_KVM - KVM handlers that get put into real, unrelocated
  135. * EXC_COMMON_* - virt, relocated common handlers
  136. *
  137. * The EXC handlers are given a name, and branch to name_common, or the
  138. * appropriate KVM or masking function. Vector handler verieties are as
  139. * follows:
  140. *
  141. * EXC_{REAL|VIRT}_BEGIN/END - used to open-code the exception
  142. *
  143. * EXC_{REAL|VIRT} - standard exception
  144. *
  145. * EXC_{REAL|VIRT}_suffix
  146. * where _suffix is:
  147. * - _MASKABLE - maskable exception
  148. * - _OOL - out of line with trampoline to common handler
  149. * - _HV - HV exception
  150. *
  151. * There can be combinations, e.g., EXC_VIRT_OOL_MASKABLE_HV
  152. *
  153. * The one unusual case is __EXC_REAL_OOL_HV_DIRECT, which is
  154. * an OOL vector that branches to a specified handler rather than the usual
  155. * trampoline that goes to common. It, and other underscore macros, should
  156. * be used with care.
  157. *
  158. * KVM handlers come in the following verieties:
  159. * TRAMP_KVM
  160. * TRAMP_KVM_SKIP
  161. * TRAMP_KVM_HV
  162. * TRAMP_KVM_HV_SKIP
  163. *
  164. * COMMON handlers come in the following verieties:
  165. * EXC_COMMON_BEGIN/END - used to open-code the handler
  166. * EXC_COMMON
  167. * EXC_COMMON_ASYNC
  168. * EXC_COMMON_HV
  169. *
  170. * TRAMP_REAL and TRAMP_VIRT can be used with BEGIN/END. KVM
  171. * and OOL handlers are implemented as types of TRAMP and TRAMP_VIRT handlers.
  172. */
  173. #define EXC_REAL_BEGIN(name, start, end) \
  174. FIXED_SECTION_ENTRY_BEGIN_LOCATION(real_vectors, exc_real_##start##_##name, start)
  175. #define EXC_REAL_END(name, start, end) \
  176. FIXED_SECTION_ENTRY_END_LOCATION(real_vectors, exc_real_##start##_##name, end)
  177. #define EXC_VIRT_BEGIN(name, start, end) \
  178. FIXED_SECTION_ENTRY_BEGIN_LOCATION(virt_vectors, exc_virt_##start##_##name, start)
  179. #define EXC_VIRT_END(name, start, end) \
  180. FIXED_SECTION_ENTRY_END_LOCATION(virt_vectors, exc_virt_##start##_##name, end)
  181. #define EXC_COMMON_BEGIN(name) \
  182. USE_TEXT_SECTION(); \
  183. .align 7; \
  184. .global name; \
  185. DEFINE_FIXED_SYMBOL(name); \
  186. name:
  187. #define TRAMP_REAL_BEGIN(name) \
  188. FIXED_SECTION_ENTRY_BEGIN(real_trampolines, name)
  189. #define TRAMP_VIRT_BEGIN(name) \
  190. FIXED_SECTION_ENTRY_BEGIN(virt_trampolines, name)
  191. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  192. #define TRAMP_KVM_BEGIN(name) \
  193. TRAMP_REAL_BEGIN(name)
  194. #else
  195. #define TRAMP_KVM_BEGIN(name)
  196. #endif
  197. #define EXC_REAL_NONE(start, end) \
  198. FIXED_SECTION_ENTRY_BEGIN_LOCATION(real_vectors, exc_real_##start##_##unused, start); \
  199. FIXED_SECTION_ENTRY_END_LOCATION(real_vectors, exc_real_##start##_##unused, end)
  200. #define EXC_VIRT_NONE(start, end) \
  201. FIXED_SECTION_ENTRY_BEGIN_LOCATION(virt_vectors, exc_virt_##start##_##unused, start); \
  202. FIXED_SECTION_ENTRY_END_LOCATION(virt_vectors, exc_virt_##start##_##unused, end);
  203. #define EXC_REAL(name, start, end) \
  204. EXC_REAL_BEGIN(name, start, end); \
  205. STD_EXCEPTION_PSERIES(start, name##_common); \
  206. EXC_REAL_END(name, start, end);
  207. #define EXC_VIRT(name, start, end, realvec) \
  208. EXC_VIRT_BEGIN(name, start, end); \
  209. STD_RELON_EXCEPTION_PSERIES(start, realvec, name##_common); \
  210. EXC_VIRT_END(name, start, end);
  211. #define EXC_REAL_MASKABLE(name, start, end) \
  212. EXC_REAL_BEGIN(name, start, end); \
  213. MASKABLE_EXCEPTION_PSERIES(start, start, name##_common); \
  214. EXC_REAL_END(name, start, end);
  215. #define EXC_VIRT_MASKABLE(name, start, end, realvec) \
  216. EXC_VIRT_BEGIN(name, start, end); \
  217. MASKABLE_RELON_EXCEPTION_PSERIES(start, realvec, name##_common); \
  218. EXC_VIRT_END(name, start, end);
  219. #define EXC_REAL_HV(name, start, end) \
  220. EXC_REAL_BEGIN(name, start, end); \
  221. STD_EXCEPTION_HV(start, start, name##_common); \
  222. EXC_REAL_END(name, start, end);
  223. #define EXC_VIRT_HV(name, start, end, realvec) \
  224. EXC_VIRT_BEGIN(name, start, end); \
  225. STD_RELON_EXCEPTION_HV(start, realvec, name##_common); \
  226. EXC_VIRT_END(name, start, end);
  227. #define __EXC_REAL_OOL(name, start, end) \
  228. EXC_REAL_BEGIN(name, start, end); \
  229. __OOL_EXCEPTION(start, label, tramp_real_##name); \
  230. EXC_REAL_END(name, start, end);
  231. #define __TRAMP_REAL_REAL_OOL(name, vec) \
  232. TRAMP_REAL_BEGIN(tramp_real_##name); \
  233. STD_EXCEPTION_PSERIES_OOL(vec, name##_common); \
  234. #define EXC_REAL_OOL(name, start, end) \
  235. __EXC_REAL_OOL(name, start, end); \
  236. __TRAMP_REAL_REAL_OOL(name, start);
  237. #define __EXC_REAL_OOL_MASKABLE(name, start, end) \
  238. __EXC_REAL_OOL(name, start, end);
  239. #define __TRAMP_REAL_REAL_OOL_MASKABLE(name, vec) \
  240. TRAMP_REAL_BEGIN(tramp_real_##name); \
  241. MASKABLE_EXCEPTION_PSERIES_OOL(vec, name##_common); \
  242. #define EXC_REAL_OOL_MASKABLE(name, start, end) \
  243. __EXC_REAL_OOL_MASKABLE(name, start, end); \
  244. __TRAMP_REAL_REAL_OOL_MASKABLE(name, start);
  245. #define __EXC_REAL_OOL_HV_DIRECT(name, start, end, handler) \
  246. EXC_REAL_BEGIN(name, start, end); \
  247. __OOL_EXCEPTION(start, label, handler); \
  248. EXC_REAL_END(name, start, end);
  249. #define __EXC_REAL_OOL_HV(name, start, end) \
  250. __EXC_REAL_OOL(name, start, end);
  251. #define __TRAMP_REAL_REAL_OOL_HV(name, vec) \
  252. TRAMP_REAL_BEGIN(tramp_real_##name); \
  253. STD_EXCEPTION_HV_OOL(vec, name##_common); \
  254. #define EXC_REAL_OOL_HV(name, start, end) \
  255. __EXC_REAL_OOL_HV(name, start, end); \
  256. __TRAMP_REAL_REAL_OOL_HV(name, start);
  257. #define __EXC_REAL_OOL_MASKABLE_HV(name, start, end) \
  258. __EXC_REAL_OOL(name, start, end);
  259. #define __TRAMP_REAL_REAL_OOL_MASKABLE_HV(name, vec) \
  260. TRAMP_REAL_BEGIN(tramp_real_##name); \
  261. MASKABLE_EXCEPTION_HV_OOL(vec, name##_common); \
  262. #define EXC_REAL_OOL_MASKABLE_HV(name, start, end) \
  263. __EXC_REAL_OOL_MASKABLE_HV(name, start, end); \
  264. __TRAMP_REAL_REAL_OOL_MASKABLE_HV(name, start);
  265. #define __EXC_VIRT_OOL(name, start, end) \
  266. EXC_VIRT_BEGIN(name, start, end); \
  267. __OOL_EXCEPTION(start, label, tramp_virt_##name); \
  268. EXC_VIRT_END(name, start, end);
  269. #define __TRAMP_REAL_VIRT_OOL(name, realvec) \
  270. TRAMP_VIRT_BEGIN(tramp_virt_##name); \
  271. STD_RELON_EXCEPTION_PSERIES_OOL(realvec, name##_common); \
  272. #define EXC_VIRT_OOL(name, start, end, realvec) \
  273. __EXC_VIRT_OOL(name, start, end); \
  274. __TRAMP_REAL_VIRT_OOL(name, realvec);
  275. #define __EXC_VIRT_OOL_MASKABLE(name, start, end) \
  276. __EXC_VIRT_OOL(name, start, end);
  277. #define __TRAMP_REAL_VIRT_OOL_MASKABLE(name, realvec) \
  278. TRAMP_VIRT_BEGIN(tramp_virt_##name); \
  279. MASKABLE_RELON_EXCEPTION_PSERIES_OOL(realvec, name##_common); \
  280. #define EXC_VIRT_OOL_MASKABLE(name, start, end, realvec) \
  281. __EXC_VIRT_OOL_MASKABLE(name, start, end); \
  282. __TRAMP_REAL_VIRT_OOL_MASKABLE(name, realvec);
  283. #define __EXC_VIRT_OOL_HV(name, start, end) \
  284. __EXC_VIRT_OOL(name, start, end);
  285. #define __TRAMP_REAL_VIRT_OOL_HV(name, realvec) \
  286. TRAMP_VIRT_BEGIN(tramp_virt_##name); \
  287. STD_RELON_EXCEPTION_HV_OOL(realvec, name##_common); \
  288. #define EXC_VIRT_OOL_HV(name, start, end, realvec) \
  289. __EXC_VIRT_OOL_HV(name, start, end); \
  290. __TRAMP_REAL_VIRT_OOL_HV(name, realvec);
  291. #define __EXC_VIRT_OOL_MASKABLE_HV(name, start, end) \
  292. __EXC_VIRT_OOL(name, start, end);
  293. #define __TRAMP_REAL_VIRT_OOL_MASKABLE_HV(name, realvec) \
  294. TRAMP_VIRT_BEGIN(tramp_virt_##name); \
  295. MASKABLE_RELON_EXCEPTION_HV_OOL(realvec, name##_common); \
  296. #define EXC_VIRT_OOL_MASKABLE_HV(name, start, end, realvec) \
  297. __EXC_VIRT_OOL_MASKABLE_HV(name, start, end); \
  298. __TRAMP_REAL_VIRT_OOL_MASKABLE_HV(name, realvec);
  299. #define TRAMP_KVM(area, n) \
  300. TRAMP_KVM_BEGIN(do_kvm_##n); \
  301. KVM_HANDLER(area, EXC_STD, n); \
  302. #define TRAMP_KVM_SKIP(area, n) \
  303. TRAMP_KVM_BEGIN(do_kvm_##n); \
  304. KVM_HANDLER_SKIP(area, EXC_STD, n); \
  305. /*
  306. * HV variant exceptions get the 0x2 bit added to their trap number.
  307. */
  308. #define TRAMP_KVM_HV(area, n) \
  309. TRAMP_KVM_BEGIN(do_kvm_H##n); \
  310. KVM_HANDLER(area, EXC_HV, n + 0x2); \
  311. #define TRAMP_KVM_HV_SKIP(area, n) \
  312. TRAMP_KVM_BEGIN(do_kvm_H##n); \
  313. KVM_HANDLER_SKIP(area, EXC_HV, n + 0x2); \
  314. #define EXC_COMMON(name, realvec, hdlr) \
  315. EXC_COMMON_BEGIN(name); \
  316. STD_EXCEPTION_COMMON(realvec, name, hdlr); \
  317. #define EXC_COMMON_ASYNC(name, realvec, hdlr) \
  318. EXC_COMMON_BEGIN(name); \
  319. STD_EXCEPTION_COMMON_ASYNC(realvec, name, hdlr); \
  320. #define EXC_COMMON_HV(name, realvec, hdlr) \
  321. EXC_COMMON_BEGIN(name); \
  322. STD_EXCEPTION_COMMON(realvec + 0x2, name, hdlr); \
  323. #endif /* _ASM_POWERPC_HEAD_64_H */