entry.S 57 KB

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