entry.S 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409
  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. 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(CONFIG_64BIT) && (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 CONFIG_64BIT
  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 CONFIG_64BIT
  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 CONFIG_64BIT
  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 CONFIG_64BIT
  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 CONFIG_64BIT
  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 CONFIG_64BIT
  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 CONFIG_64BIT
  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_float
  744. callee_save
  745. load32 _switch_to_ret, %r2
  746. STREG %r2, TASK_PT_KPC(%r26)
  747. LDREG TASK_PT_KPC(%r25), %r2
  748. STREG %r30, TASK_PT_KSP(%r26)
  749. LDREG TASK_PT_KSP(%r25), %r30
  750. LDREG TASK_THREAD_INFO(%r25), %r25
  751. bv %r0(%r2)
  752. mtctl %r25,%cr30
  753. _switch_to_ret:
  754. mtctl %r0, %cr0 /* Needed for single stepping */
  755. callee_rest
  756. callee_rest_float
  757. LDREG -RP_OFFSET(%r30), %r2
  758. bv %r0(%r2)
  759. copy %r26, %r28
  760. /*
  761. * Common rfi return path for interruptions, kernel execve, and
  762. * sys_rt_sigreturn (sometimes). The sys_rt_sigreturn syscall will
  763. * return via this path if the signal was received when the process
  764. * was running; if the process was blocked on a syscall then the
  765. * normal syscall_exit path is used. All syscalls for traced
  766. * proceses exit via intr_restore.
  767. *
  768. * XXX If any syscalls that change a processes space id ever exit
  769. * this way, then we will need to copy %sr3 in to PT_SR[3..7], and
  770. * adjust IASQ[0..1].
  771. *
  772. */
  773. .align 4096
  774. .export syscall_exit_rfi
  775. syscall_exit_rfi:
  776. mfctl %cr30,%r16
  777. LDREG TI_TASK(%r16), %r16 /* thread_info -> task_struct */
  778. ldo TASK_REGS(%r16),%r16
  779. /* Force iaoq to userspace, as the user has had access to our current
  780. * context via sigcontext. Also Filter the PSW for the same reason.
  781. */
  782. LDREG PT_IAOQ0(%r16),%r19
  783. depi 3,31,2,%r19
  784. STREG %r19,PT_IAOQ0(%r16)
  785. LDREG PT_IAOQ1(%r16),%r19
  786. depi 3,31,2,%r19
  787. STREG %r19,PT_IAOQ1(%r16)
  788. LDREG PT_PSW(%r16),%r19
  789. load32 USER_PSW_MASK,%r1
  790. #ifdef CONFIG_64BIT
  791. load32 USER_PSW_HI_MASK,%r20
  792. depd %r20,31,32,%r1
  793. #endif
  794. and %r19,%r1,%r19 /* Mask out bits that user shouldn't play with */
  795. load32 USER_PSW,%r1
  796. or %r19,%r1,%r19 /* Make sure default USER_PSW bits are set */
  797. STREG %r19,PT_PSW(%r16)
  798. /*
  799. * If we aren't being traced, we never saved space registers
  800. * (we don't store them in the sigcontext), so set them
  801. * to "proper" values now (otherwise we'll wind up restoring
  802. * whatever was last stored in the task structure, which might
  803. * be inconsistent if an interrupt occured while on the gateway
  804. * page) Note that we may be "trashing" values the user put in
  805. * them, but we don't support the the user changing them.
  806. */
  807. STREG %r0,PT_SR2(%r16)
  808. mfsp %sr3,%r19
  809. STREG %r19,PT_SR0(%r16)
  810. STREG %r19,PT_SR1(%r16)
  811. STREG %r19,PT_SR3(%r16)
  812. STREG %r19,PT_SR4(%r16)
  813. STREG %r19,PT_SR5(%r16)
  814. STREG %r19,PT_SR6(%r16)
  815. STREG %r19,PT_SR7(%r16)
  816. intr_return:
  817. /* NOTE: Need to enable interrupts incase we schedule. */
  818. ssm PSW_SM_I, %r0
  819. /* Check for software interrupts */
  820. .import irq_stat,data
  821. load32 irq_stat,%r19
  822. #ifdef CONFIG_SMP
  823. mfctl %cr30,%r1
  824. ldw TI_CPU(%r1),%r1 /* get cpu # - int */
  825. /* shift left ____cacheline_aligned (aka L1_CACHE_BYTES) amount
  826. ** irq_stat[] is defined using ____cacheline_aligned.
  827. */
  828. #ifdef CONFIG_64BIT
  829. shld %r1, 6, %r20
  830. #else
  831. shlw %r1, 5, %r20
  832. #endif
  833. add %r19,%r20,%r19 /* now have &irq_stat[smp_processor_id()] */
  834. #endif /* CONFIG_SMP */
  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 schedule,code
  872. intr_do_resched:
  873. /* Only do reschedule if we are returning to user space */
  874. LDREG PT_IASQ0(%r16), %r20
  875. CMPIB= 0,%r20,intr_restore /* backward */
  876. nop
  877. LDREG PT_IASQ1(%r16), %r20
  878. CMPIB= 0,%r20,intr_restore /* backward */
  879. nop
  880. #ifdef CONFIG_64BIT
  881. ldo -16(%r30),%r29 /* Reference param save area */
  882. #endif
  883. ldil L%intr_check_sig, %r2
  884. #ifndef CONFIG_64BIT
  885. b schedule
  886. #else
  887. load32 schedule, %r20
  888. bv %r0(%r20)
  889. #endif
  890. ldo R%intr_check_sig(%r2), %r2
  891. .import do_signal,code
  892. intr_do_signal:
  893. /*
  894. This check is critical to having LWS
  895. working. The IASQ is zero on the gateway
  896. page and we cannot deliver any signals until
  897. we get off the gateway page.
  898. Only do signals if we are returning to user space
  899. */
  900. LDREG PT_IASQ0(%r16), %r20
  901. CMPIB= 0,%r20,intr_restore /* backward */
  902. nop
  903. LDREG PT_IASQ1(%r16), %r20
  904. CMPIB= 0,%r20,intr_restore /* backward */
  905. nop
  906. copy %r0, %r24 /* unsigned long in_syscall */
  907. copy %r16, %r25 /* struct pt_regs *regs */
  908. #ifdef CONFIG_64BIT
  909. ldo -16(%r30),%r29 /* Reference param save area */
  910. #endif
  911. BL do_signal,%r2
  912. copy %r0, %r26 /* sigset_t *oldset = NULL */
  913. b intr_check_sig
  914. nop
  915. /*
  916. * External interrupts.
  917. */
  918. intr_extint:
  919. CMPIB=,n 0,%r16,1f
  920. get_stack_use_cr30
  921. b,n 3f
  922. 1:
  923. #if 0 /* Interrupt Stack support not working yet! */
  924. mfctl %cr31,%r1
  925. copy %r30,%r17
  926. /* FIXME! depi below has hardcoded idea of interrupt stack size (32k)*/
  927. #ifdef CONFIG_64BIT
  928. depdi 0,63,15,%r17
  929. #else
  930. depi 0,31,15,%r17
  931. #endif
  932. CMPB=,n %r1,%r17,2f
  933. get_stack_use_cr31
  934. b,n 3f
  935. #endif
  936. 2:
  937. get_stack_use_r30
  938. 3:
  939. save_specials %r29
  940. virt_map
  941. save_general %r29
  942. ldo PT_FR0(%r29), %r24
  943. save_fp %r24
  944. loadgp
  945. copy %r29, %r26 /* arg0 is pt_regs */
  946. copy %r29, %r16 /* save pt_regs */
  947. ldil L%intr_return, %r2
  948. #ifdef CONFIG_64BIT
  949. ldo -16(%r30),%r29 /* Reference param save area */
  950. #endif
  951. b do_cpu_irq_mask
  952. ldo R%intr_return(%r2), %r2 /* return to intr_return, not here */
  953. /* Generic interruptions (illegal insn, unaligned, page fault, etc) */
  954. .export intr_save, code /* for os_hpmc */
  955. intr_save:
  956. mfsp %sr7,%r16
  957. CMPIB=,n 0,%r16,1f
  958. get_stack_use_cr30
  959. b 2f
  960. copy %r8,%r26
  961. 1:
  962. get_stack_use_r30
  963. copy %r8,%r26
  964. 2:
  965. save_specials %r29
  966. /* If this trap is a itlb miss, skip saving/adjusting isr/ior */
  967. /*
  968. * FIXME: 1) Use a #define for the hardwired "6" below (and in
  969. * traps.c.
  970. * 2) Once we start executing code above 4 Gb, we need
  971. * to adjust iasq/iaoq here in the same way we
  972. * adjust isr/ior below.
  973. */
  974. CMPIB=,n 6,%r26,skip_save_ior
  975. mfctl %cr20, %r16 /* isr */
  976. nop /* serialize mfctl on PA 2.0 to avoid 4 cycle penalty */
  977. mfctl %cr21, %r17 /* ior */
  978. #ifdef CONFIG_64BIT
  979. /*
  980. * If the interrupted code was running with W bit off (32 bit),
  981. * clear the b bits (bits 0 & 1) in the ior.
  982. * save_specials left ipsw value in r8 for us to test.
  983. */
  984. extrd,u,*<> %r8,PSW_W_BIT,1,%r0
  985. depdi 0,1,2,%r17
  986. /*
  987. * FIXME: This code has hardwired assumptions about the split
  988. * between space bits and offset bits. This will change
  989. * when we allow alternate page sizes.
  990. */
  991. /* adjust isr/ior. */
  992. extrd,u %r16,63,7,%r1 /* get high bits from isr for ior */
  993. depd %r1,31,7,%r17 /* deposit them into ior */
  994. depdi 0,63,7,%r16 /* clear them from isr */
  995. #endif
  996. STREG %r16, PT_ISR(%r29)
  997. STREG %r17, PT_IOR(%r29)
  998. skip_save_ior:
  999. virt_map
  1000. save_general %r29
  1001. ldo PT_FR0(%r29), %r25
  1002. save_fp %r25
  1003. loadgp
  1004. copy %r29, %r25 /* arg1 is pt_regs */
  1005. #ifdef CONFIG_64BIT
  1006. ldo -16(%r30),%r29 /* Reference param save area */
  1007. #endif
  1008. ldil L%intr_check_sig, %r2
  1009. copy %r25, %r16 /* save pt_regs */
  1010. b handle_interruption
  1011. ldo R%intr_check_sig(%r2), %r2
  1012. /*
  1013. * Note for all tlb miss handlers:
  1014. *
  1015. * cr24 contains a pointer to the kernel address space
  1016. * page directory.
  1017. *
  1018. * cr25 contains a pointer to the current user address
  1019. * space page directory.
  1020. *
  1021. * sr3 will contain the space id of the user address space
  1022. * of the current running thread while that thread is
  1023. * running in the kernel.
  1024. */
  1025. /*
  1026. * register number allocations. Note that these are all
  1027. * in the shadowed registers
  1028. */
  1029. t0 = r1 /* temporary register 0 */
  1030. va = r8 /* virtual address for which the trap occured */
  1031. t1 = r9 /* temporary register 1 */
  1032. pte = r16 /* pte/phys page # */
  1033. prot = r17 /* prot bits */
  1034. spc = r24 /* space for which the trap occured */
  1035. ptp = r25 /* page directory/page table pointer */
  1036. #ifdef CONFIG_64BIT
  1037. dtlb_miss_20w:
  1038. space_adjust spc,va,t0
  1039. get_pgd spc,ptp
  1040. space_check spc,t0,dtlb_fault
  1041. L3_ptep ptp,pte,t0,va,dtlb_check_alias_20w
  1042. update_ptep ptp,pte,t0,t1
  1043. make_insert_tlb spc,pte,prot
  1044. idtlbt pte,prot
  1045. rfir
  1046. nop
  1047. dtlb_check_alias_20w:
  1048. do_alias spc,t0,t1,va,pte,prot,dtlb_fault
  1049. idtlbt pte,prot
  1050. rfir
  1051. nop
  1052. nadtlb_miss_20w:
  1053. space_adjust spc,va,t0
  1054. get_pgd spc,ptp
  1055. space_check spc,t0,nadtlb_fault
  1056. L3_ptep ptp,pte,t0,va,nadtlb_check_flush_20w
  1057. update_ptep ptp,pte,t0,t1
  1058. make_insert_tlb spc,pte,prot
  1059. idtlbt pte,prot
  1060. rfir
  1061. nop
  1062. nadtlb_check_flush_20w:
  1063. bb,>=,n pte,_PAGE_FLUSH_BIT,nadtlb_emulate
  1064. /* Insert a "flush only" translation */
  1065. depdi,z 7,7,3,prot
  1066. depdi 1,10,1,prot
  1067. /* Get rid of prot bits and convert to page addr for idtlbt */
  1068. depdi 0,63,12,pte
  1069. extrd,u pte,56,52,pte
  1070. idtlbt pte,prot
  1071. rfir
  1072. nop
  1073. #else
  1074. dtlb_miss_11:
  1075. get_pgd spc,ptp
  1076. space_check spc,t0,dtlb_fault
  1077. L2_ptep ptp,pte,t0,va,dtlb_check_alias_11
  1078. update_ptep ptp,pte,t0,t1
  1079. make_insert_tlb_11 spc,pte,prot
  1080. mfsp %sr1,t0 /* Save sr1 so we can use it in tlb inserts */
  1081. mtsp spc,%sr1
  1082. idtlba pte,(%sr1,va)
  1083. idtlbp prot,(%sr1,va)
  1084. mtsp t0, %sr1 /* Restore sr1 */
  1085. rfir
  1086. nop
  1087. dtlb_check_alias_11:
  1088. /* Check to see if fault is in the temporary alias region */
  1089. cmpib,<>,n 0,spc,dtlb_fault /* forward */
  1090. ldil L%(TMPALIAS_MAP_START),t0
  1091. copy va,t1
  1092. depwi 0,31,23,t1
  1093. cmpb,<>,n t0,t1,dtlb_fault /* forward */
  1094. ldi (_PAGE_DIRTY|_PAGE_WRITE|_PAGE_READ),prot
  1095. depw,z prot,8,7,prot
  1096. /*
  1097. * OK, it is in the temp alias region, check whether "from" or "to".
  1098. * Check "subtle" note in pacache.S re: r23/r26.
  1099. */
  1100. extrw,u,= va,9,1,r0
  1101. or,tr %r23,%r0,pte /* If "from" use "from" page */
  1102. or %r26,%r0,pte /* else "to", use "to" page */
  1103. idtlba pte,(va)
  1104. idtlbp prot,(va)
  1105. rfir
  1106. nop
  1107. nadtlb_miss_11:
  1108. get_pgd spc,ptp
  1109. space_check spc,t0,nadtlb_fault
  1110. L2_ptep ptp,pte,t0,va,nadtlb_check_flush_11
  1111. update_ptep ptp,pte,t0,t1
  1112. make_insert_tlb_11 spc,pte,prot
  1113. mfsp %sr1,t0 /* Save sr1 so we can use it in tlb inserts */
  1114. mtsp spc,%sr1
  1115. idtlba pte,(%sr1,va)
  1116. idtlbp prot,(%sr1,va)
  1117. mtsp t0, %sr1 /* Restore sr1 */
  1118. rfir
  1119. nop
  1120. nadtlb_check_flush_11:
  1121. bb,>=,n pte,_PAGE_FLUSH_BIT,nadtlb_emulate
  1122. /* Insert a "flush only" translation */
  1123. zdepi 7,7,3,prot
  1124. depi 1,10,1,prot
  1125. /* Get rid of prot bits and convert to page addr for idtlba */
  1126. depi 0,31,12,pte
  1127. extru pte,24,25,pte
  1128. mfsp %sr1,t0 /* Save sr1 so we can use it in tlb inserts */
  1129. mtsp spc,%sr1
  1130. idtlba pte,(%sr1,va)
  1131. idtlbp prot,(%sr1,va)
  1132. mtsp t0, %sr1 /* Restore sr1 */
  1133. rfir
  1134. nop
  1135. dtlb_miss_20:
  1136. space_adjust spc,va,t0
  1137. get_pgd spc,ptp
  1138. space_check spc,t0,dtlb_fault
  1139. L2_ptep ptp,pte,t0,va,dtlb_check_alias_20
  1140. update_ptep ptp,pte,t0,t1
  1141. make_insert_tlb spc,pte,prot
  1142. f_extend pte,t0
  1143. idtlbt pte,prot
  1144. rfir
  1145. nop
  1146. dtlb_check_alias_20:
  1147. do_alias spc,t0,t1,va,pte,prot,dtlb_fault
  1148. idtlbt pte,prot
  1149. rfir
  1150. nop
  1151. nadtlb_miss_20:
  1152. get_pgd spc,ptp
  1153. space_check spc,t0,nadtlb_fault
  1154. L2_ptep ptp,pte,t0,va,nadtlb_check_flush_20
  1155. update_ptep ptp,pte,t0,t1
  1156. make_insert_tlb spc,pte,prot
  1157. f_extend pte,t0
  1158. idtlbt pte,prot
  1159. rfir
  1160. nop
  1161. nadtlb_check_flush_20:
  1162. bb,>=,n pte,_PAGE_FLUSH_BIT,nadtlb_emulate
  1163. /* Insert a "flush only" translation */
  1164. depdi,z 7,7,3,prot
  1165. depdi 1,10,1,prot
  1166. /* Get rid of prot bits and convert to page addr for idtlbt */
  1167. depdi 0,63,12,pte
  1168. extrd,u pte,56,32,pte
  1169. idtlbt pte,prot
  1170. rfir
  1171. nop
  1172. #endif
  1173. nadtlb_emulate:
  1174. /*
  1175. * Non access misses can be caused by fdc,fic,pdc,lpa,probe and
  1176. * probei instructions. We don't want to fault for these
  1177. * instructions (not only does it not make sense, it can cause
  1178. * deadlocks, since some flushes are done with the mmap
  1179. * semaphore held). If the translation doesn't exist, we can't
  1180. * insert a translation, so have to emulate the side effects
  1181. * of the instruction. Since we don't insert a translation
  1182. * we can get a lot of faults during a flush loop, so it makes
  1183. * sense to try to do it here with minimum overhead. We only
  1184. * emulate fdc,fic,pdc,probew,prober instructions whose base
  1185. * and index registers are not shadowed. We defer everything
  1186. * else to the "slow" path.
  1187. */
  1188. mfctl %cr19,%r9 /* Get iir */
  1189. /* PA 2.0 Arch Ref. Book pg 382 has a good description of the insn bits.
  1190. Checks for fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw */
  1191. /* Checks for fdc,fdce,pdc,"fic,4f" only */
  1192. ldi 0x280,%r16
  1193. and %r9,%r16,%r17
  1194. cmpb,<>,n %r16,%r17,nadtlb_probe_check
  1195. bb,>=,n %r9,26,nadtlb_nullify /* m bit not set, just nullify */
  1196. BL get_register,%r25
  1197. extrw,u %r9,15,5,%r8 /* Get index register # */
  1198. CMPIB=,n -1,%r1,nadtlb_fault /* have to use slow path */
  1199. copy %r1,%r24
  1200. BL get_register,%r25
  1201. extrw,u %r9,10,5,%r8 /* Get base register # */
  1202. CMPIB=,n -1,%r1,nadtlb_fault /* have to use slow path */
  1203. BL set_register,%r25
  1204. add,l %r1,%r24,%r1 /* doesn't affect c/b bits */
  1205. nadtlb_nullify:
  1206. mfctl %ipsw,%r8
  1207. ldil L%PSW_N,%r9
  1208. or %r8,%r9,%r8 /* Set PSW_N */
  1209. mtctl %r8,%ipsw
  1210. rfir
  1211. nop
  1212. /*
  1213. When there is no translation for the probe address then we
  1214. must nullify the insn and return zero in the target regsiter.
  1215. This will indicate to the calling code that it does not have
  1216. write/read privileges to this address.
  1217. This should technically work for prober and probew in PA 1.1,
  1218. and also probe,r and probe,w in PA 2.0
  1219. WARNING: USE ONLY NON-SHADOW REGISTERS WITH PROBE INSN!
  1220. THE SLOW-PATH EMULATION HAS NOT BEEN WRITTEN YET.
  1221. */
  1222. nadtlb_probe_check:
  1223. ldi 0x80,%r16
  1224. and %r9,%r16,%r17
  1225. cmpb,<>,n %r16,%r17,nadtlb_fault /* Must be probe,[rw]*/
  1226. BL get_register,%r25 /* Find the target register */
  1227. extrw,u %r9,31,5,%r8 /* Get target register */
  1228. CMPIB=,n -1,%r1,nadtlb_fault /* have to use slow path */
  1229. BL set_register,%r25
  1230. copy %r0,%r1 /* Write zero to target register */
  1231. b nadtlb_nullify /* Nullify return insn */
  1232. nop
  1233. #ifdef CONFIG_64BIT
  1234. itlb_miss_20w:
  1235. /*
  1236. * I miss is a little different, since we allow users to fault
  1237. * on the gateway page which is in the kernel address space.
  1238. */
  1239. space_adjust spc,va,t0
  1240. get_pgd spc,ptp
  1241. space_check spc,t0,itlb_fault
  1242. L3_ptep ptp,pte,t0,va,itlb_fault
  1243. update_ptep ptp,pte,t0,t1
  1244. make_insert_tlb spc,pte,prot
  1245. iitlbt pte,prot
  1246. rfir
  1247. nop
  1248. #else
  1249. itlb_miss_11:
  1250. get_pgd spc,ptp
  1251. space_check spc,t0,itlb_fault
  1252. L2_ptep ptp,pte,t0,va,itlb_fault
  1253. update_ptep ptp,pte,t0,t1
  1254. make_insert_tlb_11 spc,pte,prot
  1255. mfsp %sr1,t0 /* Save sr1 so we can use it in tlb inserts */
  1256. mtsp spc,%sr1
  1257. iitlba pte,(%sr1,va)
  1258. iitlbp prot,(%sr1,va)
  1259. mtsp t0, %sr1 /* Restore sr1 */
  1260. rfir
  1261. nop
  1262. itlb_miss_20:
  1263. get_pgd spc,ptp
  1264. space_check spc,t0,itlb_fault
  1265. L2_ptep ptp,pte,t0,va,itlb_fault
  1266. update_ptep ptp,pte,t0,t1
  1267. make_insert_tlb spc,pte,prot
  1268. f_extend pte,t0
  1269. iitlbt pte,prot
  1270. rfir
  1271. nop
  1272. #endif
  1273. #ifdef CONFIG_64BIT
  1274. dbit_trap_20w:
  1275. space_adjust spc,va,t0
  1276. get_pgd spc,ptp
  1277. space_check spc,t0,dbit_fault
  1278. L3_ptep ptp,pte,t0,va,dbit_fault
  1279. #ifdef CONFIG_SMP
  1280. CMPIB=,n 0,spc,dbit_nolock_20w
  1281. load32 PA(pa_dbit_lock),t0
  1282. dbit_spin_20w:
  1283. ldcw 0(t0),t1
  1284. cmpib,= 0,t1,dbit_spin_20w
  1285. nop
  1286. dbit_nolock_20w:
  1287. #endif
  1288. update_dirty ptp,pte,t1
  1289. make_insert_tlb spc,pte,prot
  1290. idtlbt pte,prot
  1291. #ifdef CONFIG_SMP
  1292. CMPIB=,n 0,spc,dbit_nounlock_20w
  1293. ldi 1,t1
  1294. stw t1,0(t0)
  1295. dbit_nounlock_20w:
  1296. #endif
  1297. rfir
  1298. nop
  1299. #else
  1300. dbit_trap_11:
  1301. get_pgd spc,ptp
  1302. space_check spc,t0,dbit_fault
  1303. L2_ptep ptp,pte,t0,va,dbit_fault
  1304. #ifdef CONFIG_SMP
  1305. CMPIB=,n 0,spc,dbit_nolock_11
  1306. load32 PA(pa_dbit_lock),t0
  1307. dbit_spin_11:
  1308. ldcw 0(t0),t1
  1309. cmpib,= 0,t1,dbit_spin_11
  1310. nop
  1311. dbit_nolock_11:
  1312. #endif
  1313. update_dirty ptp,pte,t1
  1314. make_insert_tlb_11 spc,pte,prot
  1315. mfsp %sr1,t1 /* Save sr1 so we can use it in tlb inserts */
  1316. mtsp spc,%sr1
  1317. idtlba pte,(%sr1,va)
  1318. idtlbp prot,(%sr1,va)
  1319. mtsp t1, %sr1 /* Restore sr1 */
  1320. #ifdef CONFIG_SMP
  1321. CMPIB=,n 0,spc,dbit_nounlock_11
  1322. ldi 1,t1
  1323. stw t1,0(t0)
  1324. dbit_nounlock_11:
  1325. #endif
  1326. rfir
  1327. nop
  1328. dbit_trap_20:
  1329. get_pgd spc,ptp
  1330. space_check spc,t0,dbit_fault
  1331. L2_ptep ptp,pte,t0,va,dbit_fault
  1332. #ifdef CONFIG_SMP
  1333. CMPIB=,n 0,spc,dbit_nolock_20
  1334. load32 PA(pa_dbit_lock),t0
  1335. dbit_spin_20:
  1336. ldcw 0(t0),t1
  1337. cmpib,= 0,t1,dbit_spin_20
  1338. nop
  1339. dbit_nolock_20:
  1340. #endif
  1341. update_dirty ptp,pte,t1
  1342. make_insert_tlb spc,pte,prot
  1343. f_extend pte,t1
  1344. idtlbt pte,prot
  1345. #ifdef CONFIG_SMP
  1346. CMPIB=,n 0,spc,dbit_nounlock_20
  1347. ldi 1,t1
  1348. stw t1,0(t0)
  1349. dbit_nounlock_20:
  1350. #endif
  1351. rfir
  1352. nop
  1353. #endif
  1354. .import handle_interruption,code
  1355. kernel_bad_space:
  1356. b intr_save
  1357. ldi 31,%r8 /* Use an unused code */
  1358. dbit_fault:
  1359. b intr_save
  1360. ldi 20,%r8
  1361. itlb_fault:
  1362. b intr_save
  1363. ldi 6,%r8
  1364. nadtlb_fault:
  1365. b intr_save
  1366. ldi 17,%r8
  1367. dtlb_fault:
  1368. b intr_save
  1369. ldi 15,%r8
  1370. /* Register saving semantics for system calls:
  1371. %r1 clobbered by system call macro in userspace
  1372. %r2 saved in PT_REGS by gateway page
  1373. %r3 - %r18 preserved by C code (saved by signal code)
  1374. %r19 - %r20 saved in PT_REGS by gateway page
  1375. %r21 - %r22 non-standard syscall args
  1376. stored in kernel stack by gateway page
  1377. %r23 - %r26 arg3-arg0, saved in PT_REGS by gateway page
  1378. %r27 - %r30 saved in PT_REGS by gateway page
  1379. %r31 syscall return pointer
  1380. */
  1381. /* Floating point registers (FIXME: what do we do with these?)
  1382. %fr0 - %fr3 status/exception, not preserved
  1383. %fr4 - %fr7 arguments
  1384. %fr8 - %fr11 not preserved by C code
  1385. %fr12 - %fr21 preserved by C code
  1386. %fr22 - %fr31 not preserved by C code
  1387. */
  1388. .macro reg_save regs
  1389. STREG %r3, PT_GR3(\regs)
  1390. STREG %r4, PT_GR4(\regs)
  1391. STREG %r5, PT_GR5(\regs)
  1392. STREG %r6, PT_GR6(\regs)
  1393. STREG %r7, PT_GR7(\regs)
  1394. STREG %r8, PT_GR8(\regs)
  1395. STREG %r9, PT_GR9(\regs)
  1396. STREG %r10,PT_GR10(\regs)
  1397. STREG %r11,PT_GR11(\regs)
  1398. STREG %r12,PT_GR12(\regs)
  1399. STREG %r13,PT_GR13(\regs)
  1400. STREG %r14,PT_GR14(\regs)
  1401. STREG %r15,PT_GR15(\regs)
  1402. STREG %r16,PT_GR16(\regs)
  1403. STREG %r17,PT_GR17(\regs)
  1404. STREG %r18,PT_GR18(\regs)
  1405. .endm
  1406. .macro reg_restore regs
  1407. LDREG PT_GR3(\regs), %r3
  1408. LDREG PT_GR4(\regs), %r4
  1409. LDREG PT_GR5(\regs), %r5
  1410. LDREG PT_GR6(\regs), %r6
  1411. LDREG PT_GR7(\regs), %r7
  1412. LDREG PT_GR8(\regs), %r8
  1413. LDREG PT_GR9(\regs), %r9
  1414. LDREG PT_GR10(\regs),%r10
  1415. LDREG PT_GR11(\regs),%r11
  1416. LDREG PT_GR12(\regs),%r12
  1417. LDREG PT_GR13(\regs),%r13
  1418. LDREG PT_GR14(\regs),%r14
  1419. LDREG PT_GR15(\regs),%r15
  1420. LDREG PT_GR16(\regs),%r16
  1421. LDREG PT_GR17(\regs),%r17
  1422. LDREG PT_GR18(\regs),%r18
  1423. .endm
  1424. .export sys_fork_wrapper
  1425. .export child_return
  1426. sys_fork_wrapper:
  1427. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  1428. ldo TASK_REGS(%r1),%r1
  1429. reg_save %r1
  1430. mfctl %cr27, %r3
  1431. STREG %r3, PT_CR27(%r1)
  1432. STREG %r2,-RP_OFFSET(%r30)
  1433. ldo FRAME_SIZE(%r30),%r30
  1434. #ifdef CONFIG_64BIT
  1435. ldo -16(%r30),%r29 /* Reference param save area */
  1436. #endif
  1437. /* These are call-clobbered registers and therefore
  1438. also syscall-clobbered (we hope). */
  1439. STREG %r2,PT_GR19(%r1) /* save for child */
  1440. STREG %r30,PT_GR21(%r1)
  1441. LDREG PT_GR30(%r1),%r25
  1442. copy %r1,%r24
  1443. BL sys_clone,%r2
  1444. ldi SIGCHLD,%r26
  1445. LDREG -RP_OFFSET-FRAME_SIZE(%r30),%r2
  1446. wrapper_exit:
  1447. ldo -FRAME_SIZE(%r30),%r30 /* get the stackframe */
  1448. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1449. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1450. LDREG PT_CR27(%r1), %r3
  1451. mtctl %r3, %cr27
  1452. reg_restore %r1
  1453. /* strace expects syscall # to be preserved in r20 */
  1454. ldi __NR_fork,%r20
  1455. bv %r0(%r2)
  1456. STREG %r20,PT_GR20(%r1)
  1457. /* Set the return value for the child */
  1458. child_return:
  1459. BL schedule_tail, %r2
  1460. nop
  1461. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE-FRAME_SIZE(%r30), %r1
  1462. LDREG TASK_PT_GR19(%r1),%r2
  1463. b wrapper_exit
  1464. copy %r0,%r28
  1465. .export sys_clone_wrapper
  1466. sys_clone_wrapper:
  1467. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1468. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1469. reg_save %r1
  1470. mfctl %cr27, %r3
  1471. STREG %r3, PT_CR27(%r1)
  1472. STREG %r2,-RP_OFFSET(%r30)
  1473. ldo FRAME_SIZE(%r30),%r30
  1474. #ifdef CONFIG_64BIT
  1475. ldo -16(%r30),%r29 /* Reference param save area */
  1476. #endif
  1477. /* WARNING - Clobbers r19 and r21, userspace must save these! */
  1478. STREG %r2,PT_GR19(%r1) /* save for child */
  1479. STREG %r30,PT_GR21(%r1)
  1480. BL sys_clone,%r2
  1481. copy %r1,%r24
  1482. b wrapper_exit
  1483. LDREG -RP_OFFSET-FRAME_SIZE(%r30),%r2
  1484. .export sys_vfork_wrapper
  1485. sys_vfork_wrapper:
  1486. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1487. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1488. reg_save %r1
  1489. mfctl %cr27, %r3
  1490. STREG %r3, PT_CR27(%r1)
  1491. STREG %r2,-RP_OFFSET(%r30)
  1492. ldo FRAME_SIZE(%r30),%r30
  1493. #ifdef CONFIG_64BIT
  1494. ldo -16(%r30),%r29 /* Reference param save area */
  1495. #endif
  1496. STREG %r2,PT_GR19(%r1) /* save for child */
  1497. STREG %r30,PT_GR21(%r1)
  1498. BL sys_vfork,%r2
  1499. copy %r1,%r26
  1500. b wrapper_exit
  1501. LDREG -RP_OFFSET-FRAME_SIZE(%r30),%r2
  1502. .macro execve_wrapper execve
  1503. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1504. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1505. /*
  1506. * Do we need to save/restore r3-r18 here?
  1507. * I don't think so. why would new thread need old
  1508. * threads registers?
  1509. */
  1510. /* %arg0 - %arg3 are already saved for us. */
  1511. STREG %r2,-RP_OFFSET(%r30)
  1512. ldo FRAME_SIZE(%r30),%r30
  1513. #ifdef CONFIG_64BIT
  1514. ldo -16(%r30),%r29 /* Reference param save area */
  1515. #endif
  1516. BL \execve,%r2
  1517. copy %r1,%arg0
  1518. ldo -FRAME_SIZE(%r30),%r30
  1519. LDREG -RP_OFFSET(%r30),%r2
  1520. /* If exec succeeded we need to load the args */
  1521. ldo -1024(%r0),%r1
  1522. cmpb,>>= %r28,%r1,error_\execve
  1523. copy %r2,%r19
  1524. error_\execve:
  1525. bv %r0(%r19)
  1526. nop
  1527. .endm
  1528. .export sys_execve_wrapper
  1529. .import sys_execve
  1530. sys_execve_wrapper:
  1531. execve_wrapper sys_execve
  1532. #ifdef CONFIG_64BIT
  1533. .export sys32_execve_wrapper
  1534. .import sys32_execve
  1535. sys32_execve_wrapper:
  1536. execve_wrapper sys32_execve
  1537. #endif
  1538. .export sys_rt_sigreturn_wrapper
  1539. sys_rt_sigreturn_wrapper:
  1540. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r26
  1541. ldo TASK_REGS(%r26),%r26 /* get pt regs */
  1542. /* Don't save regs, we are going to restore them from sigcontext. */
  1543. STREG %r2, -RP_OFFSET(%r30)
  1544. #ifdef CONFIG_64BIT
  1545. ldo FRAME_SIZE(%r30), %r30
  1546. BL sys_rt_sigreturn,%r2
  1547. ldo -16(%r30),%r29 /* Reference param save area */
  1548. #else
  1549. BL sys_rt_sigreturn,%r2
  1550. ldo FRAME_SIZE(%r30), %r30
  1551. #endif
  1552. ldo -FRAME_SIZE(%r30), %r30
  1553. LDREG -RP_OFFSET(%r30), %r2
  1554. /* FIXME: I think we need to restore a few more things here. */
  1555. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1556. ldo TASK_REGS(%r1),%r1 /* get pt regs */
  1557. reg_restore %r1
  1558. /* If the signal was received while the process was blocked on a
  1559. * syscall, then r2 will take us to syscall_exit; otherwise r2 will
  1560. * take us to syscall_exit_rfi and on to intr_return.
  1561. */
  1562. bv %r0(%r2)
  1563. LDREG PT_GR28(%r1),%r28 /* reload original r28 for syscall_exit */
  1564. .export sys_sigaltstack_wrapper
  1565. sys_sigaltstack_wrapper:
  1566. /* Get the user stack pointer */
  1567. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1568. ldo TASK_REGS(%r1),%r24 /* get pt regs */
  1569. LDREG TASK_PT_GR30(%r24),%r24
  1570. STREG %r2, -RP_OFFSET(%r30)
  1571. #ifdef CONFIG_64BIT
  1572. ldo FRAME_SIZE(%r30), %r30
  1573. b,l do_sigaltstack,%r2
  1574. ldo -16(%r30),%r29 /* Reference param save area */
  1575. #else
  1576. bl do_sigaltstack,%r2
  1577. ldo FRAME_SIZE(%r30), %r30
  1578. #endif
  1579. ldo -FRAME_SIZE(%r30), %r30
  1580. LDREG -RP_OFFSET(%r30), %r2
  1581. bv %r0(%r2)
  1582. nop
  1583. #ifdef CONFIG_64BIT
  1584. .export sys32_sigaltstack_wrapper
  1585. sys32_sigaltstack_wrapper:
  1586. /* Get the user stack pointer */
  1587. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r24
  1588. LDREG TASK_PT_GR30(%r24),%r24
  1589. STREG %r2, -RP_OFFSET(%r30)
  1590. ldo FRAME_SIZE(%r30), %r30
  1591. b,l do_sigaltstack32,%r2
  1592. ldo -16(%r30),%r29 /* Reference param save area */
  1593. ldo -FRAME_SIZE(%r30), %r30
  1594. LDREG -RP_OFFSET(%r30), %r2
  1595. bv %r0(%r2)
  1596. nop
  1597. #endif
  1598. .export sys_rt_sigsuspend_wrapper
  1599. sys_rt_sigsuspend_wrapper:
  1600. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  1601. ldo TASK_REGS(%r1),%r24
  1602. reg_save %r24
  1603. STREG %r2, -RP_OFFSET(%r30)
  1604. #ifdef CONFIG_64BIT
  1605. ldo FRAME_SIZE(%r30), %r30
  1606. b,l sys_rt_sigsuspend,%r2
  1607. ldo -16(%r30),%r29 /* Reference param save area */
  1608. #else
  1609. bl sys_rt_sigsuspend,%r2
  1610. ldo FRAME_SIZE(%r30), %r30
  1611. #endif
  1612. ldo -FRAME_SIZE(%r30), %r30
  1613. LDREG -RP_OFFSET(%r30), %r2
  1614. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30), %r1
  1615. ldo TASK_REGS(%r1),%r1
  1616. reg_restore %r1
  1617. bv %r0(%r2)
  1618. nop
  1619. .export syscall_exit
  1620. syscall_exit:
  1621. /* NOTE: HP-UX syscalls also come through here
  1622. * after hpux_syscall_exit fixes up return
  1623. * values. */
  1624. /* NOTE: Not all syscalls exit this way. rt_sigreturn will exit
  1625. * via syscall_exit_rfi if the signal was received while the process
  1626. * was running.
  1627. */
  1628. /* save return value now */
  1629. mfctl %cr30, %r1
  1630. LDREG TI_TASK(%r1),%r1
  1631. STREG %r28,TASK_PT_GR28(%r1)
  1632. #ifdef CONFIG_HPUX
  1633. /* <linux/personality.h> cannot be easily included */
  1634. #define PER_HPUX 0x10
  1635. LDREG TASK_PERSONALITY(%r1),%r19
  1636. /* We can't use "CMPIB<> PER_HPUX" since "im5" field is sign extended */
  1637. ldo -PER_HPUX(%r19), %r19
  1638. CMPIB<>,n 0,%r19,1f
  1639. /* Save other hpux returns if personality is PER_HPUX */
  1640. STREG %r22,TASK_PT_GR22(%r1)
  1641. STREG %r29,TASK_PT_GR29(%r1)
  1642. 1:
  1643. #endif /* CONFIG_HPUX */
  1644. /* Seems to me that dp could be wrong here, if the syscall involved
  1645. * calling a module, and nothing got round to restoring dp on return.
  1646. */
  1647. loadgp
  1648. syscall_check_bh:
  1649. /* Check for software interrupts */
  1650. .import irq_stat,data
  1651. load32 irq_stat,%r19
  1652. #ifdef CONFIG_SMP
  1653. /* sched.h: int processor */
  1654. /* %r26 is used as scratch register to index into irq_stat[] */
  1655. ldw TI_CPU-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r26 /* cpu # */
  1656. /* shift left ____cacheline_aligned (aka L1_CACHE_BYTES) bits */
  1657. #ifdef CONFIG_64BIT
  1658. shld %r26, 6, %r20
  1659. #else
  1660. shlw %r26, 5, %r20
  1661. #endif
  1662. add %r19,%r20,%r19 /* now have &irq_stat[smp_processor_id()] */
  1663. #endif /* CONFIG_SMP */
  1664. syscall_check_resched:
  1665. /* check for reschedule */
  1666. LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19 /* long */
  1667. bb,<,n %r19, 31-TIF_NEED_RESCHED, syscall_do_resched /* forward */
  1668. syscall_check_sig:
  1669. LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19 /* get ti flags */
  1670. bb,<,n %r19, 31-TIF_SIGPENDING, syscall_do_signal /* forward */
  1671. syscall_restore:
  1672. /* Are we being ptraced? */
  1673. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1674. LDREG TASK_PTRACE(%r1), %r19
  1675. bb,< %r19,31,syscall_restore_rfi
  1676. nop
  1677. ldo TASK_PT_FR31(%r1),%r19 /* reload fpregs */
  1678. rest_fp %r19
  1679. LDREG TASK_PT_SAR(%r1),%r19 /* restore SAR */
  1680. mtsar %r19
  1681. LDREG TASK_PT_GR2(%r1),%r2 /* restore user rp */
  1682. LDREG TASK_PT_GR19(%r1),%r19
  1683. LDREG TASK_PT_GR20(%r1),%r20
  1684. LDREG TASK_PT_GR21(%r1),%r21
  1685. LDREG TASK_PT_GR22(%r1),%r22
  1686. LDREG TASK_PT_GR23(%r1),%r23
  1687. LDREG TASK_PT_GR24(%r1),%r24
  1688. LDREG TASK_PT_GR25(%r1),%r25
  1689. LDREG TASK_PT_GR26(%r1),%r26
  1690. LDREG TASK_PT_GR27(%r1),%r27 /* restore user dp */
  1691. LDREG TASK_PT_GR28(%r1),%r28 /* syscall return value */
  1692. LDREG TASK_PT_GR29(%r1),%r29
  1693. LDREG TASK_PT_GR31(%r1),%r31 /* restore syscall rp */
  1694. /* NOTE: We use rsm/ssm pair to make this operation atomic */
  1695. rsm PSW_SM_I, %r0
  1696. LDREG TASK_PT_GR30(%r1),%r30 /* restore user sp */
  1697. mfsp %sr3,%r1 /* Get users space id */
  1698. mtsp %r1,%sr7 /* Restore sr7 */
  1699. ssm PSW_SM_I, %r0
  1700. /* Set sr2 to zero for userspace syscalls to work. */
  1701. mtsp %r0,%sr2
  1702. mtsp %r1,%sr4 /* Restore sr4 */
  1703. mtsp %r1,%sr5 /* Restore sr5 */
  1704. mtsp %r1,%sr6 /* Restore sr6 */
  1705. depi 3,31,2,%r31 /* ensure return to user mode. */
  1706. #ifdef CONFIG_64BIT
  1707. /* decide whether to reset the wide mode bit
  1708. *
  1709. * For a syscall, the W bit is stored in the lowest bit
  1710. * of sp. Extract it and reset W if it is zero */
  1711. extrd,u,*<> %r30,63,1,%r1
  1712. rsm PSW_SM_W, %r0
  1713. /* now reset the lowest bit of sp if it was set */
  1714. xor %r30,%r1,%r30
  1715. #endif
  1716. be,n 0(%sr3,%r31) /* return to user space */
  1717. /* We have to return via an RFI, so that PSW T and R bits can be set
  1718. * appropriately.
  1719. * This sets up pt_regs so we can return via intr_restore, which is not
  1720. * the most efficient way of doing things, but it works.
  1721. */
  1722. syscall_restore_rfi:
  1723. ldo -1(%r0),%r2 /* Set recovery cntr to -1 */
  1724. mtctl %r2,%cr0 /* for immediate trap */
  1725. LDREG TASK_PT_PSW(%r1),%r2 /* Get old PSW */
  1726. ldi 0x0b,%r20 /* Create new PSW */
  1727. depi -1,13,1,%r20 /* C, Q, D, and I bits */
  1728. /* The values of PA_SINGLESTEP_BIT and PA_BLOCKSTEP_BIT are
  1729. * set in include/linux/ptrace.h and converted to PA bitmap
  1730. * numbers in asm-offsets.c */
  1731. /* if ((%r19.PA_SINGLESTEP_BIT)) { %r20.27=1} */
  1732. extru,= %r19,PA_SINGLESTEP_BIT,1,%r0
  1733. depi -1,27,1,%r20 /* R bit */
  1734. /* if ((%r19.PA_BLOCKSTEP_BIT)) { %r20.7=1} */
  1735. extru,= %r19,PA_BLOCKSTEP_BIT,1,%r0
  1736. depi -1,7,1,%r20 /* T bit */
  1737. STREG %r20,TASK_PT_PSW(%r1)
  1738. /* Always store space registers, since sr3 can be changed (e.g. fork) */
  1739. mfsp %sr3,%r25
  1740. STREG %r25,TASK_PT_SR3(%r1)
  1741. STREG %r25,TASK_PT_SR4(%r1)
  1742. STREG %r25,TASK_PT_SR5(%r1)
  1743. STREG %r25,TASK_PT_SR6(%r1)
  1744. STREG %r25,TASK_PT_SR7(%r1)
  1745. STREG %r25,TASK_PT_IASQ0(%r1)
  1746. STREG %r25,TASK_PT_IASQ1(%r1)
  1747. /* XXX W bit??? */
  1748. /* Now if old D bit is clear, it means we didn't save all registers
  1749. * on syscall entry, so do that now. This only happens on TRACEME
  1750. * calls, or if someone attached to us while we were on a syscall.
  1751. * We could make this more efficient by not saving r3-r18, but
  1752. * then we wouldn't be able to use the common intr_restore path.
  1753. * It is only for traced processes anyway, so performance is not
  1754. * an issue.
  1755. */
  1756. bb,< %r2,30,pt_regs_ok /* Branch if D set */
  1757. ldo TASK_REGS(%r1),%r25
  1758. reg_save %r25 /* Save r3 to r18 */
  1759. /* Save the current sr */
  1760. mfsp %sr0,%r2
  1761. STREG %r2,TASK_PT_SR0(%r1)
  1762. /* Save the scratch sr */
  1763. mfsp %sr1,%r2
  1764. STREG %r2,TASK_PT_SR1(%r1)
  1765. /* sr2 should be set to zero for userspace syscalls */
  1766. STREG %r0,TASK_PT_SR2(%r1)
  1767. pt_regs_ok:
  1768. LDREG TASK_PT_GR31(%r1),%r2
  1769. depi 3,31,2,%r2 /* ensure return to user mode. */
  1770. STREG %r2,TASK_PT_IAOQ0(%r1)
  1771. ldo 4(%r2),%r2
  1772. STREG %r2,TASK_PT_IAOQ1(%r1)
  1773. copy %r25,%r16
  1774. b intr_restore
  1775. nop
  1776. .import schedule,code
  1777. syscall_do_resched:
  1778. BL schedule,%r2
  1779. #ifdef CONFIG_64BIT
  1780. ldo -16(%r30),%r29 /* Reference param save area */
  1781. #else
  1782. nop
  1783. #endif
  1784. b syscall_check_bh /* if resched, we start over again */
  1785. nop
  1786. .import do_signal,code
  1787. syscall_do_signal:
  1788. /* Save callee-save registers (for sigcontext).
  1789. FIXME: After this point the process structure should be
  1790. consistent with all the relevant state of the process
  1791. before the syscall. We need to verify this. */
  1792. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1793. ldo TASK_REGS(%r1), %r25 /* struct pt_regs *regs */
  1794. reg_save %r25
  1795. ldi 1, %r24 /* unsigned long in_syscall */
  1796. #ifdef CONFIG_64BIT
  1797. ldo -16(%r30),%r29 /* Reference param save area */
  1798. #endif
  1799. BL do_signal,%r2
  1800. copy %r0, %r26 /* sigset_t *oldset = NULL */
  1801. LDREG TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
  1802. ldo TASK_REGS(%r1), %r20 /* reload pt_regs */
  1803. reg_restore %r20
  1804. b,n syscall_check_sig
  1805. /*
  1806. * get_register is used by the non access tlb miss handlers to
  1807. * copy the value of the general register specified in r8 into
  1808. * r1. This routine can't be used for shadowed registers, since
  1809. * the rfir will restore the original value. So, for the shadowed
  1810. * registers we put a -1 into r1 to indicate that the register
  1811. * should not be used (the register being copied could also have
  1812. * a -1 in it, but that is OK, it just means that we will have
  1813. * to use the slow path instead).
  1814. */
  1815. get_register:
  1816. blr %r8,%r0
  1817. nop
  1818. bv %r0(%r25) /* r0 */
  1819. copy %r0,%r1
  1820. bv %r0(%r25) /* r1 - shadowed */
  1821. ldi -1,%r1
  1822. bv %r0(%r25) /* r2 */
  1823. copy %r2,%r1
  1824. bv %r0(%r25) /* r3 */
  1825. copy %r3,%r1
  1826. bv %r0(%r25) /* r4 */
  1827. copy %r4,%r1
  1828. bv %r0(%r25) /* r5 */
  1829. copy %r5,%r1
  1830. bv %r0(%r25) /* r6 */
  1831. copy %r6,%r1
  1832. bv %r0(%r25) /* r7 */
  1833. copy %r7,%r1
  1834. bv %r0(%r25) /* r8 - shadowed */
  1835. ldi -1,%r1
  1836. bv %r0(%r25) /* r9 - shadowed */
  1837. ldi -1,%r1
  1838. bv %r0(%r25) /* r10 */
  1839. copy %r10,%r1
  1840. bv %r0(%r25) /* r11 */
  1841. copy %r11,%r1
  1842. bv %r0(%r25) /* r12 */
  1843. copy %r12,%r1
  1844. bv %r0(%r25) /* r13 */
  1845. copy %r13,%r1
  1846. bv %r0(%r25) /* r14 */
  1847. copy %r14,%r1
  1848. bv %r0(%r25) /* r15 */
  1849. copy %r15,%r1
  1850. bv %r0(%r25) /* r16 - shadowed */
  1851. ldi -1,%r1
  1852. bv %r0(%r25) /* r17 - shadowed */
  1853. ldi -1,%r1
  1854. bv %r0(%r25) /* r18 */
  1855. copy %r18,%r1
  1856. bv %r0(%r25) /* r19 */
  1857. copy %r19,%r1
  1858. bv %r0(%r25) /* r20 */
  1859. copy %r20,%r1
  1860. bv %r0(%r25) /* r21 */
  1861. copy %r21,%r1
  1862. bv %r0(%r25) /* r22 */
  1863. copy %r22,%r1
  1864. bv %r0(%r25) /* r23 */
  1865. copy %r23,%r1
  1866. bv %r0(%r25) /* r24 - shadowed */
  1867. ldi -1,%r1
  1868. bv %r0(%r25) /* r25 - shadowed */
  1869. ldi -1,%r1
  1870. bv %r0(%r25) /* r26 */
  1871. copy %r26,%r1
  1872. bv %r0(%r25) /* r27 */
  1873. copy %r27,%r1
  1874. bv %r0(%r25) /* r28 */
  1875. copy %r28,%r1
  1876. bv %r0(%r25) /* r29 */
  1877. copy %r29,%r1
  1878. bv %r0(%r25) /* r30 */
  1879. copy %r30,%r1
  1880. bv %r0(%r25) /* r31 */
  1881. copy %r31,%r1
  1882. /*
  1883. * set_register is used by the non access tlb miss handlers to
  1884. * copy the value of r1 into the general register specified in
  1885. * r8.
  1886. */
  1887. set_register:
  1888. blr %r8,%r0
  1889. nop
  1890. bv %r0(%r25) /* r0 (silly, but it is a place holder) */
  1891. copy %r1,%r0
  1892. bv %r0(%r25) /* r1 */
  1893. copy %r1,%r1
  1894. bv %r0(%r25) /* r2 */
  1895. copy %r1,%r2
  1896. bv %r0(%r25) /* r3 */
  1897. copy %r1,%r3
  1898. bv %r0(%r25) /* r4 */
  1899. copy %r1,%r4
  1900. bv %r0(%r25) /* r5 */
  1901. copy %r1,%r5
  1902. bv %r0(%r25) /* r6 */
  1903. copy %r1,%r6
  1904. bv %r0(%r25) /* r7 */
  1905. copy %r1,%r7
  1906. bv %r0(%r25) /* r8 */
  1907. copy %r1,%r8
  1908. bv %r0(%r25) /* r9 */
  1909. copy %r1,%r9
  1910. bv %r0(%r25) /* r10 */
  1911. copy %r1,%r10
  1912. bv %r0(%r25) /* r11 */
  1913. copy %r1,%r11
  1914. bv %r0(%r25) /* r12 */
  1915. copy %r1,%r12
  1916. bv %r0(%r25) /* r13 */
  1917. copy %r1,%r13
  1918. bv %r0(%r25) /* r14 */
  1919. copy %r1,%r14
  1920. bv %r0(%r25) /* r15 */
  1921. copy %r1,%r15
  1922. bv %r0(%r25) /* r16 */
  1923. copy %r1,%r16
  1924. bv %r0(%r25) /* r17 */
  1925. copy %r1,%r17
  1926. bv %r0(%r25) /* r18 */
  1927. copy %r1,%r18
  1928. bv %r0(%r25) /* r19 */
  1929. copy %r1,%r19
  1930. bv %r0(%r25) /* r20 */
  1931. copy %r1,%r20
  1932. bv %r0(%r25) /* r21 */
  1933. copy %r1,%r21
  1934. bv %r0(%r25) /* r22 */
  1935. copy %r1,%r22
  1936. bv %r0(%r25) /* r23 */
  1937. copy %r1,%r23
  1938. bv %r0(%r25) /* r24 */
  1939. copy %r1,%r24
  1940. bv %r0(%r25) /* r25 */
  1941. copy %r1,%r25
  1942. bv %r0(%r25) /* r26 */
  1943. copy %r1,%r26
  1944. bv %r0(%r25) /* r27 */
  1945. copy %r1,%r27
  1946. bv %r0(%r25) /* r28 */
  1947. copy %r1,%r28
  1948. bv %r0(%r25) /* r29 */
  1949. copy %r1,%r29
  1950. bv %r0(%r25) /* r30 */
  1951. copy %r1,%r30
  1952. bv %r0(%r25) /* r31 */
  1953. copy %r1,%r31