entry.S 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335
  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 occured */
  165. spc = r24 /* space for which the trap occured */
  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. * Note: naitlb misses will be treated
  195. * as an ordinary itlb miss for now.
  196. * However, note that naitlb misses
  197. * have the faulting address in the
  198. * IOR/ISR.
  199. */
  200. .macro naitlb_11 code
  201. mfctl %isr,spc
  202. b itlb_miss_11
  203. mfctl %ior,va
  204. /* FIXME: If user causes a naitlb miss, the priv level may not be in
  205. * lower bits of va, where the itlb miss handler is expecting them
  206. */
  207. .align 32
  208. .endm
  209. #endif
  210. /*
  211. * naitlb miss interruption handler (parisc 2.0)
  212. *
  213. * Note: naitlb misses will be treated
  214. * as an ordinary itlb miss for now.
  215. * However, note that naitlb misses
  216. * have the faulting address in the
  217. * IOR/ISR.
  218. */
  219. .macro naitlb_20 code
  220. mfctl %isr,spc
  221. #ifdef CONFIG_64BIT
  222. b itlb_miss_20w
  223. #else
  224. b itlb_miss_20
  225. #endif
  226. mfctl %ior,va
  227. /* FIXME: If user causes a naitlb miss, the priv level may not be in
  228. * lower bits of va, where the itlb miss handler is expecting them
  229. */
  230. .align 32
  231. .endm
  232. #ifndef CONFIG_64BIT
  233. /*
  234. * dtlb miss interruption handler (parisc 1.1 - 32 bit)
  235. */
  236. .macro dtlb_11 code
  237. mfctl %isr, spc
  238. b dtlb_miss_11
  239. mfctl %ior, va
  240. .align 32
  241. .endm
  242. #endif
  243. /*
  244. * dtlb miss interruption handler (parisc 2.0)
  245. */
  246. .macro dtlb_20 code
  247. mfctl %isr, spc
  248. #ifdef CONFIG_64BIT
  249. b dtlb_miss_20w
  250. #else
  251. b dtlb_miss_20
  252. #endif
  253. mfctl %ior, va
  254. .align 32
  255. .endm
  256. #ifndef CONFIG_64BIT
  257. /* nadtlb miss interruption handler (parisc 1.1 - 32 bit) */
  258. .macro nadtlb_11 code
  259. mfctl %isr,spc
  260. b nadtlb_miss_11
  261. mfctl %ior,va
  262. .align 32
  263. .endm
  264. #endif
  265. /* nadtlb miss interruption handler (parisc 2.0) */
  266. .macro nadtlb_20 code
  267. mfctl %isr,spc
  268. #ifdef CONFIG_64BIT
  269. b nadtlb_miss_20w
  270. #else
  271. b nadtlb_miss_20
  272. #endif
  273. mfctl %ior,va
  274. .align 32
  275. .endm
  276. #ifndef CONFIG_64BIT
  277. /*
  278. * dirty bit trap interruption handler (parisc 1.1 - 32 bit)
  279. */
  280. .macro dbit_11 code
  281. mfctl %isr,spc
  282. b dbit_trap_11
  283. mfctl %ior,va
  284. .align 32
  285. .endm
  286. #endif
  287. /*
  288. * dirty bit trap interruption handler (parisc 2.0)
  289. */
  290. .macro dbit_20 code
  291. mfctl %isr,spc
  292. #ifdef CONFIG_64BIT
  293. b dbit_trap_20w
  294. #else
  295. b dbit_trap_20
  296. #endif
  297. mfctl %ior,va
  298. .align 32
  299. .endm
  300. /* In LP64, the space contains part of the upper 32 bits of the
  301. * fault. We have to extract this and place it in the va,
  302. * zeroing the corresponding bits in the space register */
  303. .macro space_adjust spc,va,tmp
  304. #ifdef CONFIG_64BIT
  305. extrd,u \spc,63,SPACEID_SHIFT,\tmp
  306. depd %r0,63,SPACEID_SHIFT,\spc
  307. depd \tmp,31,SPACEID_SHIFT,\va
  308. #endif
  309. .endm
  310. .import swapper_pg_dir,code
  311. /* Get the pgd. For faults on space zero (kernel space), this
  312. * is simply swapper_pg_dir. For user space faults, the
  313. * pgd is stored in %cr25 */
  314. .macro get_pgd spc,reg
  315. ldil L%PA(swapper_pg_dir),\reg
  316. ldo R%PA(swapper_pg_dir)(\reg),\reg
  317. or,COND(=) %r0,\spc,%r0
  318. mfctl %cr25,\reg
  319. .endm
  320. /*
  321. space_check(spc,tmp,fault)
  322. spc - The space we saw the fault with.
  323. tmp - The place to store the current space.
  324. fault - Function to call on failure.
  325. Only allow faults on different spaces from the
  326. currently active one if we're the kernel
  327. */
  328. .macro space_check spc,tmp,fault
  329. mfsp %sr7,\tmp
  330. or,COND(<>) %r0,\spc,%r0 /* user may execute gateway page
  331. * as kernel, so defeat the space
  332. * check if it is */
  333. copy \spc,\tmp
  334. or,COND(=) %r0,\tmp,%r0 /* nullify if executing as kernel */
  335. cmpb,COND(<>),n \tmp,\spc,\fault
  336. .endm
  337. /* Look up a PTE in a 2-Level scheme (faulting at each
  338. * level if the entry isn't present
  339. *
  340. * NOTE: we use ldw even for LP64, since the short pointers
  341. * can address up to 1TB
  342. */
  343. .macro L2_ptep pmd,pte,index,va,fault
  344. #if PT_NLEVELS == 3
  345. extru \va,31-ASM_PMD_SHIFT,ASM_BITS_PER_PMD,\index
  346. #else
  347. extru \va,31-ASM_PGDIR_SHIFT,ASM_BITS_PER_PGD,\index
  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
  359. LDREG %r0(\pmd),\pte /* pmd is now 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 PT_NLEVELS == 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. /* Set the _PAGE_ACCESSED bit of the PTE. Be clever and
  390. * don't needlessly dirty the cache line if it was already set */
  391. .macro update_ptep ptep,pte,tmp,tmp1
  392. ldi _PAGE_ACCESSED,\tmp1
  393. or \tmp1,\pte,\tmp
  394. and,COND(<>) \tmp1,\pte,%r0
  395. STREG \tmp,0(\ptep)
  396. .endm
  397. /* Set the dirty bit (and accessed bit). No need to be
  398. * clever, this is only used from the dirty fault */
  399. .macro update_dirty ptep,pte,tmp
  400. ldi _PAGE_ACCESSED|_PAGE_DIRTY,\tmp
  401. or \tmp,\pte,\pte
  402. STREG \pte,0(\ptep)
  403. .endm
  404. /* bitshift difference between a PFN (based on kernel's PAGE_SIZE)
  405. * to a CPU TLB 4k PFN (4k => 12 bits to shift) */
  406. #define PAGE_ADD_SHIFT (PAGE_SHIFT-12)
  407. /* Drop prot bits and convert to page addr for iitlbt and idtlbt */
  408. .macro convert_for_tlb_insert20 pte
  409. extrd,u \pte,(63-ASM_PFN_PTE_SHIFT)+(63-58)+PAGE_ADD_SHIFT,\
  410. 64-PAGE_SHIFT-PAGE_ADD_SHIFT,\pte
  411. depdi _PAGE_SIZE_ENCODING_DEFAULT,63,\
  412. (63-58)+PAGE_ADD_SHIFT,\pte
  413. .endm
  414. /* Convert the pte and prot to tlb insertion values. How
  415. * this happens is quite subtle, read below */
  416. .macro make_insert_tlb spc,pte,prot
  417. space_to_prot \spc \prot /* create prot id from space */
  418. /* The following is the real subtlety. This is depositing
  419. * T <-> _PAGE_REFTRAP
  420. * D <-> _PAGE_DIRTY
  421. * B <-> _PAGE_DMB (memory break)
  422. *
  423. * Then incredible subtlety: The access rights are
  424. * _PAGE_GATEWAY _PAGE_EXEC _PAGE_READ
  425. * See 3-14 of the parisc 2.0 manual
  426. *
  427. * Finally, _PAGE_READ goes in the top bit of PL1 (so we
  428. * trigger an access rights trap in user space if the user
  429. * tries to read an unreadable page */
  430. depd \pte,8,7,\prot
  431. /* PAGE_USER indicates the page can be read with user privileges,
  432. * so deposit X1|11 to PL1|PL2 (remember the upper bit of PL1
  433. * contains _PAGE_READ */
  434. extrd,u,*= \pte,_PAGE_USER_BIT+32,1,%r0
  435. depdi 7,11,3,\prot
  436. /* If we're a gateway page, drop PL2 back to zero for promotion
  437. * to kernel privilege (so we can execute the page as kernel).
  438. * Any privilege promotion page always denys read and write */
  439. extrd,u,*= \pte,_PAGE_GATEWAY_BIT+32,1,%r0
  440. depd %r0,11,2,\prot /* If Gateway, Set PL2 to 0 */
  441. /* Enforce uncacheable pages.
  442. * This should ONLY be use for MMIO on PA 2.0 machines.
  443. * Memory/DMA is cache coherent on all PA2.0 machines we support
  444. * (that means T-class is NOT supported) and the memory controllers
  445. * on most of those machines only handles cache transactions.
  446. */
  447. extrd,u,*= \pte,_PAGE_NO_CACHE_BIT+32,1,%r0
  448. depdi 1,12,1,\prot
  449. /* Drop prot bits and convert to page addr for iitlbt and idtlbt */
  450. convert_for_tlb_insert20 \pte
  451. .endm
  452. /* Identical macro to make_insert_tlb above, except it
  453. * makes the tlb entry for the differently formatted pa11
  454. * insertion instructions */
  455. .macro make_insert_tlb_11 spc,pte,prot
  456. zdep \spc,30,15,\prot
  457. dep \pte,8,7,\prot
  458. extru,= \pte,_PAGE_NO_CACHE_BIT,1,%r0
  459. depi 1,12,1,\prot
  460. extru,= \pte,_PAGE_USER_BIT,1,%r0
  461. depi 7,11,3,\prot /* Set for user space (1 rsvd for read) */
  462. extru,= \pte,_PAGE_GATEWAY_BIT,1,%r0
  463. depi 0,11,2,\prot /* If Gateway, Set PL2 to 0 */
  464. /* Get rid of prot bits and convert to page addr for iitlba */
  465. depi 0,31,ASM_PFN_PTE_SHIFT,\pte
  466. SHRREG \pte,(ASM_PFN_PTE_SHIFT-(31-26)),\pte
  467. .endm
  468. /* This is for ILP32 PA2.0 only. The TLB insertion needs
  469. * to extend into I/O space if the address is 0xfXXXXXXX
  470. * so we extend the f's into the top word of the pte in
  471. * this case */
  472. .macro f_extend pte,tmp
  473. extrd,s \pte,42,4,\tmp
  474. addi,<> 1,\tmp,%r0
  475. extrd,s \pte,63,25,\pte
  476. .endm
  477. /* The alias region is an 8MB aligned 16MB to do clear and
  478. * copy user pages at addresses congruent with the user
  479. * virtual address.
  480. *
  481. * To use the alias page, you set %r26 up with the to TLB
  482. * entry (identifying the physical page) and %r23 up with
  483. * the from tlb entry (or nothing if only a to entry---for
  484. * clear_user_page_asm) */
  485. .macro do_alias spc,tmp,tmp1,va,pte,prot,fault
  486. cmpib,COND(<>),n 0,\spc,\fault
  487. ldil L%(TMPALIAS_MAP_START),\tmp
  488. #if defined(CONFIG_64BIT) && (TMPALIAS_MAP_START >= 0x80000000)
  489. /* on LP64, ldi will sign extend into the upper 32 bits,
  490. * which is behaviour we don't want */
  491. depdi 0,31,32,\tmp
  492. #endif
  493. copy \va,\tmp1
  494. depi 0,31,23,\tmp1
  495. cmpb,COND(<>),n \tmp,\tmp1,\fault
  496. ldi (_PAGE_DIRTY|_PAGE_WRITE|_PAGE_READ),\prot
  497. depd,z \prot,8,7,\prot
  498. /*
  499. * OK, it is in the temp alias region, check whether "from" or "to".
  500. * Check "subtle" note in pacache.S re: r23/r26.
  501. */
  502. #ifdef CONFIG_64BIT
  503. extrd,u,*= \va,41,1,%r0
  504. #else
  505. extrw,u,= \va,9,1,%r0
  506. #endif
  507. or,COND(tr) %r23,%r0,\pte
  508. or %r26,%r0,\pte
  509. .endm
  510. /*
  511. * Align fault_vector_20 on 4K boundary so that both
  512. * fault_vector_11 and fault_vector_20 are on the
  513. * same page. This is only necessary as long as we
  514. * write protect the kernel text, which we may stop
  515. * doing once we use large page translations to cover
  516. * the static part of the kernel address space.
  517. */
  518. .text
  519. .align PAGE_SIZE
  520. ENTRY(fault_vector_20)
  521. /* First vector is invalid (0) */
  522. .ascii "cows can fly"
  523. .byte 0
  524. .align 32
  525. hpmc 1
  526. def 2
  527. def 3
  528. extint 4
  529. def 5
  530. itlb_20 6
  531. def 7
  532. def 8
  533. def 9
  534. def 10
  535. def 11
  536. def 12
  537. def 13
  538. def 14
  539. dtlb_20 15
  540. #if 0
  541. naitlb_20 16
  542. #else
  543. def 16
  544. #endif
  545. nadtlb_20 17
  546. def 18
  547. def 19
  548. dbit_20 20
  549. def 21
  550. def 22
  551. def 23
  552. def 24
  553. def 25
  554. def 26
  555. def 27
  556. def 28
  557. def 29
  558. def 30
  559. def 31
  560. END(fault_vector_20)
  561. #ifndef CONFIG_64BIT
  562. .align 2048
  563. ENTRY(fault_vector_11)
  564. /* First vector is invalid (0) */
  565. .ascii "cows can fly"
  566. .byte 0
  567. .align 32
  568. hpmc 1
  569. def 2
  570. def 3
  571. extint 4
  572. def 5
  573. itlb_11 6
  574. def 7
  575. def 8
  576. def 9
  577. def 10
  578. def 11
  579. def 12
  580. def 13
  581. def 14
  582. dtlb_11 15
  583. #if 0
  584. naitlb_11 16
  585. #else
  586. def 16
  587. #endif
  588. nadtlb_11 17
  589. def 18
  590. def 19
  591. dbit_11 20
  592. def 21
  593. def 22
  594. def 23
  595. def 24
  596. def 25
  597. def 26
  598. def 27
  599. def 28
  600. def 29
  601. def 30
  602. def 31
  603. END(fault_vector_11)
  604. #endif
  605. .import handle_interruption,code
  606. .import do_cpu_irq_mask,code
  607. /*
  608. * r26 = function to be called
  609. * r25 = argument to pass in
  610. * r24 = flags for do_fork()
  611. *
  612. * Kernel threads don't ever return, so they don't need
  613. * a true register context. We just save away the arguments
  614. * for copy_thread/ret_ to properly set up the child.
  615. */
  616. #define CLONE_VM 0x100 /* Must agree with <linux/sched.h> */
  617. #define CLONE_UNTRACED 0x00800000
  618. .import do_fork
  619. ENTRY(__kernel_thread)
  620. STREG %r2, -RP_OFFSET(%r30)
  621. copy %r30, %r1
  622. ldo PT_SZ_ALGN(%r30),%r30
  623. #ifdef CONFIG_64BIT
  624. /* Yo, function pointers in wide mode are little structs... -PB */
  625. ldd 24(%r26), %r2
  626. STREG %r2, PT_GR27(%r1) /* Store childs %dp */
  627. ldd 16(%r26), %r26
  628. STREG %r22, PT_GR22(%r1) /* save r22 (arg5) */
  629. copy %r0, %r22 /* user_tid */
  630. #endif
  631. STREG %r26, PT_GR26(%r1) /* Store function & argument for child */
  632. STREG %r25, PT_GR25(%r1)
  633. ldil L%CLONE_UNTRACED, %r26
  634. ldo CLONE_VM(%r26), %r26 /* Force CLONE_VM since only init_mm */
  635. or %r26, %r24, %r26 /* will have kernel mappings. */
  636. ldi 1, %r25 /* stack_start, signals kernel thread */
  637. stw %r0, -52(%r30) /* user_tid */
  638. #ifdef CONFIG_64BIT
  639. ldo -16(%r30),%r29 /* Reference param save area */
  640. #endif
  641. BL do_fork, %r2
  642. copy %r1, %r24 /* pt_regs */
  643. /* Parent Returns here */
  644. LDREG -PT_SZ_ALGN-RP_OFFSET(%r30), %r2
  645. ldo -PT_SZ_ALGN(%r30), %r30
  646. bv %r0(%r2)
  647. nop
  648. ENDPROC(__kernel_thread)
  649. /*
  650. * Child Returns here
  651. *
  652. * copy_thread moved args from temp save area set up above
  653. * into task save area.
  654. */
  655. ENTRY(ret_from_kernel_thread)
  656. /* Call schedule_tail first though */
  657. BL schedule_tail, %r2
  658. nop
  659. LDREG TI_TASK-THREAD_SZ_ALGN(%r30), %r1
  660. LDREG TASK_PT_GR25(%r1), %r26
  661. #ifdef CONFIG_64BIT
  662. LDREG TASK_PT_GR27(%r1), %r27
  663. LDREG TASK_PT_GR22(%r1), %r22
  664. #endif
  665. LDREG TASK_PT_GR26(%r1), %r1
  666. ble 0(%sr7, %r1)
  667. copy %r31, %r2
  668. #ifdef CONFIG_64BIT
  669. ldo -16(%r30),%r29 /* Reference param save area */
  670. loadgp /* Thread could have been in a module */
  671. #endif
  672. #ifndef CONFIG_64BIT
  673. b sys_exit
  674. #else
  675. load32 sys_exit, %r1
  676. bv %r0(%r1)
  677. #endif
  678. ldi 0, %r26
  679. ENDPROC(ret_from_kernel_thread)
  680. .import sys_execve, code
  681. ENTRY(__execve)
  682. copy %r2, %r15
  683. copy %r30, %r16
  684. ldo PT_SZ_ALGN(%r30), %r30
  685. STREG %r26, PT_GR26(%r16)
  686. STREG %r25, PT_GR25(%r16)
  687. STREG %r24, PT_GR24(%r16)
  688. #ifdef CONFIG_64BIT
  689. ldo -16(%r30),%r29 /* Reference param save area */
  690. #endif
  691. BL sys_execve, %r2
  692. copy %r16, %r26
  693. cmpib,=,n 0,%r28,intr_return /* forward */
  694. /* yes, this will trap and die. */
  695. copy %r15, %r2
  696. copy %r16, %r30
  697. bv %r0(%r2)
  698. nop
  699. ENDPROC(__execve)
  700. /*
  701. * struct task_struct *_switch_to(struct task_struct *prev,
  702. * struct task_struct *next)
  703. *
  704. * switch kernel stacks and return prev */
  705. ENTRY(_switch_to)
  706. STREG %r2, -RP_OFFSET(%r30)
  707. callee_save_float
  708. callee_save
  709. load32 _switch_to_ret, %r2
  710. STREG %r2, TASK_PT_KPC(%r26)
  711. LDREG TASK_PT_KPC(%r25), %r2
  712. STREG %r30, TASK_PT_KSP(%r26)
  713. LDREG TASK_PT_KSP(%r25), %r30
  714. LDREG TASK_THREAD_INFO(%r25), %r25
  715. bv %r0(%r2)
  716. mtctl %r25,%cr30
  717. _switch_to_ret:
  718. mtctl %r0, %cr0 /* Needed for single stepping */
  719. callee_rest
  720. callee_rest_float
  721. LDREG -RP_OFFSET(%r30), %r2
  722. bv %r0(%r2)
  723. copy %r26, %r28
  724. ENDPROC(_switch_to)
  725. /*
  726. * Common rfi return path for interruptions, kernel execve, and
  727. * sys_rt_sigreturn (sometimes). The sys_rt_sigreturn syscall will
  728. * return via this path if the signal was received when the process
  729. * was running; if the process was blocked on a syscall then the
  730. * normal syscall_exit path is used. All syscalls for traced
  731. * proceses exit via intr_restore.
  732. *
  733. * XXX If any syscalls that change a processes space id ever exit
  734. * this way, then we will need to copy %sr3 in to PT_SR[3..7], and
  735. * adjust IASQ[0..1].
  736. *
  737. */
  738. .align PAGE_SIZE
  739. ENTRY(syscall_exit_rfi)
  740. mfctl %cr30,%r16
  741. LDREG TI_TASK(%r16), %r16 /* thread_info -> task_struct */
  742. ldo TASK_REGS(%r16),%r16
  743. /* Force iaoq to userspace, as the user has had access to our current
  744. * context via sigcontext. Also Filter the PSW for the same reason.
  745. */
  746. LDREG PT_IAOQ0(%r16),%r19
  747. depi 3,31,2,%r19
  748. STREG %r19,PT_IAOQ0(%r16)
  749. LDREG PT_IAOQ1(%r16),%r19
  750. depi 3,31,2,%r19
  751. STREG %r19,PT_IAOQ1(%r16)
  752. LDREG PT_PSW(%r16),%r19
  753. load32 USER_PSW_MASK,%r1
  754. #ifdef CONFIG_64BIT
  755. load32 USER_PSW_HI_MASK,%r20
  756. depd %r20,31,32,%r1
  757. #endif
  758. and %r19,%r1,%r19 /* Mask out bits that user shouldn't play with */
  759. load32 USER_PSW,%r1
  760. or %r19,%r1,%r19 /* Make sure default USER_PSW bits are set */
  761. STREG %r19,PT_PSW(%r16)
  762. /*
  763. * If we aren't being traced, we never saved space registers
  764. * (we don't store them in the sigcontext), so set them
  765. * to "proper" values now (otherwise we'll wind up restoring
  766. * whatever was last stored in the task structure, which might
  767. * be inconsistent if an interrupt occured while on the gateway
  768. * page). Note that we may be "trashing" values the user put in
  769. * them, but we don't support the user changing them.
  770. */
  771. STREG %r0,PT_SR2(%r16)
  772. mfsp %sr3,%r19
  773. STREG %r19,PT_SR0(%r16)
  774. STREG %r19,PT_SR1(%r16)
  775. STREG %r19,PT_SR3(%r16)
  776. STREG %r19,PT_SR4(%r16)
  777. STREG %r19,PT_SR5(%r16)
  778. STREG %r19,PT_SR6(%r16)
  779. STREG %r19,PT_SR7(%r16)
  780. intr_return:
  781. /* NOTE: Need to enable interrupts incase we schedule. */
  782. ssm PSW_SM_I, %r0
  783. intr_check_resched:
  784. /* check for reschedule */
  785. mfctl %cr30,%r1
  786. LDREG TI_FLAGS(%r1),%r19 /* sched.h: TIF_NEED_RESCHED */
  787. bb,<,n %r19,31-TIF_NEED_RESCHED,intr_do_resched /* forward */
  788. .import do_notify_resume,code
  789. intr_check_sig:
  790. /* As above */
  791. mfctl %cr30,%r1
  792. LDREG TI_FLAGS(%r1),%r19
  793. ldi (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK|_TIF_NOTIFY_RESUME), %r20
  794. and,COND(<>) %r19, %r20, %r0
  795. b,n intr_restore /* skip past if we've nothing to do */
  796. /* This check is critical to having LWS
  797. * working. The IASQ is zero on the gateway
  798. * page and we cannot deliver any signals until
  799. * we get off the gateway page.
  800. *
  801. * Only do signals if we are returning to user space
  802. */
  803. LDREG PT_IASQ0(%r16), %r20
  804. cmpib,COND(=),n 0,%r20,intr_restore /* backward */
  805. LDREG PT_IASQ1(%r16), %r20
  806. cmpib,COND(=),n 0,%r20,intr_restore /* backward */
  807. copy %r0, %r25 /* long in_syscall = 0 */
  808. #ifdef CONFIG_64BIT
  809. ldo -16(%r30),%r29 /* Reference param save area */
  810. #endif
  811. BL do_notify_resume,%r2
  812. copy %r16, %r26 /* struct pt_regs *regs */
  813. b,n intr_check_sig
  814. intr_restore:
  815. copy %r16,%r29
  816. ldo PT_FR31(%r29),%r1
  817. rest_fp %r1
  818. rest_general %r29
  819. /* inverse of virt_map */
  820. pcxt_ssm_bug
  821. rsm PSW_SM_QUIET,%r0 /* prepare for rfi */
  822. tophys_r1 %r29
  823. /* Restore space id's and special cr's from PT_REGS
  824. * structure pointed to by r29
  825. */
  826. rest_specials %r29
  827. /* IMPORTANT: rest_stack restores r29 last (we are using it)!
  828. * It also restores r1 and r30.
  829. */
  830. rest_stack
  831. rfi
  832. nop
  833. #ifndef CONFIG_PREEMPT
  834. # define intr_do_preempt intr_restore
  835. #endif /* !CONFIG_PREEMPT */
  836. .import schedule,code
  837. intr_do_resched:
  838. /* Only call schedule on return to userspace. If we're returning
  839. * to kernel space, we may schedule if CONFIG_PREEMPT, otherwise
  840. * we jump back to intr_restore.
  841. */
  842. LDREG PT_IASQ0(%r16), %r20
  843. cmpib,COND(=) 0, %r20, intr_do_preempt
  844. nop
  845. LDREG PT_IASQ1(%r16), %r20
  846. cmpib,COND(=) 0, %r20, intr_do_preempt
  847. nop
  848. #ifdef CONFIG_64BIT
  849. ldo -16(%r30),%r29 /* Reference param save area */
  850. #endif
  851. ldil L%intr_check_sig, %r2
  852. #ifndef CONFIG_64BIT
  853. b schedule
  854. #else
  855. load32 schedule, %r20
  856. bv %r0(%r20)
  857. #endif
  858. ldo R%intr_check_sig(%r2), %r2
  859. /* preempt the current task on returning to kernel
  860. * mode from an interrupt, iff need_resched is set,
  861. * and preempt_count is 0. otherwise, we continue on
  862. * our merry way back to the current running task.
  863. */
  864. #ifdef CONFIG_PREEMPT
  865. .import preempt_schedule_irq,code
  866. intr_do_preempt:
  867. rsm PSW_SM_I, %r0 /* disable interrupts */
  868. /* current_thread_info()->preempt_count */
  869. mfctl %cr30, %r1
  870. LDREG TI_PRE_COUNT(%r1), %r19
  871. cmpib,COND(<>) 0, %r19, intr_restore /* if preempt_count > 0 */
  872. nop /* prev insn branched backwards */
  873. /* check if we interrupted a critical path */
  874. LDREG PT_PSW(%r16), %r20
  875. bb,<,n %r20, 31 - PSW_SM_I, intr_restore
  876. nop
  877. BL preempt_schedule_irq, %r2
  878. nop
  879. b,n intr_restore /* ssm PSW_SM_I done by intr_restore */
  880. #endif /* CONFIG_PREEMPT */
  881. /*
  882. * External interrupts.
  883. */
  884. intr_extint:
  885. cmpib,COND(=),n 0,%r16,1f
  886. get_stack_use_cr30
  887. b,n 2f
  888. 1:
  889. get_stack_use_r30
  890. 2:
  891. save_specials %r29
  892. virt_map
  893. save_general %r29
  894. ldo PT_FR0(%r29), %r24
  895. save_fp %r24
  896. loadgp
  897. copy %r29, %r26 /* arg0 is pt_regs */
  898. copy %r29, %r16 /* save pt_regs */
  899. ldil L%intr_return, %r2
  900. #ifdef CONFIG_64BIT
  901. ldo -16(%r30),%r29 /* Reference param save area */
  902. #endif
  903. b do_cpu_irq_mask
  904. ldo R%intr_return(%r2), %r2 /* return to intr_return, not here */
  905. ENDPROC(syscall_exit_rfi)
  906. /* Generic interruptions (illegal insn, unaligned, page fault, etc) */
  907. ENTRY(intr_save) /* for os_hpmc */
  908. mfsp %sr7,%r16
  909. cmpib,COND(=),n 0,%r16,1f
  910. get_stack_use_cr30
  911. b 2f
  912. copy %r8,%r26
  913. 1:
  914. get_stack_use_r30
  915. copy %r8,%r26
  916. 2:
  917. save_specials %r29
  918. /* If this trap is a itlb miss, skip saving/adjusting isr/ior */
  919. /*
  920. * FIXME: 1) Use a #define for the hardwired "6" below (and in
  921. * traps.c.
  922. * 2) Once we start executing code above 4 Gb, we need
  923. * to adjust iasq/iaoq here in the same way we
  924. * adjust isr/ior below.
  925. */
  926. cmpib,COND(=),n 6,%r26,skip_save_ior
  927. mfctl %cr20, %r16 /* isr */
  928. nop /* serialize mfctl on PA 2.0 to avoid 4 cycle penalty */
  929. mfctl %cr21, %r17 /* ior */
  930. #ifdef CONFIG_64BIT
  931. /*
  932. * If the interrupted code was running with W bit off (32 bit),
  933. * clear the b bits (bits 0 & 1) in the ior.
  934. * save_specials left ipsw value in r8 for us to test.
  935. */
  936. extrd,u,*<> %r8,PSW_W_BIT,1,%r0
  937. depdi 0,1,2,%r17
  938. /*
  939. * FIXME: This code has hardwired assumptions about the split
  940. * between space bits and offset bits. This will change
  941. * when we allow alternate page sizes.
  942. */
  943. /* adjust isr/ior. */
  944. extrd,u %r16,63,SPACEID_SHIFT,%r1 /* get high bits from isr for ior */
  945. depd %r1,31,SPACEID_SHIFT,%r17 /* deposit them into ior */
  946. depdi 0,63,SPACEID_SHIFT,%r16 /* clear them from isr */
  947. #endif
  948. STREG %r16, PT_ISR(%r29)
  949. STREG %r17, PT_IOR(%r29)
  950. skip_save_ior:
  951. virt_map
  952. save_general %r29
  953. ldo PT_FR0(%r29), %r25
  954. save_fp %r25
  955. loadgp
  956. copy %r29, %r25 /* arg1 is pt_regs */
  957. #ifdef CONFIG_64BIT
  958. ldo -16(%r30),%r29 /* Reference param save area */
  959. #endif
  960. ldil L%intr_check_sig, %r2
  961. copy %r25, %r16 /* save pt_regs */
  962. b handle_interruption
  963. ldo R%intr_check_sig(%r2), %r2
  964. ENDPROC(intr_save)
  965. /*
  966. * Note for all tlb miss handlers:
  967. *
  968. * cr24 contains a pointer to the kernel address space
  969. * page directory.
  970. *
  971. * cr25 contains a pointer to the current user address
  972. * space page directory.
  973. *
  974. * sr3 will contain the space id of the user address space
  975. * of the current running thread while that thread is
  976. * running in the kernel.
  977. */
  978. /*
  979. * register number allocations. Note that these are all
  980. * in the shadowed registers
  981. */
  982. t0 = r1 /* temporary register 0 */
  983. va = r8 /* virtual address for which the trap occured */
  984. t1 = r9 /* temporary register 1 */
  985. pte = r16 /* pte/phys page # */
  986. prot = r17 /* prot bits */
  987. spc = r24 /* space for which the trap occured */
  988. ptp = r25 /* page directory/page table pointer */
  989. #ifdef CONFIG_64BIT
  990. dtlb_miss_20w:
  991. space_adjust spc,va,t0
  992. get_pgd spc,ptp
  993. space_check spc,t0,dtlb_fault
  994. L3_ptep ptp,pte,t0,va,dtlb_check_alias_20w
  995. update_ptep ptp,pte,t0,t1
  996. make_insert_tlb spc,pte,prot
  997. idtlbt pte,prot
  998. rfir
  999. nop
  1000. dtlb_check_alias_20w:
  1001. do_alias spc,t0,t1,va,pte,prot,dtlb_fault
  1002. idtlbt pte,prot
  1003. rfir
  1004. nop
  1005. nadtlb_miss_20w:
  1006. space_adjust spc,va,t0
  1007. get_pgd spc,ptp
  1008. space_check spc,t0,nadtlb_fault
  1009. L3_ptep ptp,pte,t0,va,nadtlb_check_flush_20w
  1010. update_ptep ptp,pte,t0,t1
  1011. make_insert_tlb spc,pte,prot
  1012. idtlbt pte,prot
  1013. rfir
  1014. nop
  1015. nadtlb_check_flush_20w:
  1016. bb,>=,n pte,_PAGE_FLUSH_BIT,nadtlb_emulate
  1017. /* Insert a "flush only" translation */
  1018. depdi,z 7,7,3,prot
  1019. depdi 1,10,1,prot
  1020. /* Drop prot bits from pte and convert to page addr for idtlbt */
  1021. convert_for_tlb_insert20 pte
  1022. idtlbt pte,prot
  1023. rfir
  1024. nop
  1025. #else
  1026. dtlb_miss_11:
  1027. get_pgd spc,ptp
  1028. space_check spc,t0,dtlb_fault
  1029. L2_ptep ptp,pte,t0,va,dtlb_check_alias_11
  1030. update_ptep ptp,pte,t0,t1
  1031. make_insert_tlb_11 spc,pte,prot
  1032. mfsp %sr1,t0 /* Save sr1 so we can use it in tlb inserts */
  1033. mtsp spc,%sr1
  1034. idtlba pte,(%sr1,va)
  1035. idtlbp prot,(%sr1,va)
  1036. mtsp t0, %sr1 /* Restore sr1 */
  1037. rfir
  1038. nop
  1039. dtlb_check_alias_11:
  1040. /* Check to see if fault is in the temporary alias region */
  1041. cmpib,<>,n 0,spc,dtlb_fault /* forward */
  1042. ldil L%(TMPALIAS_MAP_START),t0
  1043. copy va,t1
  1044. depwi 0,31,23,t1
  1045. cmpb,<>,n t0,t1,dtlb_fault /* forward */
  1046. ldi (_PAGE_DIRTY|_PAGE_WRITE|_PAGE_READ),prot
  1047. depw,z prot,8,7,prot
  1048. /*
  1049. * OK, it is in the temp alias region, check whether "from" or "to".
  1050. * Check "subtle" note in pacache.S re: r23/r26.
  1051. */
  1052. extrw,u,= va,9,1,r0
  1053. or,tr %r23,%r0,pte /* If "from" use "from" page */
  1054. or %r26,%r0,pte /* else "to", use "to" page */
  1055. idtlba pte,(va)
  1056. idtlbp prot,(va)
  1057. rfir
  1058. nop
  1059. nadtlb_miss_11:
  1060. get_pgd spc,ptp
  1061. space_check spc,t0,nadtlb_fault
  1062. L2_ptep ptp,pte,t0,va,nadtlb_check_flush_11
  1063. update_ptep ptp,pte,t0,t1
  1064. make_insert_tlb_11 spc,pte,prot
  1065. mfsp %sr1,t0 /* Save sr1 so we can use it in tlb inserts */
  1066. mtsp spc,%sr1
  1067. idtlba pte,(%sr1,va)
  1068. idtlbp prot,(%sr1,va)
  1069. mtsp t0, %sr1 /* Restore sr1 */
  1070. rfir
  1071. nop
  1072. nadtlb_check_flush_11:
  1073. bb,>=,n pte,_PAGE_FLUSH_BIT,nadtlb_emulate
  1074. /* Insert a "flush only" translation */
  1075. zdepi 7,7,3,prot
  1076. depi 1,10,1,prot
  1077. /* Get rid of prot bits and convert to page addr for idtlba */
  1078. depi 0,31,ASM_PFN_PTE_SHIFT,pte
  1079. SHRREG pte,(ASM_PFN_PTE_SHIFT-(31-26)),pte
  1080. mfsp %sr1,t0 /* Save sr1 so we can use it in tlb inserts */
  1081. mtsp spc,%sr1
  1082. idtlba pte,(%sr1,va)
  1083. idtlbp prot,(%sr1,va)
  1084. mtsp t0, %sr1 /* Restore sr1 */
  1085. rfir
  1086. nop
  1087. dtlb_miss_20:
  1088. space_adjust spc,va,t0
  1089. get_pgd spc,ptp
  1090. space_check spc,t0,dtlb_fault
  1091. L2_ptep ptp,pte,t0,va,dtlb_check_alias_20
  1092. update_ptep ptp,pte,t0,t1
  1093. make_insert_tlb spc,pte,prot
  1094. f_extend pte,t0
  1095. idtlbt pte,prot
  1096. rfir
  1097. nop
  1098. dtlb_check_alias_20:
  1099. do_alias spc,t0,t1,va,pte,prot,dtlb_fault
  1100. idtlbt pte,prot
  1101. rfir
  1102. nop
  1103. nadtlb_miss_20:
  1104. get_pgd spc,ptp
  1105. space_check spc,t0,nadtlb_fault
  1106. L2_ptep ptp,pte,t0,va,nadtlb_check_flush_20
  1107. update_ptep ptp,pte,t0,t1
  1108. make_insert_tlb spc,pte,prot
  1109. f_extend pte,t0
  1110. idtlbt pte,prot
  1111. rfir
  1112. nop
  1113. nadtlb_check_flush_20:
  1114. bb,>=,n pte,_PAGE_FLUSH_BIT,nadtlb_emulate
  1115. /* Insert a "flush only" translation */
  1116. depdi,z 7,7,3,prot
  1117. depdi 1,10,1,prot
  1118. /* Drop prot bits from pte and convert to page addr for idtlbt */
  1119. convert_for_tlb_insert20 pte
  1120. idtlbt pte,prot
  1121. rfir
  1122. nop
  1123. #endif
  1124. nadtlb_emulate:
  1125. /*
  1126. * Non access misses can be caused by fdc,fic,pdc,lpa,probe and
  1127. * probei instructions. We don't want to fault for these
  1128. * instructions (not only does it not make sense, it can cause
  1129. * deadlocks, since some flushes are done with the mmap
  1130. * semaphore held). If the translation doesn't exist, we can't
  1131. * insert a translation, so have to emulate the side effects
  1132. * of the instruction. Since we don't insert a translation
  1133. * we can get a lot of faults during a flush loop, so it makes
  1134. * sense to try to do it here with minimum overhead. We only
  1135. * emulate fdc,fic,pdc,probew,prober instructions whose base
  1136. * and index registers are not shadowed. We defer everything
  1137. * else to the "slow" path.
  1138. */
  1139. mfctl %cr19,%r9 /* Get iir */
  1140. /* PA 2.0 Arch Ref. Book pg 382 has a good description of the insn bits.
  1141. Checks for fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw */
  1142. /* Checks for fdc,fdce,pdc,"fic,4f" only */
  1143. ldi 0x280,%r16
  1144. and %r9,%r16,%r17
  1145. cmpb,<>,n %r16,%r17,nadtlb_probe_check
  1146. bb,>=,n %r9,26,nadtlb_nullify /* m bit not set, just nullify */
  1147. BL get_register,%r25
  1148. extrw,u %r9,15,5,%r8 /* Get index register # */
  1149. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1150. copy %r1,%r24
  1151. BL get_register,%r25
  1152. extrw,u %r9,10,5,%r8 /* Get base register # */
  1153. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1154. BL set_register,%r25
  1155. add,l %r1,%r24,%r1 /* doesn't affect c/b bits */
  1156. nadtlb_nullify:
  1157. mfctl %ipsw,%r8
  1158. ldil L%PSW_N,%r9
  1159. or %r8,%r9,%r8 /* Set PSW_N */
  1160. mtctl %r8,%ipsw
  1161. rfir
  1162. nop
  1163. /*
  1164. When there is no translation for the probe address then we
  1165. must nullify the insn and return zero in the target regsiter.
  1166. This will indicate to the calling code that it does not have
  1167. write/read privileges to this address.
  1168. This should technically work for prober and probew in PA 1.1,
  1169. and also probe,r and probe,w in PA 2.0
  1170. WARNING: USE ONLY NON-SHADOW REGISTERS WITH PROBE INSN!
  1171. THE SLOW-PATH EMULATION HAS NOT BEEN WRITTEN YET.
  1172. */
  1173. nadtlb_probe_check:
  1174. ldi 0x80,%r16
  1175. and %r9,%r16,%r17
  1176. cmpb,<>,n %r16,%r17,nadtlb_fault /* Must be probe,[rw]*/
  1177. BL get_register,%r25 /* Find the target register */
  1178. extrw,u %r9,31,5,%r8 /* Get target register */
  1179. cmpib,COND(=),n -1,%r1,nadtlb_fault /* have to use slow path */
  1180. BL set_register,%r25
  1181. copy %r0,%r1 /* Write zero to target register */
  1182. b nadtlb_nullify /* Nullify return insn */
  1183. nop
  1184. #ifdef CONFIG_64BIT
  1185. itlb_miss_20w:
  1186. /*
  1187. * I miss is a little different, since we allow users to fault
  1188. * on the gateway page which is in the kernel address space.
  1189. */
  1190. space_adjust spc,va,t0
  1191. get_pgd spc,ptp
  1192. space_check spc,t0,itlb_fault
  1193. L3_ptep ptp,pte,t0,va,itlb_fault
  1194. update_ptep ptp,pte,t0,t1
  1195. make_insert_tlb spc,pte,prot
  1196. iitlbt pte,prot
  1197. rfir
  1198. nop
  1199. #else
  1200. itlb_miss_11:
  1201. get_pgd spc,ptp
  1202. space_check spc,t0,itlb_fault
  1203. L2_ptep ptp,pte,t0,va,itlb_fault
  1204. update_ptep ptp,pte,t0,t1
  1205. make_insert_tlb_11 spc,pte,prot
  1206. mfsp %sr1,t0 /* Save sr1 so we can use it in tlb inserts */
  1207. mtsp spc,%sr1
  1208. iitlba pte,(%sr1,va)
  1209. iitlbp prot,(%sr1,va)
  1210. mtsp t0, %sr1 /* Restore sr1 */
  1211. rfir
  1212. nop
  1213. itlb_miss_20:
  1214. get_pgd spc,ptp
  1215. space_check spc,t0,itlb_fault
  1216. L2_ptep ptp,pte,t0,va,itlb_fault
  1217. update_ptep ptp,pte,t0,t1
  1218. make_insert_tlb spc,pte,prot
  1219. f_extend pte,t0
  1220. iitlbt pte,prot
  1221. rfir
  1222. nop
  1223. #endif
  1224. #ifdef CONFIG_64BIT
  1225. dbit_trap_20w:
  1226. space_adjust spc,va,t0
  1227. get_pgd spc,ptp
  1228. space_check spc,t0,dbit_fault
  1229. L3_ptep ptp,pte,t0,va,dbit_fault
  1230. #ifdef CONFIG_SMP
  1231. cmpib,COND(=),n 0,spc,dbit_nolock_20w
  1232. load32 PA(pa_dbit_lock),t0
  1233. dbit_spin_20w:
  1234. LDCW 0(t0),t1
  1235. cmpib,COND(=) 0,t1,dbit_spin_20w
  1236. nop
  1237. dbit_nolock_20w:
  1238. #endif
  1239. update_dirty ptp,pte,t1
  1240. make_insert_tlb spc,pte,prot
  1241. idtlbt pte,prot
  1242. #ifdef CONFIG_SMP
  1243. cmpib,COND(=),n 0,spc,dbit_nounlock_20w
  1244. ldi 1,t1
  1245. stw t1,0(t0)
  1246. dbit_nounlock_20w:
  1247. #endif
  1248. rfir
  1249. nop
  1250. #else
  1251. dbit_trap_11:
  1252. get_pgd spc,ptp
  1253. space_check spc,t0,dbit_fault
  1254. L2_ptep ptp,pte,t0,va,dbit_fault
  1255. #ifdef CONFIG_SMP
  1256. cmpib,COND(=),n 0,spc,dbit_nolock_11
  1257. load32 PA(pa_dbit_lock),t0
  1258. dbit_spin_11:
  1259. LDCW 0(t0),t1
  1260. cmpib,= 0,t1,dbit_spin_11
  1261. nop
  1262. dbit_nolock_11:
  1263. #endif
  1264. update_dirty ptp,pte,t1
  1265. make_insert_tlb_11 spc,pte,prot
  1266. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1267. mtsp spc,%sr1
  1268. idtlba pte,(%sr1,va)
  1269. idtlbp prot,(%sr1,va)
  1270. mtsp t1, %sr1 /* Restore sr1 */
  1271. #ifdef CONFIG_SMP
  1272. cmpib,COND(=),n 0,spc,dbit_nounlock_11
  1273. ldi 1,t1
  1274. stw t1,0(t0)
  1275. dbit_nounlock_11:
  1276. #endif
  1277. rfir
  1278. nop
  1279. dbit_trap_20:
  1280. get_pgd spc,ptp
  1281. space_check spc,t0,dbit_fault
  1282. L2_ptep ptp,pte,t0,va,dbit_fault
  1283. #ifdef CONFIG_SMP
  1284. cmpib,COND(=),n 0,spc,dbit_nolock_20
  1285. load32 PA(pa_dbit_lock),t0
  1286. dbit_spin_20:
  1287. LDCW 0(t0),t1
  1288. cmpib,= 0,t1,dbit_spin_20
  1289. nop
  1290. dbit_nolock_20:
  1291. #endif
  1292. update_dirty ptp,pte,t1
  1293. make_insert_tlb spc,pte,prot
  1294. f_extend pte,t1
  1295. idtlbt pte,prot
  1296. #ifdef CONFIG_SMP
  1297. cmpib,COND(=),n 0,spc,dbit_nounlock_20
  1298. ldi 1,t1
  1299. stw t1,0(t0)
  1300. dbit_nounlock_20:
  1301. #endif
  1302. rfir
  1303. nop
  1304. #endif
  1305. .import handle_interruption,code
  1306. kernel_bad_space:
  1307. b intr_save
  1308. ldi 31,%r8 /* Use an unused code */
  1309. dbit_fault:
  1310. b intr_save
  1311. ldi 20,%r8
  1312. itlb_fault:
  1313. b intr_save
  1314. ldi 6,%r8
  1315. nadtlb_fault:
  1316. b intr_save
  1317. ldi 17,%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. ENTRY(sys_fork_wrapper)
  1376. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  1377. ldo TASK_REGS(%r1),%r1
  1378. reg_save %r1
  1379. mfctl %cr27, %r3
  1380. STREG %r3, PT_CR27(%r1)
  1381. STREG %r2,-RP_OFFSET(%r30)
  1382. ldo FRAME_SIZE(%r30),%r30
  1383. #ifdef CONFIG_64BIT
  1384. ldo -16(%r30),%r29 /* Reference param save area */
  1385. #endif
  1386. /* These are call-clobbered registers and therefore
  1387. also syscall-clobbered (we hope). */
  1388. STREG %r2,PT_GR19(%r1) /* save for child */
  1389. STREG %r30,PT_GR21(%r1)
  1390. LDREG PT_GR30(%r1),%r25
  1391. copy %r1,%r24
  1392. BL sys_clone,%r2
  1393. ldi SIGCHLD,%r26
  1394. LDREG -RP_OFFSET-FRAME_SIZE(%r30),%r2
  1395. wrapper_exit:
  1396. ldo -FRAME_SIZE(%r30),%r30 /* get the stackframe */
  1397. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1398. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1399. LDREG PT_CR27(%r1), %r3
  1400. mtctl %r3, %cr27
  1401. reg_restore %r1
  1402. /* strace expects syscall # to be preserved in r20 */
  1403. ldi __NR_fork,%r20
  1404. bv %r0(%r2)
  1405. STREG %r20,PT_GR20(%r1)
  1406. ENDPROC(sys_fork_wrapper)
  1407. /* Set the return value for the child */
  1408. ENTRY(child_return)
  1409. BL schedule_tail, %r2
  1410. nop
  1411. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE-FRAME_SIZE(%r30), %r1
  1412. LDREG TASK_PT_GR19(%r1),%r2
  1413. b wrapper_exit
  1414. copy %r0,%r28
  1415. ENDPROC(child_return)
  1416. ENTRY(sys_clone_wrapper)
  1417. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1418. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1419. reg_save %r1
  1420. mfctl %cr27, %r3
  1421. STREG %r3, PT_CR27(%r1)
  1422. STREG %r2,-RP_OFFSET(%r30)
  1423. ldo FRAME_SIZE(%r30),%r30
  1424. #ifdef CONFIG_64BIT
  1425. ldo -16(%r30),%r29 /* Reference param save area */
  1426. #endif
  1427. /* WARNING - Clobbers r19 and r21, userspace must save these! */
  1428. STREG %r2,PT_GR19(%r1) /* save for child */
  1429. STREG %r30,PT_GR21(%r1)
  1430. BL sys_clone,%r2
  1431. copy %r1,%r24
  1432. b wrapper_exit
  1433. LDREG -RP_OFFSET-FRAME_SIZE(%r30),%r2
  1434. ENDPROC(sys_clone_wrapper)
  1435. ENTRY(sys_vfork_wrapper)
  1436. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1437. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1438. reg_save %r1
  1439. mfctl %cr27, %r3
  1440. STREG %r3, PT_CR27(%r1)
  1441. STREG %r2,-RP_OFFSET(%r30)
  1442. ldo FRAME_SIZE(%r30),%r30
  1443. #ifdef CONFIG_64BIT
  1444. ldo -16(%r30),%r29 /* Reference param save area */
  1445. #endif
  1446. STREG %r2,PT_GR19(%r1) /* save for child */
  1447. STREG %r30,PT_GR21(%r1)
  1448. BL sys_vfork,%r2
  1449. copy %r1,%r26
  1450. b wrapper_exit
  1451. LDREG -RP_OFFSET-FRAME_SIZE(%r30),%r2
  1452. ENDPROC(sys_vfork_wrapper)
  1453. .macro execve_wrapper execve
  1454. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1455. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1456. /*
  1457. * Do we need to save/restore r3-r18 here?
  1458. * I don't think so. why would new thread need old
  1459. * threads registers?
  1460. */
  1461. /* %arg0 - %arg3 are already saved for us. */
  1462. STREG %r2,-RP_OFFSET(%r30)
  1463. ldo FRAME_SIZE(%r30),%r30
  1464. #ifdef CONFIG_64BIT
  1465. ldo -16(%r30),%r29 /* Reference param save area */
  1466. #endif
  1467. BL \execve,%r2
  1468. copy %r1,%arg0
  1469. ldo -FRAME_SIZE(%r30),%r30
  1470. LDREG -RP_OFFSET(%r30),%r2
  1471. /* If exec succeeded we need to load the args */
  1472. ldo -1024(%r0),%r1
  1473. cmpb,>>= %r28,%r1,error_\execve
  1474. copy %r2,%r19
  1475. error_\execve:
  1476. bv %r0(%r19)
  1477. nop
  1478. .endm
  1479. .import sys_execve
  1480. ENTRY(sys_execve_wrapper)
  1481. execve_wrapper sys_execve
  1482. ENDPROC(sys_execve_wrapper)
  1483. #ifdef CONFIG_64BIT
  1484. .import sys32_execve
  1485. ENTRY(sys32_execve_wrapper)
  1486. execve_wrapper sys32_execve
  1487. ENDPROC(sys32_execve_wrapper)
  1488. #endif
  1489. ENTRY(sys_rt_sigreturn_wrapper)
  1490. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r26
  1491. ldo TASK_REGS(%r26),%r26 /* get pt regs */
  1492. /* Don't save regs, we are going to restore them from sigcontext. */
  1493. STREG %r2, -RP_OFFSET(%r30)
  1494. #ifdef CONFIG_64BIT
  1495. ldo FRAME_SIZE(%r30), %r30
  1496. BL sys_rt_sigreturn,%r2
  1497. ldo -16(%r30),%r29 /* Reference param save area */
  1498. #else
  1499. BL sys_rt_sigreturn,%r2
  1500. ldo FRAME_SIZE(%r30), %r30
  1501. #endif
  1502. ldo -FRAME_SIZE(%r30), %r30
  1503. LDREG -RP_OFFSET(%r30), %r2
  1504. /* FIXME: I think we need to restore a few more things here. */
  1505. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1506. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1507. reg_restore %r1
  1508. /* If the signal was received while the process was blocked on a
  1509. * syscall, then r2 will take us to syscall_exit; otherwise r2 will
  1510. * take us to syscall_exit_rfi and on to intr_return.
  1511. */
  1512. bv %r0(%r2)
  1513. LDREG PT_GR28(%r1),%r28 /* reload original r28 for syscall_exit */
  1514. ENDPROC(sys_rt_sigreturn_wrapper)
  1515. ENTRY(sys_sigaltstack_wrapper)
  1516. /* Get the user stack pointer */
  1517. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1518. ldo TASK_REGS(%r1),%r24 /* get pt regs */
  1519. LDREG TASK_PT_GR30(%r24),%r24
  1520. STREG %r2, -RP_OFFSET(%r30)
  1521. #ifdef CONFIG_64BIT
  1522. ldo FRAME_SIZE(%r30), %r30
  1523. BL do_sigaltstack,%r2
  1524. ldo -16(%r30),%r29 /* Reference param save area */
  1525. #else
  1526. BL do_sigaltstack,%r2
  1527. ldo FRAME_SIZE(%r30), %r30
  1528. #endif
  1529. ldo -FRAME_SIZE(%r30), %r30
  1530. LDREG -RP_OFFSET(%r30), %r2
  1531. bv %r0(%r2)
  1532. nop
  1533. ENDPROC(sys_sigaltstack_wrapper)
  1534. #ifdef CONFIG_64BIT
  1535. ENTRY(sys32_sigaltstack_wrapper)
  1536. /* Get the user stack pointer */
  1537. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r24
  1538. LDREG TASK_PT_GR30(%r24),%r24
  1539. STREG %r2, -RP_OFFSET(%r30)
  1540. ldo FRAME_SIZE(%r30), %r30
  1541. BL do_sigaltstack32,%r2
  1542. ldo -16(%r30),%r29 /* Reference param save area */
  1543. ldo -FRAME_SIZE(%r30), %r30
  1544. LDREG -RP_OFFSET(%r30), %r2
  1545. bv %r0(%r2)
  1546. nop
  1547. ENDPROC(sys32_sigaltstack_wrapper)
  1548. #endif
  1549. ENTRY(syscall_exit)
  1550. /* NOTE: HP-UX syscalls also come through here
  1551. * after hpux_syscall_exit fixes up return
  1552. * values. */
  1553. /* NOTE: Not all syscalls exit this way. rt_sigreturn will exit
  1554. * via syscall_exit_rfi if the signal was received while the process
  1555. * was running.
  1556. */
  1557. /* save return value now */
  1558. mfctl %cr30, %r1
  1559. LDREG TI_TASK(%r1),%r1
  1560. STREG %r28,TASK_PT_GR28(%r1)
  1561. #ifdef CONFIG_HPUX
  1562. /* <linux/personality.h> cannot be easily included */
  1563. #define PER_HPUX 0x10
  1564. ldw TASK_PERSONALITY(%r1),%r19
  1565. /* We can't use "CMPIB<> PER_HPUX" since "im5" field is sign extended */
  1566. ldo -PER_HPUX(%r19), %r19
  1567. cmpib,COND(<>),n 0,%r19,1f
  1568. /* Save other hpux returns if personality is PER_HPUX */
  1569. STREG %r22,TASK_PT_GR22(%r1)
  1570. STREG %r29,TASK_PT_GR29(%r1)
  1571. 1:
  1572. #endif /* CONFIG_HPUX */
  1573. /* Seems to me that dp could be wrong here, if the syscall involved
  1574. * calling a module, and nothing got round to restoring dp on return.
  1575. */
  1576. loadgp
  1577. syscall_check_resched:
  1578. /* check for reschedule */
  1579. LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19 /* long */
  1580. bb,<,n %r19, 31-TIF_NEED_RESCHED, syscall_do_resched /* forward */
  1581. .import do_signal,code
  1582. syscall_check_sig:
  1583. LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19
  1584. ldi (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK), %r26
  1585. and,COND(<>) %r19, %r26, %r0
  1586. b,n syscall_restore /* skip past if we've nothing to do */
  1587. syscall_do_signal:
  1588. /* Save callee-save registers (for sigcontext).
  1589. * FIXME: After this point the process structure should be
  1590. * consistent with all the relevant state of the process
  1591. * before the syscall. We need to verify this.
  1592. */
  1593. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1594. ldo TASK_REGS(%r1), %r26 /* struct pt_regs *regs */
  1595. reg_save %r26
  1596. #ifdef CONFIG_64BIT
  1597. ldo -16(%r30),%r29 /* Reference param save area */
  1598. #endif
  1599. BL do_notify_resume,%r2
  1600. ldi 1, %r25 /* long in_syscall = 1 */
  1601. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1602. ldo TASK_REGS(%r1), %r20 /* reload pt_regs */
  1603. reg_restore %r20
  1604. b,n syscall_check_sig
  1605. syscall_restore:
  1606. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1607. /* Are we being ptraced? */
  1608. ldw TASK_FLAGS(%r1),%r19
  1609. ldi (_TIF_SINGLESTEP|_TIF_BLOCKSTEP),%r2
  1610. and,COND(=) %r19,%r2,%r0
  1611. b,n syscall_restore_rfi
  1612. ldo TASK_PT_FR31(%r1),%r19 /* reload fpregs */
  1613. rest_fp %r19
  1614. LDREG TASK_PT_SAR(%r1),%r19 /* restore SAR */
  1615. mtsar %r19
  1616. LDREG TASK_PT_GR2(%r1),%r2 /* restore user rp */
  1617. LDREG TASK_PT_GR19(%r1),%r19
  1618. LDREG TASK_PT_GR20(%r1),%r20
  1619. LDREG TASK_PT_GR21(%r1),%r21
  1620. LDREG TASK_PT_GR22(%r1),%r22
  1621. LDREG TASK_PT_GR23(%r1),%r23
  1622. LDREG TASK_PT_GR24(%r1),%r24
  1623. LDREG TASK_PT_GR25(%r1),%r25
  1624. LDREG TASK_PT_GR26(%r1),%r26
  1625. LDREG TASK_PT_GR27(%r1),%r27 /* restore user dp */
  1626. LDREG TASK_PT_GR28(%r1),%r28 /* syscall return value */
  1627. LDREG TASK_PT_GR29(%r1),%r29
  1628. LDREG TASK_PT_GR31(%r1),%r31 /* restore syscall rp */
  1629. /* NOTE: We use rsm/ssm pair to make this operation atomic */
  1630. LDREG TASK_PT_GR30(%r1),%r1 /* Get user sp */
  1631. rsm PSW_SM_I, %r0
  1632. copy %r1,%r30 /* Restore user sp */
  1633. mfsp %sr3,%r1 /* Get user space id */
  1634. mtsp %r1,%sr7 /* Restore sr7 */
  1635. ssm PSW_SM_I, %r0
  1636. /* Set sr2 to zero for userspace syscalls to work. */
  1637. mtsp %r0,%sr2
  1638. mtsp %r1,%sr4 /* Restore sr4 */
  1639. mtsp %r1,%sr5 /* Restore sr5 */
  1640. mtsp %r1,%sr6 /* Restore sr6 */
  1641. depi 3,31,2,%r31 /* ensure return to user mode. */
  1642. #ifdef CONFIG_64BIT
  1643. /* decide whether to reset the wide mode bit
  1644. *
  1645. * For a syscall, the W bit is stored in the lowest bit
  1646. * of sp. Extract it and reset W if it is zero */
  1647. extrd,u,*<> %r30,63,1,%r1
  1648. rsm PSW_SM_W, %r0
  1649. /* now reset the lowest bit of sp if it was set */
  1650. xor %r30,%r1,%r30
  1651. #endif
  1652. be,n 0(%sr3,%r31) /* return to user space */
  1653. /* We have to return via an RFI, so that PSW T and R bits can be set
  1654. * appropriately.
  1655. * This sets up pt_regs so we can return via intr_restore, which is not
  1656. * the most efficient way of doing things, but it works.
  1657. */
  1658. syscall_restore_rfi:
  1659. ldo -1(%r0),%r2 /* Set recovery cntr to -1 */
  1660. mtctl %r2,%cr0 /* for immediate trap */
  1661. LDREG TASK_PT_PSW(%r1),%r2 /* Get old PSW */
  1662. ldi 0x0b,%r20 /* Create new PSW */
  1663. depi -1,13,1,%r20 /* C, Q, D, and I bits */
  1664. /* The values of SINGLESTEP_BIT and BLOCKSTEP_BIT are
  1665. * set in thread_info.h and converted to PA bitmap
  1666. * numbers in asm-offsets.c */
  1667. /* if ((%r19.SINGLESTEP_BIT)) { %r20.27=1} */
  1668. extru,= %r19,TIF_SINGLESTEP_PA_BIT,1,%r0
  1669. depi -1,27,1,%r20 /* R bit */
  1670. /* if ((%r19.BLOCKSTEP_BIT)) { %r20.7=1} */
  1671. extru,= %r19,TIF_BLOCKSTEP_PA_BIT,1,%r0
  1672. depi -1,7,1,%r20 /* T bit */
  1673. STREG %r20,TASK_PT_PSW(%r1)
  1674. /* Always store space registers, since sr3 can be changed (e.g. fork) */
  1675. mfsp %sr3,%r25
  1676. STREG %r25,TASK_PT_SR3(%r1)
  1677. STREG %r25,TASK_PT_SR4(%r1)
  1678. STREG %r25,TASK_PT_SR5(%r1)
  1679. STREG %r25,TASK_PT_SR6(%r1)
  1680. STREG %r25,TASK_PT_SR7(%r1)
  1681. STREG %r25,TASK_PT_IASQ0(%r1)
  1682. STREG %r25,TASK_PT_IASQ1(%r1)
  1683. /* XXX W bit??? */
  1684. /* Now if old D bit is clear, it means we didn't save all registers
  1685. * on syscall entry, so do that now. This only happens on TRACEME
  1686. * calls, or if someone attached to us while we were on a syscall.
  1687. * We could make this more efficient by not saving r3-r18, but
  1688. * then we wouldn't be able to use the common intr_restore path.
  1689. * It is only for traced processes anyway, so performance is not
  1690. * an issue.
  1691. */
  1692. bb,< %r2,30,pt_regs_ok /* Branch if D set */
  1693. ldo TASK_REGS(%r1),%r25
  1694. reg_save %r25 /* Save r3 to r18 */
  1695. /* Save the current sr */
  1696. mfsp %sr0,%r2
  1697. STREG %r2,TASK_PT_SR0(%r1)
  1698. /* Save the scratch sr */
  1699. mfsp %sr1,%r2
  1700. STREG %r2,TASK_PT_SR1(%r1)
  1701. /* sr2 should be set to zero for userspace syscalls */
  1702. STREG %r0,TASK_PT_SR2(%r1)
  1703. pt_regs_ok:
  1704. LDREG TASK_PT_GR31(%r1),%r2
  1705. depi 3,31,2,%r2 /* ensure return to user mode. */
  1706. STREG %r2,TASK_PT_IAOQ0(%r1)
  1707. ldo 4(%r2),%r2
  1708. STREG %r2,TASK_PT_IAOQ1(%r1)
  1709. copy %r25,%r16
  1710. b intr_restore
  1711. nop
  1712. .import schedule,code
  1713. syscall_do_resched:
  1714. BL schedule,%r2
  1715. #ifdef CONFIG_64BIT
  1716. ldo -16(%r30),%r29 /* Reference param save area */
  1717. #else
  1718. nop
  1719. #endif
  1720. b syscall_check_resched /* if resched, we start over again */
  1721. nop
  1722. ENDPROC(syscall_exit)
  1723. #ifdef CONFIG_FUNCTION_TRACER
  1724. .import ftrace_function_trampoline,code
  1725. ENTRY(_mcount)
  1726. copy %r3, %arg2
  1727. b ftrace_function_trampoline
  1728. nop
  1729. ENDPROC(_mcount)
  1730. ENTRY(return_to_handler)
  1731. load32 return_trampoline, %rp
  1732. copy %ret0, %arg0
  1733. copy %ret1, %arg1
  1734. b ftrace_return_to_handler
  1735. nop
  1736. return_trampoline:
  1737. copy %ret0, %rp
  1738. copy %r23, %ret0
  1739. copy %r24, %ret1
  1740. .globl ftrace_stub
  1741. ftrace_stub:
  1742. bv %r0(%rp)
  1743. nop
  1744. ENDPROC(return_to_handler)
  1745. #endif /* CONFIG_FUNCTION_TRACER */
  1746. get_register:
  1747. /*
  1748. * get_register is used by the non access tlb miss handlers to
  1749. * copy the value of the general register specified in r8 into
  1750. * r1. This routine can't be used for shadowed registers, since
  1751. * the rfir will restore the original value. So, for the shadowed
  1752. * registers we put a -1 into r1 to indicate that the register
  1753. * should not be used (the register being copied could also have
  1754. * a -1 in it, but that is OK, it just means that we will have
  1755. * to use the slow path instead).
  1756. */
  1757. blr %r8,%r0
  1758. nop
  1759. bv %r0(%r25) /* r0 */
  1760. copy %r0,%r1
  1761. bv %r0(%r25) /* r1 - shadowed */
  1762. ldi -1,%r1
  1763. bv %r0(%r25) /* r2 */
  1764. copy %r2,%r1
  1765. bv %r0(%r25) /* r3 */
  1766. copy %r3,%r1
  1767. bv %r0(%r25) /* r4 */
  1768. copy %r4,%r1
  1769. bv %r0(%r25) /* r5 */
  1770. copy %r5,%r1
  1771. bv %r0(%r25) /* r6 */
  1772. copy %r6,%r1
  1773. bv %r0(%r25) /* r7 */
  1774. copy %r7,%r1
  1775. bv %r0(%r25) /* r8 - shadowed */
  1776. ldi -1,%r1
  1777. bv %r0(%r25) /* r9 - shadowed */
  1778. ldi -1,%r1
  1779. bv %r0(%r25) /* r10 */
  1780. copy %r10,%r1
  1781. bv %r0(%r25) /* r11 */
  1782. copy %r11,%r1
  1783. bv %r0(%r25) /* r12 */
  1784. copy %r12,%r1
  1785. bv %r0(%r25) /* r13 */
  1786. copy %r13,%r1
  1787. bv %r0(%r25) /* r14 */
  1788. copy %r14,%r1
  1789. bv %r0(%r25) /* r15 */
  1790. copy %r15,%r1
  1791. bv %r0(%r25) /* r16 - shadowed */
  1792. ldi -1,%r1
  1793. bv %r0(%r25) /* r17 - shadowed */
  1794. ldi -1,%r1
  1795. bv %r0(%r25) /* r18 */
  1796. copy %r18,%r1
  1797. bv %r0(%r25) /* r19 */
  1798. copy %r19,%r1
  1799. bv %r0(%r25) /* r20 */
  1800. copy %r20,%r1
  1801. bv %r0(%r25) /* r21 */
  1802. copy %r21,%r1
  1803. bv %r0(%r25) /* r22 */
  1804. copy %r22,%r1
  1805. bv %r0(%r25) /* r23 */
  1806. copy %r23,%r1
  1807. bv %r0(%r25) /* r24 - shadowed */
  1808. ldi -1,%r1
  1809. bv %r0(%r25) /* r25 - shadowed */
  1810. ldi -1,%r1
  1811. bv %r0(%r25) /* r26 */
  1812. copy %r26,%r1
  1813. bv %r0(%r25) /* r27 */
  1814. copy %r27,%r1
  1815. bv %r0(%r25) /* r28 */
  1816. copy %r28,%r1
  1817. bv %r0(%r25) /* r29 */
  1818. copy %r29,%r1
  1819. bv %r0(%r25) /* r30 */
  1820. copy %r30,%r1
  1821. bv %r0(%r25) /* r31 */
  1822. copy %r31,%r1
  1823. set_register:
  1824. /*
  1825. * set_register is used by the non access tlb miss handlers to
  1826. * copy the value of r1 into the general register specified in
  1827. * r8.
  1828. */
  1829. blr %r8,%r0
  1830. nop
  1831. bv %r0(%r25) /* r0 (silly, but it is a place holder) */
  1832. copy %r1,%r0
  1833. bv %r0(%r25) /* r1 */
  1834. copy %r1,%r1
  1835. bv %r0(%r25) /* r2 */
  1836. copy %r1,%r2
  1837. bv %r0(%r25) /* r3 */
  1838. copy %r1,%r3
  1839. bv %r0(%r25) /* r4 */
  1840. copy %r1,%r4
  1841. bv %r0(%r25) /* r5 */
  1842. copy %r1,%r5
  1843. bv %r0(%r25) /* r6 */
  1844. copy %r1,%r6
  1845. bv %r0(%r25) /* r7 */
  1846. copy %r1,%r7
  1847. bv %r0(%r25) /* r8 */
  1848. copy %r1,%r8
  1849. bv %r0(%r25) /* r9 */
  1850. copy %r1,%r9
  1851. bv %r0(%r25) /* r10 */
  1852. copy %r1,%r10
  1853. bv %r0(%r25) /* r11 */
  1854. copy %r1,%r11
  1855. bv %r0(%r25) /* r12 */
  1856. copy %r1,%r12
  1857. bv %r0(%r25) /* r13 */
  1858. copy %r1,%r13
  1859. bv %r0(%r25) /* r14 */
  1860. copy %r1,%r14
  1861. bv %r0(%r25) /* r15 */
  1862. copy %r1,%r15
  1863. bv %r0(%r25) /* r16 */
  1864. copy %r1,%r16
  1865. bv %r0(%r25) /* r17 */
  1866. copy %r1,%r17
  1867. bv %r0(%r25) /* r18 */
  1868. copy %r1,%r18
  1869. bv %r0(%r25) /* r19 */
  1870. copy %r1,%r19
  1871. bv %r0(%r25) /* r20 */
  1872. copy %r1,%r20
  1873. bv %r0(%r25) /* r21 */
  1874. copy %r1,%r21
  1875. bv %r0(%r25) /* r22 */
  1876. copy %r1,%r22
  1877. bv %r0(%r25) /* r23 */
  1878. copy %r1,%r23
  1879. bv %r0(%r25) /* r24 */
  1880. copy %r1,%r24
  1881. bv %r0(%r25) /* r25 */
  1882. copy %r1,%r25
  1883. bv %r0(%r25) /* r26 */
  1884. copy %r1,%r26
  1885. bv %r0(%r25) /* r27 */
  1886. copy %r1,%r27
  1887. bv %r0(%r25) /* r28 */
  1888. copy %r1,%r28
  1889. bv %r0(%r25) /* r29 */
  1890. copy %r1,%r29
  1891. bv %r0(%r25) /* r30 */
  1892. copy %r1,%r30
  1893. bv %r0(%r25) /* r31 */
  1894. copy %r1,%r31