sysdep.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright (C) 2000-2016 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library 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 GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <common/sysdep.h>
  15. #ifdef __ASSEMBLER__
  16. # define ALIGNARG(log2) log2
  17. # define ASM_SIZE_DIRECTIVE(name) .size name,.-name
  18. /* Define an entry point visible from C. */
  19. # define ENTRY(name) \
  20. .globl C_SYMBOL_NAME(name); \
  21. .type C_SYMBOL_NAME(name),@function; \
  22. .align ALIGNARG(2); \
  23. C_LABEL(name)
  24. # undef END
  25. # define END(name) ASM_SIZE_DIRECTIVE(name)
  26. /* Local label name for asm code. */
  27. # ifndef L
  28. # define L(name) $L##name
  29. # endif
  30. /* We don't want the label for the error handler to be visible in the symbol
  31. table when we define it here. */
  32. # ifdef __PIC__
  33. # define SYSCALL_ERROR_LABEL 0f
  34. # else
  35. # define SYSCALL_ERROR_LABEL __syscall_error
  36. # endif
  37. # define DO_CALL(syscall_name, args) \
  38. addik r12,r0,SYS_ify (syscall_name); \
  39. brki r14,8; \
  40. addk r0,r0,r0;
  41. # undef PSEUDO
  42. # define PSEUDO(name, syscall_name, args) \
  43. .text; \
  44. ENTRY (name) \
  45. DO_CALL (syscall_name, args); \
  46. addik r12,r0,-4095; \
  47. cmpu r12,r12,r3; \
  48. bgei r12,SYSCALL_ERROR_LABEL;
  49. # undef PSEUDO_END
  50. # define PSEUDO_END(name) \
  51. SYSCALL_ERROR_HANDLER; \
  52. END (name)
  53. # undef PSEUDO_NOERRNO
  54. # define PSEUDO_NOERRNO(name, syscall_name, args) \
  55. .text; \
  56. ENTRY (name) \
  57. DO_CALL (syscall_name, args);
  58. # undef PSEUDO_END_NOERRNO
  59. # define PSEUDO_END_NOERRNO(name) \
  60. END (name)
  61. /* The function has to return the error code. */
  62. # undef PSEUDO_ERRVAL
  63. # define PSEUDO_ERRVAL(name, syscall_name, args) \
  64. .text; \
  65. ENTRY (name) \
  66. DO_CALL (syscall_name, args); \
  67. # undef PSEUDO_END_ERRVAL
  68. # define PSEUDO_END_ERRVAL(name) \
  69. END (name)
  70. # undef ret_NOERRNO
  71. # define ret_NOERRNO \
  72. rtsd r15,8; addk r0,r0,r0;
  73. # undef ret_ERRVAL
  74. # define ret_ERRVAL \
  75. rtsd r15,8; rsubk r3,r3,r0;
  76. #ifdef __PIC__
  77. # define SYSCALL_ERROR_LABEL_DCL 0
  78. # if defined _LIBC_REENTRANT
  79. # define SYSCALL_ERROR_HANDLER \
  80. SYSCALL_ERROR_LABEL_DCL: \
  81. addik r1,r1,-16; \
  82. swi r15,r1,0; \
  83. swi r20,r1,8; \
  84. rsubk r3,r3,r0; \
  85. swi r3,r1,12; \
  86. mfs r20,rpc; \
  87. addik r20,r20,_GLOBAL_OFFSET_TABLE_+8; \
  88. brlid r15,__errno_location@PLT; \
  89. nop; \
  90. lwi r4,r1,12; \
  91. swi r4,r3,0; \
  92. lwi r20,r1,8; \
  93. lwi r15,r1,0; \
  94. addik r1,r1,16; \
  95. rtsd r15,8; \
  96. addik r3,r0,-1;
  97. # else /* !_LIBC_REENTRANT. */
  98. # define SYSCALL_ERROR_HANDLER \
  99. SYSCALL_ERROR_LABEL_DCL: \
  100. mfs r12,rpc; \
  101. addik r12,r12,_GLOBAL_OFFSET_TABLE_+8; \
  102. lwi r12,r12,errno@GOT; \
  103. rsubk r3,r3,r0; \
  104. swi r3,r12,0; \
  105. rtsd r15,8; \
  106. addik r3,r0,-1;
  107. # endif /* _LIBC_REENTRANT. */
  108. #else
  109. # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
  110. #endif /* PIC. */
  111. #endif