entry.S 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  1. /*
  2. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  3. *
  4. * kernel entry points (interruptions, system call wrappers)
  5. * Copyright (C) 1999,2000 Philipp Rumpf
  6. * Copyright (C) 1999 SuSE GmbH Nuernberg
  7. * Copyright (C) 2000 Hewlett-Packard (John Marvin)
  8. * Copyright (C) 1999 Hewlett-Packard (Frank Rowand)
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <asm/asm-offsets.h>
  25. /* we have the following possibilities to act on an interruption:
  26. * - handle in assembly and use shadowed registers only
  27. * - save registers to kernel stack and handle in assembly or C */
  28. #include <asm/psw.h>
  29. #include <asm/cache.h> /* for L1_CACHE_SHIFT */
  30. #include <asm/assembly.h> /* for LDREG/STREG defines */
  31. #include <asm/pgtable.h>
  32. #include <asm/signal.h>
  33. #include <asm/unistd.h>
  34. #include <asm/thread_info.h>
  35. #include <linux/linkage.h>
  36. #ifdef CONFIG_64BIT
  37. .level 2.0w
  38. #else
  39. .level 2.0
  40. #endif
  41. .import pa_tlb_lock,data
  42. /* space_to_prot macro creates a prot id from a space id */
  43. #if (SPACEID_SHIFT) == 0
  44. .macro space_to_prot spc prot
  45. depd,z \spc,62,31,\prot
  46. .endm
  47. #else
  48. .macro space_to_prot spc prot
  49. extrd,u \spc,(64 - (SPACEID_SHIFT)),32,\prot
  50. .endm
  51. #endif
  52. /* Switch to virtual mapping, trashing only %r1 */
  53. .macro virt_map
  54. /* pcxt_ssm_bug */
  55. rsm PSW_SM_I, %r0 /* barrier for "Relied upon Translation */
  56. mtsp %r0, %sr4
  57. mtsp %r0, %sr5
  58. mtsp %r0, %sr6
  59. tovirt_r1 %r29
  60. load32 KERNEL_PSW, %r1
  61. rsm PSW_SM_QUIET,%r0 /* second "heavy weight" ctl op */
  62. mtctl %r0, %cr17 /* Clear IIASQ tail */
  63. mtctl %r0, %cr17 /* Clear IIASQ head */
  64. mtctl %r1, %ipsw
  65. load32 4f, %r1
  66. mtctl %r1, %cr18 /* Set IIAOQ tail */
  67. ldo 4(%r1), %r1
  68. mtctl %r1, %cr18 /* Set IIAOQ head */
  69. rfir
  70. nop
  71. 4:
  72. .endm
  73. /*
  74. * The "get_stack" macros are responsible for determining the
  75. * kernel stack value.
  76. *
  77. * If sr7 == 0
  78. * Already using a kernel stack, so call the
  79. * get_stack_use_r30 macro to push a pt_regs structure
  80. * on the stack, and store registers there.
  81. * else
  82. * Need to set up a kernel stack, so call the
  83. * get_stack_use_cr30 macro to set up a pointer
  84. * to the pt_regs structure contained within the
  85. * task pointer pointed to by cr30. Set the stack
  86. * pointer to point to the end of the task structure.
  87. *
  88. * Note that we use shadowed registers for temps until
  89. * we can save %r26 and %r29. %r26 is used to preserve
  90. * %r8 (a shadowed register) which temporarily contained
  91. * either the fault type ("code") or the eirr. We need
  92. * to use a non-shadowed register to carry the value over
  93. * the rfir in virt_map. We use %r26 since this value winds
  94. * up being passed as the argument to either do_cpu_irq_mask
  95. * or handle_interruption. %r29 is used to hold a pointer
  96. * the register save area, and once again, it needs to
  97. * be a non-shadowed register so that it survives the rfir.
  98. *
  99. * N.B. TASK_SZ_ALGN and PT_SZ_ALGN include space for a stack frame.
  100. */
  101. .macro get_stack_use_cr30
  102. /* we save the registers in the task struct */
  103. copy %r30, %r17
  104. mfctl %cr30, %r1
  105. ldo THREAD_SZ_ALGN(%r1), %r30
  106. mtsp %r0,%sr7
  107. mtsp %r16,%sr3
  108. tophys %r1,%r9
  109. LDREG TI_TASK(%r9), %r1 /* thread_info -> task_struct */
  110. tophys %r1,%r9
  111. ldo TASK_REGS(%r9),%r9
  112. STREG %r17,PT_GR30(%r9)
  113. STREG %r29,PT_GR29(%r9)
  114. STREG %r26,PT_GR26(%r9)
  115. STREG %r16,PT_SR7(%r9)
  116. copy %r9,%r29
  117. .endm
  118. .macro get_stack_use_r30
  119. /* we put a struct pt_regs on the stack and save the registers there */
  120. tophys %r30,%r9
  121. copy %r30,%r1
  122. ldo PT_SZ_ALGN(%r30),%r30
  123. STREG %r1,PT_GR30(%r9)
  124. STREG %r29,PT_GR29(%r9)
  125. STREG %r26,PT_GR26(%r9)
  126. STREG %r16,PT_SR7(%r9)
  127. copy %r9,%r29
  128. .endm
  129. .macro rest_stack
  130. LDREG PT_GR1(%r29), %r1
  131. LDREG PT_GR30(%r29),%r30
  132. LDREG PT_GR29(%r29),%r29
  133. .endm
  134. /* default interruption handler
  135. * (calls traps.c:handle_interruption) */
  136. .macro def code
  137. b intr_save
  138. ldi \code, %r8
  139. .align 32
  140. .endm
  141. /* Interrupt interruption handler
  142. * (calls irq.c:do_cpu_irq_mask) */
  143. .macro extint code
  144. b intr_extint
  145. mfsp %sr7,%r16
  146. .align 32
  147. .endm
  148. .import os_hpmc, code
  149. /* HPMC handler */
  150. .macro hpmc code
  151. nop /* must be a NOP, will be patched later */
  152. load32 PA(os_hpmc), %r3
  153. bv,n 0(%r3)
  154. nop
  155. .word 0 /* checksum (will be patched) */
  156. .word PA(os_hpmc) /* address of handler */
  157. .word 0 /* length of handler */
  158. .endm
  159. /*
  160. * Performance Note: Instructions will be moved up into
  161. * this part of the code later on, once we are sure
  162. * that the tlb miss handlers are close to final form.
  163. */
  164. /* Register definitions for tlb miss handler macros */
  165. va = r8 /* virtual address for which the trap occurred */
  166. spc = r24 /* space for which the trap occurred */
  167. #ifndef CONFIG_64BIT
  168. /*
  169. * itlb miss interruption handler (parisc 1.1 - 32 bit)
  170. */
  171. .macro itlb_11 code
  172. mfctl %pcsq, spc
  173. b itlb_miss_11
  174. mfctl %pcoq, va
  175. .align 32
  176. .endm
  177. #endif
  178. /*
  179. * itlb miss interruption handler (parisc 2.0)
  180. */
  181. .macro itlb_20 code
  182. mfctl %pcsq, spc
  183. #ifdef CONFIG_64BIT
  184. b itlb_miss_20w
  185. #else
  186. b itlb_miss_20
  187. #endif
  188. mfctl %pcoq, va
  189. .align 32
  190. .endm
  191. #ifndef CONFIG_64BIT
  192. /*
  193. * naitlb miss interruption handler (parisc 1.1 - 32 bit)
  194. */
  195. .macro naitlb_11 code
  196. mfctl %isr,spc
  197. b naitlb_miss_11
  198. mfctl %ior,va
  199. .align 32
  200. .endm
  201. #endif
  202. /*
  203. * naitlb miss interruption handler (parisc 2.0)
  204. */
  205. .macro naitlb_20 code
  206. mfctl %isr,spc
  207. #ifdef CONFIG_64BIT
  208. b naitlb_miss_20w
  209. #else
  210. b naitlb_miss_20
  211. #endif
  212. mfctl %ior,va
  213. .align 32
  214. .endm
  215. #ifndef CONFIG_64BIT
  216. /*
  217. * dtlb miss interruption handler (parisc 1.1 - 32 bit)
  218. */
  219. .macro dtlb_11 code
  220. mfctl %isr, spc
  221. b dtlb_miss_11
  222. mfctl %ior, va
  223. .align 32
  224. .endm
  225. #endif
  226. /*
  227. * dtlb miss interruption handler (parisc 2.0)
  228. */
  229. .macro dtlb_20 code
  230. mfctl %isr, spc
  231. #ifdef CONFIG_64BIT
  232. b dtlb_miss_20w
  233. #else
  234. b dtlb_miss_20
  235. #endif
  236. mfctl %ior, va
  237. .align 32
  238. .endm
  239. #ifndef CONFIG_64BIT
  240. /* nadtlb miss interruption handler (parisc 1.1 - 32 bit) */
  241. .macro nadtlb_11 code
  242. mfctl %isr,spc
  243. b nadtlb_miss_11
  244. mfctl %ior,va
  245. .align 32
  246. .endm
  247. #endif
  248. /* nadtlb miss interruption handler (parisc 2.0) */
  249. .macro nadtlb_20 code
  250. mfctl %isr,spc
  251. #ifdef CONFIG_64BIT
  252. b nadtlb_miss_20w
  253. #else
  254. b nadtlb_miss_20
  255. #endif
  256. mfctl %ior,va
  257. .align 32
  258. .endm
  259. #ifndef CONFIG_64BIT
  260. /*
  261. * dirty bit trap interruption handler (parisc 1.1 - 32 bit)
  262. */
  263. .macro dbit_11 code
  264. mfctl %isr,spc
  265. b dbit_trap_11
  266. mfctl %ior,va
  267. .align 32
  268. .endm
  269. #endif
  270. /*
  271. * dirty bit trap interruption handler (parisc 2.0)
  272. */
  273. .macro dbit_20 code
  274. mfctl %isr,spc
  275. #ifdef CONFIG_64BIT
  276. b dbit_trap_20w
  277. #else
  278. b dbit_trap_20
  279. #endif
  280. mfctl %ior,va
  281. .align 32
  282. .endm
  283. /* In LP64, the space contains part of the upper 32 bits of the
  284. * fault. We have to extract this and place it in the va,
  285. * zeroing the corresponding bits in the space register */
  286. .macro space_adjust spc,va,tmp
  287. #ifdef CONFIG_64BIT
  288. extrd,u \spc,63,SPACEID_SHIFT,\tmp
  289. depd %r0,63,SPACEID_SHIFT,\spc
  290. depd \tmp,31,SPACEID_SHIFT,\va
  291. #endif
  292. .endm
  293. .import swapper_pg_dir,code
  294. /* Get the pgd. For faults on space zero (kernel space), this
  295. * is simply swapper_pg_dir. For user space faults, the
  296. * pgd is stored in %cr25 */
  297. .macro get_pgd spc,reg
  298. ldil L%PA(swapper_pg_dir),\reg
  299. ldo R%PA(swapper_pg_dir)(\reg),\reg
  300. or,COND(=) %r0,\spc,%r0
  301. mfctl %cr25,\reg
  302. .endm
  303. /*
  304. space_check(spc,tmp,fault)
  305. spc - The space we saw the fault with.
  306. tmp - The place to store the current space.
  307. fault - Function to call on failure.
  308. Only allow faults on different spaces from the
  309. currently active one if we're the kernel
  310. */
  311. .macro space_check spc,tmp,fault
  312. mfsp %sr7,\tmp
  313. or,COND(<>) %r0,\spc,%r0 /* user may execute gateway page
  314. * as kernel, so defeat the space
  315. * check if it is */
  316. copy \spc,\tmp
  317. or,COND(=) %r0,\tmp,%r0 /* nullify if executing as kernel */
  318. cmpb,COND(<>),n \tmp,\spc,\fault
  319. .endm
  320. /* Look up a PTE in a 2-Level scheme (faulting at each
  321. * level if the entry isn't present
  322. *
  323. * NOTE: we use ldw even for LP64, since the short pointers
  324. * can address up to 1TB
  325. */
  326. .macro L2_ptep pmd,pte,index,va,fault
  327. #if CONFIG_PGTABLE_LEVELS == 3
  328. extru \va,31-ASM_PMD_SHIFT,ASM_BITS_PER_PMD,\index
  329. #else
  330. # if defined(CONFIG_64BIT)
  331. extrd,u \va,63-ASM_PGDIR_SHIFT,ASM_BITS_PER_PGD,\index
  332. #else
  333. # if PAGE_SIZE > 4096
  334. extru \va,31-ASM_PGDIR_SHIFT,32-ASM_PGDIR_SHIFT,\index
  335. # else
  336. extru \va,31-ASM_PGDIR_SHIFT,ASM_BITS_PER_PGD,\index
  337. # endif
  338. # endif
  339. #endif
  340. dep %r0,31,PAGE_SHIFT,\pmd /* clear offset */
  341. copy %r0,\pte
  342. ldw,s \index(\pmd),\pmd
  343. bb,>=,n \pmd,_PxD_PRESENT_BIT,\fault
  344. dep %r0,31,PxD_FLAG_SHIFT,\pmd /* clear flags */
  345. copy \pmd,%r9
  346. SHLREG %r9,PxD_VALUE_SHIFT,\pmd
  347. extru \va,31-PAGE_SHIFT,ASM_BITS_PER_PTE,\index
  348. dep %r0,31,PAGE_SHIFT,\pmd /* clear offset */
  349. shladd \index,BITS_PER_PTE_ENTRY,\pmd,\pmd /* pmd is now pte */
  350. LDREG %r0(\pmd),\pte
  351. bb,>=,n \pte,_PAGE_PRESENT_BIT,\fault
  352. .endm
  353. /* Look up PTE in a 3-Level scheme.
  354. *
  355. * Here we implement a Hybrid L2/L3 scheme: we allocate the
  356. * first pmd adjacent to the pgd. This means that we can
  357. * subtract a constant offset to get to it. The pmd and pgd
  358. * sizes are arranged so that a single pmd covers 4GB (giving
  359. * a full LP64 process access to 8TB) so our lookups are
  360. * effectively L2 for the first 4GB of the kernel (i.e. for
  361. * all ILP32 processes and all the kernel for machines with
  362. * under 4GB of memory) */
  363. .macro L3_ptep pgd,pte,index,va,fault
  364. #if CONFIG_PGTABLE_LEVELS == 3 /* we might have a 2-Level scheme, e.g. with 16kb page size */
  365. extrd,u \va,63-ASM_PGDIR_SHIFT,ASM_BITS_PER_PGD,\index
  366. copy %r0,\pte
  367. extrd,u,*= \va,63-ASM_PGDIR_SHIFT,64-ASM_PGDIR_SHIFT,%r0
  368. ldw,s \index(\pgd),\pgd
  369. extrd,u,*= \va,63-ASM_PGDIR_SHIFT,64-ASM_PGDIR_SHIFT,%r0
  370. bb,>=,n \pgd,_PxD_PRESENT_BIT,\fault
  371. extrd,u,*= \va,63-ASM_PGDIR_SHIFT,64-ASM_PGDIR_SHIFT,%r0
  372. shld \pgd,PxD_VALUE_SHIFT,\index
  373. extrd,u,*= \va,63-ASM_PGDIR_SHIFT,64-ASM_PGDIR_SHIFT,%r0
  374. copy \index,\pgd
  375. extrd,u,*<> \va,63-ASM_PGDIR_SHIFT,64-ASM_PGDIR_SHIFT,%r0
  376. ldo ASM_PGD_PMD_OFFSET(\pgd),\pgd
  377. #endif
  378. L2_ptep \pgd,\pte,\index,\va,\fault
  379. .endm
  380. /* Acquire pa_tlb_lock lock and recheck page is still present. */
  381. .macro tlb_lock spc,ptp,pte,tmp,tmp1,fault
  382. #ifdef CONFIG_SMP
  383. cmpib,COND(=),n 0,\spc,2f
  384. load32 PA(pa_tlb_lock),\tmp
  385. 1: LDCW 0(\tmp),\tmp1
  386. cmpib,COND(=) 0,\tmp1,1b
  387. nop
  388. LDREG 0(\ptp),\pte
  389. bb,<,n \pte,_PAGE_PRESENT_BIT,2f
  390. b \fault
  391. stw \spc,0(\tmp)
  392. 2:
  393. #endif
  394. .endm
  395. /* Release pa_tlb_lock lock without reloading lock address. */
  396. .macro tlb_unlock0 spc,tmp
  397. #ifdef CONFIG_SMP
  398. or,COND(=) %r0,\spc,%r0
  399. stw \spc,0(\tmp)
  400. #endif
  401. .endm
  402. /* Release pa_tlb_lock lock. */
  403. .macro tlb_unlock1 spc,tmp
  404. #ifdef CONFIG_SMP
  405. load32 PA(pa_tlb_lock),\tmp
  406. tlb_unlock0 \spc,\tmp
  407. #endif
  408. .endm
  409. /* Set the _PAGE_ACCESSED bit of the PTE. Be clever and
  410. * don't needlessly dirty the cache line if it was already set */
  411. .macro update_accessed ptp,pte,tmp,tmp1
  412. ldi _PAGE_ACCESSED,\tmp1
  413. or \tmp1,\pte,\tmp
  414. and,COND(<>) \tmp1,\pte,%r0
  415. STREG \tmp,0(\ptp)
  416. .endm
  417. /* Set the dirty bit (and accessed bit). No need to be
  418. * clever, this is only used from the dirty fault */
  419. .macro update_dirty ptp,pte,tmp
  420. ldi _PAGE_ACCESSED|_PAGE_DIRTY,\tmp
  421. or \tmp,\pte,\pte
  422. STREG \pte,0(\ptp)
  423. .endm
  424. /* We have (depending on the page size):
  425. * - 38 to 52-bit Physical Page Number
  426. * - 12 to 26-bit page offset
  427. */
  428. /* bitshift difference between a PFN (based on kernel's PAGE_SIZE)
  429. * to a CPU TLB 4k PFN (4k => 12 bits to shift) */
  430. #define PAGE_ADD_SHIFT (PAGE_SHIFT-12)
  431. #define PAGE_ADD_HUGE_SHIFT (REAL_HPAGE_SHIFT-12)
  432. /* Drop prot bits and convert to page addr for iitlbt and idtlbt */
  433. .macro convert_for_tlb_insert20 pte,tmp
  434. #ifdef CONFIG_HUGETLB_PAGE
  435. copy \pte,\tmp
  436. extrd,u \tmp,(63-ASM_PFN_PTE_SHIFT)+(63-58)+PAGE_ADD_SHIFT,\
  437. 64-PAGE_SHIFT-PAGE_ADD_SHIFT,\pte
  438. depdi _PAGE_SIZE_ENCODING_DEFAULT,63,\
  439. (63-58)+PAGE_ADD_SHIFT,\pte
  440. extrd,u,*= \tmp,_PAGE_HPAGE_BIT+32,1,%r0
  441. depdi _HUGE_PAGE_SIZE_ENCODING_DEFAULT,63,\
  442. (63-58)+PAGE_ADD_HUGE_SHIFT,\pte
  443. #else /* Huge pages disabled */
  444. extrd,u \pte,(63-ASM_PFN_PTE_SHIFT)+(63-58)+PAGE_ADD_SHIFT,\
  445. 64-PAGE_SHIFT-PAGE_ADD_SHIFT,\pte
  446. depdi _PAGE_SIZE_ENCODING_DEFAULT,63,\
  447. (63-58)+PAGE_ADD_SHIFT,\pte
  448. #endif
  449. .endm
  450. /* Convert the pte and prot to tlb insertion values. How
  451. * this happens is quite subtle, read below */
  452. .macro make_insert_tlb spc,pte,prot,tmp
  453. space_to_prot \spc \prot /* create prot id from space */
  454. /* The following is the real subtlety. This is depositing
  455. * T <-> _PAGE_REFTRAP
  456. * D <-> _PAGE_DIRTY
  457. * B <-> _PAGE_DMB (memory break)
  458. *
  459. * Then incredible subtlety: The access rights are
  460. * _PAGE_GATEWAY, _PAGE_EXEC and _PAGE_WRITE
  461. * See 3-14 of the parisc 2.0 manual
  462. *
  463. * Finally, _PAGE_READ goes in the top bit of PL1 (so we
  464. * trigger an access rights trap in user space if the user
  465. * tries to read an unreadable page */
  466. depd \pte,8,7,\prot
  467. /* PAGE_USER indicates the page can be read with user privileges,
  468. * so deposit X1|11 to PL1|PL2 (remember the upper bit of PL1
  469. * contains _PAGE_READ) */
  470. extrd,u,*= \pte,_PAGE_USER_BIT+32,1,%r0
  471. depdi 7,11,3,\prot
  472. /* If we're a gateway page, drop PL2 back to zero for promotion
  473. * to kernel privilege (so we can execute the page as kernel).
  474. * Any privilege promotion page always denys read and write */
  475. extrd,u,*= \pte,_PAGE_GATEWAY_BIT+32,1,%r0
  476. depd %r0,11,2,\prot /* If Gateway, Set PL2 to 0 */
  477. /* Enforce uncacheable pages.
  478. * This should ONLY be use for MMIO on PA 2.0 machines.
  479. * Memory/DMA is cache coherent on all PA2.0 machines we support
  480. * (that means T-class is NOT supported) and the memory controllers
  481. * on most of those machines only handles cache transactions.
  482. */
  483. extrd,u,*= \pte,_PAGE_NO_CACHE_BIT+32,1,%r0
  484. depdi 1,12,1,\prot
  485. /* Drop prot bits and convert to page addr for iitlbt and idtlbt */
  486. convert_for_tlb_insert20 \pte \tmp
  487. .endm
  488. /* Identical macro to make_insert_tlb above, except it
  489. * makes the tlb entry for the differently formatted pa11
  490. * insertion instructions */
  491. .macro make_insert_tlb_11 spc,pte,prot
  492. zdep \spc,30,15,\prot
  493. dep \pte,8,7,\prot
  494. extru,= \pte,_PAGE_NO_CACHE_BIT,1,%r0
  495. depi 1,12,1,\prot
  496. extru,= \pte,_PAGE_USER_BIT,1,%r0
  497. depi 7,11,3,\prot /* Set for user space (1 rsvd for read) */
  498. extru,= \pte,_PAGE_GATEWAY_BIT,1,%r0
  499. depi 0,11,2,\prot /* If Gateway, Set PL2 to 0 */
  500. /* Get rid of prot bits and convert to page addr for iitlba */
  501. depi 0,31,ASM_PFN_PTE_SHIFT,\pte
  502. SHRREG \pte,(ASM_PFN_PTE_SHIFT-(31-26)),\pte
  503. .endm
  504. /* This is for ILP32 PA2.0 only. The TLB insertion needs
  505. * to extend into I/O space if the address is 0xfXXXXXXX
  506. * so we extend the f's into the top word of the pte in
  507. * this case */
  508. .macro f_extend pte,tmp
  509. extrd,s \pte,42,4,\tmp
  510. addi,<> 1,\tmp,%r0
  511. extrd,s \pte,63,25,\pte
  512. .endm
  513. /* The alias region is an 8MB aligned 16MB to do clear and
  514. * copy user pages at addresses congruent with the user
  515. * virtual address.
  516. *
  517. * To use the alias page, you set %r26 up with the to TLB
  518. * entry (identifying the physical page) and %r23 up with
  519. * the from tlb entry (or nothing if only a to entry---for
  520. * clear_user_page_asm) */
  521. .macro do_alias spc,tmp,tmp1,va,pte,prot,fault,patype
  522. cmpib,COND(<>),n 0,\spc,\fault
  523. ldil L%(TMPALIAS_MAP_START),\tmp
  524. #if defined(CONFIG_64BIT) && (TMPALIAS_MAP_START >= 0x80000000)
  525. /* on LP64, ldi will sign extend into the upper 32 bits,
  526. * which is behaviour we don't want */
  527. depdi 0,31,32,\tmp
  528. #endif
  529. copy \va,\tmp1
  530. depi 0,31,23,\tmp1
  531. cmpb,COND(<>),n \tmp,\tmp1,\fault
  532. mfctl %cr19,\tmp /* iir */
  533. /* get the opcode (first six bits) into \tmp */
  534. extrw,u \tmp,5,6,\tmp
  535. /*
  536. * Only setting the T bit prevents data cache movein
  537. * Setting access rights to zero prevents instruction cache movein
  538. *
  539. * Note subtlety here: _PAGE_GATEWAY, _PAGE_EXEC and _PAGE_WRITE go
  540. * to type field and _PAGE_READ goes to top bit of PL1
  541. */
  542. ldi (_PAGE_REFTRAP|_PAGE_READ|_PAGE_WRITE),\prot
  543. /*
  544. * so if the opcode is one (i.e. this is a memory management
  545. * instruction) nullify the next load so \prot is only T.
  546. * Otherwise this is a normal data operation
  547. */
  548. cmpiclr,= 0x01,\tmp,%r0
  549. ldi (_PAGE_DIRTY|_PAGE_READ|_PAGE_WRITE),\prot
  550. .ifc \patype,20
  551. depd,z \prot,8,7,\prot
  552. .else
  553. .ifc \patype,11
  554. depw,z \prot,8,7,\prot
  555. .else
  556. .error "undefined PA type to do_alias"
  557. .endif
  558. .endif
  559. /*
  560. * OK, it is in the temp alias region, check whether "from" or "to".
  561. * Check "subtle" note in pacache.S re: r23/r26.
  562. */
  563. #ifdef CONFIG_64BIT
  564. extrd,u,*= \va,41,1,%r0
  565. #else
  566. extrw,u,= \va,9,1,%r0
  567. #endif
  568. or,COND(tr) %r23,%r0,\pte
  569. or %r26,%r0,\pte
  570. .endm
  571. /*
  572. * Fault_vectors are architecturally required to be aligned on a 2K
  573. * boundary
  574. */
  575. .section .text.hot
  576. .align 2048
  577. ENTRY(fault_vector_20)
  578. /* First vector is invalid (0) */
  579. .ascii "cows can fly"
  580. .byte 0
  581. .align 32
  582. hpmc 1
  583. def 2
  584. def 3
  585. extint 4
  586. def 5
  587. itlb_20 6
  588. def 7
  589. def 8
  590. def 9
  591. def 10
  592. def 11
  593. def 12
  594. def 13
  595. def 14
  596. dtlb_20 15
  597. naitlb_20 16
  598. nadtlb_20 17
  599. def 18
  600. def 19
  601. dbit_20 20
  602. def 21
  603. def 22
  604. def 23
  605. def 24
  606. def 25
  607. def 26
  608. def 27
  609. def 28
  610. def 29
  611. def 30
  612. def 31
  613. END(fault_vector_20)
  614. #ifndef CONFIG_64BIT
  615. .align 2048
  616. ENTRY(fault_vector_11)
  617. /* First vector is invalid (0) */
  618. .ascii "cows can fly"
  619. .byte 0
  620. .align 32
  621. hpmc 1
  622. def 2
  623. def 3
  624. extint 4
  625. def 5
  626. itlb_11 6
  627. def 7
  628. def 8
  629. def 9
  630. def 10
  631. def 11
  632. def 12
  633. def 13
  634. def 14
  635. dtlb_11 15
  636. naitlb_11 16
  637. nadtlb_11 17
  638. def 18
  639. def 19
  640. dbit_11 20
  641. def 21
  642. def 22
  643. def 23
  644. def 24
  645. def 25
  646. def 26
  647. def 27
  648. def 28
  649. def 29
  650. def 30
  651. def 31
  652. END(fault_vector_11)
  653. #endif
  654. /* Fault vector is separately protected and *must* be on its own page */
  655. .align PAGE_SIZE
  656. ENTRY(end_fault_vector)
  657. .import handle_interruption,code
  658. .import do_cpu_irq_mask,code
  659. /*
  660. * Child Returns here
  661. *
  662. * copy_thread moved args into task save area.
  663. */
  664. ENTRY_CFI(ret_from_kernel_thread)
  665. /* Call schedule_tail first though */
  666. BL schedule_tail, %r2
  667. nop
  668. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  669. LDREG TASK_PT_GR25(%r1), %r26
  670. #ifdef CONFIG_64BIT
  671. LDREG TASK_PT_GR27(%r1), %r27
  672. #endif
  673. LDREG TASK_PT_GR26(%r1), %r1
  674. ble 0(%sr7, %r1)
  675. copy %r31, %r2
  676. b finish_child_return
  677. nop
  678. ENDPROC_CFI(ret_from_kernel_thread)
  679. /*
  680. * struct task_struct *_switch_to(struct task_struct *prev,
  681. * struct task_struct *next)
  682. *
  683. * switch kernel stacks and return prev */
  684. ENTRY_CFI(_switch_to)
  685. STREG %r2, -RP_OFFSET(%r30)
  686. callee_save_float
  687. callee_save
  688. load32 _switch_to_ret, %r2
  689. STREG %r2, TASK_PT_KPC(%r26)
  690. LDREG TASK_PT_KPC(%r25), %r2
  691. STREG %r30, TASK_PT_KSP(%r26)
  692. LDREG TASK_PT_KSP(%r25), %r30
  693. LDREG TASK_THREAD_INFO(%r25), %r25
  694. bv %r0(%r2)
  695. mtctl %r25,%cr30
  696. _switch_to_ret:
  697. mtctl %r0, %cr0 /* Needed for single stepping */
  698. callee_rest
  699. callee_rest_float
  700. LDREG -RP_OFFSET(%r30), %r2
  701. bv %r0(%r2)
  702. copy %r26, %r28
  703. ENDPROC_CFI(_switch_to)
  704. /*
  705. * Common rfi return path for interruptions, kernel execve, and
  706. * sys_rt_sigreturn (sometimes). The sys_rt_sigreturn syscall will
  707. * return via this path if the signal was received when the process
  708. * was running; if the process was blocked on a syscall then the
  709. * normal syscall_exit path is used. All syscalls for traced
  710. * proceses exit via intr_restore.
  711. *
  712. * XXX If any syscalls that change a processes space id ever exit
  713. * this way, then we will need to copy %sr3 in to PT_SR[3..7], and
  714. * adjust IASQ[0..1].
  715. *
  716. */
  717. .align PAGE_SIZE
  718. ENTRY_CFI(syscall_exit_rfi)
  719. mfctl %cr30,%r16
  720. LDREG TI_TASK(%r16), %r16 /* thread_info -> task_struct */
  721. ldo TASK_REGS(%r16),%r16
  722. /* Force iaoq to userspace, as the user has had access to our current
  723. * context via sigcontext. Also Filter the PSW for the same reason.
  724. */
  725. LDREG PT_IAOQ0(%r16),%r19
  726. depi 3,31,2,%r19
  727. STREG %r19,PT_IAOQ0(%r16)
  728. LDREG PT_IAOQ1(%r16),%r19
  729. depi 3,31,2,%r19
  730. STREG %r19,PT_IAOQ1(%r16)
  731. LDREG PT_PSW(%r16),%r19
  732. load32 USER_PSW_MASK,%r1
  733. #ifdef CONFIG_64BIT
  734. load32 USER_PSW_HI_MASK,%r20
  735. depd %r20,31,32,%r1
  736. #endif
  737. and %r19,%r1,%r19 /* Mask out bits that user shouldn't play with */
  738. load32 USER_PSW,%r1
  739. or %r19,%r1,%r19 /* Make sure default USER_PSW bits are set */
  740. STREG %r19,PT_PSW(%r16)
  741. /*
  742. * If we aren't being traced, we never saved space registers
  743. * (we don't store them in the sigcontext), so set them
  744. * to "proper" values now (otherwise we'll wind up restoring
  745. * whatever was last stored in the task structure, which might
  746. * be inconsistent if an interrupt occurred while on the gateway
  747. * page). Note that we may be "trashing" values the user put in
  748. * them, but we don't support the user changing them.
  749. */
  750. STREG %r0,PT_SR2(%r16)
  751. mfsp %sr3,%r19
  752. STREG %r19,PT_SR0(%r16)
  753. STREG %r19,PT_SR1(%r16)
  754. STREG %r19,PT_SR3(%r16)
  755. STREG %r19,PT_SR4(%r16)
  756. STREG %r19,PT_SR5(%r16)
  757. STREG %r19,PT_SR6(%r16)
  758. STREG %r19,PT_SR7(%r16)
  759. intr_return:
  760. /* NOTE: Need to enable interrupts incase we schedule. */
  761. ssm PSW_SM_I, %r0
  762. /* check for reschedule */
  763. mfctl %cr30,%r1
  764. LDREG TI_FLAGS(%r1),%r19 /* sched.h: TIF_NEED_RESCHED */
  765. bb,<,n %r19,31-TIF_NEED_RESCHED,intr_do_resched /* forward */
  766. .import do_notify_resume,code
  767. intr_check_sig:
  768. /* As above */
  769. mfctl %cr30,%r1
  770. LDREG TI_FLAGS(%r1),%r19
  771. ldi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), %r20
  772. and,COND(<>) %r19, %r20, %r0
  773. b,n intr_restore /* skip past if we've nothing to do */
  774. /* This check is critical to having LWS
  775. * working. The IASQ is zero on the gateway
  776. * page and we cannot deliver any signals until
  777. * we get off the gateway page.
  778. *
  779. * Only do signals if we are returning to user space
  780. */
  781. LDREG PT_IASQ0(%r16), %r20
  782. cmpib,COND(=),n 0,%r20,intr_restore /* backward */
  783. LDREG PT_IASQ1(%r16), %r20
  784. cmpib,COND(=),n 0,%r20,intr_restore /* backward */
  785. copy %r0, %r25 /* long in_syscall = 0 */
  786. #ifdef CONFIG_64BIT
  787. ldo -16(%r30),%r29 /* Reference param save area */
  788. #endif
  789. BL do_notify_resume,%r2
  790. copy %r16, %r26 /* struct pt_regs *regs */
  791. b,n intr_check_sig
  792. intr_restore:
  793. copy %r16,%r29
  794. ldo PT_FR31(%r29),%r1
  795. rest_fp %r1
  796. rest_general %r29
  797. /* inverse of virt_map */
  798. pcxt_ssm_bug
  799. rsm PSW_SM_QUIET,%r0 /* prepare for rfi */
  800. tophys_r1 %r29
  801. /* Restore space id's and special cr's from PT_REGS
  802. * structure pointed to by r29
  803. */
  804. rest_specials %r29
  805. /* IMPORTANT: rest_stack restores r29 last (we are using it)!
  806. * It also restores r1 and r30.
  807. */
  808. rest_stack
  809. rfi
  810. nop
  811. #ifndef CONFIG_PREEMPT
  812. # define intr_do_preempt intr_restore
  813. #endif /* !CONFIG_PREEMPT */
  814. .import schedule,code
  815. intr_do_resched:
  816. /* Only call schedule on return to userspace. If we're returning
  817. * to kernel space, we may schedule if CONFIG_PREEMPT, otherwise
  818. * we jump back to intr_restore.
  819. */
  820. LDREG PT_IASQ0(%r16), %r20
  821. cmpib,COND(=) 0, %r20, intr_do_preempt
  822. nop
  823. LDREG PT_IASQ1(%r16), %r20
  824. cmpib,COND(=) 0, %r20, intr_do_preempt
  825. nop
  826. #ifdef CONFIG_64BIT
  827. ldo -16(%r30),%r29 /* Reference param save area */
  828. #endif
  829. ldil L%intr_check_sig, %r2
  830. #ifndef CONFIG_64BIT
  831. b schedule
  832. #else
  833. load32 schedule, %r20
  834. bv %r0(%r20)
  835. #endif
  836. ldo R%intr_check_sig(%r2), %r2
  837. /* preempt the current task on returning to kernel
  838. * mode from an interrupt, iff need_resched is set,
  839. * and preempt_count is 0. otherwise, we continue on
  840. * our merry way back to the current running task.
  841. */
  842. #ifdef CONFIG_PREEMPT
  843. .import preempt_schedule_irq,code
  844. intr_do_preempt:
  845. rsm PSW_SM_I, %r0 /* disable interrupts */
  846. /* current_thread_info()->preempt_count */
  847. mfctl %cr30, %r1
  848. LDREG TI_PRE_COUNT(%r1), %r19
  849. cmpib,COND(<>) 0, %r19, intr_restore /* if preempt_count > 0 */
  850. nop /* prev insn branched backwards */
  851. /* check if we interrupted a critical path */
  852. LDREG PT_PSW(%r16), %r20
  853. bb,<,n %r20, 31 - PSW_SM_I, intr_restore
  854. nop
  855. BL preempt_schedule_irq, %r2
  856. nop
  857. b,n intr_restore /* ssm PSW_SM_I done by intr_restore */
  858. #endif /* CONFIG_PREEMPT */
  859. /*
  860. * External interrupts.
  861. */
  862. intr_extint:
  863. cmpib,COND(=),n 0,%r16,1f
  864. get_stack_use_cr30
  865. b,n 2f
  866. 1:
  867. get_stack_use_r30
  868. 2:
  869. save_specials %r29
  870. virt_map
  871. save_general %r29
  872. ldo PT_FR0(%r29), %r24
  873. save_fp %r24
  874. loadgp
  875. copy %r29, %r26 /* arg0 is pt_regs */
  876. copy %r29, %r16 /* save pt_regs */
  877. ldil L%intr_return, %r2
  878. #ifdef CONFIG_64BIT
  879. ldo -16(%r30),%r29 /* Reference param save area */
  880. #endif
  881. b do_cpu_irq_mask
  882. ldo R%intr_return(%r2), %r2 /* return to intr_return, not here */
  883. ENDPROC_CFI(syscall_exit_rfi)
  884. /* Generic interruptions (illegal insn, unaligned, page fault, etc) */
  885. ENTRY_CFI(intr_save) /* for os_hpmc */
  886. mfsp %sr7,%r16
  887. cmpib,COND(=),n 0,%r16,1f
  888. get_stack_use_cr30
  889. b 2f
  890. copy %r8,%r26
  891. 1:
  892. get_stack_use_r30
  893. copy %r8,%r26
  894. 2:
  895. save_specials %r29
  896. /* If this trap is a itlb miss, skip saving/adjusting isr/ior */
  897. /*
  898. * FIXME: 1) Use a #define for the hardwired "6" below (and in
  899. * traps.c.
  900. * 2) Once we start executing code above 4 Gb, we need
  901. * to adjust iasq/iaoq here in the same way we
  902. * adjust isr/ior below.
  903. */
  904. cmpib,COND(=),n 6,%r26,skip_save_ior
  905. mfctl %cr20, %r16 /* isr */
  906. nop /* serialize mfctl on PA 2.0 to avoid 4 cycle penalty */
  907. mfctl %cr21, %r17 /* ior */
  908. #ifdef CONFIG_64BIT
  909. /*
  910. * If the interrupted code was running with W bit off (32 bit),
  911. * clear the b bits (bits 0 & 1) in the ior.
  912. * save_specials left ipsw value in r8 for us to test.
  913. */
  914. extrd,u,*<> %r8,PSW_W_BIT,1,%r0
  915. depdi 0,1,2,%r17
  916. /*
  917. * FIXME: This code has hardwired assumptions about the split
  918. * between space bits and offset bits. This will change
  919. * when we allow alternate page sizes.
  920. */
  921. /* adjust isr/ior. */
  922. extrd,u %r16,63,SPACEID_SHIFT,%r1 /* get high bits from isr for ior */
  923. depd %r1,31,SPACEID_SHIFT,%r17 /* deposit them into ior */
  924. depdi 0,63,SPACEID_SHIFT,%r16 /* clear them from isr */
  925. #endif
  926. STREG %r16, PT_ISR(%r29)
  927. STREG %r17, PT_IOR(%r29)
  928. skip_save_ior:
  929. virt_map
  930. save_general %r29
  931. ldo PT_FR0(%r29), %r25
  932. save_fp %r25
  933. loadgp
  934. copy %r29, %r25 /* arg1 is pt_regs */
  935. #ifdef CONFIG_64BIT
  936. ldo -16(%r30),%r29 /* Reference param save area */
  937. #endif
  938. ldil L%intr_check_sig, %r2
  939. copy %r25, %r16 /* save pt_regs */
  940. b handle_interruption
  941. ldo R%intr_check_sig(%r2), %r2
  942. ENDPROC_CFI(intr_save)
  943. /*
  944. * Note for all tlb miss handlers:
  945. *
  946. * cr24 contains a pointer to the kernel address space
  947. * page directory.
  948. *
  949. * cr25 contains a pointer to the current user address
  950. * space page directory.
  951. *
  952. * sr3 will contain the space id of the user address space
  953. * of the current running thread while that thread is
  954. * running in the kernel.
  955. */
  956. /*
  957. * register number allocations. Note that these are all
  958. * in the shadowed registers
  959. */
  960. t0 = r1 /* temporary register 0 */
  961. va = r8 /* virtual address for which the trap occurred */
  962. t1 = r9 /* temporary register 1 */
  963. pte = r16 /* pte/phys page # */
  964. prot = r17 /* prot bits */
  965. spc = r24 /* space for which the trap occurred */
  966. ptp = r25 /* page directory/page table pointer */
  967. #ifdef CONFIG_64BIT
  968. dtlb_miss_20w:
  969. space_adjust spc,va,t0
  970. get_pgd spc,ptp
  971. space_check spc,t0,dtlb_fault
  972. L3_ptep ptp,pte,t0,va,dtlb_check_alias_20w
  973. tlb_lock spc,ptp,pte,t0,t1,dtlb_check_alias_20w
  974. update_accessed ptp,pte,t0,t1
  975. make_insert_tlb spc,pte,prot,t1
  976. idtlbt pte,prot
  977. tlb_unlock1 spc,t0
  978. rfir
  979. nop
  980. dtlb_check_alias_20w:
  981. do_alias spc,t0,t1,va,pte,prot,dtlb_fault,20
  982. idtlbt pte,prot
  983. rfir
  984. nop
  985. nadtlb_miss_20w:
  986. space_adjust spc,va,t0
  987. get_pgd spc,ptp
  988. space_check spc,t0,nadtlb_fault
  989. L3_ptep ptp,pte,t0,va,nadtlb_check_alias_20w
  990. tlb_lock spc,ptp,pte,t0,t1,nadtlb_check_alias_20w
  991. update_accessed ptp,pte,t0,t1
  992. make_insert_tlb spc,pte,prot,t1
  993. idtlbt pte,prot
  994. tlb_unlock1 spc,t0
  995. rfir
  996. nop
  997. nadtlb_check_alias_20w:
  998. do_alias spc,t0,t1,va,pte,prot,nadtlb_emulate,20
  999. idtlbt pte,prot
  1000. rfir
  1001. nop
  1002. #else
  1003. dtlb_miss_11:
  1004. get_pgd spc,ptp
  1005. space_check spc,t0,dtlb_fault
  1006. L2_ptep ptp,pte,t0,va,dtlb_check_alias_11
  1007. tlb_lock spc,ptp,pte,t0,t1,dtlb_check_alias_11
  1008. update_accessed ptp,pte,t0,t1
  1009. make_insert_tlb_11 spc,pte,prot
  1010. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1011. mtsp spc,%sr1
  1012. idtlba pte,(%sr1,va)
  1013. idtlbp prot,(%sr1,va)
  1014. mtsp t1, %sr1 /* Restore sr1 */
  1015. tlb_unlock1 spc,t0
  1016. rfir
  1017. nop
  1018. dtlb_check_alias_11:
  1019. do_alias spc,t0,t1,va,pte,prot,dtlb_fault,11
  1020. idtlba pte,(va)
  1021. idtlbp prot,(va)
  1022. rfir
  1023. nop
  1024. nadtlb_miss_11:
  1025. get_pgd spc,ptp
  1026. space_check spc,t0,nadtlb_fault
  1027. L2_ptep ptp,pte,t0,va,nadtlb_check_alias_11
  1028. tlb_lock spc,ptp,pte,t0,t1,nadtlb_check_alias_11
  1029. update_accessed ptp,pte,t0,t1
  1030. make_insert_tlb_11 spc,pte,prot
  1031. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1032. mtsp spc,%sr1
  1033. idtlba pte,(%sr1,va)
  1034. idtlbp prot,(%sr1,va)
  1035. mtsp t1, %sr1 /* Restore sr1 */
  1036. tlb_unlock1 spc,t0
  1037. rfir
  1038. nop
  1039. nadtlb_check_alias_11:
  1040. do_alias spc,t0,t1,va,pte,prot,nadtlb_emulate,11
  1041. idtlba pte,(va)
  1042. idtlbp prot,(va)
  1043. rfir
  1044. nop
  1045. dtlb_miss_20:
  1046. space_adjust spc,va,t0
  1047. get_pgd spc,ptp
  1048. space_check spc,t0,dtlb_fault
  1049. L2_ptep ptp,pte,t0,va,dtlb_check_alias_20
  1050. tlb_lock spc,ptp,pte,t0,t1,dtlb_check_alias_20
  1051. update_accessed ptp,pte,t0,t1
  1052. make_insert_tlb spc,pte,prot,t1
  1053. f_extend pte,t1
  1054. idtlbt pte,prot
  1055. tlb_unlock1 spc,t0
  1056. rfir
  1057. nop
  1058. dtlb_check_alias_20:
  1059. do_alias spc,t0,t1,va,pte,prot,dtlb_fault,20
  1060. idtlbt pte,prot
  1061. rfir
  1062. nop
  1063. nadtlb_miss_20:
  1064. get_pgd spc,ptp
  1065. space_check spc,t0,nadtlb_fault
  1066. L2_ptep ptp,pte,t0,va,nadtlb_check_alias_20
  1067. tlb_lock spc,ptp,pte,t0,t1,nadtlb_check_alias_20
  1068. update_accessed ptp,pte,t0,t1
  1069. make_insert_tlb spc,pte,prot,t1
  1070. f_extend pte,t1
  1071. idtlbt pte,prot
  1072. tlb_unlock1 spc,t0
  1073. rfir
  1074. nop
  1075. nadtlb_check_alias_20:
  1076. do_alias spc,t0,t1,va,pte,prot,nadtlb_emulate,20
  1077. idtlbt pte,prot
  1078. rfir
  1079. nop
  1080. #endif
  1081. nadtlb_emulate:
  1082. /*
  1083. * Non access misses can be caused by fdc,fic,pdc,lpa,probe and
  1084. * probei instructions. We don't want to fault for these
  1085. * instructions (not only does it not make sense, it can cause
  1086. * deadlocks, since some flushes are done with the mmap
  1087. * semaphore held). If the translation doesn't exist, we can't
  1088. * insert a translation, so have to emulate the side effects
  1089. * of the instruction. Since we don't insert a translation
  1090. * we can get a lot of faults during a flush loop, so it makes
  1091. * sense to try to do it here with minimum overhead. We only
  1092. * emulate fdc,fic,pdc,probew,prober instructions whose base
  1093. * and index registers are not shadowed. We defer everything
  1094. * else to the "slow" path.
  1095. */
  1096. mfctl %cr19,%r9 /* Get iir */
  1097. /* PA 2.0 Arch Ref. Book pg 382 has a good description of the insn bits.
  1098. Checks for fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw */
  1099. /* Checks for fdc,fdce,pdc,"fic,4f" only */
  1100. ldi 0x280,%r16
  1101. and %r9,%r16,%r17
  1102. cmpb,<>,n %r16,%r17,nadtlb_probe_check
  1103. bb,>=,n %r9,26,nadtlb_nullify /* m bit not set, just nullify */
  1104. BL get_register,%r25
  1105. extrw,u %r9,15,5,%r8 /* Get index register # */
  1106. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1107. copy %r1,%r24
  1108. BL get_register,%r25
  1109. extrw,u %r9,10,5,%r8 /* Get base register # */
  1110. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1111. BL set_register,%r25
  1112. add,l %r1,%r24,%r1 /* doesn't affect c/b bits */
  1113. nadtlb_nullify:
  1114. mfctl %ipsw,%r8
  1115. ldil L%PSW_N,%r9
  1116. or %r8,%r9,%r8 /* Set PSW_N */
  1117. mtctl %r8,%ipsw
  1118. rfir
  1119. nop
  1120. /*
  1121. When there is no translation for the probe address then we
  1122. must nullify the insn and return zero in the target regsiter.
  1123. This will indicate to the calling code that it does not have
  1124. write/read privileges to this address.
  1125. This should technically work for prober and probew in PA 1.1,
  1126. and also probe,r and probe,w in PA 2.0
  1127. WARNING: USE ONLY NON-SHADOW REGISTERS WITH PROBE INSN!
  1128. THE SLOW-PATH EMULATION HAS NOT BEEN WRITTEN YET.
  1129. */
  1130. nadtlb_probe_check:
  1131. ldi 0x80,%r16
  1132. and %r9,%r16,%r17
  1133. cmpb,<>,n %r16,%r17,nadtlb_fault /* Must be probe,[rw]*/
  1134. BL get_register,%r25 /* Find the target register */
  1135. extrw,u %r9,31,5,%r8 /* Get target register */
  1136. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1137. BL set_register,%r25
  1138. copy %r0,%r1 /* Write zero to target register */
  1139. b nadtlb_nullify /* Nullify return insn */
  1140. nop
  1141. #ifdef CONFIG_64BIT
  1142. itlb_miss_20w:
  1143. /*
  1144. * I miss is a little different, since we allow users to fault
  1145. * on the gateway page which is in the kernel address space.
  1146. */
  1147. space_adjust spc,va,t0
  1148. get_pgd spc,ptp
  1149. space_check spc,t0,itlb_fault
  1150. L3_ptep ptp,pte,t0,va,itlb_fault
  1151. tlb_lock spc,ptp,pte,t0,t1,itlb_fault
  1152. update_accessed ptp,pte,t0,t1
  1153. make_insert_tlb spc,pte,prot,t1
  1154. iitlbt pte,prot
  1155. tlb_unlock1 spc,t0
  1156. rfir
  1157. nop
  1158. naitlb_miss_20w:
  1159. /*
  1160. * I miss is a little different, since we allow users to fault
  1161. * on the gateway page which is in the kernel address space.
  1162. */
  1163. space_adjust spc,va,t0
  1164. get_pgd spc,ptp
  1165. space_check spc,t0,naitlb_fault
  1166. L3_ptep ptp,pte,t0,va,naitlb_check_alias_20w
  1167. tlb_lock spc,ptp,pte,t0,t1,naitlb_check_alias_20w
  1168. update_accessed ptp,pte,t0,t1
  1169. make_insert_tlb spc,pte,prot,t1
  1170. iitlbt pte,prot
  1171. tlb_unlock1 spc,t0
  1172. rfir
  1173. nop
  1174. naitlb_check_alias_20w:
  1175. do_alias spc,t0,t1,va,pte,prot,naitlb_fault,20
  1176. iitlbt pte,prot
  1177. rfir
  1178. nop
  1179. #else
  1180. itlb_miss_11:
  1181. get_pgd spc,ptp
  1182. space_check spc,t0,itlb_fault
  1183. L2_ptep ptp,pte,t0,va,itlb_fault
  1184. tlb_lock spc,ptp,pte,t0,t1,itlb_fault
  1185. update_accessed ptp,pte,t0,t1
  1186. make_insert_tlb_11 spc,pte,prot
  1187. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1188. mtsp spc,%sr1
  1189. iitlba pte,(%sr1,va)
  1190. iitlbp prot,(%sr1,va)
  1191. mtsp t1, %sr1 /* Restore sr1 */
  1192. tlb_unlock1 spc,t0
  1193. rfir
  1194. nop
  1195. naitlb_miss_11:
  1196. get_pgd spc,ptp
  1197. space_check spc,t0,naitlb_fault
  1198. L2_ptep ptp,pte,t0,va,naitlb_check_alias_11
  1199. tlb_lock spc,ptp,pte,t0,t1,naitlb_check_alias_11
  1200. update_accessed ptp,pte,t0,t1
  1201. make_insert_tlb_11 spc,pte,prot
  1202. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1203. mtsp spc,%sr1
  1204. iitlba pte,(%sr1,va)
  1205. iitlbp prot,(%sr1,va)
  1206. mtsp t1, %sr1 /* Restore sr1 */
  1207. tlb_unlock1 spc,t0
  1208. rfir
  1209. nop
  1210. naitlb_check_alias_11:
  1211. do_alias spc,t0,t1,va,pte,prot,itlb_fault,11
  1212. iitlba pte,(%sr0, va)
  1213. iitlbp prot,(%sr0, va)
  1214. rfir
  1215. nop
  1216. itlb_miss_20:
  1217. get_pgd spc,ptp
  1218. space_check spc,t0,itlb_fault
  1219. L2_ptep ptp,pte,t0,va,itlb_fault
  1220. tlb_lock spc,ptp,pte,t0,t1,itlb_fault
  1221. update_accessed ptp,pte,t0,t1
  1222. make_insert_tlb spc,pte,prot,t1
  1223. f_extend pte,t1
  1224. iitlbt pte,prot
  1225. tlb_unlock1 spc,t0
  1226. rfir
  1227. nop
  1228. naitlb_miss_20:
  1229. get_pgd spc,ptp
  1230. space_check spc,t0,naitlb_fault
  1231. L2_ptep ptp,pte,t0,va,naitlb_check_alias_20
  1232. tlb_lock spc,ptp,pte,t0,t1,naitlb_check_alias_20
  1233. update_accessed ptp,pte,t0,t1
  1234. make_insert_tlb spc,pte,prot,t1
  1235. f_extend pte,t1
  1236. iitlbt pte,prot
  1237. tlb_unlock1 spc,t0
  1238. rfir
  1239. nop
  1240. naitlb_check_alias_20:
  1241. do_alias spc,t0,t1,va,pte,prot,naitlb_fault,20
  1242. iitlbt pte,prot
  1243. rfir
  1244. nop
  1245. #endif
  1246. #ifdef CONFIG_64BIT
  1247. dbit_trap_20w:
  1248. space_adjust spc,va,t0
  1249. get_pgd spc,ptp
  1250. space_check spc,t0,dbit_fault
  1251. L3_ptep ptp,pte,t0,va,dbit_fault
  1252. tlb_lock spc,ptp,pte,t0,t1,dbit_fault
  1253. update_dirty ptp,pte,t1
  1254. make_insert_tlb spc,pte,prot,t1
  1255. idtlbt pte,prot
  1256. tlb_unlock0 spc,t0
  1257. rfir
  1258. nop
  1259. #else
  1260. dbit_trap_11:
  1261. get_pgd spc,ptp
  1262. space_check spc,t0,dbit_fault
  1263. L2_ptep ptp,pte,t0,va,dbit_fault
  1264. tlb_lock spc,ptp,pte,t0,t1,dbit_fault
  1265. update_dirty ptp,pte,t1
  1266. make_insert_tlb_11 spc,pte,prot
  1267. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1268. mtsp spc,%sr1
  1269. idtlba pte,(%sr1,va)
  1270. idtlbp prot,(%sr1,va)
  1271. mtsp t1, %sr1 /* Restore sr1 */
  1272. tlb_unlock0 spc,t0
  1273. rfir
  1274. nop
  1275. dbit_trap_20:
  1276. get_pgd spc,ptp
  1277. space_check spc,t0,dbit_fault
  1278. L2_ptep ptp,pte,t0,va,dbit_fault
  1279. tlb_lock spc,ptp,pte,t0,t1,dbit_fault
  1280. update_dirty ptp,pte,t1
  1281. make_insert_tlb spc,pte,prot,t1
  1282. f_extend pte,t1
  1283. idtlbt pte,prot
  1284. tlb_unlock0 spc,t0
  1285. rfir
  1286. nop
  1287. #endif
  1288. .import handle_interruption,code
  1289. kernel_bad_space:
  1290. b intr_save
  1291. ldi 31,%r8 /* Use an unused code */
  1292. dbit_fault:
  1293. b intr_save
  1294. ldi 20,%r8
  1295. itlb_fault:
  1296. b intr_save
  1297. ldi 6,%r8
  1298. nadtlb_fault:
  1299. b intr_save
  1300. ldi 17,%r8
  1301. naitlb_fault:
  1302. b intr_save
  1303. ldi 16,%r8
  1304. dtlb_fault:
  1305. b intr_save
  1306. ldi 15,%r8
  1307. /* Register saving semantics for system calls:
  1308. %r1 clobbered by system call macro in userspace
  1309. %r2 saved in PT_REGS by gateway page
  1310. %r3 - %r18 preserved by C code (saved by signal code)
  1311. %r19 - %r20 saved in PT_REGS by gateway page
  1312. %r21 - %r22 non-standard syscall args
  1313. stored in kernel stack by gateway page
  1314. %r23 - %r26 arg3-arg0, saved in PT_REGS by gateway page
  1315. %r27 - %r30 saved in PT_REGS by gateway page
  1316. %r31 syscall return pointer
  1317. */
  1318. /* Floating point registers (FIXME: what do we do with these?)
  1319. %fr0 - %fr3 status/exception, not preserved
  1320. %fr4 - %fr7 arguments
  1321. %fr8 - %fr11 not preserved by C code
  1322. %fr12 - %fr21 preserved by C code
  1323. %fr22 - %fr31 not preserved by C code
  1324. */
  1325. .macro reg_save regs
  1326. STREG %r3, PT_GR3(\regs)
  1327. STREG %r4, PT_GR4(\regs)
  1328. STREG %r5, PT_GR5(\regs)
  1329. STREG %r6, PT_GR6(\regs)
  1330. STREG %r7, PT_GR7(\regs)
  1331. STREG %r8, PT_GR8(\regs)
  1332. STREG %r9, PT_GR9(\regs)
  1333. STREG %r10,PT_GR10(\regs)
  1334. STREG %r11,PT_GR11(\regs)
  1335. STREG %r12,PT_GR12(\regs)
  1336. STREG %r13,PT_GR13(\regs)
  1337. STREG %r14,PT_GR14(\regs)
  1338. STREG %r15,PT_GR15(\regs)
  1339. STREG %r16,PT_GR16(\regs)
  1340. STREG %r17,PT_GR17(\regs)
  1341. STREG %r18,PT_GR18(\regs)
  1342. .endm
  1343. .macro reg_restore regs
  1344. LDREG PT_GR3(\regs), %r3
  1345. LDREG PT_GR4(\regs), %r4
  1346. LDREG PT_GR5(\regs), %r5
  1347. LDREG PT_GR6(\regs), %r6
  1348. LDREG PT_GR7(\regs), %r7
  1349. LDREG PT_GR8(\regs), %r8
  1350. LDREG PT_GR9(\regs), %r9
  1351. LDREG PT_GR10(\regs),%r10
  1352. LDREG PT_GR11(\regs),%r11
  1353. LDREG PT_GR12(\regs),%r12
  1354. LDREG PT_GR13(\regs),%r13
  1355. LDREG PT_GR14(\regs),%r14
  1356. LDREG PT_GR15(\regs),%r15
  1357. LDREG PT_GR16(\regs),%r16
  1358. LDREG PT_GR17(\regs),%r17
  1359. LDREG PT_GR18(\regs),%r18
  1360. .endm
  1361. .macro fork_like name
  1362. ENTRY_CFI(sys_\name\()_wrapper)
  1363. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  1364. ldo TASK_REGS(%r1),%r1
  1365. reg_save %r1
  1366. mfctl %cr27, %r28
  1367. ldil L%sys_\name, %r31
  1368. be R%sys_\name(%sr4,%r31)
  1369. STREG %r28, PT_CR27(%r1)
  1370. ENDPROC_CFI(sys_\name\()_wrapper)
  1371. .endm
  1372. fork_like clone
  1373. fork_like fork
  1374. fork_like vfork
  1375. /* Set the return value for the child */
  1376. ENTRY_CFI(child_return)
  1377. BL schedule_tail, %r2
  1378. nop
  1379. finish_child_return:
  1380. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  1381. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1382. LDREG PT_CR27(%r1), %r3
  1383. mtctl %r3, %cr27
  1384. reg_restore %r1
  1385. b syscall_exit
  1386. copy %r0,%r28
  1387. ENDPROC_CFI(child_return)
  1388. ENTRY_CFI(sys_rt_sigreturn_wrapper)
  1389. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r26
  1390. ldo TASK_REGS(%r26),%r26 /* get pt regs */
  1391. /* Don't save regs, we are going to restore them from sigcontext. */
  1392. STREG %r2, -RP_OFFSET(%r30)
  1393. #ifdef CONFIG_64BIT
  1394. ldo FRAME_SIZE(%r30), %r30
  1395. BL sys_rt_sigreturn,%r2
  1396. ldo -16(%r30),%r29 /* Reference param save area */
  1397. #else
  1398. BL sys_rt_sigreturn,%r2
  1399. ldo FRAME_SIZE(%r30), %r30
  1400. #endif
  1401. ldo -FRAME_SIZE(%r30), %r30
  1402. LDREG -RP_OFFSET(%r30), %r2
  1403. /* FIXME: I think we need to restore a few more things here. */
  1404. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1405. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1406. reg_restore %r1
  1407. /* If the signal was received while the process was blocked on a
  1408. * syscall, then r2 will take us to syscall_exit; otherwise r2 will
  1409. * take us to syscall_exit_rfi and on to intr_return.
  1410. */
  1411. bv %r0(%r2)
  1412. LDREG PT_GR28(%r1),%r28 /* reload original r28 for syscall_exit */
  1413. ENDPROC_CFI(sys_rt_sigreturn_wrapper)
  1414. ENTRY_CFI(syscall_exit)
  1415. /* NOTE: Not all syscalls exit this way. rt_sigreturn will exit
  1416. * via syscall_exit_rfi if the signal was received while the process
  1417. * was running.
  1418. */
  1419. /* save return value now */
  1420. mfctl %cr30, %r1
  1421. LDREG TI_TASK(%r1),%r1
  1422. STREG %r28,TASK_PT_GR28(%r1)
  1423. /* Seems to me that dp could be wrong here, if the syscall involved
  1424. * calling a module, and nothing got round to restoring dp on return.
  1425. */
  1426. loadgp
  1427. syscall_check_resched:
  1428. /* check for reschedule */
  1429. LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19 /* long */
  1430. bb,<,n %r19, 31-TIF_NEED_RESCHED, syscall_do_resched /* forward */
  1431. .import do_signal,code
  1432. syscall_check_sig:
  1433. LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19
  1434. ldi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), %r26
  1435. and,COND(<>) %r19, %r26, %r0
  1436. b,n syscall_restore /* skip past if we've nothing to do */
  1437. syscall_do_signal:
  1438. /* Save callee-save registers (for sigcontext).
  1439. * FIXME: After this point the process structure should be
  1440. * consistent with all the relevant state of the process
  1441. * before the syscall. We need to verify this.
  1442. */
  1443. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1444. ldo TASK_REGS(%r1), %r26 /* struct pt_regs *regs */
  1445. reg_save %r26
  1446. #ifdef CONFIG_64BIT
  1447. ldo -16(%r30),%r29 /* Reference param save area */
  1448. #endif
  1449. BL do_notify_resume,%r2
  1450. ldi 1, %r25 /* long in_syscall = 1 */
  1451. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1452. ldo TASK_REGS(%r1), %r20 /* reload pt_regs */
  1453. reg_restore %r20
  1454. b,n syscall_check_sig
  1455. syscall_restore:
  1456. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1457. /* Are we being ptraced? */
  1458. ldw TASK_FLAGS(%r1),%r19
  1459. ldi _TIF_SYSCALL_TRACE_MASK,%r2
  1460. and,COND(=) %r19,%r2,%r0
  1461. b,n syscall_restore_rfi
  1462. ldo TASK_PT_FR31(%r1),%r19 /* reload fpregs */
  1463. rest_fp %r19
  1464. LDREG TASK_PT_SAR(%r1),%r19 /* restore SAR */
  1465. mtsar %r19
  1466. LDREG TASK_PT_GR2(%r1),%r2 /* restore user rp */
  1467. LDREG TASK_PT_GR19(%r1),%r19
  1468. LDREG TASK_PT_GR20(%r1),%r20
  1469. LDREG TASK_PT_GR21(%r1),%r21
  1470. LDREG TASK_PT_GR22(%r1),%r22
  1471. LDREG TASK_PT_GR23(%r1),%r23
  1472. LDREG TASK_PT_GR24(%r1),%r24
  1473. LDREG TASK_PT_GR25(%r1),%r25
  1474. LDREG TASK_PT_GR26(%r1),%r26
  1475. LDREG TASK_PT_GR27(%r1),%r27 /* restore user dp */
  1476. LDREG TASK_PT_GR28(%r1),%r28 /* syscall return value */
  1477. LDREG TASK_PT_GR29(%r1),%r29
  1478. LDREG TASK_PT_GR31(%r1),%r31 /* restore syscall rp */
  1479. /* NOTE: We use rsm/ssm pair to make this operation atomic */
  1480. LDREG TASK_PT_GR30(%r1),%r1 /* Get user sp */
  1481. rsm PSW_SM_I, %r0
  1482. copy %r1,%r30 /* Restore user sp */
  1483. mfsp %sr3,%r1 /* Get user space id */
  1484. mtsp %r1,%sr7 /* Restore sr7 */
  1485. ssm PSW_SM_I, %r0
  1486. /* Set sr2 to zero for userspace syscalls to work. */
  1487. mtsp %r0,%sr2
  1488. mtsp %r1,%sr4 /* Restore sr4 */
  1489. mtsp %r1,%sr5 /* Restore sr5 */
  1490. mtsp %r1,%sr6 /* Restore sr6 */
  1491. depi 3,31,2,%r31 /* ensure return to user mode. */
  1492. #ifdef CONFIG_64BIT
  1493. /* decide whether to reset the wide mode bit
  1494. *
  1495. * For a syscall, the W bit is stored in the lowest bit
  1496. * of sp. Extract it and reset W if it is zero */
  1497. extrd,u,*<> %r30,63,1,%r1
  1498. rsm PSW_SM_W, %r0
  1499. /* now reset the lowest bit of sp if it was set */
  1500. xor %r30,%r1,%r30
  1501. #endif
  1502. be,n 0(%sr3,%r31) /* return to user space */
  1503. /* We have to return via an RFI, so that PSW T and R bits can be set
  1504. * appropriately.
  1505. * This sets up pt_regs so we can return via intr_restore, which is not
  1506. * the most efficient way of doing things, but it works.
  1507. */
  1508. syscall_restore_rfi:
  1509. ldo -1(%r0),%r2 /* Set recovery cntr to -1 */
  1510. mtctl %r2,%cr0 /* for immediate trap */
  1511. LDREG TASK_PT_PSW(%r1),%r2 /* Get old PSW */
  1512. ldi 0x0b,%r20 /* Create new PSW */
  1513. depi -1,13,1,%r20 /* C, Q, D, and I bits */
  1514. /* The values of SINGLESTEP_BIT and BLOCKSTEP_BIT are
  1515. * set in thread_info.h and converted to PA bitmap
  1516. * numbers in asm-offsets.c */
  1517. /* if ((%r19.SINGLESTEP_BIT)) { %r20.27=1} */
  1518. extru,= %r19,TIF_SINGLESTEP_PA_BIT,1,%r0
  1519. depi -1,27,1,%r20 /* R bit */
  1520. /* if ((%r19.BLOCKSTEP_BIT)) { %r20.7=1} */
  1521. extru,= %r19,TIF_BLOCKSTEP_PA_BIT,1,%r0
  1522. depi -1,7,1,%r20 /* T bit */
  1523. STREG %r20,TASK_PT_PSW(%r1)
  1524. /* Always store space registers, since sr3 can be changed (e.g. fork) */
  1525. mfsp %sr3,%r25
  1526. STREG %r25,TASK_PT_SR3(%r1)
  1527. STREG %r25,TASK_PT_SR4(%r1)
  1528. STREG %r25,TASK_PT_SR5(%r1)
  1529. STREG %r25,TASK_PT_SR6(%r1)
  1530. STREG %r25,TASK_PT_SR7(%r1)
  1531. STREG %r25,TASK_PT_IASQ0(%r1)
  1532. STREG %r25,TASK_PT_IASQ1(%r1)
  1533. /* XXX W bit??? */
  1534. /* Now if old D bit is clear, it means we didn't save all registers
  1535. * on syscall entry, so do that now. This only happens on TRACEME
  1536. * calls, or if someone attached to us while we were on a syscall.
  1537. * We could make this more efficient by not saving r3-r18, but
  1538. * then we wouldn't be able to use the common intr_restore path.
  1539. * It is only for traced processes anyway, so performance is not
  1540. * an issue.
  1541. */
  1542. bb,< %r2,30,pt_regs_ok /* Branch if D set */
  1543. ldo TASK_REGS(%r1),%r25
  1544. reg_save %r25 /* Save r3 to r18 */
  1545. /* Save the current sr */
  1546. mfsp %sr0,%r2
  1547. STREG %r2,TASK_PT_SR0(%r1)
  1548. /* Save the scratch sr */
  1549. mfsp %sr1,%r2
  1550. STREG %r2,TASK_PT_SR1(%r1)
  1551. /* sr2 should be set to zero for userspace syscalls */
  1552. STREG %r0,TASK_PT_SR2(%r1)
  1553. LDREG TASK_PT_GR31(%r1),%r2
  1554. depi 3,31,2,%r2 /* ensure return to user mode. */
  1555. STREG %r2,TASK_PT_IAOQ0(%r1)
  1556. ldo 4(%r2),%r2
  1557. STREG %r2,TASK_PT_IAOQ1(%r1)
  1558. b intr_restore
  1559. copy %r25,%r16
  1560. pt_regs_ok:
  1561. LDREG TASK_PT_IAOQ0(%r1),%r2
  1562. depi 3,31,2,%r2 /* ensure return to user mode. */
  1563. STREG %r2,TASK_PT_IAOQ0(%r1)
  1564. LDREG TASK_PT_IAOQ1(%r1),%r2
  1565. depi 3,31,2,%r2
  1566. STREG %r2,TASK_PT_IAOQ1(%r1)
  1567. b intr_restore
  1568. copy %r25,%r16
  1569. syscall_do_resched:
  1570. load32 syscall_check_resched,%r2 /* if resched, we start over again */
  1571. load32 schedule,%r19
  1572. bv %r0(%r19) /* jumps to schedule() */
  1573. #ifdef CONFIG_64BIT
  1574. ldo -16(%r30),%r29 /* Reference param save area */
  1575. #else
  1576. nop
  1577. #endif
  1578. ENDPROC_CFI(syscall_exit)
  1579. #ifdef CONFIG_FUNCTION_TRACER
  1580. .import ftrace_function_trampoline,code
  1581. .align L1_CACHE_BYTES
  1582. .globl mcount
  1583. .type mcount, @function
  1584. ENTRY(mcount)
  1585. _mcount:
  1586. .export _mcount,data
  1587. .proc
  1588. .callinfo caller,frame=0
  1589. .entry
  1590. /*
  1591. * The 64bit mcount() function pointer needs 4 dwords, of which the
  1592. * first two are free. We optimize it here and put 2 instructions for
  1593. * calling mcount(), and 2 instructions for ftrace_stub(). That way we
  1594. * have all on one L1 cacheline.
  1595. */
  1596. b ftrace_function_trampoline
  1597. copy %r3, %arg2 /* caller original %sp */
  1598. ftrace_stub:
  1599. .globl ftrace_stub
  1600. .type ftrace_stub, @function
  1601. #ifdef CONFIG_64BIT
  1602. bve (%rp)
  1603. #else
  1604. bv %r0(%rp)
  1605. #endif
  1606. nop
  1607. #ifdef CONFIG_64BIT
  1608. .dword mcount
  1609. .dword 0 /* code in head.S puts value of global gp here */
  1610. #endif
  1611. .exit
  1612. .procend
  1613. ENDPROC(mcount)
  1614. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1615. .align 8
  1616. .globl return_to_handler
  1617. .type return_to_handler, @function
  1618. ENTRY_CFI(return_to_handler)
  1619. .proc
  1620. .callinfo caller,frame=FRAME_SIZE
  1621. .entry
  1622. .export parisc_return_to_handler,data
  1623. parisc_return_to_handler:
  1624. copy %r3,%r1
  1625. STREG %r0,-RP_OFFSET(%sp) /* store 0 as %rp */
  1626. copy %sp,%r3
  1627. STREGM %r1,FRAME_SIZE(%sp)
  1628. STREG %ret0,8(%r3)
  1629. STREG %ret1,16(%r3)
  1630. #ifdef CONFIG_64BIT
  1631. loadgp
  1632. #endif
  1633. /* call ftrace_return_to_handler(0) */
  1634. .import ftrace_return_to_handler,code
  1635. load32 ftrace_return_to_handler,%ret0
  1636. load32 .Lftrace_ret,%r2
  1637. #ifdef CONFIG_64BIT
  1638. ldo -16(%sp),%ret1 /* Reference param save area */
  1639. bve (%ret0)
  1640. #else
  1641. bv %r0(%ret0)
  1642. #endif
  1643. ldi 0,%r26
  1644. .Lftrace_ret:
  1645. copy %ret0,%rp
  1646. /* restore original return values */
  1647. LDREG 8(%r3),%ret0
  1648. LDREG 16(%r3),%ret1
  1649. /* return from function */
  1650. #ifdef CONFIG_64BIT
  1651. bve (%rp)
  1652. #else
  1653. bv %r0(%rp)
  1654. #endif
  1655. LDREGM -FRAME_SIZE(%sp),%r3
  1656. .exit
  1657. .procend
  1658. ENDPROC_CFI(return_to_handler)
  1659. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  1660. #endif /* CONFIG_FUNCTION_TRACER */
  1661. #ifdef CONFIG_IRQSTACKS
  1662. /* void call_on_stack(unsigned long param1, void *func,
  1663. unsigned long new_stack) */
  1664. ENTRY_CFI(call_on_stack)
  1665. copy %sp, %r1
  1666. /* Regarding the HPPA calling conventions for function pointers,
  1667. we assume the PIC register is not changed across call. For
  1668. CONFIG_64BIT, the argument pointer is left to point at the
  1669. argument region allocated for the call to call_on_stack. */
  1670. # ifdef CONFIG_64BIT
  1671. /* Switch to new stack. We allocate two 128 byte frames. */
  1672. ldo 256(%arg2), %sp
  1673. /* Save previous stack pointer and return pointer in frame marker */
  1674. STREG %rp, -144(%sp)
  1675. /* Calls always use function descriptor */
  1676. LDREG 16(%arg1), %arg1
  1677. bve,l (%arg1), %rp
  1678. STREG %r1, -136(%sp)
  1679. LDREG -144(%sp), %rp
  1680. bve (%rp)
  1681. LDREG -136(%sp), %sp
  1682. # else
  1683. /* Switch to new stack. We allocate two 64 byte frames. */
  1684. ldo 128(%arg2), %sp
  1685. /* Save previous stack pointer and return pointer in frame marker */
  1686. STREG %r1, -68(%sp)
  1687. STREG %rp, -84(%sp)
  1688. /* Calls use function descriptor if PLABEL bit is set */
  1689. bb,>=,n %arg1, 30, 1f
  1690. depwi 0,31,2, %arg1
  1691. LDREG 0(%arg1), %arg1
  1692. 1:
  1693. be,l 0(%sr4,%arg1), %sr0, %r31
  1694. copy %r31, %rp
  1695. LDREG -84(%sp), %rp
  1696. bv (%rp)
  1697. LDREG -68(%sp), %sp
  1698. # endif /* CONFIG_64BIT */
  1699. ENDPROC_CFI(call_on_stack)
  1700. #endif /* CONFIG_IRQSTACKS */
  1701. ENTRY_CFI(get_register)
  1702. /*
  1703. * get_register is used by the non access tlb miss handlers to
  1704. * copy the value of the general register specified in r8 into
  1705. * r1. This routine can't be used for shadowed registers, since
  1706. * the rfir will restore the original value. So, for the shadowed
  1707. * registers we put a -1 into r1 to indicate that the register
  1708. * should not be used (the register being copied could also have
  1709. * a -1 in it, but that is OK, it just means that we will have
  1710. * to use the slow path instead).
  1711. */
  1712. blr %r8,%r0
  1713. nop
  1714. bv %r0(%r25) /* r0 */
  1715. copy %r0,%r1
  1716. bv %r0(%r25) /* r1 - shadowed */
  1717. ldi -1,%r1
  1718. bv %r0(%r25) /* r2 */
  1719. copy %r2,%r1
  1720. bv %r0(%r25) /* r3 */
  1721. copy %r3,%r1
  1722. bv %r0(%r25) /* r4 */
  1723. copy %r4,%r1
  1724. bv %r0(%r25) /* r5 */
  1725. copy %r5,%r1
  1726. bv %r0(%r25) /* r6 */
  1727. copy %r6,%r1
  1728. bv %r0(%r25) /* r7 */
  1729. copy %r7,%r1
  1730. bv %r0(%r25) /* r8 - shadowed */
  1731. ldi -1,%r1
  1732. bv %r0(%r25) /* r9 - shadowed */
  1733. ldi -1,%r1
  1734. bv %r0(%r25) /* r10 */
  1735. copy %r10,%r1
  1736. bv %r0(%r25) /* r11 */
  1737. copy %r11,%r1
  1738. bv %r0(%r25) /* r12 */
  1739. copy %r12,%r1
  1740. bv %r0(%r25) /* r13 */
  1741. copy %r13,%r1
  1742. bv %r0(%r25) /* r14 */
  1743. copy %r14,%r1
  1744. bv %r0(%r25) /* r15 */
  1745. copy %r15,%r1
  1746. bv %r0(%r25) /* r16 - shadowed */
  1747. ldi -1,%r1
  1748. bv %r0(%r25) /* r17 - shadowed */
  1749. ldi -1,%r1
  1750. bv %r0(%r25) /* r18 */
  1751. copy %r18,%r1
  1752. bv %r0(%r25) /* r19 */
  1753. copy %r19,%r1
  1754. bv %r0(%r25) /* r20 */
  1755. copy %r20,%r1
  1756. bv %r0(%r25) /* r21 */
  1757. copy %r21,%r1
  1758. bv %r0(%r25) /* r22 */
  1759. copy %r22,%r1
  1760. bv %r0(%r25) /* r23 */
  1761. copy %r23,%r1
  1762. bv %r0(%r25) /* r24 - shadowed */
  1763. ldi -1,%r1
  1764. bv %r0(%r25) /* r25 - shadowed */
  1765. ldi -1,%r1
  1766. bv %r0(%r25) /* r26 */
  1767. copy %r26,%r1
  1768. bv %r0(%r25) /* r27 */
  1769. copy %r27,%r1
  1770. bv %r0(%r25) /* r28 */
  1771. copy %r28,%r1
  1772. bv %r0(%r25) /* r29 */
  1773. copy %r29,%r1
  1774. bv %r0(%r25) /* r30 */
  1775. copy %r30,%r1
  1776. bv %r0(%r25) /* r31 */
  1777. copy %r31,%r1
  1778. ENDPROC_CFI(get_register)
  1779. ENTRY_CFI(set_register)
  1780. /*
  1781. * set_register is used by the non access tlb miss handlers to
  1782. * copy the value of r1 into the general register specified in
  1783. * r8.
  1784. */
  1785. blr %r8,%r0
  1786. nop
  1787. bv %r0(%r25) /* r0 (silly, but it is a place holder) */
  1788. copy %r1,%r0
  1789. bv %r0(%r25) /* r1 */
  1790. copy %r1,%r1
  1791. bv %r0(%r25) /* r2 */
  1792. copy %r1,%r2
  1793. bv %r0(%r25) /* r3 */
  1794. copy %r1,%r3
  1795. bv %r0(%r25) /* r4 */
  1796. copy %r1,%r4
  1797. bv %r0(%r25) /* r5 */
  1798. copy %r1,%r5
  1799. bv %r0(%r25) /* r6 */
  1800. copy %r1,%r6
  1801. bv %r0(%r25) /* r7 */
  1802. copy %r1,%r7
  1803. bv %r0(%r25) /* r8 */
  1804. copy %r1,%r8
  1805. bv %r0(%r25) /* r9 */
  1806. copy %r1,%r9
  1807. bv %r0(%r25) /* r10 */
  1808. copy %r1,%r10
  1809. bv %r0(%r25) /* r11 */
  1810. copy %r1,%r11
  1811. bv %r0(%r25) /* r12 */
  1812. copy %r1,%r12
  1813. bv %r0(%r25) /* r13 */
  1814. copy %r1,%r13
  1815. bv %r0(%r25) /* r14 */
  1816. copy %r1,%r14
  1817. bv %r0(%r25) /* r15 */
  1818. copy %r1,%r15
  1819. bv %r0(%r25) /* r16 */
  1820. copy %r1,%r16
  1821. bv %r0(%r25) /* r17 */
  1822. copy %r1,%r17
  1823. bv %r0(%r25) /* r18 */
  1824. copy %r1,%r18
  1825. bv %r0(%r25) /* r19 */
  1826. copy %r1,%r19
  1827. bv %r0(%r25) /* r20 */
  1828. copy %r1,%r20
  1829. bv %r0(%r25) /* r21 */
  1830. copy %r1,%r21
  1831. bv %r0(%r25) /* r22 */
  1832. copy %r1,%r22
  1833. bv %r0(%r25) /* r23 */
  1834. copy %r1,%r23
  1835. bv %r0(%r25) /* r24 */
  1836. copy %r1,%r24
  1837. bv %r0(%r25) /* r25 */
  1838. copy %r1,%r25
  1839. bv %r0(%r25) /* r26 */
  1840. copy %r1,%r26
  1841. bv %r0(%r25) /* r27 */
  1842. copy %r1,%r27
  1843. bv %r0(%r25) /* r28 */
  1844. copy %r1,%r28
  1845. bv %r0(%r25) /* r29 */
  1846. copy %r1,%r29
  1847. bv %r0(%r25) /* r30 */
  1848. copy %r1,%r30
  1849. bv %r0(%r25) /* r31 */
  1850. copy %r1,%r31
  1851. ENDPROC_CFI(set_register)