entry.S 55 KB

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