entry.S 52 KB

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