From a455f472aa3fa3854603d03a4790d8aca5974478 Mon Sep 17 00:00:00 2001 From: robertmh Date: Sun, 22 Feb 2009 00:44:22 +0000 Subject: [PATCH] 2009-02-22 Robert Millan * include/multiboot.h (MULTIBOOT_INFO_ALIGN): New macro. * loader/i386/pc/multiboot.c (grub_multiboot): Include the MBI in our relocation, instead of using it directly from heap. Also use `MULTIBOOT_INFO_ALIGN' to ensure it is aligned. --- ChangeLog | 7 +++++++ include/multiboot.h | 5 ++++- loader/i386/pc/multiboot.c | 17 +++++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ec24e970..25c27a9aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-02-22 Robert Millan + + * include/multiboot.h (MULTIBOOT_INFO_ALIGN): New macro. + * loader/i386/pc/multiboot.c (grub_multiboot): Include the MBI + in our relocation, instead of using it directly from heap. Also + use `MULTIBOOT_INFO_ALIGN' to ensure it is aligned. + 2009-02-21 Robert Millan Implement USB keyboard support (based on patch by Marco Gerards) diff --git a/include/multiboot.h b/include/multiboot.h index 9adc8736a..2298fa200 100644 --- a/include/multiboot.h +++ b/include/multiboot.h @@ -1,7 +1,7 @@ /* multiboot.h - multiboot header file. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2007,2009 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,6 +35,9 @@ /* Alignment of multiboot modules. */ #define MULTIBOOT_MOD_ALIGN 0x00001000 +/* Alignment of the multiboot info structure. */ +#define MULTIBOOT_INFO_ALIGN 0x00000004 + /* * Flags set in the 'flags' member of the multiboot header. */ diff --git a/loader/i386/pc/multiboot.c b/loader/i386/pc/multiboot.c index c0d1fe1ca..b45bc472a 100644 --- a/loader/i386/pc/multiboot.c +++ b/loader/i386/pc/multiboot.c @@ -1,7 +1,7 @@ /* multiboot.c - boot a multiboot OS image. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 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 @@ -363,6 +363,7 @@ grub_multiboot (int argc, char *argv[]) char buffer[MULTIBOOT_SEARCH], *cmdline = 0, *p; struct grub_multiboot_header *header; grub_ssize_t len; + grub_uint32_t mmap_length; int i; grub_loader_unset (); @@ -417,14 +418,9 @@ grub_multiboot (int argc, char *argv[]) playground = NULL; } - mbi = grub_malloc (sizeof (struct grub_multiboot_info)); - if (! mbi) - goto fail; + mmap_length = grub_get_multiboot_mmap_len (); - grub_memset (mbi, 0, sizeof (struct grub_multiboot_info)); - - mbi->mmap_length = grub_get_multiboot_mmap_len (); - grub_multiboot_payload_size = mbi->mmap_length; + grub_multiboot_payload_size = sizeof (struct grub_multiboot_info) + mmap_length + MULTIBOOT_INFO_ALIGN; if (header->flags & MULTIBOOT_AOUT_KLUDGE) { @@ -462,6 +458,11 @@ grub_multiboot (int argc, char *argv[]) else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE) goto fail; + grub_multiboot_payload_size = ALIGN_UP (grub_multiboot_payload_size, MULTIBOOT_INFO_ALIGN); + + mbi = grub_multiboot_payload_orig + grub_multiboot_payload_size - mmap_length - sizeof (struct grub_multiboot_info); + grub_memset (mbi, 0, sizeof (struct grub_multiboot_info)); + mbi->mmap_length = mmap_length; grub_fill_multiboot_mmap ((struct grub_multiboot_mmap_entry *) (grub_multiboot_payload_orig + grub_multiboot_payload_size