entry.S 57 KB

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