asm-386.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. .file "asm-FreeBSD-386.S"
  2. #include <sys/syscall.h>
  3. /*
  4. * executeonnewstack(void *tos, void (*tramp)(void *arg), void *arg)
  5. */
  6. .type ournewstack,@function
  7. .global executeonnewstack
  8. executeonnewstack:
  9. pushl %ebp
  10. movl %esp, %ebp
  11. pushl %esi
  12. movl 8(%ebp), %esi /* get tos */
  13. subl $4, %esi
  14. movl 16(%ebp), %eax
  15. movl %eax, (%esi) /* stash arg on new stack */
  16. subl $4, %esi
  17. movl 12(%ebp), %eax
  18. movl %eax, (%esi) /* stash tramp on new stack */
  19. mov %esi, %esp /* swap stacks pronto */
  20. popl %eax /* recover the tramp address */
  21. call *%eax /* and jump to it (ho ho) */
  22. /* if we return here, tramp didn't do it's job */
  23. addl $8, %esp /* clean up for pose value */
  24. leal SYS_exit, %eax
  25. int $0x80
  26. /*
  27. * unlockandexit(int *key)
  28. *
  29. * NB: the return status may be rubbish if the stack is reused
  30. * between the unlock and the system call, but this should
  31. * not matter since no task is waiting for the result
  32. */
  33. .type unlockandexit,@function
  34. .global unlockandexit
  35. unlockandexit:
  36. pushl %ebp
  37. movl %esp, %ebp
  38. movl 8(%ebp), %esi /* get the key address */
  39. pushl $0 /* exit status 0 */
  40. movl $0, %eax /* unlock the stack allocator */
  41. movl %eax, (%esi)
  42. leal SYS_exit, %eax /* call exit */
  43. int $0x80
  44. /*
  45. * umult(ulong m1, ulong m2, ulong *hi)
  46. */
  47. .type umult,@function
  48. .global umult
  49. umult:
  50. pushl %ebp
  51. movl %esp, %ebp
  52. pushl %ebx
  53. movl 8(%ebp), %eax
  54. movl 12(%ebp), %ebx
  55. mull %ebx
  56. movl 16(%ebp), %ebx
  57. movl %edx, (%ebx)
  58. popl %ebx
  59. popl %ebp
  60. ret
  61. .type FPsave,@function
  62. .global FPsave
  63. FPsave:
  64. pushl %ebp
  65. movl %esp, %ebp
  66. movl 8(%ebp), %eax
  67. fstenv (%eax)
  68. popl %ebp
  69. ret
  70. .type FPrestore,@function
  71. .global FPrestore
  72. FPrestore:
  73. pushl %ebp
  74. movl %esp, %ebp
  75. movl 8(%ebp), %eax
  76. fldenv (%eax)
  77. popl %ebp
  78. ret
  79. .type getcallerpc,@function
  80. .global getcallerpc
  81. getcallerpc:
  82. movl 4(%ebp), %eax
  83. ret
  84. .type _tas,@function
  85. .globl _tas
  86. _tas:
  87. movl $1, %eax
  88. movl 4(%esp), %ecx
  89. xchgl %eax, 0(%ecx)
  90. ret