entry.S 57 KB

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