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