entry.S 54 KB

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