sysdep.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Copyright (C) 1991, 1992 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA. */
  15. #include <sys/syscall.h>
  16. /* Not that using a `PASTE' macro loses. */
  17. #ifdef __STDC__
  18. #ifdef __ELF__
  19. #define SYSCALL_WEAK_ALIAS(alias,orig) \
  20. .weak alias; \
  21. alias=__libc_##orig
  22. /*
  23. #ifdef _POSIX_THREADS
  24. */
  25. #if 1
  26. #ifdef PTHREAD_KERNEL
  27. /* Use the regular ELF conventions about underscores, and provide the
  28. weak symbol, as required */
  29. #define SYSCALL__(name,args) PSEUDO (__machdep_sys_##name, name, args) \
  30. .weak machdep_sys_##name; \
  31. machdep_sys_##name = __machdep_sys_##name; \
  32. .type __machdep_sys_##name,@function; \
  33. .type machdep_sys_##name,@function; \
  34. .L__machdep_sys_##name##end: .size __machdep_sys_##name,.L__machdep_sys_##name##end - __machdep_sys_##name
  35. #define SYSCALL(name,args) PSEUDO (__machdep_sys_##name, name, args) \
  36. .weak machdep_sys_##name; \
  37. machdep_sys_##name = __machdep_sys_##name; \
  38. .type __machdep_sys_##name,@function; \
  39. .type machdep_sys_##name,@function; \
  40. .L__machdep_sys_##name##end: .size __machdep_sys_##name,.L__machdep_sys_##name##end - __machdep_sys_##name
  41. #else /* PTHREAD_KERNEL */
  42. /* Use the regular ELF conventions about underscores, and provide the
  43. weak symbol, as required */
  44. #define SYSCALL__(name,args) PSEUDO (__libc_##name, name, args) \
  45. .weak __##name; \
  46. .weak name; \
  47. __##name = __libc_##name; \
  48. name = __libc_##name; \
  49. .type __libc_##name,@function; \
  50. .type name,@function; \
  51. .type __##name,@function; \
  52. .L__libc_##name##end: .size __libc_##name,.L__libc_##name##end - __libc_##name
  53. #define SYSCALL(name,args) PSEUDO (__libc_##name, name, args) \
  54. .weak name; \
  55. name = __libc_##name; \
  56. .type __libc_##name,@function; \
  57. .type name,@function; \
  58. .L__libc_##name##end: .size __libc_##name,.L__libc_##name##end - __libc_##name
  59. #endif /* PTHREAD_KERNEL */
  60. #else /* _POSIX_THREADS */
  61. /* Use the regular ELF conventions about underscores, and provide the
  62. weak symbol, as required */
  63. #define SYSCALL__(name,args) PSEUDO (__libc_##name, name, args) \
  64. .weak name; \
  65. __##name = __libc_##name; \
  66. name = __libc_##name; \
  67. .type __libc_##name,@function; \
  68. .type name,@function; \
  69. .type __##name,@function; \
  70. .L__libc_##name##end: .size __libc_##name,.L__libc_##name##end - __libc_##name
  71. #define SYSCALL(name,args) PSEUDO (__libc_##name, name, args) \
  72. name = __libc_##name; \
  73. .type __libc_##name,@function; \
  74. .type name,@function; \
  75. .L__libc_##name##end: .size __libc_##name,.L__libc_##name##end - __libc_##name
  76. #endif /* _POSIX_THREADS */
  77. #else /* __ELF__ */
  78. #define SYSCALL_WEAK_ALIAS(alias,orig)
  79. /* Regular a.out definition */
  80. #define SYSCALL__(name,args) PSEUDO (__##name, name, args)
  81. #define SYSCALL(name,args) PSEUDO (name, name, args)
  82. #endif /* __ELF__ */
  83. #else /* __STDC__ */
  84. #define SYSCALL__(name,args) PSEUDO (__/**/name, name, args)
  85. #define SYSCALL(name,args) PSEUDO (name, name, args)
  86. #endif /* __STDC__ */
  87. /* Machine-dependent sysdep.h files are expected to define the macro
  88. PSEUDO (function_name, syscall_name) to emit assembly code to define the
  89. C-callable function FUNCTION_NAME to do system call SYSCALL_NAME.
  90. r0 and r1 are the system call outputs. movl should be defined as
  91. an instruction such that "movl r1, r0" works. ret should be defined
  92. as the return instruction. */
  93. #if !defined(HAVE_GNU_LD) && !defined (__ELF__)
  94. #define ___errno _errno
  95. #endif
  96. #define HAVE_SYSCALLS
  97. #define ENTRY(name)
  98. .global name;
  99. .align 4;
  100. #define END(name)
  101. .size name,.-name;
  102. #define PSEUDO(name, syscall_name, args) \
  103. .text; \
  104. ENTRY(name); \
  105. ta 0x10; \
  106. bcc,a 9000f; \
  107. nop; \
  108. 9000:;
  109. #define PSEUDO_END(name) \
  110. .size name,.-name;