From 261bd4bc56f062c8e5a26ef2f56b87d16aab33be Mon Sep 17 00:00:00 2001 From: robertmh Date: Mon, 21 Jan 2008 15:48:27 +0000 Subject: [PATCH] 2008-01-21 Robert Millan * conf/i386-pc.rmk (GRUB_MEMORY_MACHINE_LINK_ADDR): New variable. (kernel_img_LDFLAGS): Use `GRUB_MEMORY_MACHINE_LINK_ADDR' as link address. (grub_mkimage_CFLAGS): Propagate `GRUB_MEMORY_MACHINE_LINK_ADDR' as a C macro. * include/grub/i386/pc/memory.h (GRUB_MEMORY_MACHINE_UPPER): New macro. Indicates start of upper memory. * util/i386/pc/grub-mkimage.c: Include `'. (generate_image): Abort when image size is big enough to corrupt upper memory. * include/grub/i386/pc/vga.h: Include `'. (GRUB_MEMORY_MACHINE_VGA_ADDR): Alias for `GRUB_MEMORY_MACHINE_UPPER'. * term/i386/pc/vga.c (VGA_MEM): Use `GRUB_MEMORY_MACHINE_VGA_ADDR' instead of hardcoding 0xA0000. * video/i386/pc/vbe.c: Include `'. (grub_vbe_set_video_mode): Use `GRUB_MEMORY_MACHINE_VGA_ADDR' instead of hardcoding 0xA0000. --- ChangeLog | 21 +++++++++++++++++++++ conf/i386-pc.mk | 5 ++++- conf/i386-pc.rmk | 5 ++++- include/grub/i386/pc/memory.h | 5 ++++- include/grub/i386/pc/vga.h | 6 +++++- term/i386/pc/vga.c | 4 ++-- util/i386/pc/grub-mkimage.c | 7 ++++++- video/i386/pc/vbe.c | 3 ++- 8 files changed, 48 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 46aa97dd2..b9177dda7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2008-01-21 Robert Millan + + * conf/i386-pc.rmk (GRUB_MEMORY_MACHINE_LINK_ADDR): New variable. + (kernel_img_LDFLAGS): Use `GRUB_MEMORY_MACHINE_LINK_ADDR' as link + address. + (grub_mkimage_CFLAGS): Propagate `GRUB_MEMORY_MACHINE_LINK_ADDR' as + a C macro. + * include/grub/i386/pc/memory.h (GRUB_MEMORY_MACHINE_UPPER): New macro. + Indicates start of upper memory. + * util/i386/pc/grub-mkimage.c: Include `'. + (generate_image): Abort when image size is big enough to corrupt + upper memory. + + * include/grub/i386/pc/vga.h: Include `'. + (GRUB_MEMORY_MACHINE_VGA_ADDR): Alias for `GRUB_MEMORY_MACHINE_UPPER'. + * term/i386/pc/vga.c (VGA_MEM): Use `GRUB_MEMORY_MACHINE_VGA_ADDR' + instead of hardcoding 0xA0000. + * video/i386/pc/vbe.c: Include `'. + (grub_vbe_set_video_mode): Use `GRUB_MEMORY_MACHINE_VGA_ADDR' + instead of hardcoding 0xA0000. + 2008-01-21 Robert Millan * disk/memdisk.c (memdisk_size): New variable. diff --git a/conf/i386-pc.mk b/conf/i386-pc.mk index 9ecbbc039..c995df609 100644 --- a/conf/i386-pc.mk +++ b/conf/i386-pc.mk @@ -1,5 +1,7 @@ # -*- makefile -*- +GRUB_MEMORY_MACHINE_LINK_ADDR = 0x8200 + COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 COMMON_LDFLAGS = -m32 -nostdlib @@ -183,7 +185,7 @@ kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h machine/kernel.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,8200 $(COMMON_CFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst @@ -222,6 +224,7 @@ grub_mkimage-util_resolve.o: util/resolve.c $(util/resolve.c_DEPENDENCIES) $(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_mkimage_CFLAGS) -MD -c -o $@ $< -include grub_mkimage-util_resolve.d +grub_mkimage_CFLAGS = -DGRUB_MEMORY_MACHINE_LINK_ADDR=$(GRUB_MEMORY_MACHINE_LINK_ADDR) grub_mkimage_LDFLAGS = $(LIBLZO) # For grub-setup. diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 6df833a0e..26a39e282 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -1,5 +1,7 @@ # -*- makefile -*- +GRUB_MEMORY_MACHINE_LINK_ADDR = 0x8200 + COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 COMMON_LDFLAGS = -m32 -nostdlib @@ -42,7 +44,7 @@ kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h machine/kernel.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,8200 $(COMMON_CFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst @@ -63,6 +65,7 @@ endif # For grub-mkimage. grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \ util/resolve.c +grub_mkimage_CFLAGS = -DGRUB_MEMORY_MACHINE_LINK_ADDR=$(GRUB_MEMORY_MACHINE_LINK_ADDR) grub_mkimage_LDFLAGS = $(LIBLZO) # For grub-setup. diff --git a/include/grub/i386/pc/memory.h b/include/grub/i386/pc/memory.h index c0ad73d4d..536291d5a 100644 --- a/include/grub/i386/pc/memory.h +++ b/include/grub/i386/pc/memory.h @@ -1,7 +1,7 @@ /* memory.h - describe the memory map */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +36,9 @@ /* The size of the protect mode stack. */ #define GRUB_MEMORY_MACHINE_PROT_STACK_SIZE 0x8000 +/* The upper memory area (starting at 640 kiB). */ +#define GRUB_MEMORY_MACHINE_UPPER 0xa0000 + /* The protected mode stack. */ #define GRUB_MEMORY_MACHINE_PROT_STACK \ (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + GRUB_MEMORY_MACHINE_SCRATCH_SIZE \ diff --git a/include/grub/i386/pc/vga.h b/include/grub/i386/pc/vga.h index d2be9396f..b9822395b 100644 --- a/include/grub/i386/pc/vga.h +++ b/include/grub/i386/pc/vga.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,10 @@ #define GRUB_VGA_MACHINE_HEADER 1 #include +#include + +/* The VGA (at the beginning of upper memory). */ +#define GRUB_MEMORY_MACHINE_VGA_ADDR GRUB_MEMORY_MACHINE_UPPER /* Set the video mode to MODE and return the previous mode. */ unsigned char EXPORT_FUNC(grub_vga_set_mode) (unsigned char mode); diff --git a/term/i386/pc/vga.c b/term/i386/pc/vga.c index 16e4dee24..ebcc54d1d 100644 --- a/term/i386/pc/vga.c +++ b/term/i386/pc/vga.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2000,2001,2002,2003,2004,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,7 +35,7 @@ #define CHAR_HEIGHT 16 #define TEXT_WIDTH (VGA_WIDTH / CHAR_WIDTH) #define TEXT_HEIGHT (VGA_HEIGHT / CHAR_HEIGHT) -#define VGA_MEM ((unsigned char *) 0xA0000) +#define VGA_MEM ((grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR) #define PAGE_OFFSET(x) ((x) * (VGA_WIDTH * VGA_HEIGHT / 8)) #define DEFAULT_FG_COLOR 0xa diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c index c002c0e69..48d6dfce7 100644 --- a/util/i386/pc/grub-mkimage.c +++ b/util/i386/pc/grub-mkimage.c @@ -1,7 +1,7 @@ /* grub-mkimage.c - make a bootable image */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,10 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *me = grub_cpu_to_le32 (memdisk_size); *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE)) = grub_cpu_to_le32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE); + + if (core_size > GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR) + grub_util_error ("Core image is too big (%p > %p)\n", core_size, + GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR); grub_util_write_image (core_img, core_size, out); free (kernel_img); diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index 11242ce63..edd73d50d 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -193,7 +194,7 @@ grub_vbe_set_video_mode (grub_uint32_t mode, if (mode < 0x100) { /* If this is not a VESA mode, guess address. */ - framebuffer.ptr = (grub_uint8_t *) 0xA0000; + framebuffer.ptr = (grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR; framebuffer.index_color_mode = 1; } else