xref: /titanic_52/usr/src/grub/grub-0.97/acinclude.m4 (revision 5c51f1241dbbdf2656d0e10011981411ed0c9673)
1dnl grub_ASM_USCORE checks if C symbols get an underscore after
2dnl compiling to assembler.
3dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
4dnl Erich Boleyn and modified by OKUJI Yoshinori
5AC_DEFUN([grub_ASM_USCORE],
6[AC_REQUIRE([AC_PROG_CC])
7AC_MSG_CHECKING([if C symbols get an underscore after compilation])
8AC_CACHE_VAL(grub_cv_asm_uscore,
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
25  grub_cv_asm_uscore=yes
26else
27  grub_cv_asm_uscore=no
28fi
29
30rm -f conftest*])
31
32if test "x$grub_cv_asm_uscore" = xyes; then
33  AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
34    [Define if C symbols get an underscore after compilation])
35fi
36
37AC_MSG_RESULT([$grub_cv_asm_uscore])
38])
39
40
41dnl Some versions of `objcopy -O binary' vary their output depending
42dnl on the link address.
43AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
44[AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
45AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
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
58grub_cv_prog_objcopy_absolute=yes
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
71    grub_cv_prog_objcopy_absolute=no
72    break
73  fi
74done
75rm -f conftest*])
76AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])])
77
78dnl Mass confusion!
79dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
80dnl instructions, but implicitly insert addr32 and data32 bytes so
81dnl that the code works in real mode''.
82dnl
83dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
84dnl instructions,'' which seems right.  This requires the programmer
85dnl to explicitly insert addr32 and data32 instructions when they want
86dnl them.
87dnl
88dnl We only support the newer versions, because the old versions cause
89dnl major pain, by requiring manual assembly to get 16-bit instructions into
90dnl stage1/stage1.S.
91AC_DEFUN([grub_ASM_ADDR32],
92[AC_REQUIRE([AC_PROG_CC])
93AC_REQUIRE([grub_ASM_PREFIX_REQUIREMENT])
94AC_MSG_CHECKING([for .code16 addr32 assembler support])
95AC_CACHE_VAL(grub_cv_asm_addr32,
96[cat > conftest.s.in <<\EOF
97	.code16
98l1:	@ADDR32@	movb	%al, l1
99EOF
100
101if test "x$grub_cv_asm_prefix_requirement" = xyes; then
102  sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
103else
104  sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
105fi
106
107if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
108  grub_cv_asm_addr32=yes
109else
110  grub_cv_asm_addr32=no
111fi
112
113rm -f conftest*])
114
115AC_MSG_RESULT([$grub_cv_asm_addr32])])
116
117dnl
118dnl Later versions of GAS requires that addr32 and data32 prefixes
119dnl appear in the same lines as the instructions they modify, while
120dnl earlier versions requires that they appear in separate lines.
121AC_DEFUN([grub_ASM_PREFIX_REQUIREMENT],
122[AC_REQUIRE([AC_PROG_CC])
123AC_MSG_CHECKING(dnl
124[whether addr32 must be in the same line as the instruction])
125AC_CACHE_VAL(grub_cv_asm_prefix_requirement,
126[cat > conftest.s <<\EOF
127	.code16
128l1:	addr32	movb	%al, l1
129EOF
130
131if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
132  grub_cv_asm_prefix_requirement=yes
133else
134  grub_cv_asm_prefix_requirement=no
135fi
136
137rm -f conftest*])
138
139if test "x$grub_cv_asm_prefix_requirement" = xyes; then
140  grub_tmp_addr32="addr32"
141  grub_tmp_data32="data32"
142else
143  grub_tmp_addr32="addr32;"
144  grub_tmp_data32="data32;"
145fi
146
147AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
148  [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
149AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
150  [Define it to \"data32\" or \"data32;\" to make GAS happy])
151
152AC_MSG_RESULT([$grub_cv_asm_prefix_requirement])])
153
154dnl
155dnl Older versions of GAS require that absolute indirect calls/jumps are
156dnl not prefixed with `*', while later versions warn if not prefixed.
157AC_DEFUN([grub_ASM_ABSOLUTE_WITHOUT_ASTERISK],
158[AC_REQUIRE([AC_PROG_CC])
159AC_MSG_CHECKING(dnl
160[whether an absolute indirect call/jump must not be prefixed with an asterisk])
161AC_CACHE_VAL(grub_cv_asm_absolute_without_asterisk,
162[cat > conftest.s <<\EOF
163	lcall	*(offset)
164offset:
165	.long	0
166	.word	0
167EOF
168
169if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
170  grub_cv_asm_absolute_without_asterisk=no
171else
172  grub_cv_asm_absolute_without_asterisk=yes
173fi
174
175rm -f conftest*])
176
177if test "x$grub_cv_asm_absolute_without_asterisk" = xyes; then
178  AC_DEFINE(ABSOLUTE_WITHOUT_ASTERISK, 1, [Define if an absolute indirect call/jump must NOT be prefixed with `*'])
179fi
180
181AC_MSG_RESULT([$grub_cv_asm_absolute_without_asterisk])])
182
183dnl
184dnl grub_CHECK_START_SYMBOL checks if start is automatically defined by
185dnl the compiler.
186dnl Written by OKUJI Yoshinori
187AC_DEFUN([grub_CHECK_START_SYMBOL],
188[AC_REQUIRE([AC_PROG_CC])
189AC_MSG_CHECKING([if start is defined by the compiler])
190AC_CACHE_VAL(grub_cv_check_start_symbol,
191[AC_TRY_LINK([], [asm ("incl start")],
192   grub_cv_check_start_symbol=yes,
193   grub_cv_check_start_symbol=no)])
194
195if test "x$grub_cv_check_start_symbol" = xyes; then
196  AC_DEFINE(HAVE_START_SYMBOL, 1, [Define if start is defined])
197fi
198
199AC_MSG_RESULT([$grub_cv_check_start_symbol])
200])
201
202dnl
203dnl grub_CHECK_USCORE_START_SYMBOL checks if _start is automatically
204dnl defined by the compiler.
205dnl Written by OKUJI Yoshinori
206AC_DEFUN([grub_CHECK_USCORE_START_SYMBOL],
207[AC_REQUIRE([AC_PROG_CC])
208AC_MSG_CHECKING([if _start is defined by the compiler])
209AC_CACHE_VAL(grub_cv_check_uscore_start_symbol,
210[AC_TRY_LINK([], [asm ("incl _start")],
211   grub_cv_check_uscore_start_symbol=yes,
212   grub_cv_check_uscore_start_symbol=no)])
213
214if test "x$grub_cv_check_uscore_start_symbol" = xyes; then
215  AC_DEFINE(HAVE_USCORE_START_SYMBOL, 1, [Define if _start is defined])
216fi
217
218AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol])
219])
220
221dnl
222dnl grub_CHECK_USCORE_USCORE_BSS_START_SYMBOL checks if __bss_start is
223dnl automatically defined by the compiler.
224dnl Written by Michael Hohmoth.
225AC_DEFUN([grub_CHECK_USCORE_USCORE_BSS_START_SYMBOL],
226[AC_REQUIRE([AC_PROG_CC])
227AC_MSG_CHECKING([if __bss_start is defined by the compiler])
228AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
229[AC_TRY_LINK([], [asm ("incl __bss_start")],
230   grub_cv_check_uscore_uscore_bss_start_symbol=yes,
231   grub_cv_check_uscore_uscore_bss_start_symbol=no)])
232
233if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
234  AC_DEFINE(HAVE_USCORE_USCORE_BSS_START_SYMBOL, 1, [Define if __bss_start is defined])
235fi
236
237AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
238])
239
240dnl
241dnl grub_CHECK_EDATA_SYMBOL checks if edata is automatically defined by the
242dnl compiler.
243dnl Written by Michael Hohmuth.
244AC_DEFUN([grub_CHECK_EDATA_SYMBOL],
245[AC_REQUIRE([AC_PROG_CC])
246AC_MSG_CHECKING([if edata is defined by the compiler])
247AC_CACHE_VAL(grub_cv_check_edata_symbol,
248[AC_TRY_LINK([], [asm ("incl edata")],
249   grub_cv_check_edata_symbol=yes,
250   grub_cv_check_edata_symbol=no)])
251
252if test "x$grub_cv_check_edata_symbol" = xyes; then
253  AC_DEFINE(HAVE_EDATA_SYMBOL, 1, [Define if edata is defined])
254fi
255
256AC_MSG_RESULT([$grub_cv_check_edata_symbol])
257])
258
259dnl
260dnl grub_CHECK_USCORE_EDATA_SYMBOL checks if _edata is automatically
261dnl defined by the compiler.
262dnl Written by Michael Hohmuth.
263AC_DEFUN([grub_CHECK_USCORE_EDATA_SYMBOL],
264[AC_REQUIRE([AC_PROG_CC])
265AC_MSG_CHECKING([if _edata is defined by the compiler])
266AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
267[AC_TRY_LINK([], [asm ("incl _edata")],
268   grub_cv_check_uscore_edata_symbol=yes,
269   grub_cv_check_uscore_edata_symbol=no)])
270
271if test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
272  AC_DEFINE(HAVE_USCORE_EDATA_SYMBOL, 1, [Define if _edata is defined])
273fi
274
275AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
276])
277
278dnl
279dnl grub_CHECK_END_SYMBOL checks if end is automatically defined by the
280dnl compiler.
281dnl Written by OKUJI Yoshinori
282AC_DEFUN([grub_CHECK_END_SYMBOL],
283[AC_REQUIRE([AC_PROG_CC])
284AC_MSG_CHECKING([if end is defined by the compiler])
285AC_CACHE_VAL(grub_cv_check_end_symbol,
286[AC_TRY_LINK([], [asm ("incl end")],
287   grub_cv_check_end_symbol=yes,
288   grub_cv_check_end_symbol=no)])
289
290if test "x$grub_cv_check_end_symbol" = xyes; then
291  AC_DEFINE(HAVE_END_SYMBOL, 1, [Define if end is defined])
292fi
293
294AC_MSG_RESULT([$grub_cv_check_end_symbol])
295])
296
297dnl
298dnl grub_CHECK_USCORE_END_SYMBOL checks if _end is automatically defined
299dnl by the compiler.
300dnl Written by OKUJI Yoshinori
301AC_DEFUN([grub_CHECK_USCORE_END_SYMBOL],
302[AC_REQUIRE([AC_PROG_CC])
303AC_MSG_CHECKING([if _end is defined by the compiler])
304AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
305[AC_TRY_LINK([], [asm ("incl _end")],
306   grub_cv_check_uscore_end_symbol=yes,
307   grub_cv_check_uscore_end_symbol=no)])
308
309if test "x$grub_cv_check_uscore_end_symbol" = xyes; then
310  AC_DEFINE(HAVE_USCORE_END_SYMBOL, 1, [Define if end is defined])
311fi
312
313AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
314])
315
316dnl grub_DEFINE_FILE(MACRO_NAME, FILE_NAME, DESCRIPTION)
317dnl grub_DEFINE_FILE defines a macro as the contents of a file safely.
318dnl Replace some escape sequences, because autoconf doesn't handle them
319dnl gracefully.
320dnl Written by OKUJI Yoshinori.
321AC_DEFUN([grub_DEFINE_FILE],
322[AC_REQUIRE([AC_PROG_CC])
323# Because early versions of GNU sed 3.x are too buggy, use a C program
324# instead of shell commands. *sigh*
325cat >conftest.c <<\EOF
326#include <stdio.h>
327
328int
329main (void)
330{
331  int c;
332
333  while ((c = getchar ()) != EOF)
334    {
335      switch (c)
336        {
337	case '\n':
338	  fputs ("\\n", stdout);
339	  break;
340	case '\r':
341	  fputs ("\\r", stdout);
342	  break;
343	case '\\':
344	  fputs ("\\\\", stdout);
345	  break;
346	case '"':
347	  fputs ("\\\"", stdout);
348	  break;
349	default:
350	  putchar (c);
351	}
352    }
353
354  return 0;
355}
356EOF
357
358if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} conftest.c -o conftest]) && test -s conftest; then
359  grub_tmp_value=`./conftest < "[$2]"`
360else
361  AC_MSG_ERROR([${CC-cc} failed to produce an executable file])
362fi
363
364AC_DEFINE_UNQUOTED([$1], "$grub_tmp_value", [$3])
365rm -f conftest*
366])
367