syscallas.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include "asm-offsets.h"
  21. .global syscalldb
  22. .type syscalldb, @function
  23. .extern shim_table, debug_unsupp
  24. syscalldb:
  25. .cfi_startproc
  26. # Create shim_regs struct on the stack.
  27. pushq %rbp
  28. pushq %rbx
  29. pushq %rdi
  30. pushq %rsi
  31. pushq %rdx
  32. pushq %rcx
  33. pushq %r8
  34. pushq %r9
  35. pushq %r10
  36. pushq %r11
  37. pushq %r12
  38. pushq %r13
  39. pushq %r14
  40. pushq %r15
  41. # shim_regs struct ends here.
  42. movq %rsp, %rbp
  43. .cfi_def_cfa_offset SHIM_REGS_SIZE+8 # +8 for ret_addr
  44. .cfi_offset 6,-16 # saved_rbp is at CFA-16 (ret + saved_rbp)
  45. .cfi_def_cfa_register 6 # %rbp
  46. cmp $LIBOS_SYSCALL_BOUND, %rax
  47. jae isundef
  48. movq shim_table@GOTPCREL(%rip), %rbx
  49. movq (%rbx,%rax,8), %rbx
  50. cmp $0, %rbx
  51. je isundef
  52. movq %rax, %fs:(SHIM_TCB_OFFSET + TCB_SYSCALL_NR)
  53. leaq SHIM_REGS_SIZE+8(%rbp), %rax
  54. movq %rax, %fs:(SHIM_TCB_OFFSET + TCB_SP)
  55. movq SHIM_REGS_SIZE(%rbp), %rax
  56. movq %rax, %fs:(SHIM_TCB_OFFSET + TCB_RET_IP)
  57. movq %rbp, %fs:(SHIM_TCB_OFFSET + TCB_REGS)
  58. /* Translating x86_64 kernel calling convention to user-space
  59. * calling convention */
  60. movq %r10, %rcx
  61. andq $~0xF, %rsp # Required by System V AMD64 ABI.
  62. call *%rbx
  63. movq $0, %fs:(SHIM_TCB_OFFSET + TCB_SYSCALL_NR)
  64. movq $0, %fs:(SHIM_TCB_OFFSET + TCB_SP)
  65. movq $0, %fs:(SHIM_TCB_OFFSET + TCB_RET_IP)
  66. movq $0, %fs:(SHIM_TCB_OFFSET + TCB_REGS)
  67. ret:
  68. movq %rbp, %rsp
  69. popq %r15
  70. popq %r14
  71. popq %r13
  72. popq %r12
  73. popq %r11
  74. popq %r10
  75. popq %r9
  76. popq %r8
  77. popq %rcx
  78. popq %rdx
  79. popq %rsi
  80. popq %rdi
  81. popq %rbx
  82. popq %rbp
  83. retq
  84. isundef:
  85. #ifdef DEBUG
  86. mov %rax, %rdi
  87. andq $~0xF, %rsp # Required by System V AMD64 ABI.
  88. call *debug_unsupp@GOTPCREL(%rip)
  89. #endif
  90. movq $-38, %rax # ENOSYS
  91. jmp ret
  92. .cfi_endproc
  93. .size syscalldb, .-syscalldb