entry.S 56 KB

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