x86-asm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* $NetBSD: asm.h,v 1.40 2011/06/16 13:16:20 joerg Exp $ */
  2. /*-
  3. * Copyright (c) 1990 The Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * William Jolitz.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the University nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * @(#)asm.h 5.5 (Berkeley) 5/7/91
  34. */
  35. #ifndef _I386_ASM_H_
  36. #define _I386_ASM_H_
  37. #ifdef _KERNEL_OPT
  38. #include "opt_multiprocessor.h"
  39. #endif
  40. #ifdef PIC
  41. #define PIC_PROLOGUE \
  42. pushl %ebx; \
  43. call 1f; \
  44. 1: \
  45. popl %ebx; \
  46. addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
  47. #define PIC_EPILOGUE \
  48. popl %ebx
  49. #define PIC_PLT(x) x@PLT
  50. #define PIC_GOT(x) x@GOT(%ebx)
  51. #define PIC_GOTOFF(x) x@GOTOFF(%ebx)
  52. #else
  53. #define PIC_PROLOGUE
  54. #define PIC_EPILOGUE
  55. #define PIC_PLT(x) x
  56. #define PIC_GOT(x) x
  57. #define PIC_GOTOFF(x) x
  58. #endif
  59. #ifdef __ELF__
  60. # define _C_LABEL(x) x
  61. #else
  62. # ifdef __STDC__
  63. # define _C_LABEL(x) _ ## x
  64. # else
  65. # define _C_LABEL(x) _/**/x
  66. # endif
  67. #endif
  68. #define _ASM_LABEL(x) x
  69. #define CVAROFF(x, y) _C_LABEL(x) + y
  70. #ifdef __STDC__
  71. # define __CONCAT(x,y) x ## y
  72. # define __STRING(x) #x
  73. #else
  74. # define __CONCAT(x,y) x/**/y
  75. # define __STRING(x) "x"
  76. #endif
  77. /* let kernels and others override entrypoint alignment */
  78. #if !defined(_ALIGN_TEXT) && !defined(_KERNEL)
  79. # ifdef _STANDALONE
  80. # define _ALIGN_TEXT .align 1
  81. # elif defined __ELF__
  82. # define _ALIGN_TEXT .align 16
  83. # else
  84. # define _ALIGN_TEXT .align 4
  85. # endif
  86. #endif
  87. #define _ENTRY(x) \
  88. .text; _ALIGN_TEXT; .globl x; .type x,@function; x:
  89. #define _LABEL(x) \
  90. .globl x; x:
  91. #ifdef _KERNEL
  92. #define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off)
  93. /* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
  94. #ifdef __ELF__
  95. #ifdef __STDC__
  96. #define IDTVEC(name) \
  97. ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
  98. #define IDTVEC_END(name) \
  99. .size X ## name, . - X ## name
  100. #else
  101. #define IDTVEC(name) \
  102. ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
  103. #define IDTVEC_END(name) \
  104. .size X/**/name, . - X/**/name
  105. #endif /* __STDC__ */
  106. #else
  107. #ifdef __STDC__
  108. #define IDTVEC(name) \
  109. ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name:
  110. #define IDTVEC_END(name) \
  111. .size _X ## name, . - _X ## name
  112. #else
  113. #define IDTVEC(name) \
  114. ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name:
  115. #define IDTVEC_END(name) \
  116. .size _X/**/name, . - _X/**/name
  117. #endif /* __STDC__ */
  118. #endif /* __ELF__ */
  119. #ifdef _STANDALONE
  120. #define ALIGN_DATA .align 4
  121. #define ALIGN_TEXT .align 4 /* 4-byte boundaries */
  122. #define SUPERALIGN_TEXT .align 16 /* 15-byte boundaries */
  123. #elif defined __ELF__
  124. #define ALIGN_DATA .align 4
  125. #define ALIGN_TEXT .align 16 /* 16-byte boundaries */
  126. #define SUPERALIGN_TEXT .align 16 /* 16-byte boundaries */
  127. #else
  128. #define ALIGN_DATA .align 2
  129. #define ALIGN_TEXT .align 4 /* 16-byte boundaries */
  130. #define SUPERALIGN_TEXT .align 4 /* 16-byte boundaries */
  131. #endif /* __ELF__ */
  132. #define _ALIGN_TEXT ALIGN_TEXT
  133. #ifdef GPROF
  134. #ifdef __ELF__
  135. #define MCOUNT_ASM call _C_LABEL(__mcount)
  136. #else /* __ELF__ */
  137. #define MCOUNT_ASM call _C_LABEL(mcount)
  138. #endif /* __ELF__ */
  139. #else /* GPROF */
  140. #define MCOUNT_ASM /* nothing */
  141. #endif /* GPROF */
  142. #endif /* _KERNEL */
  143. #ifdef GPROF
  144. # ifdef __ELF__
  145. # define _PROF_PROLOGUE \
  146. pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp
  147. # else
  148. # define _PROF_PROLOGUE \
  149. pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp
  150. # endif
  151. #else
  152. # define _PROF_PROLOGUE
  153. #endif
  154. #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
  155. #define NENTRY(y) _ENTRY(_C_LABEL(y))
  156. #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
  157. #define LABEL(y) _LABEL(_C_LABEL(y))
  158. #define END(y) .size y, . - y
  159. #define ASMSTR .asciz
  160. #ifdef __ELF__
  161. #define RCSID(x) .pushsection ".ident"; .asciz x; .popsection
  162. #else
  163. #define RCSID(x) .text; .asciz x
  164. #endif
  165. #ifdef NO_KERNEL_RCSIDS
  166. #define __KERNEL_RCSID(_n, _s) /* nothing */
  167. #else
  168. #define __KERNEL_RCSID(_n, _s) RCSID(_s)
  169. #endif
  170. #ifdef __ELF__
  171. #define WEAK_ALIAS(alias,sym) \
  172. .weak alias; \
  173. alias = sym
  174. #endif
  175. /*
  176. * STRONG_ALIAS: create a strong alias.
  177. */
  178. #define STRONG_ALIAS(alias,sym) \
  179. .globl alias; \
  180. alias = sym
  181. #ifdef __STDC__
  182. #define WARN_REFERENCES(sym,msg) \
  183. .pushsection .gnu.warning. ## sym; \
  184. .ascii msg; \
  185. .popsection
  186. #else
  187. #define WARN_REFERENCES(sym,msg) \
  188. .pushsection .gnu.warning./**/sym; \
  189. .ascii msg; \
  190. .popsection
  191. #endif /* __STDC__ */
  192. #endif /* !_I386_ASM_H_ */