syscallas.S 3.1 KB

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