entry.S 55 KB

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