2008-08-17 Robert Millan <rmh@aybabtu.com>

* conf/i386-pc.rmk (kernel_img_SOURCES): Add `kern/i386/pc/mmap.c'.

        * include/grub/i386/pc/init.h (GRUB_MACHINE_MEMORY_AVAILABLE)
        (GRUB_MACHINE_MEMORY_RESERVED): New macros.
        (grub_machine_mmap_iterate): New function declaration.
        * include/grub/multiboot.h (struct grub_multiboot_mmap_entry): New
        structure.
        (GRUB_MMAP_MEMORY_AVAILABLE, GRUB_MMAP_MEMORY_RESERVED): New
        macros.

        * kern/i386/pc/init.c (grub_machine_init): Replace hardcoded region
        type check value with `GRUB_MACHINE_MEMORY_AVAILABLE'.
        Move e820 parsing from here ...
        * kern/i386/pc/mmap.c: New file.
        (grub_machine_mmap_iterate): ... to here.

        * include/grub/i386/coreboot/memory.h: Remove `<grub/err.h>'.
        (GRUB_LINUXBIOS_MEMORY_AVAILABLE): Rename (for consistency) to ...
        (GRUB_MACHINE_MEMORY_AVAILABLE): ... this.  Update all users.
        (grub_available_iterate): Redeclare to return `void', and redeclare
        its hook to use grub_uint64_t as addr and size parameters, and rename
        to ...
        (grub_machine_mmap_iterate): ... this.  Update all users.

        * kern/i386/coreboot/mmap.c (grub_mmap_iterate): Simplify parser loop
        to make it more readable.  Rename to ...
        (grub_machine_mmap_iterate): ... this.

        * loader/i386/pc/multiboot.c (mmap_addr, mmap_length): New variables.
        (grub_get_multiboot_mmap_len, grub_fill_multiboot_mmap): New functions.
        (grub_multiboot): Allocate an extra region after the payload, and fill
        it with a Multiboot memory map.  Adjust a.out loader to calculate size
        with the extra space.
        (grub_multiboot_load_elf32): Adjust elf32 loader to calculate size
        with the extra space.
This commit is contained in:
robertmh 2008-08-17 16:32:18 +00:00
parent 9807deb97d
commit deceb3ecd3
10 changed files with 289 additions and 70 deletions

View file

@ -0,0 +1,67 @@
/* memory.h - describe the memory map */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2007 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GRUB_MEMORY_MACHINE_LB_HEADER
#define _GRUB_MEMORY_MACHINE_LB_HEADER 1
#include <grub/symbol.h>
#include <grub/i386/pc/memory.h>
#ifndef ASM_FILE
#include <grub/types.h>
#endif
#define GRUB_MEMORY_MACHINE_LOWER_USABLE 0x9fc00 /* 640 kiB - 1 kiB */
#define GRUB_MEMORY_MACHINE_LOWER_SIZE 0xf0000 /* 960 kiB */
#define GRUB_MEMORY_MACHINE_UPPER_START 0x100000 /* 1 MiB */
#ifndef ASM_FILE
struct grub_linuxbios_table_header
{
char signature[4];
grub_uint32_t size;
};
typedef struct grub_linuxbios_table_header *grub_linuxbios_table_header_t;
struct grub_linuxbios_table_item
{
#define GRUB_LINUXBIOS_MEMBER_UNUSED 0
#define GRUB_LINUXBIOS_MEMBER_MEMORY 1
grub_uint32_t tag;
grub_uint32_t size;
};
typedef struct grub_linuxbios_table_item *grub_linuxbios_table_item_t;
struct grub_linuxbios_mem_region
{
grub_uint64_t addr;
grub_uint64_t size;
#define GRUB_MACHINE_MEMORY_AVAILABLE 1
grub_uint32_t type;
};
typedef struct grub_linuxbios_mem_region *mem_region_t;
void EXPORT_FUNC(grub_machine_mmap_iterate)
(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
#endif
#endif /* ! _GRUB_MEMORY_MACHINE_HEADER */

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2004,2005,2007 Free Software Foundation, Inc.
* Copyright (C) 2002,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,6 +35,8 @@ struct grub_machine_mmap_entry
grub_uint32_t size;
grub_uint64_t addr;
grub_uint64_t len;
#define GRUB_MACHINE_MEMORY_AVAILABLE 1
#define GRUB_MACHINE_MEMORY_RESERVED 2
grub_uint32_t type;
} __attribute__((packed));
@ -43,6 +45,9 @@ struct grub_machine_mmap_entry
grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_machine_mmap_entry *entry,
grub_uint32_t cont);
void EXPORT_FUNC(grub_machine_mmap_iterate)
(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
/* Turn on/off Gate A20. */
void grub_gate_a20 (int on);

View file

@ -1,7 +1,7 @@
/* multiboot.h - multiboot header file with grub definitions. */
/*
* 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
@ -101,6 +101,16 @@ struct grub_multiboot_info
grub_uint16_t vbe_interface_len;
};
struct grub_multiboot_mmap_entry
{
grub_uint32_t size;
grub_uint64_t addr;
grub_uint64_t len;
#define GRUB_MULTIBOOT_MEMORY_AVAILABLE 1
#define GRUB_MULTIBOOT_MEMORY_RESERVED 2
grub_uint32_t type;
} __attribute__((packed));
struct grub_mod_list
{
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */