diff --git a/ChangeLog b/ChangeLog index acdc3bb9c..455f2e43e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,43 @@ 1999-03-13 Gordon Matzigkeit + * shared_src/gunzip.c (border): Rename to bitorder, to resolve + clash with curses. + * shared_src/stage2.c (timeout): Rename to grub_timeout. + + * configure.in: Check for curses libraries for use with + /sbin/grub. + + * shared_src/shared.h (KEY_DELETE): Rename to KEY_DC, for + compatibility with curses. + (KEY_INSERT): Rename to KEY_IC. + (KEY_PGDN): Rename to KEY_NPAGE. + (KEY_PGUP): Rename to KEY_PPAGE. + + * shared_src/asm.S (asm_getkey): Renamed to getkey. + + * shared_src/char_io.c (getkey): Delete, because it's useless. + + * shared_src/shared.h: Resolve name clashes with libc by renaming + overlapping functions to have grub_ prefixes, then defining + macros. + + * grub/asmstub.c (start_stage2): Make some assertions about our + scratch memory area. + + * shared_src/shared.h (end): Delete declaration. + (RAW_ADDR, RAW_SEG): Macros to redirect /sbin/grub memory requests + through grub_scratch_mem. + + * grub/asmstub.c (get_mem_map): Implement, simulating 4MB + contiguous memory. + (get_code_end): Implement, simulating with a malloced area. + grub/asmstub.c (start_stage2): Initialize grub_scratch_mem. + + * shared_src/asm.S (get_mem_map): Some BIOSes expect the high word + of %eax to be zero. + (get_code_end): Move this from common.c so that we can stub it out + in the simulator. + * debian/rules: Make sure info files end up in /usr/info, not /info. diff --git a/configure b/configure index fe533ba24..4f31253dc 100644 --- a/configure +++ b/configure @@ -816,7 +816,6 @@ esac # Options # sbingrub= -stage2debug= # Check whether --enable-sbin-grub or --disable-sbin-grub was given. if test "${enable_sbin_grub+set}" = set; then enableval="$enable_sbin_grub" @@ -824,6 +823,8 @@ if test "${enable_sbin_grub+set}" = set; then fi + +stage2debug= # Check whether --enable-debug or --disable-debug was given. if test "${enable_debug+set}" = set; then enableval="$enable_debug" @@ -832,14 +833,12 @@ fi - - # # Programs # echo $ac_n "checking build system type""... $ac_c" 1>&6 -echo "configure:843: checking build system type" >&5 +echo "configure:842: checking build system type" >&5 build_alias=$build case "$build_alias" in @@ -865,7 +864,7 @@ fi # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:869: checking for $ac_word" >&5 +echo "configure:868: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -896,7 +895,7 @@ fi # Extract the first word of "${ac_tool_prefix}ld", so it can be a program name with args. set dummy ${ac_tool_prefix}ld; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:900: checking for $ac_word" >&5 +echo "configure:899: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_LD'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -927,7 +926,7 @@ fi # Extract the first word of "${ac_tool_prefix}objcopy", so it can be a program name with args. set dummy ${ac_tool_prefix}objcopy; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:931: checking for $ac_word" >&5 +echo "configure:930: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_OBJCOPY'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -960,7 +959,7 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:964: checking for $ac_word" >&5 +echo "configure:963: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -989,7 +988,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:993: checking for $ac_word" >&5 +echo "configure:992: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1037,7 +1036,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:1041: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:1040: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -1047,11 +1046,11 @@ ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1054: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -1071,12 +1070,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:1075: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:1074: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:1080: checking whether we are using GNU C" >&5 +echo "configure:1079: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1085,7 +1084,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1089: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1088: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -1100,7 +1099,7 @@ if test $ac_cv_prog_gcc = yes; then ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:1104: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:1103: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1129,7 +1128,7 @@ fi echo $ac_n "checking symbol names produced by ${CC-cc}""... $ac_c" 1>&6 -echo "configure:1133: checking symbol names produced by ${CC-cc}" >&5 +echo "configure:1132: checking symbol names produced by ${CC-cc}" >&5 if eval "test \"`echo '$''{'grub_cv_asm_ext_c'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1142,7 +1141,7 @@ func (int *list) } EOF -if { ac_try='${CC-cc} -S conftest.c'; { (eval echo configure:1146: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } && test -s conftest.s; then : +if { ac_try='${CC-cc} -S conftest.c'; { (eval echo configure:1145: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } && test -s conftest.s; then : else { echo "configure: error: ${CC-cc} failed to produce assembly code" 1>&2; exit 1; } fi @@ -1170,7 +1169,7 @@ EOF echo $ac_n "checking whether ${OBJCOPY} works for absolute addresses""... $ac_c" 1>&6 -echo "configure:1174: checking whether ${OBJCOPY} works for absolute addresses" >&5 +echo "configure:1173: checking whether ${OBJCOPY} works for absolute addresses" >&5 if eval "test \"`echo '$''{'grub_cv_prog_objcopy_absolute'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1182,21 +1181,21 @@ blah (void) } EOF -if { (eval echo configure:1186: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; } && test -s conftest.o; then : +if { (eval echo configure:1185: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; } && test -s conftest.o; then : else { echo "configure: error: ${CC-cc} cannot compile C source code" 1>&2; exit 1; } fi grub_cv_prog_objcopy_absolute=yes for link_addr in 2000 8000 7C00; do - if { ac_try='${LD-ld} -N -Ttext $link_addr conftest.o -o conftest.exec'; { (eval echo configure:1192: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then : + if { ac_try='${LD-ld} -N -Ttext $link_addr conftest.o -o conftest.exec'; { (eval echo configure:1191: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then : else { echo "configure: error: ${LD-ld} cannot link at address $link_addr" 1>&2; exit 1; } fi - if { ac_try='${OBJCOPY-objcopy} -O binary conftest.exec conftest'; { (eval echo configure:1196: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then : + if { ac_try='${OBJCOPY-objcopy} -O binary conftest.exec conftest'; { (eval echo configure:1195: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then : else { echo "configure: error: ${OBJCOPY-objcopy} cannot create binary files" 1>&2; exit 1; } fi - if test ! -f conftest.old || { ac_try='cmp -s conftest.old conftest'; { (eval echo configure:1200: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then + if test ! -f conftest.old || { ac_try='cmp -s conftest.old conftest'; { (eval echo configure:1199: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then mv -f conftest conftest.old else grub_cv_prog_objcopy_absolute=no @@ -1213,7 +1212,7 @@ fi echo $ac_n "checking for .code16 addr32 assembler support""... $ac_c" 1>&6 -echo "configure:1217: checking for .code16 addr32 assembler support" >&5 +echo "configure:1216: checking for .code16 addr32 assembler support" >&5 if eval "test \"`echo '$''{'grub_cv_asm_addr32'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1223,7 +1222,7 @@ l1: addr32 movb %al, l1 EOF -if { ac_try='${CC-cc} -c conftest.s'; { (eval echo configure:1227: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } && test -s conftest.o; then +if { ac_try='${CC-cc} -c conftest.s'; { (eval echo configure:1226: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } && test -s conftest.o; then grub_cv_asm_addr32=yes else grub_cv_asm_addr32=no @@ -1236,6 +1235,98 @@ if test "x$grub_cv_asm_addr32" != xyes; then { echo "configure: error: GRUB requires GAS .code16 addr32 support; upgrade your binutils" 1>&2; exit 1; } fi +# Check for curses libraries if we are building /sbin/grub. +if test -n "$sbingrub"; then + echo $ac_n "checking for getch in -lncurses""... $ac_c" 1>&6 +echo "configure:1242: checking for getch in -lncurses" >&5 +ac_lib_var=`echo ncurses'_'getch | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lncurses $LIBS" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + LIBS="$LIBS -lncurses" +cat >> confdefs.h <<\EOF +#define HAVE_LIBCURSES 1 +EOF + +else + echo "$ac_t""no" 1>&6 +echo $ac_n "checking for getch in -lcurses""... $ac_c" 1>&6 +echo "configure:1284: checking for getch in -lcurses" >&5 +ac_lib_var=`echo curses'_'getch | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lcurses $LIBS" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + LIBS="$LIBS -lcurses" +cat >> confdefs.h <<\EOF +#define HAVE_LIBCURSES 1 +EOF + +else + echo "$ac_t""no" 1>&6 +fi + +fi + +fi + # Create rules for our shared sources. SHARED_SRC_RULES=./ssrcrules.mk echo creating $SHARED_SRC_RULES diff --git a/configure.in b/configure.in index 8164d1cb5..669ca53c4 100644 --- a/configure.in +++ b/configure.in @@ -33,16 +33,15 @@ AC_SUBST(host_vendor) # Options # sbingrub= -stage2debug= AC_ARG_ENABLE(sbin-grub, [ --enable-sbin-grub build /sbin/grub command-line utility], [test "x$enableval" = xno || sbingrub=grub]) +AC_SUBST(sbingrub) +stage2debug= AC_ARG_ENABLE(debug, [ --enable-debug build debugging version of stage2], [test "x$enableval" = xno || stage2debug=stage2_debug]) - -AC_SUBST(sbingrub) AC_SUBST(stage2debug) # @@ -65,6 +64,14 @@ if test "x$grub_cv_asm_addr32" != xyes; then AC_MSG_ERROR([GRUB requires GAS .code16 addr32 support; upgrade your binutils]) fi +# Check for curses libraries if we are building /sbin/grub. +if test -n "$sbingrub"; then + AC_CHECK_LIB(ncurses, getch, [LIBS="$LIBS -lncurses" +AC_DEFINE(HAVE_LIBCURSES)], + [AC_CHECK_LIB(curses, getch, [LIBS="$LIBS -lcurses" +AC_DEFINE(HAVE_LIBCURSES)])]) +fi + # Create rules for our shared sources. AC_SUBST_FILE(SHARED_SRC_RULES)dnl SHARED_SRC_RULES=./ssrcrules.mk diff --git a/debian/changelog b/debian/changelog index 4328f5ac0..fe70a5d48 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,7 +5,7 @@ grub (0.5.91) unstable; urgency=low * GRUB data now installed in /share/grub/$(host_cpu)-$(host_vendor). * Preliminary Texinfo documentation. - -- Gordon Matzigkeit Sat, 13 Mar 1999 17:37:25 -0600 + -- grub (0.5.90) unstable; urgency=low diff --git a/grub/Makefile.am b/grub/Makefile.am index 288a7bae5..e28f98c5d 100644 --- a/grub/Makefile.am +++ b/grub/Makefile.am @@ -2,6 +2,7 @@ EXTRA_PROGRAMS = grub sbin_PROGRAMS = $(sbingrub) CLEANFILES = $(EXTRA_PROGRAMS) +COMPILE = $(CC) -DGRUB_UTIL=1 $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) INCLUDES = -I$(top_srcdir)/shared_src grub_SOURCES = main.c asmstub.c diff --git a/grub/Makefile.in b/grub/Makefile.in index 6ba2b8853..2e30427ab 100644 --- a/grub/Makefile.in +++ b/grub/Makefile.in @@ -74,6 +74,7 @@ EXTRA_PROGRAMS = grub sbin_PROGRAMS = $(sbingrub) CLEANFILES = $(EXTRA_PROGRAMS) +COMPILE = $(CC) -DGRUB_UTIL=1 $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) INCLUDES = -I$(top_srcdir)/shared_src grub_SOURCES = main.c asmstub.c @@ -96,7 +97,6 @@ grub_DEPENDENCIES = boot.o common.o char_io.o cmdline.o disk_io.o \ gunzip.o fsys_ffs.o fsys_ext2fs.o fsys_fat.o stage2.o grub_LDFLAGS = CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ DIST_COMMON = Makefile.am Makefile.in diff --git a/grub/asmstub.c b/grub/asmstub.c index 611965672..0e84bf3a9 100644 --- a/grub/asmstub.c +++ b/grub/asmstub.c @@ -18,37 +18,78 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define end _end #include "shared.h" -#undef end +/* We want to prevent any circularararity in our stubs, as well as + libc name clashes. */ +#undef NULL +#undef bcopy +#undef bzero +#undef getc +#undef isspace +#undef printf +#undef putchar +#undef strncat +#undef strstr +#undef tolower + +#include +#include +#include + +/* Simulated memory sizes. */ +#define EXTENDED_MEMSIZE (4 * 1024 * 1024) /* 4MB */ +#define CONVENTIONAL_MEMSIZE (640) /* 640kB */ -char *end = _end; unsigned long install_partition = 0x20000; unsigned long boot_drive = 0; char version_string[] = "0.5"; char config_file[] = "/boot/grub/menu.lst"; - +char *grub_scratch_mem = 0; /* The main entry point into this mess. */ void start_stage2 (void) { + grub_scratch_mem = memalign (16, EXTENDED_MEMSIZE); + + /* Check some invariants. */ + assert (BUFFERADDR + BUFFERLEN == SCRATCHADDR); + assert (FSYS_BUF % 16 == 0); + assert (FSYS_BUF + FSYS_BUFLEN == BUFFERADDR); + +#ifdef HAVE_LIBCURSES + /* Get into char-at-a-time mode. */ + initscr (); + cbreak (); + noecho (); + scrollok (stdscr, TRUE); +#endif + init_bios_info (); } + +void +stop (void) +{ + fprintf (stderr, "grub: aborting...\n"); + exit (1); +} + + /* calls for direct boot-loader chaining */ void chain_stage1 (int segment, int offset, int part_table_addr) { - + stop (); } void chain_stage2 (int segment, int offset) { - + stop (); } @@ -56,7 +97,7 @@ chain_stage2 (int segment, int offset) void linux_boot (void) { - + stop (); } @@ -64,7 +105,7 @@ linux_boot (void) void big_linux_boot (void) { - + stop (); } @@ -72,7 +113,7 @@ big_linux_boot (void) void multi_boot (int start, int mbi) { - + stop (); } /* sets it to linear or wired A20 operation */ @@ -83,34 +124,70 @@ gateA20 (int linear) } +void * +get_code_end (void) +{ + /* Just return a little area for simulation. */ + return malloc (1024); +} + + /* memory probe routines */ int get_memsize (int type) { if (!type) - return 640 * 1024; /* 640kB conventional */ + return CONVENTIONAL_MEMSIZE; else - return 4 * 1024 * 1024; /* 4MB extended */ + return EXTENDED_MEMSIZE; } +/* get_eisamemsize() : return packed EISA memory map, lower 16 bits is + * memory between 1M and 16M in 1K parts, upper 16 bits is + * memory above 16M in 64K parts. If error, return -1. + */ int get_eisamemsize (void) { + return (EXTENDED_MEMSIZE / 1024); } -int -get_mmap_entry (int buf, int cont) -{ -} +#define MMAR_DESC_TYPE_AVAILABLE 1 /* available to OS */ +#define MMAR_DESC_TYPE_RESERVED 2 /* not available */ +#define MMAR_DESC_TYPE_ACPI_RECLAIM 3 /* usable by OS after reading ACPI */ +#define MMAR_DESC_TYPE_ACPI_NVS 4 /* required to save between NVS sessions */ - -/* Address and old continuation value for the Query System Address Map - BIOS call. */ -int -get_mem_map (int addr, int cont) +/* Memory map address range descriptor. */ +struct mmar_desc { + unsigned long desc_len; /* Size of this descriptor. */ + unsigned long long addr; /* Base address. */ + unsigned long long length; /* Length in bytes. */ + unsigned long type; /* Type of address range. */ +}; + +/* Fetch the next entry in the memory map and return the continuation + value. DESC is a pointer to the descriptor buffer, and CONT is the + previous continuation value (0 to get the first entry in the + map). */ +int +get_mem_map (struct mmar_desc *desc, int cont) +{ + if (! cont) + { + /* First entry, located at 1MB. */ + desc->desc_len = sizeof (*desc) - sizeof (desc->desc_len); + desc->addr = 1024 * 1024; + desc->length = EXTENDED_MEMSIZE; + desc->type = MMAR_DESC_TYPE_AVAILABLE; + } + else + { + /* No more entries, so give an error. */ + desc->desc_len = 0; + } return 0; } @@ -146,15 +223,21 @@ gotoxy (int x, int y) /* displays an ASCII character. IBM displays will translate some characters to special graphical ones */ void -putchar (int c) +grub_putchar (int c) { + addch (c); } /* returns packed BIOS/ASCII code */ int -asm_getkey (void) +getkey (void) { + int c; + nodelay (stdscr, FALSE); + c = getch (); + nodelay (stdscr, TRUE); + return c; } @@ -162,6 +245,7 @@ asm_getkey (void) int checkkey (void) { + getch (); } diff --git a/shared_src/asm.S b/shared_src/asm.S index d996816aa..a63b654a5 100644 --- a/shared_src/asm.S +++ b/shared_src/asm.S @@ -753,6 +753,15 @@ pc_notnewline: pop %ebp ret +/* get_code_end() : return the address of the end of the code + * This is here so that it can be replaced by asmstub.c. + */ +ENTRY(get_code_end) + movl $EXT_C(end), %eax /* will be the end of the bss */ + shrl $2, %eax /* Round up to the next word. */ + incl %eax + shll $2, %eax + ret /* * @@ -843,7 +852,6 @@ xnoteisa: pop %ebp ret - /* * * get_mem_map(addr, cont) : address and old continuation value (zero to @@ -886,7 +894,7 @@ ENTRY(get_mem_map) .code16 movw %si, %es - movw $0xe820, %ax + movl $0xe820, %eax int $0x15 data32 @@ -1298,14 +1306,14 @@ gottime: /* - * asm_getkey() + * getkey() * BIOS call "INT 16H Function 00H" to read character from keyboard * Call with %ah = 0x0 * Return: %ah = keyboard scan code * %al = ASCII character */ -ENTRY(asm_getkey) +ENTRY(getkey) push %ebp push %ebx /* save %ebx */ diff --git a/shared_src/char_io.c b/shared_src/char_io.c index 37e258ddd..0c8ac47b5 100644 --- a/shared_src/char_io.c +++ b/shared_src/char_io.c @@ -23,14 +23,6 @@ #include "shared.h" -#ifndef STAGE1_5 -int -getkey (void) -{ - return asm_getkey (); -} -#endif /* STAGE1_5 */ - void print_error (void) @@ -244,7 +236,7 @@ get_cmdline (char *prompt, char *commands, char *cmdline, int maxlen) case KEY_END: c = 5; break; - case KEY_DELETE: + case KEY_DC: c = 8; default: } diff --git a/shared_src/common.c b/shared_src/common.c index dc4f900aa..e89e4168d 100644 --- a/shared_src/common.c +++ b/shared_src/common.c @@ -118,7 +118,8 @@ init_bios_info (void) * unused by GRUB. */ - mbi.mmap_addr = (addr = (((int) end) & ~3) + 4); + addr = get_code_end (); + mbi.mmap_addr = addr; mbi.mmap_length = 0; cont = 0; @@ -126,6 +127,7 @@ init_bios_info (void) { cont = get_mem_map (addr, cont); + /* If the returned buffer's base is zero, quit. */ if (!*((int *) addr)) break; diff --git a/shared_src/gunzip.c b/shared_src/gunzip.c index d17efa5a1..84c3cbb96 100644 --- a/shared_src/gunzip.c +++ b/shared_src/gunzip.c @@ -71,7 +71,7 @@ chunks), otherwise the dynamic method is used. In the latter case, the codes are customized to the probabilities in the current block, and so can code it much better than the pre-determined fixed codes. - + The Huffman codes themselves are decoded using a mutli-level table lookup, in order to maximize the speed of decoding plus the speed of building the decoding tables. See the comments below that precede the @@ -358,7 +358,7 @@ static unsigned wp; /* Tables for deflate from PKZIP's appnote.txt. */ -static unsigned border[] = +static unsigned bitorder[] = { /* Order of the bit length code lengths */ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; static ush cplens[] = @@ -429,7 +429,7 @@ static unsigned hufts; /* track memory usage */ /* Macros for inflate() bit peeking and grabbing. The usage is: - + NEEDBITS(j) x = b & mask_bits[j]; DUMPBITS(j) @@ -942,11 +942,11 @@ init_dynamic_block (void) for (j = 0; j < nb; j++) { NEEDBITS (3); - ll[border[j]] = (unsigned) b & 7; + ll[bitorder[j]] = (unsigned) b & 7; DUMPBITS (3); } for (; j < 19; j++) - ll[border[j]] = 0; + ll[bitorder[j]] = 0; /* build decoding table for trees--single level, 7 bit lookup */ bl = 7; diff --git a/shared_src/shared.h b/shared_src/shared.h index e285cbddd..b514080a3 100644 --- a/shared_src/shared.h +++ b/shared_src/shared.h @@ -22,6 +22,16 @@ * Generic defines to use anywhere */ +/* Maybe redirect memory requests through grub_scratch_mem. */ +#ifdef GRUB_UTIL +extern char *grub_scratch_mem; +# define RAW_ADDR(x) ((x) + (int) grub_scratch_mem) +# define RAW_SEG(x) (RAW_ADDR ((x) << 4) >> 4) +#else +# define RAW_ADDR(x) x +# define RAW_SEG(x) x +#endif + /* * Integer sizes */ @@ -29,8 +39,8 @@ #define MAXINT 0x7FFFFFFF /* 512-byte scratch area */ -#define SCRATCHADDR 0x77e00 -#define SCRATCHSEG 0x77e0 +#define SCRATCHADDR RAW_ADDR (0x77e00) +#define SCRATCHSEG RAW_SEG (0x77e0) /* * This is the location of the raw device buffer. It is 31.5K @@ -38,12 +48,8 @@ */ #define BUFFERLEN 0x7e00 -#define BUFFERADDR 0x70000 -#define BUFFERSEG 0x7000 - -#if (BUFFERADDR + BUFFERLEN) != SCRATCHADDR -# error "scratch area isn't at the end of the device buffer" -#endif +#define BUFFERADDR RAW_ADDR (0x70000) +#define BUFFERSEG RAW_SEG (0x7000) /* * BIOS disk defines @@ -58,24 +64,16 @@ */ #define FSYS_BUFLEN 0x8000 -#define FSYS_BUF 0x68000 - -#if (FSYS_BUF % 16) != 0 -# error "FSYS_BUF is not segment-aligned" -#endif - -#if (FSYS_BUF + FSYS_BUFLEN) != BUFFERADDR -# error "device buffer buffer isn't at the end of the filesystem buffer" -#endif +#define FSYS_BUF RAW_ADDR (0x68000) /* * Linux setup parameters */ -#define LINUX_STAGING_AREA 0x100000 -#define LINUX_SETUP 0x90000 +#define LINUX_STAGING_AREA RAW_ADDR (0x100000) +#define LINUX_SETUP RAW_ADDR (0x90000) #define LINUX_SETUP_MAXLEN 0x1E00 -#define LINUX_KERNEL 0x10000 +#define LINUX_KERNEL RAW_ADDR (0x10000) #define LINUX_KERNEL_MAXLEN 0x7F000 #define LINUX_SETUP_SEG 0x9020 #define LINUX_INIT_SEG 0x9000 @@ -89,12 +87,12 @@ #define LINUX_SETUP_CODE_START 0x214 #define LINUX_SETUP_INITRD 0x218 -#define CL_MY_LOCATION 0x92000 -#define CL_MY_END_ADDR 0x920FF -#define CL_MAGIC_ADDR 0x90020 +#define CL_MY_LOCATION RAW_ADDR (0x92000) +#define CL_MY_END_ADDR RAW_ADDR (0x920FF) +#define CL_MAGIC_ADDR RAW_ADDR (0x90020) #define CL_MAGIC 0xA33F -#define CL_BASE_ADDR 0x90000 -#define CL_OFFSET 0x90022 +#define CL_BASE_ADDR RAW_ADDR (0x90000) +#define CL_OFFSET RAW_ADDR (0x90022) /* * General disk stuff @@ -103,7 +101,7 @@ #define SECTOR_SIZE 0x200 #define BIOS_FLAG_FIXED_DISK 0x80 -#define BOOTSEC_LOCATION 0x7C00 +#define BOOTSEC_LOCATION RAW_ADDR (0x7C00) #define BOOTSEC_SIGNATURE 0xAA55 #define BOOTSEC_BPB_OFFSET 0x3 #define BOOTSEC_BPB_LENGTH 0x3B @@ -169,6 +167,36 @@ enable clock line */ #define KB_A20_ENABLE 0x02 +/* Codes for getchar. */ +#define ASCII_CHAR(x) ((x) & 0xFF) +#if !defined(GRUB_UTIL) || !defined(HAVE_LIBCURSES) +# define KEY_LEFT 0x4B00 +# define KEY_RIGHT 0x4D00 +# define KEY_UP 0x4800 +# define KEY_DOWN 0x5000 +# define KEY_IC 0x5200 /* insert char */ +# define KEY_DC 0x5300 /* delete char */ +# define KEY_HOME 0x4700 +# define KEY_END 0x4F00 +# define KEY_NPAGE 0x4900 +# define KEY_PPAGE 0x5100 +#else +# include +#endif + +/* Remap some names so that we don't conflict with libc. */ +#define bcopy grub_bcopy +#define bzero grub_bzero +#define isspace grub_isspace +#define open grub_open +#define printf grub_printf +#undef putchar +#define putchar grub_putchar +#define read grub_read +#define strncat grub_strncat +#define strstr grub_strstr +#define tolower grub_tolower + #ifndef ASM_FILE @@ -199,13 +227,12 @@ outb (unsigned short port, unsigned char val) #include "mb_header.h" #include "mb_info.h" -extern char end[]; /* will be the end of the bss */ - /* this function must be called somewhere... */ void cmain (void) __attribute__ ((noreturn)); +#undef NULL #define NULL ((void *) 0) @@ -218,6 +245,8 @@ __attribute__ ((noreturn)); extern char version_string[]; extern char config_file[]; +void stop (void) __attribute__ ((noreturn)); + /* calls for direct boot-loader chaining */ void chain_stage1 (int segment, int offset, int part_table_addr) __attribute__ ((noreturn)); @@ -226,6 +255,9 @@ __attribute__ ((noreturn)); /* do some funky stuff, then boot linux */ void linux_boot (void) __attribute__ ((noreturn)); +/* do some funky stuff, then boot bzImage linux */ + void big_linux_boot (void) __attribute__ ((noreturn)); + /* booting a multiboot executable */ void multi_boot (int start, int mbi) __attribute__ ((noreturn)); @@ -258,23 +290,11 @@ __attribute__ ((noreturn)); #define DISP_UP 0x18 #define DISP_DOWN 0x19 void putchar (int c); - /* returns packed BIOS/ASCII code */ -#define BIOS_CODE(x) ((x) >> 8) -#define ASCII_CHAR(x) ((x) & 0xFF) -#define KEY_LEFT 0x4B00 -#define KEY_RIGHT 0x4D00 -#define KEY_UP 0x4800 -#define KEY_DOWN 0x5000 -#define KEY_INSERT 0x5200 -#define KEY_DELETE 0x5300 -#define KEY_HOME 0x4700 -#define KEY_END 0x4F00 -#define KEY_PGUP 0x4900 -#define KEY_PGDN 0x5100 - int asm_getkey (void); + int getkey (void); /* returns 0 if non-ASCII character */ +#undef getc #define getc() ASCII_CHAR(getkey()) /* like 'getkey', but doesn't wait, returns -1 if nothing available */ @@ -355,32 +375,16 @@ __attribute__ ((noreturn)); MAX_ERR_NUM }; -/* returns packed BIOS/ASCII code */ -#define BIOS_CODE(x) ((x) >> 8) -#define ASCII_CHAR(x) ((x) & 0xFF) -#define KEY_LEFT 0x4B00 -#define KEY_RIGHT 0x4D00 -#define KEY_UP 0x4800 -#define KEY_DOWN 0x5000 -#define KEY_INSERT 0x5200 -#define KEY_DELETE 0x5300 -#define KEY_HOME 0x4700 -#define KEY_END 0x4F00 -#define KEY_PGUP 0x4900 -#define KEY_PGDN 0x5100 - int getkey (void); /* actually just calls asm_getkey and invalidates the - disk buffer */ - void init_page (void); void print_error (void); char *convert_to_ascii (char *buf, int c,...); - void printf (char *format,...); + void grub_printf (char *format,...); int get_cmdline (char *prompt, char *commands, char *cmdline, int maxlen); - int tolower (int c); - int isspace (int c); - int strncat (char *s1, char *s2, int n); + int grub_tolower (int c); + int grub_isspace (int c); + int grub_strncat (char *s1, char *s2, int n); int substring (char *s1, char *s2); - char *strstr (char *s1, char *s2); + char *grub_strstr (char *s1, char *s2); int bcopy (char *from, char *to, int len); int bzero (char *start, int len); int get_based_digit (int c, int base); @@ -448,8 +452,8 @@ __attribute__ ((noreturn)); int make_saved_active (void); /* sets the active partition to the that represented by the "saved_" parameters */ - int open (char *filename); - int read (int addr, int len); /* if "length" is -1, read all the + int grub_open (char *filename); + int grub_read (int addr, int len); /* if "length" is -1, read all the remaining data in the file */ int dir (char *dirname); /* list directory, printing all completions */ diff --git a/shared_src/stage2.c b/shared_src/stage2.c index ea06db564..aad07a117 100644 --- a/shared_src/stage2.c +++ b/shared_src/stage2.c @@ -131,7 +131,7 @@ set_line(int y, int attr) } -int timeout; +static int grub_timeout; void @@ -189,31 +189,31 @@ restart: /* initilize to NULL just in case... */ cur_entry = NULL; - if (timeout >= 0 && (time1 = getrtsecs()) != time2 && time1 != 0xFF) + if (grub_timeout >= 0 && (time1 = getrtsecs()) != time2 && time1 != 0xFF) { - if (timeout <= 0) + if (grub_timeout <= 0) { - timeout = -1; + grub_timeout = -1; break; } /* else not booting yet! */ time2 = time1; gotoxy(3, 22); - printf("The highlighted entry will be booted automatically in %d seconds. ", timeout); + printf("The highlighted entry will be booted automatically in %d seconds. ", grub_timeout); gotoxy(74, 4+entryno); - timeout--; + grub_timeout --; } if (checkkey() != -1) { c = getkey(); - if (timeout >= 0) + if (grub_timeout >= 0) { gotoxy(3, 22); printf(" "); - timeout = -1; + grub_timeout = -1; fallback = -1; gotoxy(74, 4+entryno); } @@ -514,7 +514,7 @@ cmain(void) config_len = 0; menu_len = 0; num_entries = 0; default_entry = 0; config_entries = (char *)(mbi.mmap_addr + mbi.mmap_length); menu_entries = (char *)(BUFFERADDR + (32 * 1024)); - password = NULL; fallback = -1; timeout = -1; + password = NULL; fallback = -1; grub_timeout = -1; /* * Here load the configuration file. @@ -552,7 +552,7 @@ cmain(void) else if (!state) { if (substring("timeout", cmdline) < 1) - safe_parse_maxint(&ptr, &timeout); + safe_parse_maxint(&ptr, &grub_timeout); if (substring("fallback", cmdline) < 1) safe_parse_maxint(&ptr, &fallback); if (substring("default", cmdline) < 1)