entry.S 57 KB

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