entry.S 50 KB

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