entry.S 56 KB

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