ontop.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright Oliver Kowalke 2009.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*******************************************************
  8. * *
  9. * ------------------------------------------------- *
  10. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
  11. * ------------------------------------------------- *
  12. * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
  13. * ------------------------------------------------- *
  14. * | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | *
  15. * ------------------------------------------------- *
  16. * ------------------------------------------------- *
  17. * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  18. * ------------------------------------------------- *
  19. * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
  20. * ------------------------------------------------- *
  21. * | FP |hiddn| RA | PC | GP | FCTX| DATA| | *
  22. * ------------------------------------------------- *
  23. * *
  24. * *****************************************************/
  25. .text
  26. .globl ontop_fcontext
  27. .align 2
  28. .type ontop_fcontext,@function
  29. .ent ontop_fcontext
  30. ontop_fcontext:
  31. # reserve space on stack
  32. addiu $sp, $sp, -112
  33. sw $s0, ($sp) # save S0
  34. sw $s1, 4($sp) # save S1
  35. sw $s2, 8($sp) # save S2
  36. sw $s3, 12($sp) # save S3
  37. sw $s4, 16($sp) # save S4
  38. sw $s5, 20($sp) # save S5
  39. sw $s6, 24($sp) # save S6
  40. sw $s7, 28($sp) # save S7
  41. sw $fp, 32($sp) # save FP
  42. sw $a0, 36($sp) # save hidden, address of returned transfer_t
  43. sw $ra, 40($sp) # save RA
  44. sw $ra, 44($sp) # save RA as PC
  45. # store SP (pointing to context-data) in A0
  46. move $a0, $sp
  47. # restore SP (pointing to context-data) from A1
  48. move $sp, $a1
  49. lw $s0, ($sp) # restore S0
  50. lw $s1, 4($sp) # restore S1
  51. lw $s2, 8($sp) # restore S2
  52. lw $s3, 12($sp) # restore S3
  53. lw $s4, 16($sp) # restore S4
  54. lw $s5, 20($sp) # restore S5
  55. lw $s6, 24($sp) # restore S6
  56. lw $s7, 28($sp) # restore S7
  57. lw $fp, 32($sp) # restore FP
  58. lw $t0, 36($sp) # restore hidden, address of returned transfer_t
  59. lw $ra, 40($sp) # restore RA
  60. # load PC
  61. lw $t9, 44($sp)
  62. # adjust stack
  63. addiu $sp, $sp, 112
  64. # return transfer_t from jump
  65. sw $a0, ($t0) # fctx of transfer_t
  66. sw $a2, 4($t0) # data of transfer_t
  67. # pass transfer_t as first arg in context function
  68. # A0 == hidden, A1 == fctx, A2 == data
  69. move $a1, $a0
  70. move $a0, $t0
  71. # jump to context
  72. jr $a3
  73. .end ontop_fcontext
  74. .size ontop_fcontext, .-ontop_fcontext
  75. /* Mark that we don't need executable stack. */
  76. .section .note.GNU-stack,"",%progbits