syscallas.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright (C) 2014 OSCAR lab, Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * syscallas.S
  15. *
  16. * This file contains the entry point of system call table in library OS.
  17. */
  18. #include <shim_tls.h>
  19. .text
  20. .global syscalldb
  21. .type syscalldb, @function
  22. .extern shim_table
  23. syscalldb:
  24. .cfi_startproc
  25. # avoid red zone for previous rsp
  26. subq $128, %rsp
  27. .cfi_def_cfa_offset 136
  28. # DEP 7/9/12: Push a stack pointer so clone can find the return address
  29. pushq %rbp
  30. .cfi_def_cfa_offset 144
  31. movq %rsp, %rbp
  32. .cfi_offset 6,-144
  33. .cfi_def_cfa_register 6
  34. pushq %rbx
  35. leaq shim_table(%rip), %rbx
  36. movq (%rbx,%rax,8), %rbx
  37. cmp $0, (%rbx)
  38. je isundef
  39. isdef:
  40. pushq %rdi
  41. pushq %rsi
  42. pushq %rdx
  43. pushq %rcx
  44. pushq %r8
  45. pushq %r9
  46. pushq %r12
  47. pushq %r13
  48. pushq %r14
  49. pushq %r15
  50. movq %rax, %fs:(SHIM_TCB_OFFSET + 24)
  51. leaq 232(%rsp), %rax
  52. movq %rax, %fs:(SHIM_TCB_OFFSET + 32)
  53. movq -8(%rax), %rax
  54. movq %rax, %fs:(SHIM_TCB_OFFSET + 40)
  55. movq %rsp, %fs:(SHIM_TCB_OFFSET + 48)
  56. call *%rbx
  57. movq $0, %fs:(SHIM_TCB_OFFSET + 24)
  58. movq $0, %fs:(SHIM_TCB_OFFSET + 32)
  59. movq $0, %fs:(SHIM_TCB_OFFSET + 40)
  60. movq $0, %fs:(SHIM_TCB_OFFSET + 48)
  61. popq %r15
  62. popq %r14
  63. popq %r13
  64. popq %r12
  65. popq %r9
  66. popq %r8
  67. popq %rcx
  68. popq %rdx
  69. popq %rsi
  70. popq %rdi
  71. jmp ret
  72. isundef:
  73. movq $-38, %rax
  74. ret:
  75. popq %rbx
  76. popq %rbp
  77. addq $128, %rsp
  78. retq
  79. .cfi_endproc
  80. .size syscalldb, .-syscalldb