Skip to contentSkip to conversation

decouple mmap parsing by using grub_available_iterate()

PATCH In review Robert Millan 3 participants 12 messages Aug 11, 2008 – Aug 17, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 decouple mmap parsing by using grub_available_iterate()

Hi,

This patch decouples memory map parsing into a separate grub_available_iterate() function, for i386-pc and i386-coreboot. It is mostly intended as a cleanup. Makes the code more modular so that, for example, the multiboot loader can construct a memory map without having specific knowledge of the platform, allows to recombine various init.c & mmap.c in different ways, etc.

Maybe it will be possible to recombine pc/init.c with coreboot/init.c in a single file later on, although I'm not sure if that might be overkill.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

2008-08-11 Robert Millan <[email protected]>

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

* include/grub/i386/pc/init.h (GRUB_MACHINE_MEMORY_AVAILABLE): New macro.
(grub_available_iterate): New function declaration.
* kern/i386/pc/init.c (grub_machine_init): Move e820 parsing from here ...
* kern/i386/pc/mmap.c: New file. (grub_available_iterate): ... to here. Replace hardcoded region type check value with `GRUB_MACHINE_MEMORY_AVAILABLE'.

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

* kern/i386/coreboot/init.c (grub_machine_init): Adjust heap_init() parameters to match with new grub_available_iterate() declaration. Move region type check from here ...
* kern/i386/coreboot/mmap.c (grub_available_iterate): ... to here.

i386-pc.rmk +2 -1
Index: conf/i386-pc.rmk
===================================================================
@@ -43,7 +43,8 @@
 	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/time.c \
-	kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \
+	kern/i386/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \
+	kern/parser.c kern/partition.c \
 	kern/i386/tsc.c kern/i386/pit.c \
 	kern/generic/rtc_get_time_ms.c \
 	kern/generic/millisleep.c \
i386/pc/init.c +24 -47

88 lines not on this page · raw message

i386/pc/mmap.c +61 -0

61 lines not on this page · raw message

i386/coreboot/init.c +2 -8
Index: kern/i386/coreboot/init.c
===================================================================
@@ -82,12 +82,9 @@
   grub_lower_mem = GRUB_MEMORY_MACHINE_LOWER_USABLE;
   grub_upper_mem = 0;
 
-  auto int heap_init (mem_region_t);
-  int heap_init (mem_region_t mem_region)
+  auto int heap_init (grub_uint64_t, grub_uint64_t);
+  int heap_init (grub_uint64_t addr, grub_uint64_t size)
   {
-    grub_uint64_t addr = mem_region->addr;
-    grub_uint64_t size = mem_region->size;
-
 #if GRUB_CPU_SIZEOF_VOID_P == 4
     /* Restrict ourselves to 32-bit memory space.  */
     if (addr > ULONG_MAX)
@@ -101,9 +98,6 @@
 
     grub_upper_mem = grub_max (grub_upper_mem, addr + size);
 
-    if (mem_region->type != GRUB_LINUXBIOS_MEMORY_AVAILABLE)
-      return 0;
-
     /* Avoid the lower memory.  */
     if (addr < GRUB_MEMORY_MACHINE_LOWER_SIZE)
       {
i386/coreboot/mmap.c +8 -3
Index: kern/i386/coreboot/mmap.c
===================================================================
@@ -64,7 +64,7 @@
 }
 
 grub_err_t
-grub_available_iterate (int (*hook) (mem_region_t))
+grub_available_iterate (int (*hook) (grub_uint64_t, grub_uint64_t))
 {
   mem_region_t mem_region;
 
@@ -79,8 +79,13 @@
 				 sizeof (struct grub_linuxbios_table_item));
     for (; (long) mem_region < (long) table_item + (long) table_item->size;
 	 mem_region++)
-      if (hook (mem_region))
-	return 1;
+      {
+	if (mem_region->type != GRUB_MACHINE_MEMORY_AVAILABLE)
+	  continue;
+	
+	if (hook (mem_region->addr, mem_region->size))
+	  return 1;
+      }
 
     return 0;
   }
grub/i386/pc/init.h +5 -1
Index: include/grub/i386/pc/init.h
===================================================================
@@ -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,7 @@
   grub_uint32_t size;
   grub_uint64_t addr;
   grub_uint64_t len;
+#define GRUB_MACHINE_MEMORY_AVAILABLE		1
   grub_uint32_t type;
 } __attribute__((packed));
 
@@ -43,6 +44,9 @@
 grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_machine_mmap_entry *entry,
 				   grub_uint32_t cont);
 
+void EXPORT_FUNC(grub_available_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t));
+
 /* Turn on/off Gate A20.  */
 void grub_gate_a20 (int on);
 
grub/i386/coreboot/memory.h +3 -4
Index: include/grub/i386/coreboot/memory.h
===================================================================
@@ -25,7 +25,6 @@
 
 #ifndef ASM_FILE
 #include <grub/types.h>
-#include <grub/err.h>
 #endif
 
 #define GRUB_MEMORY_MACHINE_LOWER_USABLE		0x9fc00		/* 640 kiB - 1 kiB */
@@ -55,13 +54,13 @@
 {
   grub_uint64_t addr;
   grub_uint64_t size;
-#define GRUB_LINUXBIOS_MEMORY_AVAILABLE	1
+#define GRUB_MACHINE_MEMORY_AVAILABLE		1
   grub_uint32_t type;
 };
 typedef struct grub_linuxbios_mem_region *mem_region_t;
 
-grub_err_t EXPORT_FUNC(grub_available_iterate)
-     (int (*hook) (mem_region_t));
+void EXPORT_FUNC(grub_available_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t));
 
 #endif
 
#1 lore raw
Quoted 7 lines · Robert Millan

Hi,

This patch decouples memory map parsing into a separate grub_available_iterate() function, for i386-pc and i386-coreboot. It is mostly intended as a cleanup. Makes the code more modular so that, for example, the multiboot loader can construct a memory map without having specific knowledge of the platform, allows to recombine various init.c & mmap.c in different ways, etc.

Why not use grub_mmap prefix ?

#2 lore raw
Quoted 11 lines · Vesa Jääskeläinen
Quoted 9 lines · Robert Millan

Hi,

This patch decouples memory map parsing into a separate grub_available_iterate()
function, for i386-pc and i386-coreboot. It is mostly intended as a cleanup.
Makes the code more modular so that, for example, the multiboot loader can construct a memory map without having specific knowledge of the platform, allows to recombine various init.c & mmap.c in different ways, etc.

Quoted 1 line

Why not use grub_mmap prefix ?

You mean like grub_mmap_iterate ? Seems fine (since the change is trivial, I'll skip sending a new patch).

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#3 lore raw
Quoted 12 lines · Robert Millan
Quoted 11 lines · Vesa Jääskeläinen
Quoted 9 lines · Robert Millan

Hi,

This patch decouples memory map parsing into a separate grub_available_iterate()
function, for i386-pc and i386-coreboot. It is mostly intended as a cleanup.
Makes the code more modular so that, for example, the multiboot loader can construct a memory map without having specific knowledge of the platform, allows to recombine various init.c & mmap.c in different ways, etc.

Quoted 4 lines
Quoted 1 line

Why not use grub_mmap prefix ?

You mean like grub_mmap_iterate ? Seems fine (since the change is trivial, I'll skip sending a new patch).

Now that I think, grub_mmap_iterate() would be misleading, as we're only iterating through the parts of mmap that are marked as available, not through the whole thing. How about grub_mmap_available_iterate?

But this reminds me; with this interface, it's not possible to gather information about regions other than the ones that are marked as available. However, AFAICS, there's no purpose for marking a region as reserved, since the OS is only going to use regions marked as available anyway.

Therefore, if we implement support for Multiboot mmaps in our loader (as defined in the spec), we wouldn't be able to include non-available regions in our map.

Does anyone see a problem in this? If so, then I think we'd need a function that can for example handle a third argument, for example `type', for this purpose.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#4 lore raw

PATCH 1/1 decouple mmap parsing and implement Multiboot mmap in the loader

Quoted 4 lines · Robert Millan

Does anyone see a problem in this? If so, then I think we'd need a function that can for example handle a third argument, for example `type', for this purpose.

Actually, adding that third argument was trivial, so I've done that.

Here's a new patch. This one additionally takes advantage of the new framework to implement Multiboot mmap in the loader (you can test it using docs/kernel.c in GRUB Legacy source).

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

2008-08-12 Robert Millan <[email protected]>

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

* include/grub/i386/pc/init.h: Include `<grub/multiboot.h>'. (GRUB_MACHINE_MEMORY_AVAILABLE, GRUB_MACHINE_MEMORY_RESERVED): New macros.
(grub_mmap_iterate): New function declaration.
(struct grub_machine_mmap_entry): Move from here ...
* include/grub/multiboot.h (struct grub_mmap_entry): ... to here. Update all users.
(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_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_mmap_iterate): ... this. Update all users.

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

* loader/i386/pc/multiboot.c (mmap_addr, mmap_length): New variables. (grub_get_multiboot_mmap_len, grub_fill_multiboot_mmap): New functions. (grub_multiboot_load_elf32): Allocate an extra region after the payload, and put the Multiboot memory map there.
(grub_multiboot): If the loader we're using supports Multiboot memory map, refer to it in the Multiboot Information Structure.

i386-pc.rmk +2 -1
Index: conf/i386-pc.rmk
===================================================================
@@ -43,7 +43,8 @@
 	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/time.c \
-	kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \
+	kern/i386/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \
+	kern/parser.c kern/partition.c \
 	kern/i386/tsc.c kern/i386/pit.c \
 	kern/generic/rtc_get_time_ms.c \
 	kern/generic/millisleep.c \
i386/pc/init.c +24 -47

88 lines not on this page · raw message

i386/pc/mmap.c +60 -0

60 lines not on this page · raw message

i386/coreboot/init.c +4 -7
Index: kern/i386/coreboot/init.c
===================================================================
@@ -82,12 +82,9 @@
   grub_lower_mem = GRUB_MEMORY_MACHINE_LOWER_USABLE;
   grub_upper_mem = 0;
 
-  auto int heap_init (mem_region_t);
-  int heap_init (mem_region_t mem_region)
+  auto int heap_init (grub_uint64_t, grub_uint64_t, grub_uint32_t);
+  int heap_init (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
   {
-    grub_uint64_t addr = mem_region->addr;
-    grub_uint64_t size = mem_region->size;
-
 #if GRUB_CPU_SIZEOF_VOID_P == 4
     /* Restrict ourselves to 32-bit memory space.  */
     if (addr > ULONG_MAX)
@@ -101,7 +98,7 @@
 
     grub_upper_mem = grub_max (grub_upper_mem, addr + size);
 
-    if (mem_region->type != GRUB_LINUXBIOS_MEMORY_AVAILABLE)
+    if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
       return 0;
 
     /* Avoid the lower memory.  */
@@ -134,7 +131,7 @@
     return 0;
   }
 
-  grub_available_iterate (heap_init);
+  grub_mmap_iterate (heap_init);
 
   /* This variable indicates size, not offset.  */
   grub_upper_mem -= GRUB_MEMORY_MACHINE_UPPER_START;
i386/coreboot/mmap.c +12 -6
Index: kern/i386/coreboot/mmap.c
===================================================================
@@ -63,8 +63,8 @@
   return 0;
 }
 
-grub_err_t
-grub_available_iterate (int (*hook) (mem_region_t))
+void
+grub_mmap_iterate (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
 {
   mem_region_t mem_region;
 
@@ -77,11 +77,17 @@
     mem_region =
       (mem_region_t) ((long) table_item +
 				 sizeof (struct grub_linuxbios_table_item));
-    for (; (long) mem_region < (long) table_item + (long) table_item->size;
-	 mem_region++)
-      if (hook (mem_region))
-	return 1;
+    while ((long) mem_region < (long) table_item + (long) table_item->size)
+      {
+	if (hook (mem_region->addr, mem_region->size,
+		  /* Multiboot mmaps match with the coreboot mmap definition.
+		     Therefore, we can just pass type through.  */
+		  mem_region->type))
+	  return 1;
 
+	mem_region++;
+      }
+
     return 0;
   }
 
grub/i386/pc/init.h +10 -9
Index: include/grub/i386/pc/init.h
===================================================================
@@ -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
@@ -21,6 +21,8 @@
 
 #include <grub/types.h>
 #include <grub/symbol.h>
+#include <grub/multiboot.h>	/* For struct grub_mmap_entry, which is also
+				   needed by Multiboot.  */
 
 /* Get the memory size in KB. If EXTENDED is zero, return conventional
    memory, otherwise return extended memory.  */
@@ -30,19 +32,18 @@
    in 1KB parts, and upper 16 bits are above 16MB in 64KB parts.  */
 grub_uint32_t grub_get_eisa_mmap (void);
 
-struct grub_machine_mmap_entry
-{
-  grub_uint32_t size;
-  grub_uint64_t addr;
-  grub_uint64_t len;
-  grub_uint32_t type;
-} __attribute__((packed));
+/* Multiboot mmaps have been defined to match with the E820 definition.  */
+#define GRUB_MACHINE_MEMORY_AVAILABLE	GRUB_MMAP_MEMORY_AVAILABLE
+#define GRUB_MACHINE_MEMORY_RESERVED	GRUB_MMAP_MEMORY_RESERVED
 
 /* Get a memory map entry. Return next continuation value. Zero means
    the end.  */
-grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_machine_mmap_entry *entry,
+grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_mmap_entry *entry,
 				   grub_uint32_t cont);
 
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
+
 /* Turn on/off Gate A20.  */
 void grub_gate_a20 (int on);
 
grub/i386/coreboot/memory.h +3 -4
Index: include/grub/i386/coreboot/memory.h
===================================================================
@@ -25,7 +25,6 @@
 
 #ifndef ASM_FILE
 #include <grub/types.h>
-#include <grub/err.h>
 #endif
 
 #define GRUB_MEMORY_MACHINE_LOWER_USABLE		0x9fc00		/* 640 kiB - 1 kiB */
@@ -55,13 +54,13 @@
 {
   grub_uint64_t addr;
   grub_uint64_t size;
-#define GRUB_LINUXBIOS_MEMORY_AVAILABLE	1
+#define GRUB_MACHINE_MEMORY_AVAILABLE		1
   grub_uint32_t type;
 };
 typedef struct grub_linuxbios_mem_region *mem_region_t;
 
-grub_err_t EXPORT_FUNC(grub_available_iterate)
-     (int (*hook) (mem_region_t));
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
 
 #endif
 
grub/multiboot.h +11 -1
Index: include/grub/multiboot.h
===================================================================
@@ -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 @@
   grub_uint16_t vbe_interface_len;
 };
 
+struct grub_mmap_entry
+{
+  grub_uint32_t size;
+  grub_uint64_t addr;
+  grub_uint64_t len;
+#define GRUB_MMAP_MEMORY_AVAILABLE	1
+#define GRUB_MMAP_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 */
i386/pc/multiboot.c +67 -5

106 lines not on this page · raw message

i386/bsd.c +1 -1
Index: loader/i386/bsd.c
===================================================================
@@ -313,7 +313,7 @@
 grub_openbsd_boot (void)
 {
   char *buf = (char *) GRUB_BSD_TEMP_BUFFER;
-  struct grub_machine_mmap_entry mmap;
+  struct grub_mmap_entry mmap;
   struct grub_openbsd_bios_mmap *pm;
   struct grub_openbsd_bootargs *pa;
   grub_uint32_t bootdev, biosdev, unit, slice, part, cont;
#5 lore raw

Re: [PATCH] decouple mmap parsing and implement Multiboot mmap in the loader

My last commit just broke my own patch (sigh).

Here's an updated version.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

2008-08-12 Robert Millan <[email protected]>

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

* include/grub/i386/pc/init.h: Include `<grub/multiboot.h>'. (GRUB_MACHINE_MEMORY_AVAILABLE, GRUB_MACHINE_MEMORY_RESERVED): New macros.
(grub_mmap_iterate): New function declaration.
(struct grub_machine_mmap_entry): Move from here ...
* include/grub/multiboot.h (struct grub_mmap_entry): ... to here. Update all users.
(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_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_mmap_iterate): ... this. Update all users.

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

* 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.

i386-pc.rmk +2 -1
Index: conf/i386-pc.rmk
===================================================================
@@ -43,7 +43,8 @@
 	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/time.c \
-	kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \
+	kern/i386/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \
+	kern/parser.c kern/partition.c \
 	kern/i386/tsc.c kern/i386/pit.c \
 	kern/generic/rtc_get_time_ms.c \
 	kern/generic/millisleep.c \
i386/pc/init.c +24 -47

88 lines not on this page · raw message

i386/pc/mmap.c +60 -0

60 lines not on this page · raw message

i386/coreboot/init.c +4 -7
Index: kern/i386/coreboot/init.c
===================================================================
@@ -82,12 +82,9 @@
   grub_lower_mem = GRUB_MEMORY_MACHINE_LOWER_USABLE;
   grub_upper_mem = 0;
 
-  auto int heap_init (mem_region_t);
-  int heap_init (mem_region_t mem_region)
+  auto int heap_init (grub_uint64_t, grub_uint64_t, grub_uint32_t);
+  int heap_init (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
   {
-    grub_uint64_t addr = mem_region->addr;
-    grub_uint64_t size = mem_region->size;
-
 #if GRUB_CPU_SIZEOF_VOID_P == 4
     /* Restrict ourselves to 32-bit memory space.  */
     if (addr > ULONG_MAX)
@@ -101,7 +98,7 @@
 
     grub_upper_mem = grub_max (grub_upper_mem, addr + size);
 
-    if (mem_region->type != GRUB_LINUXBIOS_MEMORY_AVAILABLE)
+    if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
       return 0;
 
     /* Avoid the lower memory.  */
@@ -134,7 +131,7 @@
     return 0;
   }
 
-  grub_available_iterate (heap_init);
+  grub_mmap_iterate (heap_init);
 
   /* This variable indicates size, not offset.  */
   grub_upper_mem -= GRUB_MEMORY_MACHINE_UPPER_START;
i386/coreboot/mmap.c +12 -6
Index: kern/i386/coreboot/mmap.c
===================================================================
@@ -63,8 +63,8 @@
   return 0;
 }
 
-grub_err_t
-grub_available_iterate (int (*hook) (mem_region_t))
+void
+grub_mmap_iterate (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
 {
   mem_region_t mem_region;
 
@@ -77,11 +77,17 @@
     mem_region =
       (mem_region_t) ((long) table_item +
 				 sizeof (struct grub_linuxbios_table_item));
-    for (; (long) mem_region < (long) table_item + (long) table_item->size;
-	 mem_region++)
-      if (hook (mem_region))
-	return 1;
+    while ((long) mem_region < (long) table_item + (long) table_item->size)
+      {
+	if (hook (mem_region->addr, mem_region->size,
+		  /* Multiboot mmaps match with the coreboot mmap definition.
+		     Therefore, we can just pass type through.  */
+		  mem_region->type))
+	  return 1;
 
+	mem_region++;
+      }
+
     return 0;
   }
 
grub/i386/pc/init.h +10 -9
Index: include/grub/i386/pc/init.h
===================================================================
@@ -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
@@ -21,6 +21,8 @@
 
 #include <grub/types.h>
 #include <grub/symbol.h>
+#include <grub/multiboot.h>	/* For struct grub_mmap_entry, which is also
+				   needed by Multiboot.  */
 
 /* Get the memory size in KB. If EXTENDED is zero, return conventional
    memory, otherwise return extended memory.  */
@@ -30,19 +32,18 @@
    in 1KB parts, and upper 16 bits are above 16MB in 64KB parts.  */
 grub_uint32_t grub_get_eisa_mmap (void);
 
-struct grub_machine_mmap_entry
-{
-  grub_uint32_t size;
-  grub_uint64_t addr;
-  grub_uint64_t len;
-  grub_uint32_t type;
-} __attribute__((packed));
+/* Multiboot mmaps have been defined to match with the E820 definition.  */
+#define GRUB_MACHINE_MEMORY_AVAILABLE	GRUB_MMAP_MEMORY_AVAILABLE
+#define GRUB_MACHINE_MEMORY_RESERVED	GRUB_MMAP_MEMORY_RESERVED
 
 /* Get a memory map entry. Return next continuation value. Zero means
    the end.  */
-grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_machine_mmap_entry *entry,
+grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_mmap_entry *entry,
 				   grub_uint32_t cont);
 
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
+
 /* Turn on/off Gate A20.  */
 void grub_gate_a20 (int on);
 
grub/i386/coreboot/memory.h +3 -4
Index: include/grub/i386/coreboot/memory.h
===================================================================
@@ -25,7 +25,6 @@
 
 #ifndef ASM_FILE
 #include <grub/types.h>
-#include <grub/err.h>
 #endif
 
 #define GRUB_MEMORY_MACHINE_LOWER_USABLE		0x9fc00		/* 640 kiB - 1 kiB */
@@ -55,13 +54,13 @@
 {
   grub_uint64_t addr;
   grub_uint64_t size;
-#define GRUB_LINUXBIOS_MEMORY_AVAILABLE	1
+#define GRUB_MACHINE_MEMORY_AVAILABLE		1
   grub_uint32_t type;
 };
 typedef struct grub_linuxbios_mem_region *mem_region_t;
 
-grub_err_t EXPORT_FUNC(grub_available_iterate)
-     (int (*hook) (mem_region_t));
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
 
 #endif
 
grub/multiboot.h +11 -1
Index: include/grub/multiboot.h
===================================================================
@@ -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 @@
   grub_uint16_t vbe_interface_len;
 };
 
+struct grub_mmap_entry
+{
+  grub_uint32_t size;
+  grub_uint64_t addr;
+  grub_uint64_t len;
+#define GRUB_MMAP_MEMORY_AVAILABLE	1
+#define GRUB_MMAP_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 */
i386/pc/multiboot.c +65 -7

119 lines not on this page · raw message

i386/bsd.c +1 -1
Index: loader/i386/bsd.c
===================================================================
@@ -313,7 +313,7 @@
 grub_openbsd_boot (void)
 {
   char *buf = (char *) GRUB_BSD_TEMP_BUFFER;
-  struct grub_machine_mmap_entry mmap;
+  struct grub_mmap_entry mmap;
   struct grub_openbsd_bios_mmap *pm;
   struct grub_openbsd_bootargs *pa;
   grub_uint32_t bootdev, biosdev, unit, slice, part, cont;
#6 lore raw

Re: [PATCH] decouple mmap parsing and implement Multiboot mmap in the loader

And here's a new one, using NESTED_FUNC_ATTR to prevent %ecx being trashed as Bean pointed out on IRC.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

2008-08-12 Robert Millan <[email protected]>

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

* include/grub/i386/pc/init.h: Include `<grub/multiboot.h>'. (GRUB_MACHINE_MEMORY_AVAILABLE, GRUB_MACHINE_MEMORY_RESERVED): New macros.
(grub_mmap_iterate): New function declaration.
(struct grub_machine_mmap_entry): Move from here ...
* include/grub/multiboot.h (struct grub_mmap_entry): ... to here. Update all users.
(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_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_mmap_iterate): ... this. Update all users.

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

* 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.

i386-pc.rmk +2 -1
Index: conf/i386-pc.rmk
===================================================================
@@ -43,7 +43,8 @@
 	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/time.c \
-	kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \
+	kern/i386/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \
+	kern/parser.c kern/partition.c \
 	kern/i386/tsc.c kern/i386/pit.c \
 	kern/generic/rtc_get_time_ms.c \
 	kern/generic/millisleep.c \
i386/pc/init.c +24 -47

88 lines not on this page · raw message

i386/coreboot/init.c +4 -7
Index: kern/i386/coreboot/init.c
===================================================================
@@ -82,12 +82,9 @@
   grub_lower_mem = GRUB_MEMORY_MACHINE_LOWER_USABLE;
   grub_upper_mem = 0;
 
-  auto int heap_init (mem_region_t);
-  int heap_init (mem_region_t mem_region)
+  auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t, grub_uint64_t, grub_uint32_t);
+  int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
   {
-    grub_uint64_t addr = mem_region->addr;
-    grub_uint64_t size = mem_region->size;
-
 #if GRUB_CPU_SIZEOF_VOID_P == 4
     /* Restrict ourselves to 32-bit memory space.  */
     if (addr > ULONG_MAX)
@@ -101,7 +98,7 @@
 
     grub_upper_mem = grub_max (grub_upper_mem, addr + size);
 
-    if (mem_region->type != GRUB_LINUXBIOS_MEMORY_AVAILABLE)
+    if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
       return 0;
 
     /* Avoid the lower memory.  */
@@ -134,7 +131,7 @@
     return 0;
   }
 
-  grub_available_iterate (heap_init);
+  grub_mmap_iterate (heap_init);
 
   /* This variable indicates size, not offset.  */
   grub_upper_mem -= GRUB_MEMORY_MACHINE_UPPER_START;
i386/coreboot/mmap.c +12 -6
Index: kern/i386/coreboot/mmap.c
===================================================================
@@ -63,8 +63,8 @@
   return 0;
 }
 
-grub_err_t
-grub_available_iterate (int (*hook) (mem_region_t))
+void
+grub_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
 {
   mem_region_t mem_region;
 
@@ -77,11 +77,17 @@
     mem_region =
       (mem_region_t) ((long) table_item +
 				 sizeof (struct grub_linuxbios_table_item));
-    for (; (long) mem_region < (long) table_item + (long) table_item->size;
-	 mem_region++)
-      if (hook (mem_region))
-	return 1;
+    while ((long) mem_region < (long) table_item + (long) table_item->size)
+      {
+	if (hook (mem_region->addr, mem_region->size,
+		  /* Multiboot mmaps match with the coreboot mmap definition.
+		     Therefore, we can just pass type through.  */
+		  mem_region->type))
+	  return 1;
 
+	mem_region++;
+      }
+
     return 0;
   }
 
grub/i386/pc/init.h +10 -9
Index: include/grub/i386/pc/init.h
===================================================================
@@ -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
@@ -21,6 +21,8 @@
 
 #include <grub/types.h>
 #include <grub/symbol.h>
+#include <grub/multiboot.h>	/* For struct grub_mmap_entry, which is also
+				   needed by Multiboot.  */
 
 /* Get the memory size in KB. If EXTENDED is zero, return conventional
    memory, otherwise return extended memory.  */
@@ -30,19 +32,18 @@
    in 1KB parts, and upper 16 bits are above 16MB in 64KB parts.  */
 grub_uint32_t grub_get_eisa_mmap (void);
 
-struct grub_machine_mmap_entry
-{
-  grub_uint32_t size;
-  grub_uint64_t addr;
-  grub_uint64_t len;
-  grub_uint32_t type;
-} __attribute__((packed));
+/* Multiboot mmaps have been defined to match with the E820 definition.  */
+#define GRUB_MACHINE_MEMORY_AVAILABLE	GRUB_MMAP_MEMORY_AVAILABLE
+#define GRUB_MACHINE_MEMORY_RESERVED	GRUB_MMAP_MEMORY_RESERVED
 
 /* Get a memory map entry. Return next continuation value. Zero means
    the end.  */
-grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_machine_mmap_entry *entry,
+grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_mmap_entry *entry,
 				   grub_uint32_t cont);
 
+void EXPORT_FUNC(grub_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);
 
grub/i386/coreboot/memory.h +3 -4
Index: include/grub/i386/coreboot/memory.h
===================================================================
@@ -25,7 +25,6 @@
 
 #ifndef ASM_FILE
 #include <grub/types.h>
-#include <grub/err.h>
 #endif
 
 #define GRUB_MEMORY_MACHINE_LOWER_USABLE		0x9fc00		/* 640 kiB - 1 kiB */
@@ -55,13 +54,13 @@
 {
   grub_uint64_t addr;
   grub_uint64_t size;
-#define GRUB_LINUXBIOS_MEMORY_AVAILABLE	1
+#define GRUB_MACHINE_MEMORY_AVAILABLE		1
   grub_uint32_t type;
 };
 typedef struct grub_linuxbios_mem_region *mem_region_t;
 
-grub_err_t EXPORT_FUNC(grub_available_iterate)
-     (int (*hook) (mem_region_t));
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
 
 #endif
 
grub/multiboot.h +11 -1
Index: include/grub/multiboot.h
===================================================================
@@ -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 @@
   grub_uint16_t vbe_interface_len;
 };
 
+struct grub_mmap_entry
+{
+  grub_uint32_t size;
+  grub_uint64_t addr;
+  grub_uint64_t len;
+#define GRUB_MMAP_MEMORY_AVAILABLE	1
+#define GRUB_MMAP_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 */
i386/pc/multiboot.c +65 -7

119 lines not on this page · raw message

i386/bsd.c +1 -1
Index: loader/i386/bsd.c
===================================================================
@@ -313,7 +313,7 @@
 grub_openbsd_boot (void)
 {
   char *buf = (char *) GRUB_BSD_TEMP_BUFFER;
-  struct grub_machine_mmap_entry mmap;
+  struct grub_mmap_entry mmap;
   struct grub_openbsd_bios_mmap *pm;
   struct grub_openbsd_bootargs *pa;
   grub_uint32_t bootdev, biosdev, unit, slice, part, cont;
#7 lore raw

Re: [PATCH] decouple mmap parsing and implement Multiboot mmap in the loader

And here we go *AGAIN*, this time not forgetting to include all files in the patch.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

2008-08-12 Robert Millan <[email protected]>

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

* include/grub/i386/pc/init.h: Include `<grub/multiboot.h>'. (GRUB_MACHINE_MEMORY_AVAILABLE, GRUB_MACHINE_MEMORY_RESERVED): New macros.
(grub_mmap_iterate): New function declaration.
(struct grub_machine_mmap_entry): Move from here ...
* include/grub/multiboot.h (struct grub_mmap_entry): ... to here. Update all users.
(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_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_mmap_iterate): ... this. Update all users.

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

* 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.

i386-pc.rmk +2 -1
Index: conf/i386-pc.rmk
===================================================================
@@ -43,7 +43,8 @@
 	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/time.c \
-	kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \
+	kern/i386/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \
+	kern/parser.c kern/partition.c \
 	kern/i386/tsc.c kern/i386/pit.c \
 	kern/generic/rtc_get_time_ms.c \
 	kern/generic/millisleep.c \
i386/pc/init.c +24 -47

88 lines not on this page · raw message

i386/pc/mmap.c +60 -0

60 lines not on this page · raw message

i386/coreboot/init.c +4 -7
Index: kern/i386/coreboot/init.c
===================================================================
@@ -82,12 +82,9 @@
   grub_lower_mem = GRUB_MEMORY_MACHINE_LOWER_USABLE;
   grub_upper_mem = 0;
 
-  auto int heap_init (mem_region_t);
-  int heap_init (mem_region_t mem_region)
+  auto int heap_init (grub_uint64_t, grub_uint64_t, grub_uint32_t);
+  int heap_init (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
   {
-    grub_uint64_t addr = mem_region->addr;
-    grub_uint64_t size = mem_region->size;
-
 #if GRUB_CPU_SIZEOF_VOID_P == 4
     /* Restrict ourselves to 32-bit memory space.  */
     if (addr > ULONG_MAX)
@@ -101,7 +98,7 @@
 
     grub_upper_mem = grub_max (grub_upper_mem, addr + size);
 
-    if (mem_region->type != GRUB_LINUXBIOS_MEMORY_AVAILABLE)
+    if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
       return 0;
 
     /* Avoid the lower memory.  */
@@ -134,7 +131,7 @@
     return 0;
   }
 
-  grub_available_iterate (heap_init);
+  grub_mmap_iterate (heap_init);
 
   /* This variable indicates size, not offset.  */
   grub_upper_mem -= GRUB_MEMORY_MACHINE_UPPER_START;
i386/coreboot/mmap.c +12 -6
Index: kern/i386/coreboot/mmap.c
===================================================================
@@ -63,8 +63,8 @@
   return 0;
 }
 
-grub_err_t
-grub_available_iterate (int (*hook) (mem_region_t))
+void
+grub_mmap_iterate (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
 {
   mem_region_t mem_region;
 
@@ -77,11 +77,17 @@
     mem_region =
       (mem_region_t) ((long) table_item +
 				 sizeof (struct grub_linuxbios_table_item));
-    for (; (long) mem_region < (long) table_item + (long) table_item->size;
-	 mem_region++)
-      if (hook (mem_region))
-	return 1;
+    while ((long) mem_region < (long) table_item + (long) table_item->size)
+      {
+	if (hook (mem_region->addr, mem_region->size,
+		  /* Multiboot mmaps match with the coreboot mmap definition.
+		     Therefore, we can just pass type through.  */
+		  mem_region->type))
+	  return 1;
 
+	mem_region++;
+      }
+
     return 0;
   }
 
grub/i386/pc/init.h +10 -9
Index: include/grub/i386/pc/init.h
===================================================================
@@ -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
@@ -21,6 +21,8 @@
 
 #include <grub/types.h>
 #include <grub/symbol.h>
+#include <grub/multiboot.h>	/* For struct grub_mmap_entry, which is also
+				   needed by Multiboot.  */
 
 /* Get the memory size in KB. If EXTENDED is zero, return conventional
    memory, otherwise return extended memory.  */
@@ -30,19 +32,18 @@
    in 1KB parts, and upper 16 bits are above 16MB in 64KB parts.  */
 grub_uint32_t grub_get_eisa_mmap (void);
 
-struct grub_machine_mmap_entry
-{
-  grub_uint32_t size;
-  grub_uint64_t addr;
-  grub_uint64_t len;
-  grub_uint32_t type;
-} __attribute__((packed));
+/* Multiboot mmaps have been defined to match with the E820 definition.  */
+#define GRUB_MACHINE_MEMORY_AVAILABLE	GRUB_MMAP_MEMORY_AVAILABLE
+#define GRUB_MACHINE_MEMORY_RESERVED	GRUB_MMAP_MEMORY_RESERVED
 
 /* Get a memory map entry. Return next continuation value. Zero means
    the end.  */
-grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_machine_mmap_entry *entry,
+grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_mmap_entry *entry,
 				   grub_uint32_t cont);
 
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
+
 /* Turn on/off Gate A20.  */
 void grub_gate_a20 (int on);
 
grub/i386/coreboot/memory.h +3 -4
Index: include/grub/i386/coreboot/memory.h
===================================================================
@@ -25,7 +25,6 @@
 
 #ifndef ASM_FILE
 #include <grub/types.h>
-#include <grub/err.h>
 #endif
 
 #define GRUB_MEMORY_MACHINE_LOWER_USABLE		0x9fc00		/* 640 kiB - 1 kiB */
@@ -55,13 +54,13 @@
 {
   grub_uint64_t addr;
   grub_uint64_t size;
-#define GRUB_LINUXBIOS_MEMORY_AVAILABLE	1
+#define GRUB_MACHINE_MEMORY_AVAILABLE		1
   grub_uint32_t type;
 };
 typedef struct grub_linuxbios_mem_region *mem_region_t;
 
-grub_err_t EXPORT_FUNC(grub_available_iterate)
-     (int (*hook) (mem_region_t));
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
 
 #endif
 
grub/multiboot.h +11 -1
Index: include/grub/multiboot.h
===================================================================
@@ -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 @@
   grub_uint16_t vbe_interface_len;
 };
 
+struct grub_mmap_entry
+{
+  grub_uint32_t size;
+  grub_uint64_t addr;
+  grub_uint64_t len;
+#define GRUB_MMAP_MEMORY_AVAILABLE	1
+#define GRUB_MMAP_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 */
i386/pc/multiboot.c +65 -7

119 lines not on this page · raw message

i386/bsd.c +1 -1
Index: loader/i386/bsd.c
===================================================================
@@ -313,7 +313,7 @@
 grub_openbsd_boot (void)
 {
   char *buf = (char *) GRUB_BSD_TEMP_BUFFER;
-  struct grub_machine_mmap_entry mmap;
+  struct grub_mmap_entry mmap;
   struct grub_openbsd_bios_mmap *pm;
   struct grub_openbsd_bootargs *pa;
   grub_uint32_t bootdev, biosdev, unit, slice, part, cont;
#8 lore raw

Re: [PATCH] decouple mmap parsing and implement Multiboot mmap in the loader

Hi,

Quoted 2 lines · Robert Millan

And here we go *AGAIN*, this time not forgetting to include all files in the patch.

[...]

Quoted 13 lines

Index: include/grub/i386/pc/init.h
===================================================================

grub/i386/pc/init.h +1 -1
@@ -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

grub/i386/pc/init.h line 25

Quoted 5 lines
grub/i386/pc/init.h +2 -0
@@ -21,6 +21,8 @@
 
 #include <grub/types.h>
 #include <grub/symbol.h>
+#include <grub/multiboot.h>	/* For struct grub_mmap_entry, which is also
+				   needed by Multiboot.  */

Isn't it better to split the header file? This seems like a hack.

Quoted 93 lines
grub/i386/pc/init.h +7 -8
 /* Get the memory size in KB. If EXTENDED is zero, return conventional
    memory, otherwise return extended memory.  */
@@ -30,19 +32,18 @@
    in 1KB parts, and upper 16 bits are above 16MB in 64KB parts.  */
 grub_uint32_t grub_get_eisa_mmap (void);
 
-struct grub_machine_mmap_entry
-{
-  grub_uint32_t size;
-  grub_uint64_t addr;
-  grub_uint64_t len;
-  grub_uint32_t type;
-} __attribute__((packed));
+/* Multiboot mmaps have been defined to match with the E820 definition.  */
+#define GRUB_MACHINE_MEMORY_AVAILABLE	GRUB_MMAP_MEMORY_AVAILABLE
+#define GRUB_MACHINE_MEMORY_RESERVED	GRUB_MMAP_MEMORY_RESERVED
 
 /* Get a memory map entry. Return next continuation value. Zero means
    the end.  */
-grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_machine_mmap_entry *entry,
+grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_mmap_entry *entry,
 				   grub_uint32_t cont);
 
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
+
 /* Turn on/off Gate A20.  */
 void grub_gate_a20 (int on);
 

Index: include/grub/i386/coreboot/memory.h
===================================================================

grub/i386/coreboot/memory.h +3 -4
@@ -25,7 +25,6 @@
 
 #ifndef ASM_FILE
 #include <grub/types.h>
-#include <grub/err.h>
 #endif
 
 #define GRUB_MEMORY_MACHINE_LOWER_USABLE		0x9fc00		/* 640 kiB - 1 kiB */
@@ -55,13 +54,13 @@
 {
   grub_uint64_t addr;
   grub_uint64_t size;
-#define GRUB_LINUXBIOS_MEMORY_AVAILABLE	1
+#define GRUB_MACHINE_MEMORY_AVAILABLE		1
   grub_uint32_t type;
 };
 typedef struct grub_linuxbios_mem_region *mem_region_t;
 
-grub_err_t EXPORT_FUNC(grub_available_iterate)
-     (int (*hook) (mem_region_t));
+void EXPORT_FUNC(grub_mmap_iterate)
+     (int (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
 
 #endif
 

Index: include/grub/multiboot.h
===================================================================

grub/multiboot.h +11 -1
@@ -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 @@
   grub_uint16_t vbe_interface_len;
 };
 
+struct grub_mmap_entry
+{
+  grub_uint32_t size;
+  grub_uint64_t addr;
+  grub_uint64_t len;
+#define GRUB_MMAP_MEMORY_AVAILABLE	1
+#define GRUB_MMAP_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 */

Index: loader/i386/pc/multiboot.c
===================================================================

i386/pc/multiboot.c line 81

Quoted 6 lines
i386/pc/multiboot.c +1 -2
@@ -78,14 +78,60 @@
       grub_free ((void *) mbi->cmdline);
       grub_free (mbi);
     }
-
-
+  

Hm? :-)

--
Marco

#9 lore raw

Re: [PATCH] decouple mmap parsing and implement Multiboot mmap in the loader

Quoted 6 lines · Marco Gerards

grub/i386/pc/init.h line 25

Quoted 4 lines

#include <grub/types.h>
#include <grub/symbol.h>

grub/i386/pc/init.h +2 -0
+#include <grub/multiboot.h>	/* For struct grub_mmap_entry, which is also
+				   needed by Multiboot.  */

Isn't it better to split the header file? This seems like a hack.

The definition is part of the Multiboot spec, so it really needs to be present in multiboot.h.

We could also define it separately as grub_mmap_entry in multiboot.h and keep the grub_machine_mmap_entry definition in pc/init.h. Then other arches could have their own grub_machine_mmap_entry variant which _does_ differ from grub_mmap_entry (like coreboot).

What do you think?

Quoted 5 lines
Quoted 5 lines

Index: loader/i386/pc/multiboot.c
===================================================================

i386/pc/multiboot.c +0 -0
@@ -78,14 +78,60 @@
Quoted 8 lines

i386/pc/multiboot.c line 81

Quoted 6 lines
i386/pc/multiboot.c +1 -2
       grub_free ((void *) mbi->cmdline);
       grub_free (mbi);
     }
-
-
+  

Hm? :-)

Some minor janitor work ;-)

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#10 lore raw

Re: [PATCH] decouple mmap parsing and implement Multiboot mmap in the loader

Quoted 11 lines · Robert Millan
Quoted 6 lines · Marco Gerards

grub/i386/pc/init.h line 25

Quoted 4 lines

#include <grub/types.h>
#include <grub/symbol.h>

grub/i386/pc/init.h +2 -0
+#include <grub/multiboot.h>	/* For struct grub_mmap_entry, which is also
+				   needed by Multiboot.  */

Isn't it better to split the header file? This seems like a hack.

The definition is part of the Multiboot spec, so it really needs to be present in multiboot.h.

Quoted 6 lines

We could also define it separately as grub_mmap_entry in multiboot.h and keep the grub_machine_mmap_entry definition in pc/init.h. Then other arches could have their own grub_machine_mmap_entry variant which _does_ differ from grub_mmap_entry (like coreboot).

What do you think?

This sounds fine to me.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines

Index: loader/i386/pc/multiboot.c
===================================================================

i386/pc/multiboot.c +0 -0
@@ -78,14 +78,60 @@
Quoted 8 lines

i386/pc/multiboot.c line 81

Quoted 6 lines
i386/pc/multiboot.c +1 -2
       grub_free ((void *) mbi->cmdline);
       grub_free (mbi);
     }
-
-
+  

Hm? :-)

Quoted 1 line

Some minor janitor work ;-)

:-)

--
Marco

#11 lore raw

Re: [PATCH] decouple mmap parsing and implement Multiboot mmap in the loader

Committed.

Quoted 50 lines · Marco Gerards
Quoted 11 lines · Robert Millan
Quoted 6 lines · Marco Gerards

grub/i386/pc/init.h line 25

Quoted 4 lines

#include <grub/types.h>
#include <grub/symbol.h>

grub/i386/pc/init.h +2 -0
+#include <grub/multiboot.h>	/* For struct grub_mmap_entry, which is also
+				   needed by Multiboot.  */

Isn't it better to split the header file? This seems like a hack.

The definition is part of the Multiboot spec, so it really needs to be present in multiboot.h.

Quoted 6 lines

We could also define it separately as grub_mmap_entry in multiboot.h and keep the grub_machine_mmap_entry definition in pc/init.h. Then other arches could have their own grub_machine_mmap_entry variant which _does_ differ from grub_mmap_entry (like coreboot).

What do you think?

This sounds fine to me.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines

Index: loader/i386/pc/multiboot.c
===================================================================

i386/pc/multiboot.c +0 -0
@@ -78,14 +78,60 @@
Quoted 8 lines

i386/pc/multiboot.c line 81

Quoted 6 lines
i386/pc/multiboot.c +1 -2
       grub_free ((void *) mbi->cmdline);
       grub_free (mbi);
     }
-
-
+  

Hm? :-)

Quoted 1 line

Some minor janitor work ;-)

:-)

--
Marco

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."