entry.S 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193
  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. /* bitshift difference between a PFN (based on kernel's PAGE_SIZE)
  425. * to a CPU TLB 4k PFN (4k => 12 bits to shift) */
  426. #define PAGE_ADD_SHIFT (PAGE_SHIFT-12)
  427. /* Drop prot bits and convert to page addr for iitlbt and idtlbt */
  428. .macro convert_for_tlb_insert20 pte
  429. extrd,u \pte,(63-ASM_PFN_PTE_SHIFT)+(63-58)+PAGE_ADD_SHIFT,\
  430. 64-PAGE_SHIFT-PAGE_ADD_SHIFT,\pte
  431. depdi _PAGE_SIZE_ENCODING_DEFAULT,63,\
  432. (63-58)+PAGE_ADD_SHIFT,\pte
  433. .endm
  434. /* Convert the pte and prot to tlb insertion values. How
  435. * this happens is quite subtle, read below */
  436. .macro make_insert_tlb spc,pte,prot
  437. space_to_prot \spc \prot /* create prot id from space */
  438. /* The following is the real subtlety. This is depositing
  439. * T <-> _PAGE_REFTRAP
  440. * D <-> _PAGE_DIRTY
  441. * B <-> _PAGE_DMB (memory break)
  442. *
  443. * Then incredible subtlety: The access rights are
  444. * _PAGE_GATEWAY, _PAGE_EXEC and _PAGE_WRITE
  445. * See 3-14 of the parisc 2.0 manual
  446. *
  447. * Finally, _PAGE_READ goes in the top bit of PL1 (so we
  448. * trigger an access rights trap in user space if the user
  449. * tries to read an unreadable page */
  450. depd \pte,8,7,\prot
  451. /* PAGE_USER indicates the page can be read with user privileges,
  452. * so deposit X1|11 to PL1|PL2 (remember the upper bit of PL1
  453. * contains _PAGE_READ) */
  454. extrd,u,*= \pte,_PAGE_USER_BIT+32,1,%r0
  455. depdi 7,11,3,\prot
  456. /* If we're a gateway page, drop PL2 back to zero for promotion
  457. * to kernel privilege (so we can execute the page as kernel).
  458. * Any privilege promotion page always denys read and write */
  459. extrd,u,*= \pte,_PAGE_GATEWAY_BIT+32,1,%r0
  460. depd %r0,11,2,\prot /* If Gateway, Set PL2 to 0 */
  461. /* Enforce uncacheable pages.
  462. * This should ONLY be use for MMIO on PA 2.0 machines.
  463. * Memory/DMA is cache coherent on all PA2.0 machines we support
  464. * (that means T-class is NOT supported) and the memory controllers
  465. * on most of those machines only handles cache transactions.
  466. */
  467. extrd,u,*= \pte,_PAGE_NO_CACHE_BIT+32,1,%r0
  468. depdi 1,12,1,\prot
  469. /* Drop prot bits and convert to page addr for iitlbt and idtlbt */
  470. convert_for_tlb_insert20 \pte
  471. .endm
  472. /* Identical macro to make_insert_tlb above, except it
  473. * makes the tlb entry for the differently formatted pa11
  474. * insertion instructions */
  475. .macro make_insert_tlb_11 spc,pte,prot
  476. zdep \spc,30,15,\prot
  477. dep \pte,8,7,\prot
  478. extru,= \pte,_PAGE_NO_CACHE_BIT,1,%r0
  479. depi 1,12,1,\prot
  480. extru,= \pte,_PAGE_USER_BIT,1,%r0
  481. depi 7,11,3,\prot /* Set for user space (1 rsvd for read) */
  482. extru,= \pte,_PAGE_GATEWAY_BIT,1,%r0
  483. depi 0,11,2,\prot /* If Gateway, Set PL2 to 0 */
  484. /* Get rid of prot bits and convert to page addr for iitlba */
  485. depi 0,31,ASM_PFN_PTE_SHIFT,\pte
  486. SHRREG \pte,(ASM_PFN_PTE_SHIFT-(31-26)),\pte
  487. .endm
  488. /* This is for ILP32 PA2.0 only. The TLB insertion needs
  489. * to extend into I/O space if the address is 0xfXXXXXXX
  490. * so we extend the f's into the top word of the pte in
  491. * this case */
  492. .macro f_extend pte,tmp
  493. extrd,s \pte,42,4,\tmp
  494. addi,<> 1,\tmp,%r0
  495. extrd,s \pte,63,25,\pte
  496. .endm
  497. /* The alias region is an 8MB aligned 16MB to do clear and
  498. * copy user pages at addresses congruent with the user
  499. * virtual address.
  500. *
  501. * To use the alias page, you set %r26 up with the to TLB
  502. * entry (identifying the physical page) and %r23 up with
  503. * the from tlb entry (or nothing if only a to entry---for
  504. * clear_user_page_asm) */
  505. .macro do_alias spc,tmp,tmp1,va,pte,prot,fault,patype
  506. cmpib,COND(<>),n 0,\spc,\fault
  507. ldil L%(TMPALIAS_MAP_START),\tmp
  508. #if defined(CONFIG_64BIT) && (TMPALIAS_MAP_START >= 0x80000000)
  509. /* on LP64, ldi will sign extend into the upper 32 bits,
  510. * which is behaviour we don't want */
  511. depdi 0,31,32,\tmp
  512. #endif
  513. copy \va,\tmp1
  514. depi 0,31,23,\tmp1
  515. cmpb,COND(<>),n \tmp,\tmp1,\fault
  516. mfctl %cr19,\tmp /* iir */
  517. /* get the opcode (first six bits) into \tmp */
  518. extrw,u \tmp,5,6,\tmp
  519. /*
  520. * Only setting the T bit prevents data cache movein
  521. * Setting access rights to zero prevents instruction cache movein
  522. *
  523. * Note subtlety here: _PAGE_GATEWAY, _PAGE_EXEC and _PAGE_WRITE go
  524. * to type field and _PAGE_READ goes to top bit of PL1
  525. */
  526. ldi (_PAGE_REFTRAP|_PAGE_READ|_PAGE_WRITE),\prot
  527. /*
  528. * so if the opcode is one (i.e. this is a memory management
  529. * instruction) nullify the next load so \prot is only T.
  530. * Otherwise this is a normal data operation
  531. */
  532. cmpiclr,= 0x01,\tmp,%r0
  533. ldi (_PAGE_DIRTY|_PAGE_READ|_PAGE_WRITE),\prot
  534. .ifc \patype,20
  535. depd,z \prot,8,7,\prot
  536. .else
  537. .ifc \patype,11
  538. depw,z \prot,8,7,\prot
  539. .else
  540. .error "undefined PA type to do_alias"
  541. .endif
  542. .endif
  543. /*
  544. * OK, it is in the temp alias region, check whether "from" or "to".
  545. * Check "subtle" note in pacache.S re: r23/r26.
  546. */
  547. #ifdef CONFIG_64BIT
  548. extrd,u,*= \va,41,1,%r0
  549. #else
  550. extrw,u,= \va,9,1,%r0
  551. #endif
  552. or,COND(tr) %r23,%r0,\pte
  553. or %r26,%r0,\pte
  554. .endm
  555. /*
  556. * Align fault_vector_20 on 4K boundary so that both
  557. * fault_vector_11 and fault_vector_20 are on the
  558. * same page. This is only necessary as long as we
  559. * write protect the kernel text, which we may stop
  560. * doing once we use large page translations to cover
  561. * the static part of the kernel address space.
  562. */
  563. .text
  564. .align 4096
  565. ENTRY(fault_vector_20)
  566. /* First vector is invalid (0) */
  567. .ascii "cows can fly"
  568. .byte 0
  569. .align 32
  570. hpmc 1
  571. def 2
  572. def 3
  573. extint 4
  574. def 5
  575. itlb_20 6
  576. def 7
  577. def 8
  578. def 9
  579. def 10
  580. def 11
  581. def 12
  582. def 13
  583. def 14
  584. dtlb_20 15
  585. naitlb_20 16
  586. nadtlb_20 17
  587. def 18
  588. def 19
  589. dbit_20 20
  590. def 21
  591. def 22
  592. def 23
  593. def 24
  594. def 25
  595. def 26
  596. def 27
  597. def 28
  598. def 29
  599. def 30
  600. def 31
  601. END(fault_vector_20)
  602. #ifndef CONFIG_64BIT
  603. .align 2048
  604. ENTRY(fault_vector_11)
  605. /* First vector is invalid (0) */
  606. .ascii "cows can fly"
  607. .byte 0
  608. .align 32
  609. hpmc 1
  610. def 2
  611. def 3
  612. extint 4
  613. def 5
  614. itlb_11 6
  615. def 7
  616. def 8
  617. def 9
  618. def 10
  619. def 11
  620. def 12
  621. def 13
  622. def 14
  623. dtlb_11 15
  624. naitlb_11 16
  625. nadtlb_11 17
  626. def 18
  627. def 19
  628. dbit_11 20
  629. def 21
  630. def 22
  631. def 23
  632. def 24
  633. def 25
  634. def 26
  635. def 27
  636. def 28
  637. def 29
  638. def 30
  639. def 31
  640. END(fault_vector_11)
  641. #endif
  642. /* Fault vector is separately protected and *must* be on its own page */
  643. .align PAGE_SIZE
  644. ENTRY(end_fault_vector)
  645. .import handle_interruption,code
  646. .import do_cpu_irq_mask,code
  647. /*
  648. * Child Returns here
  649. *
  650. * copy_thread moved args into task save area.
  651. */
  652. ENTRY(ret_from_kernel_thread)
  653. /* Call schedule_tail first though */
  654. BL schedule_tail, %r2
  655. nop
  656. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  657. LDREG TASK_PT_GR25(%r1), %r26
  658. #ifdef CONFIG_64BIT
  659. LDREG TASK_PT_GR27(%r1), %r27
  660. #endif
  661. LDREG TASK_PT_GR26(%r1), %r1
  662. ble 0(%sr7, %r1)
  663. copy %r31, %r2
  664. b finish_child_return
  665. nop
  666. ENDPROC(ret_from_kernel_thread)
  667. /*
  668. * struct task_struct *_switch_to(struct task_struct *prev,
  669. * struct task_struct *next)
  670. *
  671. * switch kernel stacks and return prev */
  672. ENTRY(_switch_to)
  673. STREG %r2, -RP_OFFSET(%r30)
  674. callee_save_float
  675. callee_save
  676. load32 _switch_to_ret, %r2
  677. STREG %r2, TASK_PT_KPC(%r26)
  678. LDREG TASK_PT_KPC(%r25), %r2
  679. STREG %r30, TASK_PT_KSP(%r26)
  680. LDREG TASK_PT_KSP(%r25), %r30
  681. LDREG TASK_THREAD_INFO(%r25), %r25
  682. bv %r0(%r2)
  683. mtctl %r25,%cr30
  684. _switch_to_ret:
  685. mtctl %r0, %cr0 /* Needed for single stepping */
  686. callee_rest
  687. callee_rest_float
  688. LDREG -RP_OFFSET(%r30), %r2
  689. bv %r0(%r2)
  690. copy %r26, %r28
  691. ENDPROC(_switch_to)
  692. /*
  693. * Common rfi return path for interruptions, kernel execve, and
  694. * sys_rt_sigreturn (sometimes). The sys_rt_sigreturn syscall will
  695. * return via this path if the signal was received when the process
  696. * was running; if the process was blocked on a syscall then the
  697. * normal syscall_exit path is used. All syscalls for traced
  698. * proceses exit via intr_restore.
  699. *
  700. * XXX If any syscalls that change a processes space id ever exit
  701. * this way, then we will need to copy %sr3 in to PT_SR[3..7], and
  702. * adjust IASQ[0..1].
  703. *
  704. */
  705. .align PAGE_SIZE
  706. ENTRY(syscall_exit_rfi)
  707. mfctl %cr30,%r16
  708. LDREG TI_TASK(%r16), %r16 /* thread_info -> task_struct */
  709. ldo TASK_REGS(%r16),%r16
  710. /* Force iaoq to userspace, as the user has had access to our current
  711. * context via sigcontext. Also Filter the PSW for the same reason.
  712. */
  713. LDREG PT_IAOQ0(%r16),%r19
  714. depi 3,31,2,%r19
  715. STREG %r19,PT_IAOQ0(%r16)
  716. LDREG PT_IAOQ1(%r16),%r19
  717. depi 3,31,2,%r19
  718. STREG %r19,PT_IAOQ1(%r16)
  719. LDREG PT_PSW(%r16),%r19
  720. load32 USER_PSW_MASK,%r1
  721. #ifdef CONFIG_64BIT
  722. load32 USER_PSW_HI_MASK,%r20
  723. depd %r20,31,32,%r1
  724. #endif
  725. and %r19,%r1,%r19 /* Mask out bits that user shouldn't play with */
  726. load32 USER_PSW,%r1
  727. or %r19,%r1,%r19 /* Make sure default USER_PSW bits are set */
  728. STREG %r19,PT_PSW(%r16)
  729. /*
  730. * If we aren't being traced, we never saved space registers
  731. * (we don't store them in the sigcontext), so set them
  732. * to "proper" values now (otherwise we'll wind up restoring
  733. * whatever was last stored in the task structure, which might
  734. * be inconsistent if an interrupt occurred while on the gateway
  735. * page). Note that we may be "trashing" values the user put in
  736. * them, but we don't support the user changing them.
  737. */
  738. STREG %r0,PT_SR2(%r16)
  739. mfsp %sr3,%r19
  740. STREG %r19,PT_SR0(%r16)
  741. STREG %r19,PT_SR1(%r16)
  742. STREG %r19,PT_SR3(%r16)
  743. STREG %r19,PT_SR4(%r16)
  744. STREG %r19,PT_SR5(%r16)
  745. STREG %r19,PT_SR6(%r16)
  746. STREG %r19,PT_SR7(%r16)
  747. intr_return:
  748. /* check for reschedule */
  749. mfctl %cr30,%r1
  750. LDREG TI_FLAGS(%r1),%r19 /* sched.h: TIF_NEED_RESCHED */
  751. bb,<,n %r19,31-TIF_NEED_RESCHED,intr_do_resched /* forward */
  752. .import do_notify_resume,code
  753. intr_check_sig:
  754. /* As above */
  755. mfctl %cr30,%r1
  756. LDREG TI_FLAGS(%r1),%r19
  757. ldi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), %r20
  758. and,COND(<>) %r19, %r20, %r0
  759. b,n intr_restore /* skip past if we've nothing to do */
  760. /* This check is critical to having LWS
  761. * working. The IASQ is zero on the gateway
  762. * page and we cannot deliver any signals until
  763. * we get off the gateway page.
  764. *
  765. * Only do signals if we are returning to user space
  766. */
  767. LDREG PT_IASQ0(%r16), %r20
  768. cmpib,COND(=),n 0,%r20,intr_restore /* backward */
  769. LDREG PT_IASQ1(%r16), %r20
  770. cmpib,COND(=),n 0,%r20,intr_restore /* backward */
  771. /* NOTE: We need to enable interrupts if we have to deliver
  772. * signals. We used to do this earlier but it caused kernel
  773. * stack overflows. */
  774. ssm PSW_SM_I, %r0
  775. copy %r0, %r25 /* long in_syscall = 0 */
  776. #ifdef CONFIG_64BIT
  777. ldo -16(%r30),%r29 /* Reference param save area */
  778. #endif
  779. BL do_notify_resume,%r2
  780. copy %r16, %r26 /* struct pt_regs *regs */
  781. b,n intr_check_sig
  782. intr_restore:
  783. copy %r16,%r29
  784. ldo PT_FR31(%r29),%r1
  785. rest_fp %r1
  786. rest_general %r29
  787. /* inverse of virt_map */
  788. pcxt_ssm_bug
  789. rsm PSW_SM_QUIET,%r0 /* prepare for rfi */
  790. tophys_r1 %r29
  791. /* Restore space id's and special cr's from PT_REGS
  792. * structure pointed to by r29
  793. */
  794. rest_specials %r29
  795. /* IMPORTANT: rest_stack restores r29 last (we are using it)!
  796. * It also restores r1 and r30.
  797. */
  798. rest_stack
  799. rfi
  800. nop
  801. #ifndef CONFIG_PREEMPT
  802. # define intr_do_preempt intr_restore
  803. #endif /* !CONFIG_PREEMPT */
  804. .import schedule,code
  805. intr_do_resched:
  806. /* Only call schedule on return to userspace. If we're returning
  807. * to kernel space, we may schedule if CONFIG_PREEMPT, otherwise
  808. * we jump back to intr_restore.
  809. */
  810. LDREG PT_IASQ0(%r16), %r20
  811. cmpib,COND(=) 0, %r20, intr_do_preempt
  812. nop
  813. LDREG PT_IASQ1(%r16), %r20
  814. cmpib,COND(=) 0, %r20, intr_do_preempt
  815. nop
  816. /* NOTE: We need to enable interrupts if we schedule. We used
  817. * to do this earlier but it caused kernel stack overflows. */
  818. ssm PSW_SM_I, %r0
  819. #ifdef CONFIG_64BIT
  820. ldo -16(%r30),%r29 /* Reference param save area */
  821. #endif
  822. ldil L%intr_check_sig, %r2
  823. #ifndef CONFIG_64BIT
  824. b schedule
  825. #else
  826. load32 schedule, %r20
  827. bv %r0(%r20)
  828. #endif
  829. ldo R%intr_check_sig(%r2), %r2
  830. /* preempt the current task on returning to kernel
  831. * mode from an interrupt, iff need_resched is set,
  832. * and preempt_count is 0. otherwise, we continue on
  833. * our merry way back to the current running task.
  834. */
  835. #ifdef CONFIG_PREEMPT
  836. .import preempt_schedule_irq,code
  837. intr_do_preempt:
  838. rsm PSW_SM_I, %r0 /* disable interrupts */
  839. /* current_thread_info()->preempt_count */
  840. mfctl %cr30, %r1
  841. LDREG TI_PRE_COUNT(%r1), %r19
  842. cmpib,COND(<>) 0, %r19, intr_restore /* if preempt_count > 0 */
  843. nop /* prev insn branched backwards */
  844. /* check if we interrupted a critical path */
  845. LDREG PT_PSW(%r16), %r20
  846. bb,<,n %r20, 31 - PSW_SM_I, intr_restore
  847. nop
  848. BL preempt_schedule_irq, %r2
  849. nop
  850. b,n intr_restore /* ssm PSW_SM_I done by intr_restore */
  851. #endif /* CONFIG_PREEMPT */
  852. /*
  853. * External interrupts.
  854. */
  855. intr_extint:
  856. cmpib,COND(=),n 0,%r16,1f
  857. get_stack_use_cr30
  858. b,n 2f
  859. 1:
  860. get_stack_use_r30
  861. 2:
  862. save_specials %r29
  863. virt_map
  864. save_general %r29
  865. ldo PT_FR0(%r29), %r24
  866. save_fp %r24
  867. loadgp
  868. copy %r29, %r26 /* arg0 is pt_regs */
  869. copy %r29, %r16 /* save pt_regs */
  870. ldil L%intr_return, %r2
  871. #ifdef CONFIG_64BIT
  872. ldo -16(%r30),%r29 /* Reference param save area */
  873. #endif
  874. b do_cpu_irq_mask
  875. ldo R%intr_return(%r2), %r2 /* return to intr_return, not here */
  876. ENDPROC(syscall_exit_rfi)
  877. /* Generic interruptions (illegal insn, unaligned, page fault, etc) */
  878. ENTRY(intr_save) /* for os_hpmc */
  879. mfsp %sr7,%r16
  880. cmpib,COND(=),n 0,%r16,1f
  881. get_stack_use_cr30
  882. b 2f
  883. copy %r8,%r26
  884. 1:
  885. get_stack_use_r30
  886. copy %r8,%r26
  887. 2:
  888. save_specials %r29
  889. /* If this trap is a itlb miss, skip saving/adjusting isr/ior */
  890. /*
  891. * FIXME: 1) Use a #define for the hardwired "6" below (and in
  892. * traps.c.
  893. * 2) Once we start executing code above 4 Gb, we need
  894. * to adjust iasq/iaoq here in the same way we
  895. * adjust isr/ior below.
  896. */
  897. cmpib,COND(=),n 6,%r26,skip_save_ior
  898. mfctl %cr20, %r16 /* isr */
  899. nop /* serialize mfctl on PA 2.0 to avoid 4 cycle penalty */
  900. mfctl %cr21, %r17 /* ior */
  901. #ifdef CONFIG_64BIT
  902. /*
  903. * If the interrupted code was running with W bit off (32 bit),
  904. * clear the b bits (bits 0 & 1) in the ior.
  905. * save_specials left ipsw value in r8 for us to test.
  906. */
  907. extrd,u,*<> %r8,PSW_W_BIT,1,%r0
  908. depdi 0,1,2,%r17
  909. /*
  910. * FIXME: This code has hardwired assumptions about the split
  911. * between space bits and offset bits. This will change
  912. * when we allow alternate page sizes.
  913. */
  914. /* adjust isr/ior. */
  915. extrd,u %r16,63,SPACEID_SHIFT,%r1 /* get high bits from isr for ior */
  916. depd %r1,31,SPACEID_SHIFT,%r17 /* deposit them into ior */
  917. depdi 0,63,SPACEID_SHIFT,%r16 /* clear them from isr */
  918. #endif
  919. STREG %r16, PT_ISR(%r29)
  920. STREG %r17, PT_IOR(%r29)
  921. skip_save_ior:
  922. virt_map
  923. save_general %r29
  924. ldo PT_FR0(%r29), %r25
  925. save_fp %r25
  926. loadgp
  927. copy %r29, %r25 /* arg1 is pt_regs */
  928. #ifdef CONFIG_64BIT
  929. ldo -16(%r30),%r29 /* Reference param save area */
  930. #endif
  931. ldil L%intr_check_sig, %r2
  932. copy %r25, %r16 /* save pt_regs */
  933. b handle_interruption
  934. ldo R%intr_check_sig(%r2), %r2
  935. ENDPROC(intr_save)
  936. /*
  937. * Note for all tlb miss handlers:
  938. *
  939. * cr24 contains a pointer to the kernel address space
  940. * page directory.
  941. *
  942. * cr25 contains a pointer to the current user address
  943. * space page directory.
  944. *
  945. * sr3 will contain the space id of the user address space
  946. * of the current running thread while that thread is
  947. * running in the kernel.
  948. */
  949. /*
  950. * register number allocations. Note that these are all
  951. * in the shadowed registers
  952. */
  953. t0 = r1 /* temporary register 0 */
  954. va = r8 /* virtual address for which the trap occurred */
  955. t1 = r9 /* temporary register 1 */
  956. pte = r16 /* pte/phys page # */
  957. prot = r17 /* prot bits */
  958. spc = r24 /* space for which the trap occurred */
  959. ptp = r25 /* page directory/page table pointer */
  960. #ifdef CONFIG_64BIT
  961. dtlb_miss_20w:
  962. space_adjust spc,va,t0
  963. get_pgd spc,ptp
  964. space_check spc,t0,dtlb_fault
  965. L3_ptep ptp,pte,t0,va,dtlb_check_alias_20w
  966. tlb_lock spc,ptp,pte,t0,t1,dtlb_check_alias_20w
  967. update_accessed ptp,pte,t0,t1
  968. make_insert_tlb spc,pte,prot
  969. idtlbt pte,prot
  970. tlb_unlock1 spc,t0
  971. rfir
  972. nop
  973. dtlb_check_alias_20w:
  974. do_alias spc,t0,t1,va,pte,prot,dtlb_fault,20
  975. idtlbt pte,prot
  976. rfir
  977. nop
  978. nadtlb_miss_20w:
  979. space_adjust spc,va,t0
  980. get_pgd spc,ptp
  981. space_check spc,t0,nadtlb_fault
  982. L3_ptep ptp,pte,t0,va,nadtlb_check_alias_20w
  983. tlb_lock spc,ptp,pte,t0,t1,nadtlb_check_alias_20w
  984. update_accessed ptp,pte,t0,t1
  985. make_insert_tlb spc,pte,prot
  986. idtlbt pte,prot
  987. tlb_unlock1 spc,t0
  988. rfir
  989. nop
  990. nadtlb_check_alias_20w:
  991. do_alias spc,t0,t1,va,pte,prot,nadtlb_emulate,20
  992. idtlbt pte,prot
  993. rfir
  994. nop
  995. #else
  996. dtlb_miss_11:
  997. get_pgd spc,ptp
  998. space_check spc,t0,dtlb_fault
  999. L2_ptep ptp,pte,t0,va,dtlb_check_alias_11
  1000. tlb_lock spc,ptp,pte,t0,t1,dtlb_check_alias_11
  1001. update_accessed ptp,pte,t0,t1
  1002. make_insert_tlb_11 spc,pte,prot
  1003. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1004. mtsp spc,%sr1
  1005. idtlba pte,(%sr1,va)
  1006. idtlbp prot,(%sr1,va)
  1007. mtsp t1, %sr1 /* Restore sr1 */
  1008. tlb_unlock1 spc,t0
  1009. rfir
  1010. nop
  1011. dtlb_check_alias_11:
  1012. do_alias spc,t0,t1,va,pte,prot,dtlb_fault,11
  1013. idtlba pte,(va)
  1014. idtlbp prot,(va)
  1015. rfir
  1016. nop
  1017. nadtlb_miss_11:
  1018. get_pgd spc,ptp
  1019. space_check spc,t0,nadtlb_fault
  1020. L2_ptep ptp,pte,t0,va,nadtlb_check_alias_11
  1021. tlb_lock spc,ptp,pte,t0,t1,nadtlb_check_alias_11
  1022. update_accessed ptp,pte,t0,t1
  1023. make_insert_tlb_11 spc,pte,prot
  1024. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1025. mtsp spc,%sr1
  1026. idtlba pte,(%sr1,va)
  1027. idtlbp prot,(%sr1,va)
  1028. mtsp t1, %sr1 /* Restore sr1 */
  1029. tlb_unlock1 spc,t0
  1030. rfir
  1031. nop
  1032. nadtlb_check_alias_11:
  1033. do_alias spc,t0,t1,va,pte,prot,nadtlb_emulate,11
  1034. idtlba pte,(va)
  1035. idtlbp prot,(va)
  1036. rfir
  1037. nop
  1038. dtlb_miss_20:
  1039. space_adjust spc,va,t0
  1040. get_pgd spc,ptp
  1041. space_check spc,t0,dtlb_fault
  1042. L2_ptep ptp,pte,t0,va,dtlb_check_alias_20
  1043. tlb_lock spc,ptp,pte,t0,t1,dtlb_check_alias_20
  1044. update_accessed ptp,pte,t0,t1
  1045. make_insert_tlb spc,pte,prot
  1046. f_extend pte,t1
  1047. idtlbt pte,prot
  1048. tlb_unlock1 spc,t0
  1049. rfir
  1050. nop
  1051. dtlb_check_alias_20:
  1052. do_alias spc,t0,t1,va,pte,prot,dtlb_fault,20
  1053. idtlbt pte,prot
  1054. rfir
  1055. nop
  1056. nadtlb_miss_20:
  1057. get_pgd spc,ptp
  1058. space_check spc,t0,nadtlb_fault
  1059. L2_ptep ptp,pte,t0,va,nadtlb_check_alias_20
  1060. tlb_lock spc,ptp,pte,t0,t1,nadtlb_check_alias_20
  1061. update_accessed ptp,pte,t0,t1
  1062. make_insert_tlb spc,pte,prot
  1063. f_extend pte,t1
  1064. idtlbt pte,prot
  1065. tlb_unlock1 spc,t0
  1066. rfir
  1067. nop
  1068. nadtlb_check_alias_20:
  1069. do_alias spc,t0,t1,va,pte,prot,nadtlb_emulate,20
  1070. idtlbt pte,prot
  1071. rfir
  1072. nop
  1073. #endif
  1074. nadtlb_emulate:
  1075. /*
  1076. * Non access misses can be caused by fdc,fic,pdc,lpa,probe and
  1077. * probei instructions. We don't want to fault for these
  1078. * instructions (not only does it not make sense, it can cause
  1079. * deadlocks, since some flushes are done with the mmap
  1080. * semaphore held). If the translation doesn't exist, we can't
  1081. * insert a translation, so have to emulate the side effects
  1082. * of the instruction. Since we don't insert a translation
  1083. * we can get a lot of faults during a flush loop, so it makes
  1084. * sense to try to do it here with minimum overhead. We only
  1085. * emulate fdc,fic,pdc,probew,prober instructions whose base
  1086. * and index registers are not shadowed. We defer everything
  1087. * else to the "slow" path.
  1088. */
  1089. mfctl %cr19,%r9 /* Get iir */
  1090. /* PA 2.0 Arch Ref. Book pg 382 has a good description of the insn bits.
  1091. Checks for fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw */
  1092. /* Checks for fdc,fdce,pdc,"fic,4f" only */
  1093. ldi 0x280,%r16
  1094. and %r9,%r16,%r17
  1095. cmpb,<>,n %r16,%r17,nadtlb_probe_check
  1096. bb,>=,n %r9,26,nadtlb_nullify /* m bit not set, just nullify */
  1097. BL get_register,%r25
  1098. extrw,u %r9,15,5,%r8 /* Get index register # */
  1099. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1100. copy %r1,%r24
  1101. BL get_register,%r25
  1102. extrw,u %r9,10,5,%r8 /* Get base register # */
  1103. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1104. BL set_register,%r25
  1105. add,l %r1,%r24,%r1 /* doesn't affect c/b bits */
  1106. nadtlb_nullify:
  1107. mfctl %ipsw,%r8
  1108. ldil L%PSW_N,%r9
  1109. or %r8,%r9,%r8 /* Set PSW_N */
  1110. mtctl %r8,%ipsw
  1111. rfir
  1112. nop
  1113. /*
  1114. When there is no translation for the probe address then we
  1115. must nullify the insn and return zero in the target regsiter.
  1116. This will indicate to the calling code that it does not have
  1117. write/read privileges to this address.
  1118. This should technically work for prober and probew in PA 1.1,
  1119. and also probe,r and probe,w in PA 2.0
  1120. WARNING: USE ONLY NON-SHADOW REGISTERS WITH PROBE INSN!
  1121. THE SLOW-PATH EMULATION HAS NOT BEEN WRITTEN YET.
  1122. */
  1123. nadtlb_probe_check:
  1124. ldi 0x80,%r16
  1125. and %r9,%r16,%r17
  1126. cmpb,<>,n %r16,%r17,nadtlb_fault /* Must be probe,[rw]*/
  1127. BL get_register,%r25 /* Find the target register */
  1128. extrw,u %r9,31,5,%r8 /* Get target register */
  1129. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1130. BL set_register,%r25
  1131. copy %r0,%r1 /* Write zero to target register */
  1132. b nadtlb_nullify /* Nullify return insn */
  1133. nop
  1134. #ifdef CONFIG_64BIT
  1135. itlb_miss_20w:
  1136. /*
  1137. * I miss is a little different, since we allow users to fault
  1138. * on the gateway page which is in the kernel address space.
  1139. */
  1140. space_adjust spc,va,t0
  1141. get_pgd spc,ptp
  1142. space_check spc,t0,itlb_fault
  1143. L3_ptep ptp,pte,t0,va,itlb_fault
  1144. tlb_lock spc,ptp,pte,t0,t1,itlb_fault
  1145. update_accessed ptp,pte,t0,t1
  1146. make_insert_tlb spc,pte,prot
  1147. iitlbt pte,prot
  1148. tlb_unlock1 spc,t0
  1149. rfir
  1150. nop
  1151. naitlb_miss_20w:
  1152. /*
  1153. * I miss is a little different, since we allow users to fault
  1154. * on the gateway page which is in the kernel address space.
  1155. */
  1156. space_adjust spc,va,t0
  1157. get_pgd spc,ptp
  1158. space_check spc,t0,naitlb_fault
  1159. L3_ptep ptp,pte,t0,va,naitlb_check_alias_20w
  1160. tlb_lock spc,ptp,pte,t0,t1,naitlb_check_alias_20w
  1161. update_accessed ptp,pte,t0,t1
  1162. make_insert_tlb spc,pte,prot
  1163. iitlbt pte,prot
  1164. tlb_unlock1 spc,t0
  1165. rfir
  1166. nop
  1167. naitlb_check_alias_20w:
  1168. do_alias spc,t0,t1,va,pte,prot,naitlb_fault,20
  1169. iitlbt pte,prot
  1170. rfir
  1171. nop
  1172. #else
  1173. itlb_miss_11:
  1174. get_pgd spc,ptp
  1175. space_check spc,t0,itlb_fault
  1176. L2_ptep ptp,pte,t0,va,itlb_fault
  1177. tlb_lock spc,ptp,pte,t0,t1,itlb_fault
  1178. update_accessed ptp,pte,t0,t1
  1179. make_insert_tlb_11 spc,pte,prot
  1180. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1181. mtsp spc,%sr1
  1182. iitlba pte,(%sr1,va)
  1183. iitlbp prot,(%sr1,va)
  1184. mtsp t1, %sr1 /* Restore sr1 */
  1185. tlb_unlock1 spc,t0
  1186. rfir
  1187. nop
  1188. naitlb_miss_11:
  1189. get_pgd spc,ptp
  1190. space_check spc,t0,naitlb_fault
  1191. L2_ptep ptp,pte,t0,va,naitlb_check_alias_11
  1192. tlb_lock spc,ptp,pte,t0,t1,naitlb_check_alias_11
  1193. update_accessed ptp,pte,t0,t1
  1194. make_insert_tlb_11 spc,pte,prot
  1195. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1196. mtsp spc,%sr1
  1197. iitlba pte,(%sr1,va)
  1198. iitlbp prot,(%sr1,va)
  1199. mtsp t1, %sr1 /* Restore sr1 */
  1200. tlb_unlock1 spc,t0
  1201. rfir
  1202. nop
  1203. naitlb_check_alias_11:
  1204. do_alias spc,t0,t1,va,pte,prot,itlb_fault,11
  1205. iitlba pte,(%sr0, va)
  1206. iitlbp prot,(%sr0, va)
  1207. rfir
  1208. nop
  1209. itlb_miss_20:
  1210. get_pgd spc,ptp
  1211. space_check spc,t0,itlb_fault
  1212. L2_ptep ptp,pte,t0,va,itlb_fault
  1213. tlb_lock spc,ptp,pte,t0,t1,itlb_fault
  1214. update_accessed ptp,pte,t0,t1
  1215. make_insert_tlb spc,pte,prot
  1216. f_extend pte,t1
  1217. iitlbt pte,prot
  1218. tlb_unlock1 spc,t0
  1219. rfir
  1220. nop
  1221. naitlb_miss_20:
  1222. get_pgd spc,ptp
  1223. space_check spc,t0,naitlb_fault
  1224. L2_ptep ptp,pte,t0,va,naitlb_check_alias_20
  1225. tlb_lock spc,ptp,pte,t0,t1,naitlb_check_alias_20
  1226. update_accessed ptp,pte,t0,t1
  1227. make_insert_tlb spc,pte,prot
  1228. f_extend pte,t1
  1229. iitlbt pte,prot
  1230. tlb_unlock1 spc,t0
  1231. rfir
  1232. nop
  1233. naitlb_check_alias_20:
  1234. do_alias spc,t0,t1,va,pte,prot,naitlb_fault,20
  1235. iitlbt pte,prot
  1236. rfir
  1237. nop
  1238. #endif
  1239. #ifdef CONFIG_64BIT
  1240. dbit_trap_20w:
  1241. space_adjust spc,va,t0
  1242. get_pgd spc,ptp
  1243. space_check spc,t0,dbit_fault
  1244. L3_ptep ptp,pte,t0,va,dbit_fault
  1245. tlb_lock spc,ptp,pte,t0,t1,dbit_fault
  1246. update_dirty ptp,pte,t1
  1247. make_insert_tlb spc,pte,prot
  1248. idtlbt pte,prot
  1249. tlb_unlock0 spc,t0
  1250. rfir
  1251. nop
  1252. #else
  1253. dbit_trap_11:
  1254. get_pgd spc,ptp
  1255. space_check spc,t0,dbit_fault
  1256. L2_ptep ptp,pte,t0,va,dbit_fault
  1257. tlb_lock spc,ptp,pte,t0,t1,dbit_fault
  1258. update_dirty ptp,pte,t1
  1259. make_insert_tlb_11 spc,pte,prot
  1260. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1261. mtsp spc,%sr1
  1262. idtlba pte,(%sr1,va)
  1263. idtlbp prot,(%sr1,va)
  1264. mtsp t1, %sr1 /* Restore sr1 */
  1265. tlb_unlock0 spc,t0
  1266. rfir
  1267. nop
  1268. dbit_trap_20:
  1269. get_pgd spc,ptp
  1270. space_check spc,t0,dbit_fault
  1271. L2_ptep ptp,pte,t0,va,dbit_fault
  1272. tlb_lock spc,ptp,pte,t0,t1,dbit_fault
  1273. update_dirty ptp,pte,t1
  1274. make_insert_tlb spc,pte,prot
  1275. f_extend pte,t1
  1276. idtlbt pte,prot
  1277. tlb_unlock0 spc,t0
  1278. rfir
  1279. nop
  1280. #endif
  1281. .import handle_interruption,code
  1282. kernel_bad_space:
  1283. b intr_save
  1284. ldi 31,%r8 /* Use an unused code */
  1285. dbit_fault:
  1286. b intr_save
  1287. ldi 20,%r8
  1288. itlb_fault:
  1289. b intr_save
  1290. ldi 6,%r8
  1291. nadtlb_fault:
  1292. b intr_save
  1293. ldi 17,%r8
  1294. naitlb_fault:
  1295. b intr_save
  1296. ldi 16,%r8
  1297. dtlb_fault:
  1298. b intr_save
  1299. ldi 15,%r8
  1300. /* Register saving semantics for system calls:
  1301. %r1 clobbered by system call macro in userspace
  1302. %r2 saved in PT_REGS by gateway page
  1303. %r3 - %r18 preserved by C code (saved by signal code)
  1304. %r19 - %r20 saved in PT_REGS by gateway page
  1305. %r21 - %r22 non-standard syscall args
  1306. stored in kernel stack by gateway page
  1307. %r23 - %r26 arg3-arg0, saved in PT_REGS by gateway page
  1308. %r27 - %r30 saved in PT_REGS by gateway page
  1309. %r31 syscall return pointer
  1310. */
  1311. /* Floating point registers (FIXME: what do we do with these?)
  1312. %fr0 - %fr3 status/exception, not preserved
  1313. %fr4 - %fr7 arguments
  1314. %fr8 - %fr11 not preserved by C code
  1315. %fr12 - %fr21 preserved by C code
  1316. %fr22 - %fr31 not preserved by C code
  1317. */
  1318. .macro reg_save regs
  1319. STREG %r3, PT_GR3(\regs)
  1320. STREG %r4, PT_GR4(\regs)
  1321. STREG %r5, PT_GR5(\regs)
  1322. STREG %r6, PT_GR6(\regs)
  1323. STREG %r7, PT_GR7(\regs)
  1324. STREG %r8, PT_GR8(\regs)
  1325. STREG %r9, PT_GR9(\regs)
  1326. STREG %r10,PT_GR10(\regs)
  1327. STREG %r11,PT_GR11(\regs)
  1328. STREG %r12,PT_GR12(\regs)
  1329. STREG %r13,PT_GR13(\regs)
  1330. STREG %r14,PT_GR14(\regs)
  1331. STREG %r15,PT_GR15(\regs)
  1332. STREG %r16,PT_GR16(\regs)
  1333. STREG %r17,PT_GR17(\regs)
  1334. STREG %r18,PT_GR18(\regs)
  1335. .endm
  1336. .macro reg_restore regs
  1337. LDREG PT_GR3(\regs), %r3
  1338. LDREG PT_GR4(\regs), %r4
  1339. LDREG PT_GR5(\regs), %r5
  1340. LDREG PT_GR6(\regs), %r6
  1341. LDREG PT_GR7(\regs), %r7
  1342. LDREG PT_GR8(\regs), %r8
  1343. LDREG PT_GR9(\regs), %r9
  1344. LDREG PT_GR10(\regs),%r10
  1345. LDREG PT_GR11(\regs),%r11
  1346. LDREG PT_GR12(\regs),%r12
  1347. LDREG PT_GR13(\regs),%r13
  1348. LDREG PT_GR14(\regs),%r14
  1349. LDREG PT_GR15(\regs),%r15
  1350. LDREG PT_GR16(\regs),%r16
  1351. LDREG PT_GR17(\regs),%r17
  1352. LDREG PT_GR18(\regs),%r18
  1353. .endm
  1354. .macro fork_like name
  1355. ENTRY(sys_\name\()_wrapper)
  1356. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  1357. ldo TASK_REGS(%r1),%r1
  1358. reg_save %r1
  1359. mfctl %cr27, %r28
  1360. ldil L%sys_\name, %r31
  1361. be R%sys_\name(%sr4,%r31)
  1362. STREG %r28, PT_CR27(%r1)
  1363. ENDPROC(sys_\name\()_wrapper)
  1364. .endm
  1365. fork_like clone
  1366. fork_like fork
  1367. fork_like vfork
  1368. /* Set the return value for the child */
  1369. ENTRY(child_return)
  1370. BL schedule_tail, %r2
  1371. nop
  1372. finish_child_return:
  1373. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  1374. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1375. LDREG PT_CR27(%r1), %r3
  1376. mtctl %r3, %cr27
  1377. reg_restore %r1
  1378. b syscall_exit
  1379. copy %r0,%r28
  1380. ENDPROC(child_return)
  1381. ENTRY(sys_rt_sigreturn_wrapper)
  1382. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r26
  1383. ldo TASK_REGS(%r26),%r26 /* get pt regs */
  1384. /* Don't save regs, we are going to restore them from sigcontext. */
  1385. STREG %r2, -RP_OFFSET(%r30)
  1386. #ifdef CONFIG_64BIT
  1387. ldo FRAME_SIZE(%r30), %r30
  1388. BL sys_rt_sigreturn,%r2
  1389. ldo -16(%r30),%r29 /* Reference param save area */
  1390. #else
  1391. BL sys_rt_sigreturn,%r2
  1392. ldo FRAME_SIZE(%r30), %r30
  1393. #endif
  1394. ldo -FRAME_SIZE(%r30), %r30
  1395. LDREG -RP_OFFSET(%r30), %r2
  1396. /* FIXME: I think we need to restore a few more things here. */
  1397. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1398. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1399. reg_restore %r1
  1400. /* If the signal was received while the process was blocked on a
  1401. * syscall, then r2 will take us to syscall_exit; otherwise r2 will
  1402. * take us to syscall_exit_rfi and on to intr_return.
  1403. */
  1404. bv %r0(%r2)
  1405. LDREG PT_GR28(%r1),%r28 /* reload original r28 for syscall_exit */
  1406. ENDPROC(sys_rt_sigreturn_wrapper)
  1407. ENTRY(syscall_exit)
  1408. /* NOTE: Not all syscalls exit this way. rt_sigreturn will exit
  1409. * via syscall_exit_rfi if the signal was received while the process
  1410. * was running.
  1411. */
  1412. /* save return value now */
  1413. mfctl %cr30, %r1
  1414. LDREG TI_TASK(%r1),%r1
  1415. STREG %r28,TASK_PT_GR28(%r1)
  1416. /* Seems to me that dp could be wrong here, if the syscall involved
  1417. * calling a module, and nothing got round to restoring dp on return.
  1418. */
  1419. loadgp
  1420. syscall_check_resched:
  1421. /* check for reschedule */
  1422. LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19 /* long */
  1423. bb,<,n %r19, 31-TIF_NEED_RESCHED, syscall_do_resched /* forward */
  1424. .import do_signal,code
  1425. syscall_check_sig:
  1426. LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19
  1427. ldi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), %r26
  1428. and,COND(<>) %r19, %r26, %r0
  1429. b,n syscall_restore /* skip past if we've nothing to do */
  1430. syscall_do_signal:
  1431. /* Save callee-save registers (for sigcontext).
  1432. * FIXME: After this point the process structure should be
  1433. * consistent with all the relevant state of the process
  1434. * before the syscall. We need to verify this.
  1435. */
  1436. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1437. ldo TASK_REGS(%r1), %r26 /* struct pt_regs *regs */
  1438. reg_save %r26
  1439. #ifdef CONFIG_64BIT
  1440. ldo -16(%r30),%r29 /* Reference param save area */
  1441. #endif
  1442. BL do_notify_resume,%r2
  1443. ldi 1, %r25 /* long in_syscall = 1 */
  1444. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1445. ldo TASK_REGS(%r1), %r20 /* reload pt_regs */
  1446. reg_restore %r20
  1447. b,n syscall_check_sig
  1448. syscall_restore:
  1449. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1450. /* Are we being ptraced? */
  1451. ldw TASK_FLAGS(%r1),%r19
  1452. ldi _TIF_SYSCALL_TRACE_MASK,%r2
  1453. and,COND(=) %r19,%r2,%r0
  1454. b,n syscall_restore_rfi
  1455. ldo TASK_PT_FR31(%r1),%r19 /* reload fpregs */
  1456. rest_fp %r19
  1457. LDREG TASK_PT_SAR(%r1),%r19 /* restore SAR */
  1458. mtsar %r19
  1459. LDREG TASK_PT_GR2(%r1),%r2 /* restore user rp */
  1460. LDREG TASK_PT_GR19(%r1),%r19
  1461. LDREG TASK_PT_GR20(%r1),%r20
  1462. LDREG TASK_PT_GR21(%r1),%r21
  1463. LDREG TASK_PT_GR22(%r1),%r22
  1464. LDREG TASK_PT_GR23(%r1),%r23
  1465. LDREG TASK_PT_GR24(%r1),%r24
  1466. LDREG TASK_PT_GR25(%r1),%r25
  1467. LDREG TASK_PT_GR26(%r1),%r26
  1468. LDREG TASK_PT_GR27(%r1),%r27 /* restore user dp */
  1469. LDREG TASK_PT_GR28(%r1),%r28 /* syscall return value */
  1470. LDREG TASK_PT_GR29(%r1),%r29
  1471. LDREG TASK_PT_GR31(%r1),%r31 /* restore syscall rp */
  1472. /* NOTE: We use rsm/ssm pair to make this operation atomic */
  1473. LDREG TASK_PT_GR30(%r1),%r1 /* Get user sp */
  1474. rsm PSW_SM_I, %r0
  1475. copy %r1,%r30 /* Restore user sp */
  1476. mfsp %sr3,%r1 /* Get user space id */
  1477. mtsp %r1,%sr7 /* Restore sr7 */
  1478. ssm PSW_SM_I, %r0
  1479. /* Set sr2 to zero for userspace syscalls to work. */
  1480. mtsp %r0,%sr2
  1481. mtsp %r1,%sr4 /* Restore sr4 */
  1482. mtsp %r1,%sr5 /* Restore sr5 */
  1483. mtsp %r1,%sr6 /* Restore sr6 */
  1484. depi 3,31,2,%r31 /* ensure return to user mode. */
  1485. #ifdef CONFIG_64BIT
  1486. /* decide whether to reset the wide mode bit
  1487. *
  1488. * For a syscall, the W bit is stored in the lowest bit
  1489. * of sp. Extract it and reset W if it is zero */
  1490. extrd,u,*<> %r30,63,1,%r1
  1491. rsm PSW_SM_W, %r0
  1492. /* now reset the lowest bit of sp if it was set */
  1493. xor %r30,%r1,%r30
  1494. #endif
  1495. be,n 0(%sr3,%r31) /* return to user space */
  1496. /* We have to return via an RFI, so that PSW T and R bits can be set
  1497. * appropriately.
  1498. * This sets up pt_regs so we can return via intr_restore, which is not
  1499. * the most efficient way of doing things, but it works.
  1500. */
  1501. syscall_restore_rfi:
  1502. ldo -1(%r0),%r2 /* Set recovery cntr to -1 */
  1503. mtctl %r2,%cr0 /* for immediate trap */
  1504. LDREG TASK_PT_PSW(%r1),%r2 /* Get old PSW */
  1505. ldi 0x0b,%r20 /* Create new PSW */
  1506. depi -1,13,1,%r20 /* C, Q, D, and I bits */
  1507. /* The values of SINGLESTEP_BIT and BLOCKSTEP_BIT are
  1508. * set in thread_info.h and converted to PA bitmap
  1509. * numbers in asm-offsets.c */
  1510. /* if ((%r19.SINGLESTEP_BIT)) { %r20.27=1} */
  1511. extru,= %r19,TIF_SINGLESTEP_PA_BIT,1,%r0
  1512. depi -1,27,1,%r20 /* R bit */
  1513. /* if ((%r19.BLOCKSTEP_BIT)) { %r20.7=1} */
  1514. extru,= %r19,TIF_BLOCKSTEP_PA_BIT,1,%r0
  1515. depi -1,7,1,%r20 /* T bit */
  1516. STREG %r20,TASK_PT_PSW(%r1)
  1517. /* Always store space registers, since sr3 can be changed (e.g. fork) */
  1518. mfsp %sr3,%r25
  1519. STREG %r25,TASK_PT_SR3(%r1)
  1520. STREG %r25,TASK_PT_SR4(%r1)
  1521. STREG %r25,TASK_PT_SR5(%r1)
  1522. STREG %r25,TASK_PT_SR6(%r1)
  1523. STREG %r25,TASK_PT_SR7(%r1)
  1524. STREG %r25,TASK_PT_IASQ0(%r1)
  1525. STREG %r25,TASK_PT_IASQ1(%r1)
  1526. /* XXX W bit??? */
  1527. /* Now if old D bit is clear, it means we didn't save all registers
  1528. * on syscall entry, so do that now. This only happens on TRACEME
  1529. * calls, or if someone attached to us while we were on a syscall.
  1530. * We could make this more efficient by not saving r3-r18, but
  1531. * then we wouldn't be able to use the common intr_restore path.
  1532. * It is only for traced processes anyway, so performance is not
  1533. * an issue.
  1534. */
  1535. bb,< %r2,30,pt_regs_ok /* Branch if D set */
  1536. ldo TASK_REGS(%r1),%r25
  1537. reg_save %r25 /* Save r3 to r18 */
  1538. /* Save the current sr */
  1539. mfsp %sr0,%r2
  1540. STREG %r2,TASK_PT_SR0(%r1)
  1541. /* Save the scratch sr */
  1542. mfsp %sr1,%r2
  1543. STREG %r2,TASK_PT_SR1(%r1)
  1544. /* sr2 should be set to zero for userspace syscalls */
  1545. STREG %r0,TASK_PT_SR2(%r1)
  1546. LDREG TASK_PT_GR31(%r1),%r2
  1547. depi 3,31,2,%r2 /* ensure return to user mode. */
  1548. STREG %r2,TASK_PT_IAOQ0(%r1)
  1549. ldo 4(%r2),%r2
  1550. STREG %r2,TASK_PT_IAOQ1(%r1)
  1551. b intr_restore
  1552. copy %r25,%r16
  1553. pt_regs_ok:
  1554. LDREG TASK_PT_IAOQ0(%r1),%r2
  1555. depi 3,31,2,%r2 /* ensure return to user mode. */
  1556. STREG %r2,TASK_PT_IAOQ0(%r1)
  1557. LDREG TASK_PT_IAOQ1(%r1),%r2
  1558. depi 3,31,2,%r2
  1559. STREG %r2,TASK_PT_IAOQ1(%r1)
  1560. b intr_restore
  1561. copy %r25,%r16
  1562. .import schedule,code
  1563. syscall_do_resched:
  1564. BL schedule,%r2
  1565. #ifdef CONFIG_64BIT
  1566. ldo -16(%r30),%r29 /* Reference param save area */
  1567. #else
  1568. nop
  1569. #endif
  1570. b syscall_check_resched /* if resched, we start over again */
  1571. nop
  1572. ENDPROC(syscall_exit)
  1573. #ifdef CONFIG_FUNCTION_TRACER
  1574. .import ftrace_function_trampoline,code
  1575. ENTRY(_mcount)
  1576. copy %r3, %arg2
  1577. b ftrace_function_trampoline
  1578. nop
  1579. ENDPROC(_mcount)
  1580. ENTRY(return_to_handler)
  1581. load32 return_trampoline, %rp
  1582. copy %ret0, %arg0
  1583. copy %ret1, %arg1
  1584. b ftrace_return_to_handler
  1585. nop
  1586. return_trampoline:
  1587. copy %ret0, %rp
  1588. copy %r23, %ret0
  1589. copy %r24, %ret1
  1590. .globl ftrace_stub
  1591. ftrace_stub:
  1592. bv %r0(%rp)
  1593. nop
  1594. ENDPROC(return_to_handler)
  1595. #endif /* CONFIG_FUNCTION_TRACER */
  1596. #ifdef CONFIG_IRQSTACKS
  1597. /* void call_on_stack(unsigned long param1, void *func,
  1598. unsigned long new_stack) */
  1599. ENTRY(call_on_stack)
  1600. copy %sp, %r1
  1601. /* Regarding the HPPA calling conventions for function pointers,
  1602. we assume the PIC register is not changed across call. For
  1603. CONFIG_64BIT, the argument pointer is left to point at the
  1604. argument region allocated for the call to call_on_stack. */
  1605. # ifdef CONFIG_64BIT
  1606. /* Switch to new stack. We allocate two 128 byte frames. */
  1607. ldo 256(%arg2), %sp
  1608. /* Save previous stack pointer and return pointer in frame marker */
  1609. STREG %rp, -144(%sp)
  1610. /* Calls always use function descriptor */
  1611. LDREG 16(%arg1), %arg1
  1612. bve,l (%arg1), %rp
  1613. STREG %r1, -136(%sp)
  1614. LDREG -144(%sp), %rp
  1615. bve (%rp)
  1616. LDREG -136(%sp), %sp
  1617. # else
  1618. /* Switch to new stack. We allocate two 64 byte frames. */
  1619. ldo 128(%arg2), %sp
  1620. /* Save previous stack pointer and return pointer in frame marker */
  1621. STREG %r1, -68(%sp)
  1622. STREG %rp, -84(%sp)
  1623. /* Calls use function descriptor if PLABEL bit is set */
  1624. bb,>=,n %arg1, 30, 1f
  1625. depwi 0,31,2, %arg1
  1626. LDREG 0(%arg1), %arg1
  1627. 1:
  1628. be,l 0(%sr4,%arg1), %sr0, %r31
  1629. copy %r31, %rp
  1630. LDREG -84(%sp), %rp
  1631. bv (%rp)
  1632. LDREG -68(%sp), %sp
  1633. # endif /* CONFIG_64BIT */
  1634. ENDPROC(call_on_stack)
  1635. #endif /* CONFIG_IRQSTACKS */
  1636. get_register:
  1637. /*
  1638. * get_register is used by the non access tlb miss handlers to
  1639. * copy the value of the general register specified in r8 into
  1640. * r1. This routine can't be used for shadowed registers, since
  1641. * the rfir will restore the original value. So, for the shadowed
  1642. * registers we put a -1 into r1 to indicate that the register
  1643. * should not be used (the register being copied could also have
  1644. * a -1 in it, but that is OK, it just means that we will have
  1645. * to use the slow path instead).
  1646. */
  1647. blr %r8,%r0
  1648. nop
  1649. bv %r0(%r25) /* r0 */
  1650. copy %r0,%r1
  1651. bv %r0(%r25) /* r1 - shadowed */
  1652. ldi -1,%r1
  1653. bv %r0(%r25) /* r2 */
  1654. copy %r2,%r1
  1655. bv %r0(%r25) /* r3 */
  1656. copy %r3,%r1
  1657. bv %r0(%r25) /* r4 */
  1658. copy %r4,%r1
  1659. bv %r0(%r25) /* r5 */
  1660. copy %r5,%r1
  1661. bv %r0(%r25) /* r6 */
  1662. copy %r6,%r1
  1663. bv %r0(%r25) /* r7 */
  1664. copy %r7,%r1
  1665. bv %r0(%r25) /* r8 - shadowed */
  1666. ldi -1,%r1
  1667. bv %r0(%r25) /* r9 - shadowed */
  1668. ldi -1,%r1
  1669. bv %r0(%r25) /* r10 */
  1670. copy %r10,%r1
  1671. bv %r0(%r25) /* r11 */
  1672. copy %r11,%r1
  1673. bv %r0(%r25) /* r12 */
  1674. copy %r12,%r1
  1675. bv %r0(%r25) /* r13 */
  1676. copy %r13,%r1
  1677. bv %r0(%r25) /* r14 */
  1678. copy %r14,%r1
  1679. bv %r0(%r25) /* r15 */
  1680. copy %r15,%r1
  1681. bv %r0(%r25) /* r16 - shadowed */
  1682. ldi -1,%r1
  1683. bv %r0(%r25) /* r17 - shadowed */
  1684. ldi -1,%r1
  1685. bv %r0(%r25) /* r18 */
  1686. copy %r18,%r1
  1687. bv %r0(%r25) /* r19 */
  1688. copy %r19,%r1
  1689. bv %r0(%r25) /* r20 */
  1690. copy %r20,%r1
  1691. bv %r0(%r25) /* r21 */
  1692. copy %r21,%r1
  1693. bv %r0(%r25) /* r22 */
  1694. copy %r22,%r1
  1695. bv %r0(%r25) /* r23 */
  1696. copy %r23,%r1
  1697. bv %r0(%r25) /* r24 - shadowed */
  1698. ldi -1,%r1
  1699. bv %r0(%r25) /* r25 - shadowed */
  1700. ldi -1,%r1
  1701. bv %r0(%r25) /* r26 */
  1702. copy %r26,%r1
  1703. bv %r0(%r25) /* r27 */
  1704. copy %r27,%r1
  1705. bv %r0(%r25) /* r28 */
  1706. copy %r28,%r1
  1707. bv %r0(%r25) /* r29 */
  1708. copy %r29,%r1
  1709. bv %r0(%r25) /* r30 */
  1710. copy %r30,%r1
  1711. bv %r0(%r25) /* r31 */
  1712. copy %r31,%r1
  1713. set_register:
  1714. /*
  1715. * set_register is used by the non access tlb miss handlers to
  1716. * copy the value of r1 into the general register specified in
  1717. * r8.
  1718. */
  1719. blr %r8,%r0
  1720. nop
  1721. bv %r0(%r25) /* r0 (silly, but it is a place holder) */
  1722. copy %r1,%r0
  1723. bv %r0(%r25) /* r1 */
  1724. copy %r1,%r1
  1725. bv %r0(%r25) /* r2 */
  1726. copy %r1,%r2
  1727. bv %r0(%r25) /* r3 */
  1728. copy %r1,%r3
  1729. bv %r0(%r25) /* r4 */
  1730. copy %r1,%r4
  1731. bv %r0(%r25) /* r5 */
  1732. copy %r1,%r5
  1733. bv %r0(%r25) /* r6 */
  1734. copy %r1,%r6
  1735. bv %r0(%r25) /* r7 */
  1736. copy %r1,%r7
  1737. bv %r0(%r25) /* r8 */
  1738. copy %r1,%r8
  1739. bv %r0(%r25) /* r9 */
  1740. copy %r1,%r9
  1741. bv %r0(%r25) /* r10 */
  1742. copy %r1,%r10
  1743. bv %r0(%r25) /* r11 */
  1744. copy %r1,%r11
  1745. bv %r0(%r25) /* r12 */
  1746. copy %r1,%r12
  1747. bv %r0(%r25) /* r13 */
  1748. copy %r1,%r13
  1749. bv %r0(%r25) /* r14 */
  1750. copy %r1,%r14
  1751. bv %r0(%r25) /* r15 */
  1752. copy %r1,%r15
  1753. bv %r0(%r25) /* r16 */
  1754. copy %r1,%r16
  1755. bv %r0(%r25) /* r17 */
  1756. copy %r1,%r17
  1757. bv %r0(%r25) /* r18 */
  1758. copy %r1,%r18
  1759. bv %r0(%r25) /* r19 */
  1760. copy %r1,%r19
  1761. bv %r0(%r25) /* r20 */
  1762. copy %r1,%r20
  1763. bv %r0(%r25) /* r21 */
  1764. copy %r1,%r21
  1765. bv %r0(%r25) /* r22 */
  1766. copy %r1,%r22
  1767. bv %r0(%r25) /* r23 */
  1768. copy %r1,%r23
  1769. bv %r0(%r25) /* r24 */
  1770. copy %r1,%r24
  1771. bv %r0(%r25) /* r25 */
  1772. copy %r1,%r25
  1773. bv %r0(%r25) /* r26 */
  1774. copy %r1,%r26
  1775. bv %r0(%r25) /* r27 */
  1776. copy %r1,%r27
  1777. bv %r0(%r25) /* r28 */
  1778. copy %r1,%r28
  1779. bv %r0(%r25) /* r29 */
  1780. copy %r1,%r29
  1781. bv %r0(%r25) /* r30 */
  1782. copy %r1,%r30
  1783. bv %r0(%r25) /* r31 */
  1784. copy %r1,%r31