entry.S 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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. blbs $3, strace
  449. beq $4, 1f
  450. ldq $27, 0($5)
  451. 1: jsr $26, ($27), alpha_ni_syscall
  452. ldgp $gp, 0($26)
  453. blt $0, $syscall_error /* the call failed */
  454. stq $0, 0($sp)
  455. stq $31, 72($sp) /* a3=0 => no error */
  456. .align 4
  457. .globl ret_from_sys_call
  458. ret_from_sys_call:
  459. cmovne $26, 0, $18 /* $18 = 0 => non-restartable */
  460. ldq $0, SP_OFF($sp)
  461. and $0, 8, $0
  462. beq $0, ret_to_kernel
  463. ret_to_user:
  464. /* Make sure need_resched and sigpending don't change between
  465. sampling and the rti. */
  466. lda $16, 7
  467. call_pal PAL_swpipl
  468. ldl $17, TI_FLAGS($8)
  469. and $17, _TIF_WORK_MASK, $2
  470. bne $2, work_pending
  471. restore_all:
  472. .cfi_remember_state
  473. RESTORE_ALL
  474. call_pal PAL_rti
  475. ret_to_kernel:
  476. .cfi_restore_state
  477. lda $16, 7
  478. call_pal PAL_swpipl
  479. br restore_all
  480. .align 3
  481. $syscall_error:
  482. /*
  483. * Some system calls (e.g., ptrace) can return arbitrary
  484. * values which might normally be mistaken as error numbers.
  485. * Those functions must zero $0 (v0) directly in the stack
  486. * frame to indicate that a negative return value wasn't an
  487. * error number..
  488. */
  489. ldq $18, 0($sp) /* old syscall nr (zero if success) */
  490. beq $18, $ret_success
  491. ldq $19, 72($sp) /* .. and this a3 */
  492. subq $31, $0, $0 /* with error in v0 */
  493. addq $31, 1, $1 /* set a3 for errno return */
  494. stq $0, 0($sp)
  495. mov $31, $26 /* tell "ret_from_sys_call" we can restart */
  496. stq $1, 72($sp) /* a3 for return */
  497. br ret_from_sys_call
  498. $ret_success:
  499. stq $0, 0($sp)
  500. stq $31, 72($sp) /* a3=0 => no error */
  501. br ret_from_sys_call
  502. /*
  503. * Do all cleanup when returning from all interrupts and system calls.
  504. *
  505. * Arguments:
  506. * $8: current.
  507. * $17: TI_FLAGS.
  508. * $18: The old syscall number, or zero if this is not a return
  509. * from a syscall that errored and is possibly restartable.
  510. * $19: The old a3 value
  511. */
  512. .align 4
  513. .type work_pending, @function
  514. work_pending:
  515. and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING, $2
  516. bne $2, $work_notifysig
  517. $work_resched:
  518. /*
  519. * We can get here only if we returned from syscall without SIGPENDING
  520. * or got through work_notifysig already. Either case means no syscall
  521. * restarts for us, so let $18 and $19 burn.
  522. */
  523. jsr $26, schedule
  524. mov 0, $18
  525. br ret_to_user
  526. $work_notifysig:
  527. mov $sp, $16
  528. DO_SWITCH_STACK
  529. jsr $26, do_work_pending
  530. UNDO_SWITCH_STACK
  531. br restore_all
  532. /*
  533. * PTRACE syscall handler
  534. */
  535. .align 4
  536. .type strace, @function
  537. strace:
  538. /* set up signal stack, call syscall_trace */
  539. DO_SWITCH_STACK
  540. jsr $26, syscall_trace_enter /* returns the syscall number */
  541. UNDO_SWITCH_STACK
  542. /* get the arguments back.. */
  543. ldq $16, SP_OFF+24($sp)
  544. ldq $17, SP_OFF+32($sp)
  545. ldq $18, SP_OFF+40($sp)
  546. ldq $19, 72($sp)
  547. ldq $20, 80($sp)
  548. ldq $21, 88($sp)
  549. /* get the system call pointer.. */
  550. lda $1, NR_SYSCALLS($31)
  551. lda $2, sys_call_table
  552. lda $27, alpha_ni_syscall
  553. cmpult $0, $1, $1
  554. s8addq $0, $2, $2
  555. beq $1, 1f
  556. ldq $27, 0($2)
  557. 1: jsr $26, ($27), sys_gettimeofday
  558. ret_from_straced:
  559. ldgp $gp, 0($26)
  560. /* check return.. */
  561. blt $0, $strace_error /* the call failed */
  562. stq $31, 72($sp) /* a3=0 => no error */
  563. $strace_success:
  564. stq $0, 0($sp) /* save return value */
  565. DO_SWITCH_STACK
  566. jsr $26, syscall_trace_leave
  567. UNDO_SWITCH_STACK
  568. br $31, ret_from_sys_call
  569. .align 3
  570. $strace_error:
  571. ldq $18, 0($sp) /* old syscall nr (zero if success) */
  572. beq $18, $strace_success
  573. ldq $19, 72($sp) /* .. and this a3 */
  574. subq $31, $0, $0 /* with error in v0 */
  575. addq $31, 1, $1 /* set a3 for errno return */
  576. stq $0, 0($sp)
  577. stq $1, 72($sp) /* a3 for return */
  578. DO_SWITCH_STACK
  579. mov $18, $9 /* save old syscall number */
  580. mov $19, $10 /* save old a3 */
  581. jsr $26, syscall_trace_leave
  582. mov $9, $18
  583. mov $10, $19
  584. UNDO_SWITCH_STACK
  585. mov $31, $26 /* tell "ret_from_sys_call" we can restart */
  586. br ret_from_sys_call
  587. CFI_END_OSF_FRAME entSys
  588. /*
  589. * Save and restore the switch stack -- aka the balance of the user context.
  590. */
  591. .align 4
  592. .type do_switch_stack, @function
  593. .cfi_startproc simple
  594. .cfi_return_column 64
  595. .cfi_def_cfa $sp, 0
  596. .cfi_register 64, $1
  597. do_switch_stack:
  598. lda $sp, -SWITCH_STACK_SIZE($sp)
  599. .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
  600. stq $9, 0($sp)
  601. stq $10, 8($sp)
  602. stq $11, 16($sp)
  603. stq $12, 24($sp)
  604. stq $13, 32($sp)
  605. stq $14, 40($sp)
  606. stq $15, 48($sp)
  607. stq $26, 56($sp)
  608. stt $f0, 64($sp)
  609. stt $f1, 72($sp)
  610. stt $f2, 80($sp)
  611. stt $f3, 88($sp)
  612. stt $f4, 96($sp)
  613. stt $f5, 104($sp)
  614. stt $f6, 112($sp)
  615. stt $f7, 120($sp)
  616. stt $f8, 128($sp)
  617. stt $f9, 136($sp)
  618. stt $f10, 144($sp)
  619. stt $f11, 152($sp)
  620. stt $f12, 160($sp)
  621. stt $f13, 168($sp)
  622. stt $f14, 176($sp)
  623. stt $f15, 184($sp)
  624. stt $f16, 192($sp)
  625. stt $f17, 200($sp)
  626. stt $f18, 208($sp)
  627. stt $f19, 216($sp)
  628. stt $f20, 224($sp)
  629. stt $f21, 232($sp)
  630. stt $f22, 240($sp)
  631. stt $f23, 248($sp)
  632. stt $f24, 256($sp)
  633. stt $f25, 264($sp)
  634. stt $f26, 272($sp)
  635. stt $f27, 280($sp)
  636. mf_fpcr $f0 # get fpcr
  637. stt $f28, 288($sp)
  638. stt $f29, 296($sp)
  639. stt $f30, 304($sp)
  640. stt $f0, 312($sp) # save fpcr in slot of $f31
  641. ldt $f0, 64($sp) # dont let "do_switch_stack" change fp state.
  642. ret $31, ($1), 1
  643. .cfi_endproc
  644. .size do_switch_stack, .-do_switch_stack
  645. .align 4
  646. .type undo_switch_stack, @function
  647. .cfi_startproc simple
  648. .cfi_def_cfa $sp, 0
  649. .cfi_register 64, $1
  650. undo_switch_stack:
  651. ldq $9, 0($sp)
  652. ldq $10, 8($sp)
  653. ldq $11, 16($sp)
  654. ldq $12, 24($sp)
  655. ldq $13, 32($sp)
  656. ldq $14, 40($sp)
  657. ldq $15, 48($sp)
  658. ldq $26, 56($sp)
  659. ldt $f30, 312($sp) # get saved fpcr
  660. ldt $f0, 64($sp)
  661. ldt $f1, 72($sp)
  662. ldt $f2, 80($sp)
  663. ldt $f3, 88($sp)
  664. mt_fpcr $f30 # install saved fpcr
  665. ldt $f4, 96($sp)
  666. ldt $f5, 104($sp)
  667. ldt $f6, 112($sp)
  668. ldt $f7, 120($sp)
  669. ldt $f8, 128($sp)
  670. ldt $f9, 136($sp)
  671. ldt $f10, 144($sp)
  672. ldt $f11, 152($sp)
  673. ldt $f12, 160($sp)
  674. ldt $f13, 168($sp)
  675. ldt $f14, 176($sp)
  676. ldt $f15, 184($sp)
  677. ldt $f16, 192($sp)
  678. ldt $f17, 200($sp)
  679. ldt $f18, 208($sp)
  680. ldt $f19, 216($sp)
  681. ldt $f20, 224($sp)
  682. ldt $f21, 232($sp)
  683. ldt $f22, 240($sp)
  684. ldt $f23, 248($sp)
  685. ldt $f24, 256($sp)
  686. ldt $f25, 264($sp)
  687. ldt $f26, 272($sp)
  688. ldt $f27, 280($sp)
  689. ldt $f28, 288($sp)
  690. ldt $f29, 296($sp)
  691. ldt $f30, 304($sp)
  692. lda $sp, SWITCH_STACK_SIZE($sp)
  693. ret $31, ($1), 1
  694. .cfi_endproc
  695. .size undo_switch_stack, .-undo_switch_stack
  696. /*
  697. * The meat of the context switch code.
  698. */
  699. .align 4
  700. .globl alpha_switch_to
  701. .type alpha_switch_to, @function
  702. .cfi_startproc
  703. alpha_switch_to:
  704. DO_SWITCH_STACK
  705. call_pal PAL_swpctx
  706. lda $8, 0x3fff
  707. UNDO_SWITCH_STACK
  708. bic $sp, $8, $8
  709. mov $17, $0
  710. ret
  711. .cfi_endproc
  712. .size alpha_switch_to, .-alpha_switch_to
  713. /*
  714. * New processes begin life here.
  715. */
  716. .globl ret_from_fork
  717. .align 4
  718. .ent ret_from_fork
  719. ret_from_fork:
  720. lda $26, ret_from_sys_call
  721. mov $17, $16
  722. jmp $31, schedule_tail
  723. .end ret_from_fork
  724. /*
  725. * ... and new kernel threads - here
  726. */
  727. .align 4
  728. .globl ret_from_kernel_thread
  729. .ent ret_from_kernel_thread
  730. ret_from_kernel_thread:
  731. mov $17, $16
  732. jsr $26, schedule_tail
  733. mov $9, $27
  734. mov $10, $16
  735. jsr $26, ($9)
  736. mov $31, $19 /* to disable syscall restarts */
  737. br $31, ret_to_user
  738. .end ret_from_kernel_thread
  739. /*
  740. * Special system calls. Most of these are special in that they either
  741. * have to play switch_stack games or in some way use the pt_regs struct.
  742. */
  743. .macro fork_like name
  744. .align 4
  745. .globl alpha_\name
  746. .ent alpha_\name
  747. alpha_\name:
  748. .prologue 0
  749. bsr $1, do_switch_stack
  750. jsr $26, sys_\name
  751. ldq $26, 56($sp)
  752. lda $sp, SWITCH_STACK_SIZE($sp)
  753. ret
  754. .end alpha_\name
  755. .endm
  756. fork_like fork
  757. fork_like vfork
  758. fork_like clone
  759. .align 4
  760. .globl sys_sigreturn
  761. .ent sys_sigreturn
  762. sys_sigreturn:
  763. .prologue 0
  764. lda $9, ret_from_straced
  765. cmpult $26, $9, $9
  766. lda $sp, -SWITCH_STACK_SIZE($sp)
  767. jsr $26, do_sigreturn
  768. bne $9, 1f
  769. jsr $26, syscall_trace_leave
  770. 1: br $1, undo_switch_stack
  771. br ret_from_sys_call
  772. .end sys_sigreturn
  773. .align 4
  774. .globl sys_rt_sigreturn
  775. .ent sys_rt_sigreturn
  776. sys_rt_sigreturn:
  777. .prologue 0
  778. lda $9, ret_from_straced
  779. cmpult $26, $9, $9
  780. lda $sp, -SWITCH_STACK_SIZE($sp)
  781. jsr $26, do_rt_sigreturn
  782. bne $9, 1f
  783. jsr $26, syscall_trace_leave
  784. 1: br $1, undo_switch_stack
  785. br ret_from_sys_call
  786. .end sys_rt_sigreturn
  787. .align 4
  788. .globl alpha_ni_syscall
  789. .ent alpha_ni_syscall
  790. alpha_ni_syscall:
  791. .prologue 0
  792. /* Special because it also implements overflow handling via
  793. syscall number 0. And if you recall, zero is a special
  794. trigger for "not an error". Store large non-zero there. */
  795. lda $0, -ENOSYS
  796. unop
  797. stq $0, 0($sp)
  798. ret
  799. .end alpha_ni_syscall