syscallas.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (C) 2014 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 Lesser 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser 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 $LIBOS_SYSCALL_BOUND, %rax
  33. jae 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. /* Translating x86_64 kernel calling convention to user-space
  58. * calling convention */
  59. movq %r10, %rcx
  60. call *%rbx
  61. movq $0, %fs:(SHIM_TCB_OFFSET + 24)
  62. movq $0, %fs:(SHIM_TCB_OFFSET + 32)
  63. movq $0, %fs:(SHIM_TCB_OFFSET + 40)
  64. movq $0, %fs:(SHIM_TCB_OFFSET + 48)
  65. popq %r15
  66. popq %r14
  67. popq %r13
  68. popq %r12
  69. popq %r11
  70. popq %r10
  71. popq %r9
  72. popq %r8
  73. popq %rcx
  74. popq %rdx
  75. popq %rsi
  76. popq %rdi
  77. jmp ret
  78. isundef:
  79. #ifdef DEBUG
  80. mov %rax, %rdi
  81. call debug_unsupp
  82. #endif
  83. movq $-38, %rax
  84. ret:
  85. popq %rbx
  86. popq %rbp
  87. retq
  88. .cfi_endproc
  89. .size syscalldb, .-syscalldb