entry.S 55 KB

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