syscallas.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. # DEP 7/9/12: Push a stack pointer so clone can find the return address
  26. pushq %rbp
  27. .cfi_def_cfa_offset 16
  28. movq %rsp, %rbp
  29. .cfi_offset 6,-16
  30. .cfi_def_cfa_register 6
  31. pushq %rbx
  32. cmp $SHIM_NSYSCALLS, %rax
  33. jge isundef
  34. leaq shim_table(%rip), %rbx
  35. movq (%rbx,%rax,8), %rbx
  36. cmp $0, (%rbx)
  37. je isundef
  38. isdef:
  39. pushq %rdi
  40. pushq %rsi
  41. pushq %rdx
  42. pushq %rcx
  43. pushq %r8
  44. pushq %r9
  45. pushq %r10
  46. pushq %r11
  47. pushq %r12
  48. pushq %r13
  49. pushq %r14
  50. pushq %r15
  51. movq %rax, %fs:(SHIM_TCB_OFFSET + 24)
  52. leaq 16(%rbp), %rax
  53. movq %rax, %fs:(SHIM_TCB_OFFSET + 32)
  54. movq 8(%rbp), %rax
  55. movq %rax, %fs:(SHIM_TCB_OFFSET + 40)
  56. movq %rsp, %fs:(SHIM_TCB_OFFSET + 48)
  57. call *%rbx
  58. movq $0, %fs:(SHIM_TCB_OFFSET + 24)
  59. movq $0, %fs:(SHIM_TCB_OFFSET + 32)
  60. movq $0, %fs:(SHIM_TCB_OFFSET + 40)
  61. movq $0, %fs:(SHIM_TCB_OFFSET + 48)
  62. popq %r15
  63. popq %r14
  64. popq %r13
  65. popq %r12
  66. popq %r11
  67. popq %r10
  68. popq %r9
  69. popq %r8
  70. popq %rcx
  71. popq %rdx
  72. popq %rsi
  73. popq %rdi
  74. jmp ret
  75. isundef:
  76. #ifdef DEBUG
  77. mov %rax, %rdi
  78. call debug_unsupp
  79. #endif
  80. movq $-38, %rax
  81. ret:
  82. popq %rbx
  83. popq %rbp
  84. retq
  85. .cfi_endproc
  86. .size syscalldb, .-syscalldb