entry.S 55 KB

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