entry.S 53 KB

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