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