entry.S 54 KB

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