entry.S 55 KB

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