entry.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. /*
  2. * arch/alpha/kernel/entry.S
  3. *
  4. * Kernel entry-points.
  5. */
  6. #include <asm/asm-offsets.h>
  7. #include <asm/thread_info.h>
  8. #include <asm/pal.h>
  9. #include <asm/errno.h>
  10. #include <asm/unistd.h>
  11. .text
  12. .set noat
  13. .cfi_sections .debug_frame
  14. /* Stack offsets. */
  15. #define SP_OFF 184
  16. #define SWITCH_STACK_SIZE 320
  17. .macro CFI_START_OSF_FRAME func
  18. .align 4
  19. .globl \func
  20. .type \func,@function
  21. \func:
  22. .cfi_startproc simple
  23. .cfi_return_column 64
  24. .cfi_def_cfa $sp, 48
  25. .cfi_rel_offset 64, 8
  26. .cfi_rel_offset $gp, 16
  27. .cfi_rel_offset $16, 24
  28. .cfi_rel_offset $17, 32
  29. .cfi_rel_offset $18, 40
  30. .endm
  31. .macro CFI_END_OSF_FRAME func
  32. .cfi_endproc
  33. .size \func, . - \func
  34. .endm
  35. /*
  36. * This defines the normal kernel pt-regs layout.
  37. *
  38. * regs 9-15 preserved by C code
  39. * regs 16-18 saved by PAL-code
  40. * regs 29-30 saved and set up by PAL-code
  41. * JRP - Save regs 16-18 in a special area of the stack, so that
  42. * the palcode-provided values are available to the signal handler.
  43. */
  44. .macro SAVE_ALL
  45. subq $sp, SP_OFF, $sp
  46. .cfi_adjust_cfa_offset SP_OFF
  47. stq $0, 0($sp)
  48. stq $1, 8($sp)
  49. stq $2, 16($sp)
  50. stq $3, 24($sp)
  51. stq $4, 32($sp)
  52. stq $28, 144($sp)
  53. .cfi_rel_offset $0, 0
  54. .cfi_rel_offset $1, 8
  55. .cfi_rel_offset $2, 16
  56. .cfi_rel_offset $3, 24
  57. .cfi_rel_offset $4, 32
  58. .cfi_rel_offset $28, 144
  59. lda $2, alpha_mv
  60. stq $5, 40($sp)
  61. stq $6, 48($sp)
  62. stq $7, 56($sp)
  63. stq $8, 64($sp)
  64. stq $19, 72($sp)
  65. stq $20, 80($sp)
  66. stq $21, 88($sp)
  67. ldq $2, HAE_CACHE($2)
  68. stq $22, 96($sp)
  69. stq $23, 104($sp)
  70. stq $24, 112($sp)
  71. stq $25, 120($sp)
  72. stq $26, 128($sp)
  73. stq $27, 136($sp)
  74. stq $2, 152($sp)
  75. stq $16, 160($sp)
  76. stq $17, 168($sp)
  77. stq $18, 176($sp)
  78. .cfi_rel_offset $5, 40
  79. .cfi_rel_offset $6, 48
  80. .cfi_rel_offset $7, 56
  81. .cfi_rel_offset $8, 64
  82. .cfi_rel_offset $19, 72
  83. .cfi_rel_offset $20, 80
  84. .cfi_rel_offset $21, 88
  85. .cfi_rel_offset $22, 96
  86. .cfi_rel_offset $23, 104
  87. .cfi_rel_offset $24, 112
  88. .cfi_rel_offset $25, 120
  89. .cfi_rel_offset $26, 128
  90. .cfi_rel_offset $27, 136
  91. .endm
  92. .macro RESTORE_ALL
  93. lda $19, alpha_mv
  94. ldq $0, 0($sp)
  95. ldq $1, 8($sp)
  96. ldq $2, 16($sp)
  97. ldq $3, 24($sp)
  98. ldq $21, 152($sp)
  99. ldq $20, HAE_CACHE($19)
  100. ldq $4, 32($sp)
  101. ldq $5, 40($sp)
  102. ldq $6, 48($sp)
  103. ldq $7, 56($sp)
  104. subq $20, $21, $20
  105. ldq $8, 64($sp)
  106. beq $20, 99f
  107. ldq $20, HAE_REG($19)
  108. stq $21, HAE_CACHE($19)
  109. stq $21, 0($20)
  110. 99: ldq $19, 72($sp)
  111. ldq $20, 80($sp)
  112. ldq $21, 88($sp)
  113. ldq $22, 96($sp)
  114. ldq $23, 104($sp)
  115. ldq $24, 112($sp)
  116. ldq $25, 120($sp)
  117. ldq $26, 128($sp)
  118. ldq $27, 136($sp)
  119. ldq $28, 144($sp)
  120. addq $sp, SP_OFF, $sp
  121. .cfi_restore $0
  122. .cfi_restore $1
  123. .cfi_restore $2
  124. .cfi_restore $3
  125. .cfi_restore $4
  126. .cfi_restore $5
  127. .cfi_restore $6
  128. .cfi_restore $7
  129. .cfi_restore $8
  130. .cfi_restore $19
  131. .cfi_restore $20
  132. .cfi_restore $21
  133. .cfi_restore $22
  134. .cfi_restore $23
  135. .cfi_restore $24
  136. .cfi_restore $25
  137. .cfi_restore $26
  138. .cfi_restore $27
  139. .cfi_restore $28
  140. .cfi_adjust_cfa_offset -SP_OFF
  141. .endm
  142. .macro DO_SWITCH_STACK
  143. bsr $1, do_switch_stack
  144. .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
  145. .cfi_rel_offset $9, 0
  146. .cfi_rel_offset $10, 8
  147. .cfi_rel_offset $11, 16
  148. .cfi_rel_offset $12, 24
  149. .cfi_rel_offset $13, 32
  150. .cfi_rel_offset $14, 40
  151. .cfi_rel_offset $15, 48
  152. /* We don't really care about the FP registers for debugging. */
  153. .endm
  154. .macro UNDO_SWITCH_STACK
  155. bsr $1, undo_switch_stack
  156. .cfi_restore $9
  157. .cfi_restore $10
  158. .cfi_restore $11
  159. .cfi_restore $12
  160. .cfi_restore $13
  161. .cfi_restore $14
  162. .cfi_restore $15
  163. .cfi_adjust_cfa_offset -SWITCH_STACK_SIZE
  164. .endm
  165. /*
  166. * Non-syscall kernel entry points.
  167. */
  168. CFI_START_OSF_FRAME entInt
  169. SAVE_ALL
  170. lda $8, 0x3fff
  171. lda $26, ret_from_sys_call
  172. bic $sp, $8, $8
  173. mov $sp, $19
  174. jsr $31, do_entInt
  175. CFI_END_OSF_FRAME entInt
  176. CFI_START_OSF_FRAME entArith
  177. SAVE_ALL
  178. lda $8, 0x3fff
  179. lda $26, ret_from_sys_call
  180. bic $sp, $8, $8
  181. mov $sp, $18
  182. jsr $31, do_entArith
  183. CFI_END_OSF_FRAME entArith
  184. CFI_START_OSF_FRAME entMM
  185. SAVE_ALL
  186. /* save $9 - $15 so the inline exception code can manipulate them. */
  187. subq $sp, 56, $sp
  188. .cfi_adjust_cfa_offset 56
  189. stq $9, 0($sp)
  190. stq $10, 8($sp)
  191. stq $11, 16($sp)
  192. stq $12, 24($sp)
  193. stq $13, 32($sp)
  194. stq $14, 40($sp)
  195. stq $15, 48($sp)
  196. .cfi_rel_offset $9, 0
  197. .cfi_rel_offset $10, 8
  198. .cfi_rel_offset $11, 16
  199. .cfi_rel_offset $12, 24
  200. .cfi_rel_offset $13, 32
  201. .cfi_rel_offset $14, 40
  202. .cfi_rel_offset $15, 48
  203. addq $sp, 56, $19
  204. /* handle the fault */
  205. lda $8, 0x3fff
  206. bic $sp, $8, $8
  207. jsr $26, do_page_fault
  208. /* reload the registers after the exception code played. */
  209. ldq $9, 0($sp)
  210. ldq $10, 8($sp)
  211. ldq $11, 16($sp)
  212. ldq $12, 24($sp)
  213. ldq $13, 32($sp)
  214. ldq $14, 40($sp)
  215. ldq $15, 48($sp)
  216. addq $sp, 56, $sp
  217. .cfi_restore $9
  218. .cfi_restore $10
  219. .cfi_restore $11
  220. .cfi_restore $12
  221. .cfi_restore $13
  222. .cfi_restore $14
  223. .cfi_restore $15
  224. .cfi_adjust_cfa_offset -56
  225. /* finish up the syscall as normal. */
  226. br ret_from_sys_call
  227. CFI_END_OSF_FRAME entMM
  228. CFI_START_OSF_FRAME entIF
  229. SAVE_ALL
  230. lda $8, 0x3fff
  231. lda $26, ret_from_sys_call
  232. bic $sp, $8, $8
  233. mov $sp, $17
  234. jsr $31, do_entIF
  235. CFI_END_OSF_FRAME entIF
  236. CFI_START_OSF_FRAME entUna
  237. lda $sp, -256($sp)
  238. .cfi_adjust_cfa_offset 256
  239. stq $0, 0($sp)
  240. .cfi_rel_offset $0, 0
  241. .cfi_remember_state
  242. ldq $0, 256($sp) /* get PS */
  243. stq $1, 8($sp)
  244. stq $2, 16($sp)
  245. stq $3, 24($sp)
  246. and $0, 8, $0 /* user mode? */
  247. stq $4, 32($sp)
  248. bne $0, entUnaUser /* yup -> do user-level unaligned fault */
  249. stq $5, 40($sp)
  250. stq $6, 48($sp)
  251. stq $7, 56($sp)
  252. stq $8, 64($sp)
  253. stq $9, 72($sp)
  254. stq $10, 80($sp)
  255. stq $11, 88($sp)
  256. stq $12, 96($sp)
  257. stq $13, 104($sp)
  258. stq $14, 112($sp)
  259. stq $15, 120($sp)
  260. /* 16-18 PAL-saved */
  261. stq $19, 152($sp)
  262. stq $20, 160($sp)
  263. stq $21, 168($sp)
  264. stq $22, 176($sp)
  265. stq $23, 184($sp)
  266. stq $24, 192($sp)
  267. stq $25, 200($sp)
  268. stq $26, 208($sp)
  269. stq $27, 216($sp)
  270. stq $28, 224($sp)
  271. mov $sp, $19
  272. stq $gp, 232($sp)
  273. .cfi_rel_offset $1, 1*8
  274. .cfi_rel_offset $2, 2*8
  275. .cfi_rel_offset $3, 3*8
  276. .cfi_rel_offset $4, 4*8
  277. .cfi_rel_offset $5, 5*8
  278. .cfi_rel_offset $6, 6*8
  279. .cfi_rel_offset $7, 7*8
  280. .cfi_rel_offset $8, 8*8
  281. .cfi_rel_offset $9, 9*8
  282. .cfi_rel_offset $10, 10*8
  283. .cfi_rel_offset $11, 11*8
  284. .cfi_rel_offset $12, 12*8
  285. .cfi_rel_offset $13, 13*8
  286. .cfi_rel_offset $14, 14*8
  287. .cfi_rel_offset $15, 15*8
  288. .cfi_rel_offset $19, 19*8
  289. .cfi_rel_offset $20, 20*8
  290. .cfi_rel_offset $21, 21*8
  291. .cfi_rel_offset $22, 22*8
  292. .cfi_rel_offset $23, 23*8
  293. .cfi_rel_offset $24, 24*8
  294. .cfi_rel_offset $25, 25*8
  295. .cfi_rel_offset $26, 26*8
  296. .cfi_rel_offset $27, 27*8
  297. .cfi_rel_offset $28, 28*8
  298. .cfi_rel_offset $29, 29*8
  299. lda $8, 0x3fff
  300. stq $31, 248($sp)
  301. bic $sp, $8, $8
  302. jsr $26, do_entUna
  303. ldq $0, 0($sp)
  304. ldq $1, 8($sp)
  305. ldq $2, 16($sp)
  306. ldq $3, 24($sp)
  307. ldq $4, 32($sp)
  308. ldq $5, 40($sp)
  309. ldq $6, 48($sp)
  310. ldq $7, 56($sp)
  311. ldq $8, 64($sp)
  312. ldq $9, 72($sp)
  313. ldq $10, 80($sp)
  314. ldq $11, 88($sp)
  315. ldq $12, 96($sp)
  316. ldq $13, 104($sp)
  317. ldq $14, 112($sp)
  318. ldq $15, 120($sp)
  319. /* 16-18 PAL-saved */
  320. ldq $19, 152($sp)
  321. ldq $20, 160($sp)
  322. ldq $21, 168($sp)
  323. ldq $22, 176($sp)
  324. ldq $23, 184($sp)
  325. ldq $24, 192($sp)
  326. ldq $25, 200($sp)
  327. ldq $26, 208($sp)
  328. ldq $27, 216($sp)
  329. ldq $28, 224($sp)
  330. ldq $gp, 232($sp)
  331. lda $sp, 256($sp)
  332. .cfi_restore $1
  333. .cfi_restore $2
  334. .cfi_restore $3
  335. .cfi_restore $4
  336. .cfi_restore $5
  337. .cfi_restore $6
  338. .cfi_restore $7
  339. .cfi_restore $8
  340. .cfi_restore $9
  341. .cfi_restore $10
  342. .cfi_restore $11
  343. .cfi_restore $12
  344. .cfi_restore $13
  345. .cfi_restore $14
  346. .cfi_restore $15
  347. .cfi_restore $19
  348. .cfi_restore $20
  349. .cfi_restore $21
  350. .cfi_restore $22
  351. .cfi_restore $23
  352. .cfi_restore $24
  353. .cfi_restore $25
  354. .cfi_restore $26
  355. .cfi_restore $27
  356. .cfi_restore $28
  357. .cfi_restore $29
  358. .cfi_adjust_cfa_offset -256
  359. call_pal PAL_rti
  360. .align 4
  361. entUnaUser:
  362. .cfi_restore_state
  363. ldq $0, 0($sp) /* restore original $0 */
  364. lda $sp, 256($sp) /* pop entUna's stack frame */
  365. .cfi_restore $0
  366. .cfi_adjust_cfa_offset -256
  367. SAVE_ALL /* setup normal kernel stack */
  368. lda $sp, -56($sp)
  369. .cfi_adjust_cfa_offset 56
  370. stq $9, 0($sp)
  371. stq $10, 8($sp)
  372. stq $11, 16($sp)
  373. stq $12, 24($sp)
  374. stq $13, 32($sp)
  375. stq $14, 40($sp)
  376. stq $15, 48($sp)
  377. .cfi_rel_offset $9, 0
  378. .cfi_rel_offset $10, 8
  379. .cfi_rel_offset $11, 16
  380. .cfi_rel_offset $12, 24
  381. .cfi_rel_offset $13, 32
  382. .cfi_rel_offset $14, 40
  383. .cfi_rel_offset $15, 48
  384. lda $8, 0x3fff
  385. addq $sp, 56, $19
  386. bic $sp, $8, $8
  387. jsr $26, do_entUnaUser
  388. ldq $9, 0($sp)
  389. ldq $10, 8($sp)
  390. ldq $11, 16($sp)
  391. ldq $12, 24($sp)
  392. ldq $13, 32($sp)
  393. ldq $14, 40($sp)
  394. ldq $15, 48($sp)
  395. lda $sp, 56($sp)
  396. .cfi_restore $9
  397. .cfi_restore $10
  398. .cfi_restore $11
  399. .cfi_restore $12
  400. .cfi_restore $13
  401. .cfi_restore $14
  402. .cfi_restore $15
  403. .cfi_adjust_cfa_offset -56
  404. br ret_from_sys_call
  405. CFI_END_OSF_FRAME entUna
  406. CFI_START_OSF_FRAME entDbg
  407. SAVE_ALL
  408. lda $8, 0x3fff
  409. lda $26, ret_from_sys_call
  410. bic $sp, $8, $8
  411. mov $sp, $16
  412. jsr $31, do_entDbg
  413. CFI_END_OSF_FRAME entDbg
  414. /*
  415. * The system call entry point is special. Most importantly, it looks
  416. * like a function call to userspace as far as clobbered registers. We
  417. * do preserve the argument registers (for syscall restarts) and $26
  418. * (for leaf syscall functions).
  419. *
  420. * So much for theory. We don't take advantage of this yet.
  421. *
  422. * Note that a0-a2 are not saved by PALcode as with the other entry points.
  423. */
  424. .align 4
  425. .globl entSys
  426. .type entSys, @function
  427. .cfi_startproc simple
  428. .cfi_return_column 64
  429. .cfi_def_cfa $sp, 48
  430. .cfi_rel_offset 64, 8
  431. .cfi_rel_offset $gp, 16
  432. entSys:
  433. SAVE_ALL
  434. lda $8, 0x3fff
  435. bic $sp, $8, $8
  436. lda $4, NR_SYSCALLS($31)
  437. stq $16, SP_OFF+24($sp)
  438. lda $5, sys_call_table
  439. lda $27, sys_ni_syscall
  440. cmpult $0, $4, $4
  441. ldl $3, TI_FLAGS($8)
  442. stq $17, SP_OFF+32($sp)
  443. s8addq $0, $5, $5
  444. stq $18, SP_OFF+40($sp)
  445. .cfi_rel_offset $16, SP_OFF+24
  446. .cfi_rel_offset $17, SP_OFF+32
  447. .cfi_rel_offset $18, SP_OFF+40
  448. #ifdef CONFIG_AUDITSYSCALL
  449. lda $6, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
  450. and $3, $6, $3
  451. #endif
  452. bne $3, strace
  453. beq $4, 1f
  454. ldq $27, 0($5)
  455. 1: jsr $26, ($27), alpha_ni_syscall
  456. ldgp $gp, 0($26)
  457. blt $0, $syscall_error /* the call failed */
  458. stq $0, 0($sp)
  459. stq $31, 72($sp) /* a3=0 => no error */
  460. .align 4
  461. .globl ret_from_sys_call
  462. ret_from_sys_call:
  463. cmovne $26, 0, $18 /* $18 = 0 => non-restartable */
  464. ldq $0, SP_OFF($sp)
  465. and $0, 8, $0
  466. beq $0, ret_to_kernel
  467. ret_to_user:
  468. /* Make sure need_resched and sigpending don't change between
  469. sampling and the rti. */
  470. lda $16, 7
  471. call_pal PAL_swpipl
  472. ldl $17, TI_FLAGS($8)
  473. and $17, _TIF_WORK_MASK, $2
  474. bne $2, work_pending
  475. restore_all:
  476. .cfi_remember_state
  477. RESTORE_ALL
  478. call_pal PAL_rti
  479. ret_to_kernel:
  480. .cfi_restore_state
  481. lda $16, 7
  482. call_pal PAL_swpipl
  483. br restore_all
  484. .align 3
  485. $syscall_error:
  486. /*
  487. * Some system calls (e.g., ptrace) can return arbitrary
  488. * values which might normally be mistaken as error numbers.
  489. * Those functions must zero $0 (v0) directly in the stack
  490. * frame to indicate that a negative return value wasn't an
  491. * error number..
  492. */
  493. ldq $18, 0($sp) /* old syscall nr (zero if success) */
  494. beq $18, $ret_success
  495. ldq $19, 72($sp) /* .. and this a3 */
  496. subq $31, $0, $0 /* with error in v0 */
  497. addq $31, 1, $1 /* set a3 for errno return */
  498. stq $0, 0($sp)
  499. mov $31, $26 /* tell "ret_from_sys_call" we can restart */
  500. stq $1, 72($sp) /* a3 for return */
  501. br ret_from_sys_call
  502. $ret_success:
  503. stq $0, 0($sp)
  504. stq $31, 72($sp) /* a3=0 => no error */
  505. br ret_from_sys_call
  506. /*
  507. * Do all cleanup when returning from all interrupts and system calls.
  508. *
  509. * Arguments:
  510. * $8: current.
  511. * $17: TI_FLAGS.
  512. * $18: The old syscall number, or zero if this is not a return
  513. * from a syscall that errored and is possibly restartable.
  514. * $19: The old a3 value
  515. */
  516. .align 4
  517. .type work_pending, @function
  518. work_pending:
  519. and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING, $2
  520. bne $2, $work_notifysig
  521. $work_resched:
  522. /*
  523. * We can get here only if we returned from syscall without SIGPENDING
  524. * or got through work_notifysig already. Either case means no syscall
  525. * restarts for us, so let $18 and $19 burn.
  526. */
  527. jsr $26, schedule
  528. mov 0, $18
  529. br ret_to_user
  530. $work_notifysig:
  531. mov $sp, $16
  532. DO_SWITCH_STACK
  533. jsr $26, do_work_pending
  534. UNDO_SWITCH_STACK
  535. br restore_all
  536. /*
  537. * PTRACE syscall handler
  538. */
  539. .align 4
  540. .type strace, @function
  541. strace:
  542. /* set up signal stack, call syscall_trace */
  543. DO_SWITCH_STACK
  544. jsr $26, syscall_trace_enter /* returns the syscall number */
  545. UNDO_SWITCH_STACK
  546. /* get the arguments back.. */
  547. ldq $16, SP_OFF+24($sp)
  548. ldq $17, SP_OFF+32($sp)
  549. ldq $18, SP_OFF+40($sp)
  550. ldq $19, 72($sp)
  551. ldq $20, 80($sp)
  552. ldq $21, 88($sp)
  553. /* get the system call pointer.. */
  554. lda $1, NR_SYSCALLS($31)
  555. lda $2, sys_call_table
  556. lda $27, alpha_ni_syscall
  557. cmpult $0, $1, $1
  558. s8addq $0, $2, $2
  559. beq $1, 1f
  560. ldq $27, 0($2)
  561. 1: jsr $26, ($27), sys_gettimeofday
  562. ret_from_straced:
  563. ldgp $gp, 0($26)
  564. /* check return.. */
  565. blt $0, $strace_error /* the call failed */
  566. stq $31, 72($sp) /* a3=0 => no error */
  567. $strace_success:
  568. stq $0, 0($sp) /* save return value */
  569. DO_SWITCH_STACK
  570. jsr $26, syscall_trace_leave
  571. UNDO_SWITCH_STACK
  572. br $31, ret_from_sys_call
  573. .align 3
  574. $strace_error:
  575. ldq $18, 0($sp) /* old syscall nr (zero if success) */
  576. beq $18, $strace_success
  577. ldq $19, 72($sp) /* .. and this a3 */
  578. subq $31, $0, $0 /* with error in v0 */
  579. addq $31, 1, $1 /* set a3 for errno return */
  580. stq $0, 0($sp)
  581. stq $1, 72($sp) /* a3 for return */
  582. DO_SWITCH_STACK
  583. mov $18, $9 /* save old syscall number */
  584. mov $19, $10 /* save old a3 */
  585. jsr $26, syscall_trace_leave
  586. mov $9, $18
  587. mov $10, $19
  588. UNDO_SWITCH_STACK
  589. mov $31, $26 /* tell "ret_from_sys_call" we can restart */
  590. br ret_from_sys_call
  591. CFI_END_OSF_FRAME entSys
  592. /*
  593. * Save and restore the switch stack -- aka the balance of the user context.
  594. */
  595. .align 4
  596. .type do_switch_stack, @function
  597. .cfi_startproc simple
  598. .cfi_return_column 64
  599. .cfi_def_cfa $sp, 0
  600. .cfi_register 64, $1
  601. do_switch_stack:
  602. lda $sp, -SWITCH_STACK_SIZE($sp)
  603. .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
  604. stq $9, 0($sp)
  605. stq $10, 8($sp)
  606. stq $11, 16($sp)
  607. stq $12, 24($sp)
  608. stq $13, 32($sp)
  609. stq $14, 40($sp)
  610. stq $15, 48($sp)
  611. stq $26, 56($sp)
  612. stt $f0, 64($sp)
  613. stt $f1, 72($sp)
  614. stt $f2, 80($sp)
  615. stt $f3, 88($sp)
  616. stt $f4, 96($sp)
  617. stt $f5, 104($sp)
  618. stt $f6, 112($sp)
  619. stt $f7, 120($sp)
  620. stt $f8, 128($sp)
  621. stt $f9, 136($sp)
  622. stt $f10, 144($sp)
  623. stt $f11, 152($sp)
  624. stt $f12, 160($sp)
  625. stt $f13, 168($sp)
  626. stt $f14, 176($sp)
  627. stt $f15, 184($sp)
  628. stt $f16, 192($sp)
  629. stt $f17, 200($sp)
  630. stt $f18, 208($sp)
  631. stt $f19, 216($sp)
  632. stt $f20, 224($sp)
  633. stt $f21, 232($sp)
  634. stt $f22, 240($sp)
  635. stt $f23, 248($sp)
  636. stt $f24, 256($sp)
  637. stt $f25, 264($sp)
  638. stt $f26, 272($sp)
  639. stt $f27, 280($sp)
  640. mf_fpcr $f0 # get fpcr
  641. stt $f28, 288($sp)
  642. stt $f29, 296($sp)
  643. stt $f30, 304($sp)
  644. stt $f0, 312($sp) # save fpcr in slot of $f31
  645. ldt $f0, 64($sp) # dont let "do_switch_stack" change fp state.
  646. ret $31, ($1), 1
  647. .cfi_endproc
  648. .size do_switch_stack, .-do_switch_stack
  649. .align 4
  650. .type undo_switch_stack, @function
  651. .cfi_startproc simple
  652. .cfi_def_cfa $sp, 0
  653. .cfi_register 64, $1
  654. undo_switch_stack:
  655. ldq $9, 0($sp)
  656. ldq $10, 8($sp)
  657. ldq $11, 16($sp)
  658. ldq $12, 24($sp)
  659. ldq $13, 32($sp)
  660. ldq $14, 40($sp)
  661. ldq $15, 48($sp)
  662. ldq $26, 56($sp)
  663. ldt $f30, 312($sp) # get saved fpcr
  664. ldt $f0, 64($sp)
  665. ldt $f1, 72($sp)
  666. ldt $f2, 80($sp)
  667. ldt $f3, 88($sp)
  668. mt_fpcr $f30 # install saved fpcr
  669. ldt $f4, 96($sp)
  670. ldt $f5, 104($sp)
  671. ldt $f6, 112($sp)
  672. ldt $f7, 120($sp)
  673. ldt $f8, 128($sp)
  674. ldt $f9, 136($sp)
  675. ldt $f10, 144($sp)
  676. ldt $f11, 152($sp)
  677. ldt $f12, 160($sp)
  678. ldt $f13, 168($sp)
  679. ldt $f14, 176($sp)
  680. ldt $f15, 184($sp)
  681. ldt $f16, 192($sp)
  682. ldt $f17, 200($sp)
  683. ldt $f18, 208($sp)
  684. ldt $f19, 216($sp)
  685. ldt $f20, 224($sp)
  686. ldt $f21, 232($sp)
  687. ldt $f22, 240($sp)
  688. ldt $f23, 248($sp)
  689. ldt $f24, 256($sp)
  690. ldt $f25, 264($sp)
  691. ldt $f26, 272($sp)
  692. ldt $f27, 280($sp)
  693. ldt $f28, 288($sp)
  694. ldt $f29, 296($sp)
  695. ldt $f30, 304($sp)
  696. lda $sp, SWITCH_STACK_SIZE($sp)
  697. ret $31, ($1), 1
  698. .cfi_endproc
  699. .size undo_switch_stack, .-undo_switch_stack
  700. /*
  701. * The meat of the context switch code.
  702. */
  703. .align 4
  704. .globl alpha_switch_to
  705. .type alpha_switch_to, @function
  706. .cfi_startproc
  707. alpha_switch_to:
  708. DO_SWITCH_STACK
  709. call_pal PAL_swpctx
  710. lda $8, 0x3fff
  711. UNDO_SWITCH_STACK
  712. bic $sp, $8, $8
  713. mov $17, $0
  714. ret
  715. .cfi_endproc
  716. .size alpha_switch_to, .-alpha_switch_to
  717. /*
  718. * New processes begin life here.
  719. */
  720. .globl ret_from_fork
  721. .align 4
  722. .ent ret_from_fork
  723. ret_from_fork:
  724. lda $26, ret_from_sys_call
  725. mov $17, $16
  726. jmp $31, schedule_tail
  727. .end ret_from_fork
  728. /*
  729. * ... and new kernel threads - here
  730. */
  731. .align 4
  732. .globl ret_from_kernel_thread
  733. .ent ret_from_kernel_thread
  734. ret_from_kernel_thread:
  735. mov $17, $16
  736. jsr $26, schedule_tail
  737. mov $9, $27
  738. mov $10, $16
  739. jsr $26, ($9)
  740. mov $31, $19 /* to disable syscall restarts */
  741. br $31, ret_to_user
  742. .end ret_from_kernel_thread
  743. /*
  744. * Special system calls. Most of these are special in that they either
  745. * have to play switch_stack games or in some way use the pt_regs struct.
  746. */
  747. .macro fork_like name
  748. .align 4
  749. .globl alpha_\name
  750. .ent alpha_\name
  751. alpha_\name:
  752. .prologue 0
  753. bsr $1, do_switch_stack
  754. jsr $26, sys_\name
  755. ldq $26, 56($sp)
  756. lda $sp, SWITCH_STACK_SIZE($sp)
  757. ret
  758. .end alpha_\name
  759. .endm
  760. fork_like fork
  761. fork_like vfork
  762. fork_like clone
  763. .align 4
  764. .globl sys_sigreturn
  765. .ent sys_sigreturn
  766. sys_sigreturn:
  767. .prologue 0
  768. lda $9, ret_from_straced
  769. cmpult $26, $9, $9
  770. lda $sp, -SWITCH_STACK_SIZE($sp)
  771. jsr $26, do_sigreturn
  772. bne $9, 1f
  773. jsr $26, syscall_trace_leave
  774. 1: br $1, undo_switch_stack
  775. br ret_from_sys_call
  776. .end sys_sigreturn
  777. .align 4
  778. .globl sys_rt_sigreturn
  779. .ent sys_rt_sigreturn
  780. sys_rt_sigreturn:
  781. .prologue 0
  782. lda $9, ret_from_straced
  783. cmpult $26, $9, $9
  784. lda $sp, -SWITCH_STACK_SIZE($sp)
  785. jsr $26, do_rt_sigreturn
  786. bne $9, 1f
  787. jsr $26, syscall_trace_leave
  788. 1: br $1, undo_switch_stack
  789. br ret_from_sys_call
  790. .end sys_rt_sigreturn
  791. .align 4
  792. .globl alpha_ni_syscall
  793. .ent alpha_ni_syscall
  794. alpha_ni_syscall:
  795. .prologue 0
  796. /* Special because it also implements overflow handling via
  797. syscall number 0. And if you recall, zero is a special
  798. trigger for "not an error". Store large non-zero there. */
  799. lda $0, -ENOSYS
  800. unop
  801. stq $0, 0($sp)
  802. ret
  803. .end alpha_ni_syscall