sysdep.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* Assembler macros for i386.
  2. Copyright (C) 1991-93,95,96,98,2002,2003,2005,2006
  3. Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <common/sysdep.h>
  18. #ifdef __ASSEMBLER__
  19. /* Syntactic details of assembler. */
  20. /* ELF uses byte-counts for .align, most others use log2 of count of bytes. */
  21. #define ALIGNARG(log2) 1<<log2
  22. /* For ELF we need the `.type' directive to make shared libs work right. */
  23. #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
  24. #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
  25. /* In ELF C symbols are asm symbols. */
  26. #undef NO_UNDERSCORES
  27. #define NO_UNDERSCORES
  28. /* Define an entry point visible from C.
  29. There is currently a bug in gdb which prevents us from specifying
  30. incomplete stabs information. Fake some entries here which specify
  31. the current source file. */
  32. #define ENTRY(name) \
  33. STABS_CURRENT_FILE1("") \
  34. STABS_CURRENT_FILE(name) \
  35. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  36. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
  37. .align ALIGNARG(4); \
  38. STABS_FUN(name) \
  39. C_LABEL(name) \
  40. cfi_startproc; \
  41. CALL_MCOUNT
  42. #undef END
  43. #define END(name) \
  44. cfi_endproc; \
  45. ASM_SIZE_DIRECTIVE(name) \
  46. STABS_FUN_END(name)
  47. #ifdef HAVE_CPP_ASM_DEBUGINFO
  48. /* Disable that goop, because we just pass -g through to the assembler
  49. and it generates proper line number information directly. */
  50. # define STABS_CURRENT_FILE1(name)
  51. # define STABS_CURRENT_FILE(name)
  52. # define STABS_FUN(name)
  53. # define STABS_FUN_END(name)
  54. #else
  55. /* Remove the following two lines once the gdb bug is fixed. */
  56. #define STABS_CURRENT_FILE(name) \
  57. STABS_CURRENT_FILE1 (#name)
  58. #define STABS_CURRENT_FILE1(name) \
  59. 1: .stabs name,100,0,0,1b;
  60. /* Emit stabs definition lines. We use F(0,1) and define t(0,1) as `int',
  61. the same way gcc does it. */
  62. #define STABS_FUN(name) STABS_FUN2(name, name##:F(0,1))
  63. #define STABS_FUN2(name, namestr) \
  64. .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0; \
  65. .stabs #namestr,36,0,0,name;
  66. #define STABS_FUN_END(name) \
  67. 1: .stabs "",36,0,0,1b-name;
  68. #endif
  69. /* If compiled for profiling, call `mcount' at the start of each function. */
  70. #ifdef PROF
  71. /* The mcount code relies on a normal frame pointer being on the stack
  72. to locate our caller, so push one just for its benefit. */
  73. #define CALL_MCOUNT \
  74. pushl %ebp; cfi_adjust_cfa_offset (4); movl %esp, %ebp; \
  75. cfi_def_cfa_register (ebp); call JUMPTARGET(mcount); \
  76. popl %ebp; cfi_def_cfa (esp, 4);
  77. #else
  78. #define CALL_MCOUNT /* Do nothing. */
  79. #endif
  80. #ifdef NO_UNDERSCORES
  81. /* Since C identifiers are not normally prefixed with an underscore
  82. on this system, the asm identifier `syscall_error' intrudes on the
  83. C name space. Make sure we use an innocuous name. */
  84. #define syscall_error __syscall_error
  85. #define mcount _mcount
  86. #endif
  87. #define PSEUDO(name, syscall_name, args) \
  88. .globl syscall_error; \
  89. lose: SYSCALL_PIC_SETUP \
  90. jmp JUMPTARGET(syscall_error); \
  91. ENTRY (name) \
  92. DO_CALL (syscall_name, args); \
  93. jb lose
  94. #undef PSEUDO_END
  95. #define PSEUDO_END(name) \
  96. END (name)
  97. #undef JUMPTARGET
  98. #ifdef __PIC__
  99. #define JUMPTARGET(name) name##@PLT
  100. #define SYSCALL_PIC_SETUP \
  101. pushl %ebx; \
  102. cfi_adjust_cfa_offset (4); \
  103. call 0f; \
  104. 0: popl %ebx; \
  105. cfi_adjust_cfa_offset (-4); \
  106. addl $_GLOBAL_OFFSET_TABLE+[.-0b], %ebx;
  107. # define SETUP_PIC_REG(reg) \
  108. .ifndef __x86.get_pc_thunk.reg; \
  109. .section .gnu.linkonce.t.__x86.get_pc_thunk.reg,"ax",@progbits; \
  110. .globl __x86.get_pc_thunk.reg; \
  111. .hidden __x86.get_pc_thunk.reg; \
  112. .type __x86.get_pc_thunk.reg,@function; \
  113. __x86.get_pc_thunk.reg: \
  114. movl (%esp), %e##reg; \
  115. ret; \
  116. .size __x86.get_pc_thunk.reg, . - __x86.get_pc_thunk.reg; \
  117. .previous; \
  118. .endif; \
  119. call __x86.get_pc_thunk.reg
  120. # define LOAD_PIC_REG(reg) \
  121. SETUP_PIC_REG(reg); addl $_GLOBAL_OFFSET_TABLE_, %e##reg
  122. #else
  123. #define JUMPTARGET(name) name
  124. #define SYSCALL_PIC_SETUP /* Nothing. */
  125. #endif
  126. /* Local label name for asm code. */
  127. #ifndef L
  128. #ifdef HAVE_ELF
  129. #define L(name) .L##name
  130. #else
  131. #define L(name) name
  132. #endif
  133. #endif
  134. #endif /* __ASSEMBLER__ */