entry.S 54 KB

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