]> git.proxmox.com Git - grub2.git/blame - aclocal.m4
2006-05-30 Yoshinori K. Okuji <okuji@enbug.org>
[grub2.git] / aclocal.m4
CommitLineData
4b13b216 1dnl grub_ASM_USCORE checks if C symbols get an underscore after
6a161fa9 2dnl compiling to assembler.
3dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
4dnl Erich Boleyn and modified by Yoshinori K. Okuji.
4b13b216 5AC_DEFUN(grub_ASM_USCORE,
6a161fa9 6[AC_REQUIRE([AC_PROG_CC])
7AC_MSG_CHECKING([if C symbols get an underscore after compilation])
4b13b216 8AC_CACHE_VAL(grub_cv_asm_uscore,
6a161fa9 9[cat > conftest.c <<\EOF
10int
11func (int *list)
12{
13 *list = 0;
14 return *list;
15}
16EOF
17
18if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
19 true
20else
21 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
22fi
23
24if grep _func conftest.s >/dev/null 2>&1; then
4b13b216 25 grub_cv_asm_uscore=yes
6a161fa9 26else
4b13b216 27 grub_cv_asm_uscore=no
6a161fa9 28fi
29
30rm -f conftest*])
31
4b13b216 32if test "x$grub_cv_asm_uscore" = xyes; then
33 AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
6a161fa9 34 [Define if C symbols get an underscore after compilation])
35fi
36
4b13b216 37AC_MSG_RESULT([$grub_cv_asm_uscore])
6a161fa9 38])
39
40
41dnl Some versions of `objcopy -O binary' vary their output depending
42dnl on the link address.
4b13b216 43AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE,
6a161fa9 44[AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
4b13b216 45AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
6a161fa9 46[cat > conftest.c <<\EOF
47void
48cmain (void)
49{
50 *((int *) 0x1000) = 2;
51}
52EOF
53
54if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
55else
56 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
57fi
4b13b216 58grub_cv_prog_objcopy_absolute=yes
6a161fa9 59for link_addr in 2000 8000 7C00; do
60 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
61 else
62 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
63 fi
64 if AC_TRY_COMMAND([${OBJCOPY-objcopy} -O binary conftest.exec conftest]); then :
65 else
66 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
67 fi
68 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
69 mv -f conftest conftest.old
70 else
4b13b216 71 grub_cv_prog_objcopy_absolute=no
6a161fa9 72 break
73 fi
74done
75rm -f conftest*])
4b13b216 76AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
6a161fa9 77
4b13b216 78if test "x$grub_cv_prog_objcopy_absolute" = xno; then
79 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
6a161fa9 80fi
81])
82
83
84dnl Mass confusion!
85dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
86dnl instructions, but implicitly insert addr32 and data32 bytes so
87dnl that the code works in real mode''.
88dnl
89dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
90dnl instructions,'' which seems right. This requires the programmer
91dnl to explicitly insert addr32 and data32 instructions when they want
92dnl them.
93dnl
94dnl We only support the newer versions, because the old versions cause
95dnl major pain, by requiring manual assembly to get 16-bit instructions into
96dnl asm files.
4b13b216 97AC_DEFUN(grub_I386_ASM_ADDR32,
6a161fa9 98[AC_REQUIRE([AC_PROG_CC])
4b13b216 99AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
6a161fa9 100AC_MSG_CHECKING([for .code16 addr32 assembler support])
4b13b216 101AC_CACHE_VAL(grub_cv_i386_asm_addr32,
6a161fa9 102[cat > conftest.s.in <<\EOF
103 .code16
104l1: @ADDR32@ movb %al, l1
105EOF
106
4b13b216 107if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
6a161fa9 108 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
109else
110 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
111fi
112
113if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
4b13b216 114 grub_cv_i386_asm_addr32=yes
6a161fa9 115else
4b13b216 116 grub_cv_i386_asm_addr32=no
6a161fa9 117fi
118
119rm -f conftest*])
120
4b13b216 121AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
6a161fa9 122
123
124dnl Later versions of GAS requires that addr32 and data32 prefixes
125dnl appear in the same lines as the instructions they modify, while
126dnl earlier versions requires that they appear in separate lines.
4b13b216 127AC_DEFUN(grub_I386_ASM_PREFIX_REQUIREMENT,
6a161fa9 128[AC_REQUIRE([AC_PROG_CC])
129AC_MSG_CHECKING(dnl
130[whether addr32 must be in the same line as the instruction])
4b13b216 131AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
6a161fa9 132[cat > conftest.s <<\EOF
133 .code16
134l1: addr32 movb %al, l1
135EOF
136
137if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
4b13b216 138 grub_cv_i386_asm_prefix_requirement=yes
6a161fa9 139else
4b13b216 140 grub_cv_i386_asm_prefix_requirement=no
6a161fa9 141fi
142
143rm -f conftest*])
144
4b13b216 145if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
146 grub_tmp_addr32="addr32"
147 grub_tmp_data32="data32"
6a161fa9 148else
4b13b216 149 grub_tmp_addr32="addr32;"
150 grub_tmp_data32="data32;"
6a161fa9 151fi
152
4b13b216 153AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
6a161fa9 154 [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
4b13b216 155AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
6a161fa9 156 [Define it to \"data32\" or \"data32;\" to make GAS happy])
157
4b13b216 158AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
6a161fa9 159
160
161dnl Older versions of GAS require that absolute indirect calls/jumps are
162dnl not prefixed with `*', while later versions warn if not prefixed.
4b13b216 163AC_DEFUN(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK,
6a161fa9 164[AC_REQUIRE([AC_PROG_CC])
165AC_MSG_CHECKING(dnl
166[whether an absolute indirect call/jump must not be prefixed with an asterisk])
4b13b216 167AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
6a161fa9 168[cat > conftest.s <<\EOF
169 lcall *(offset)
170offset:
171 .long 0
172 .word 0
173EOF
174
175if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
4b13b216 176 grub_cv_i386_asm_absolute_without_asterisk=no
6a161fa9 177else
4b13b216 178 grub_cv_i386_asm_absolute_without_asterisk=yes
6a161fa9 179fi
180
181rm -f conftest*])
182
4b13b216 183if test "x$grub_cv_i386_asm_absolute_without_asterisk" = xyes; then
6a161fa9 184 AC_DEFINE([ABSOLUTE_WITHOUT_ASTERISK], 1,
185 [Define it if GAS requires that absolute indirect calls/jumps are not prefixed with an asterisk])
186fi
187
4b13b216 188AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
6a161fa9 189
190
191dnl Check what symbol is defined as a start symbol.
192dnl Written by Yoshinori K. Okuji.
4b13b216 193AC_DEFUN(grub_CHECK_START_SYMBOL,
6a161fa9 194[AC_REQUIRE([AC_PROG_CC])
195AC_MSG_CHECKING([if start is defined by the compiler])
4b13b216 196AC_CACHE_VAL(grub_cv_check_start_symbol,
6a161fa9 197[AC_TRY_LINK([], [asm ("incl start")],
4b13b216 198 grub_cv_check_start_symbol=yes,
199 grub_cv_check_start_symbol=no)])
6a161fa9 200
4b13b216 201AC_MSG_RESULT([$grub_cv_check_start_symbol])
6a161fa9 202
203AC_MSG_CHECKING([if _start is defined by the compiler])
4b13b216 204AC_CACHE_VAL(grub_cv_check_uscore_start_symbol,
6a161fa9 205[AC_TRY_LINK([], [asm ("incl _start")],
4b13b216 206 grub_cv_check_uscore_start_symbol=yes,
207 grub_cv_check_uscore_start_symbol=no)])
6a161fa9 208
4b13b216 209AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol])
6a161fa9 210
211AH_TEMPLATE([START_SYMBOL], [Define it to either start or _start])
212
4b13b216 213if test "x$grub_cv_check_start_symbol" = xyes; then
6a161fa9 214 AC_DEFINE([START_SYMBOL], [start])
4b13b216 215elif test "x$grub_cv_check_uscore_start_symbol" = xyes; then
6a161fa9 216 AC_DEFINE([START_SYMBOL], [_start])
217else
218 AC_MSG_ERROR([neither start nor _start is defined])
219fi
220])
221
222dnl Check what symbol is defined as a bss start symbol.
223dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
4b13b216 224AC_DEFUN(grub_CHECK_BSS_START_SYMBOL,
6a161fa9 225[AC_REQUIRE([AC_PROG_CC])
226AC_MSG_CHECKING([if __bss_start is defined by the compiler])
4b13b216 227AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
6a161fa9 228[AC_TRY_LINK([], [asm ("incl __bss_start")],
4b13b216 229 grub_cv_check_uscore_uscore_bss_start_symbol=yes,
230 grub_cv_check_uscore_uscore_bss_start_symbol=no)])
6a161fa9 231
4b13b216 232AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
6a161fa9 233
234AC_MSG_CHECKING([if edata is defined by the compiler])
4b13b216 235AC_CACHE_VAL(grub_cv_check_edata_symbol,
6a161fa9 236[AC_TRY_LINK([], [asm ("incl edata")],
4b13b216 237 grub_cv_check_edata_symbol=yes,
238 grub_cv_check_edata_symbol=no)])
6a161fa9 239
4b13b216 240AC_MSG_RESULT([$grub_cv_check_edata_symbol])
6a161fa9 241
242AC_MSG_CHECKING([if _edata is defined by the compiler])
4b13b216 243AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
6a161fa9 244[AC_TRY_LINK([], [asm ("incl _edata")],
4b13b216 245 grub_cv_check_uscore_edata_symbol=yes,
246 grub_cv_check_uscore_edata_symbol=no)])
6a161fa9 247
4b13b216 248AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
6a161fa9 249
250AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata])
251
4b13b216 252if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
6a161fa9 253 AC_DEFINE([BSS_START_SYMBOL], [__bss_start])
4b13b216 254elif test "x$grub_cv_check_edata_symbol" = xyes; then
6a161fa9 255 AC_DEFINE([BSS_START_SYMBOL], [edata])
4b13b216 256elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
6a161fa9 257 AC_DEFINE([BSS_START_SYMBOL], [_edata])
258else
259 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
260fi
261])
262
263dnl Check what symbol is defined as an end symbol.
264dnl Written by Yoshinori K. Okuji.
4b13b216 265AC_DEFUN(grub_CHECK_END_SYMBOL,
6a161fa9 266[AC_REQUIRE([AC_PROG_CC])
267AC_MSG_CHECKING([if end is defined by the compiler])
4b13b216 268AC_CACHE_VAL(grub_cv_check_end_symbol,
6a161fa9 269[AC_TRY_LINK([], [asm ("incl end")],
4b13b216 270 grub_cv_check_end_symbol=yes,
271 grub_cv_check_end_symbol=no)])
6a161fa9 272
4b13b216 273AC_MSG_RESULT([$grub_cv_check_end_symbol])
6a161fa9 274
275AC_MSG_CHECKING([if _end is defined by the compiler])
4b13b216 276AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
6a161fa9 277[AC_TRY_LINK([], [asm ("incl _end")],
4b13b216 278 grub_cv_check_uscore_end_symbol=yes,
279 grub_cv_check_uscore_end_symbol=no)])
6a161fa9 280
4b13b216 281AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
6a161fa9 282
283AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end])
284
4b13b216 285if test "x$grub_cv_check_end_symbol" = xyes; then
6a161fa9 286 AC_DEFINE([END_SYMBOL], [end])
4b13b216 287elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
6a161fa9 288 AC_DEFINE([END_SYMBOL], [_end])
289else
290 AC_MSG_ERROR([neither end nor _end is defined])
291fi
292])
5aded270 293
294dnl Check if the C compiler has a bug while using nested functions when
295dnl mregparm is used on the i386. Some gcc versions do not pass the third
296dnl parameter correctly to the nested function.
297dnl Written by Marco Gerards.
4b13b216 298AC_DEFUN(grub_I386_CHECK_REGPARM_BUG,
5aded270 299[AC_REQUIRE([AC_PROG_CC])
300AC_MSG_CHECKING([if GCC has the regparm=3 bug])
4b13b216 301AC_CACHE_VAL(grub_cv_i386_check_nested_functions,
5aded270 302[AC_RUN_IFELSE([AC_LANG_SOURCE(
e9c6f39b 303[[
304static int
305test (int *n)
306{
307 return *n == -1;
308}
5aded270 309
e9c6f39b 310static int
311testfunc (int __attribute__ ((__regparm__ (3))) (*hook) (int a, int b, int *c))
5aded270 312{
e9c6f39b 313 int a = 0;
314 int b = 0;
315 int c = -1;
316 return hook (a, b, &c);
317}
5aded270 318
e9c6f39b 319int
320main (void)
321{
322 int __attribute__ ((__regparm__ (3))) nestedfunc (int a, int b, int *c)
5aded270 323 {
e9c6f39b 324 return a == b && test (c);
5aded270 325 }
e9c6f39b 326 return testfunc (nestedfunc) ? 0 : 1;
5aded270 327}
328]])],
e9c6f39b 329 [grub_cv_i386_check_nested_functions=no],
330 [grub_cv_i386_check_nested_functions=yes])])
5aded270 331
4b13b216 332AC_MSG_RESULT([$grub_cv_i386_check_nested_functions])
5aded270 333
4b13b216 334if test "x$grub_cv_i386_check_nested_functions" = xyes; then
5aded270 335 AC_DEFINE([NESTED_FUNC_ATTR],
336 [__attribute__ ((__regparm__ (2)))],
337 [Catch gcc bug])
338else
e9c6f39b 339dnl Unfortunately, the above test does not detect a bug in gcc-4.0.
340dnl So use regparm 2 until a better test is found.
341 AC_DEFINE([NESTED_FUNC_ATTR],
342 [__attribute__ ((__regparm__ (2)))],
343 [Catch gcc bug])
5aded270 344fi
345])