syscallas.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include <shim_unistd_defs.h>
  20. .global syscalldb
  21. .type syscalldb, @function
  22. .extern shim_table, debug_unsupp
  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. cmp $SHIM_NSYSCALLS, %rax
  36. jge isundef
  37. leaq shim_table(%rip), %rbx
  38. movq (%rbx,%rax,8), %rbx
  39. cmp $0, (%rbx)
  40. je isundef
  41. isdef:
  42. pushq %rdi
  43. pushq %rsi
  44. pushq %rdx
  45. pushq %rcx
  46. pushq %r8
  47. pushq %r9
  48. pushq %r12
  49. pushq %r13
  50. pushq %r14
  51. pushq %r15
  52. movq %rax, %fs:(SHIM_TCB_OFFSET + 24)
  53. leaq 232(%rsp), %rax
  54. movq %rax, %fs:(SHIM_TCB_OFFSET + 32)
  55. movq -8(%rax), %rax
  56. movq %rax, %fs:(SHIM_TCB_OFFSET + 40)
  57. movq %rsp, %fs:(SHIM_TCB_OFFSET + 48)
  58. call *%rbx
  59. movq $0, %fs:(SHIM_TCB_OFFSET + 24)
  60. movq $0, %fs:(SHIM_TCB_OFFSET + 32)
  61. movq $0, %fs:(SHIM_TCB_OFFSET + 40)
  62. movq $0, %fs:(SHIM_TCB_OFFSET + 48)
  63. popq %r15
  64. popq %r14
  65. popq %r13
  66. popq %r12
  67. popq %r9
  68. popq %r8
  69. popq %rcx
  70. popq %rdx
  71. popq %rsi
  72. popq %rdi
  73. jmp ret
  74. isundef:
  75. #ifdef DEBUG
  76. mov %rax, %rdi
  77. call debug_unsupp
  78. #endif
  79. movq $-38, %rax
  80. ret:
  81. popq %rbx
  82. popq %rbp
  83. addq $128, %rsp
  84. retq
  85. .cfi_endproc
  86. .size syscalldb, .-syscalldb