heap memory allocation
PATCH 1/1 heap memory allocation
Ok, this is much simpler than the last patch; it just changes which hardcoded region of memory we use. These are the areas I think we need to watch out for (from memory, so not authoritative):
0-16 KB exception handlers 4-5 MB Old World Mac firmware 8-? MB some older RS/6000 12-20 MB newer RS/6000 / pSeries 20+-32 MB other bits on pSeries, like NVRAM
Our link base was chosen at 2MB, which is working fine. This patch uses all the memory from the exception handlers (which may or may not be claimed by firmware) to the link base. That should give us plenty of room for the GRUB heap, while also leaving as much as possible open for the OSs to be loaded at.
I've tested this by getting to the GRUB command line on Old World Mac, New World Mac, and CodeGen firmware (briQ).
Ok?
-Hollis
2004-10-13 Hollis Blanchard <[email protected]>
* include/grub/powerpc/ieee1275/ieee1275.h (abort): Add function prototype.
* kern/powerpc/ieee1275/init.c (grub_machine_init): Call grub_console_init first.
Change the memory range used for grub_ieee1275_claim and grub_mm_init_region.
Print an error message if the claim fails.
Index: include/grub/powerpc/ieee1275/ieee1275.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/ieee1275.h,v retrieving revision 1.6
grub/powerpc/ieee1275/ieee1275.h +2 -0
@@ -102,5 +102,7 @@grub_err_t EXPORT_FUNC (grub_devalias_iterate ) (int (*hook) (struct grub_ieee1275_devalias *alias)); +void EXPORT_FUNC (abort ) (void ); +#endif /* ! GRUB_IEEE1275_MACHINE_HEADER */
Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v retrieving revision 1.6
powerpc/ieee1275/init.c +20 -6
@@ -28,6 +28,7 @@#include <grub/fs.h> #include <grub/setjmp.h> #include <grub/env.h> +#include <grub/misc.h> void grub_ofdisk_init (void );void grub_console_init (void );
@@ -49,11 +50,25 @@void grub_machine_init (void ) { -if (grub_ieee1275_claim (0x300000 ,0x150000 ,0 ,0 ) ==-1 ) -abort ();/* Damn, we are in trouble! */ - -/* The memory allocations were copied from yaboot. */ -grub_mm_init_region ((void *)0x300000 ,0x150000 ); +extern char _start; +grub_addr_t heap_start; +grub_addr_t heap_len; + +grub_console_init (); + +/* Apple OF 1.0.5 reserves 0x4000 bytes for the exception handlers. */ + heap_start =0x4000 ; +/* Apple OF 3.1.1 reserves an extra 0x1000 bytes below the load address +* of an ELF file. */ + heap_len = (grub_addr_t ) &_start -0x1000 - heap_start; + +if (grub_ieee1275_claim (heap_start, heap_len,0 ,0 )) + { +grub_printf ("Failed to claim heap at 0x%x, len 0x%x\n" , heap_start, + heap_len); +abort (); + } +grub_mm_init_region ((void *) heap_start, heap_len);/* XXX: Loadable modules are not supported. */ grub_env_set ("prefix" ,"" );
@@ -64,7 +79,6 @@grub_linux_init ();grub_linux_normal_init ();grub_ofdisk_init (); -grub_console_init (); }int
Quoted 5 lines · Hollis Blanchard
[...]
I've tested this by getting to the GRUB command line on Old World Mac, New World Mac, and CodeGen firmware (briQ).Ok?
I won't address the technical issues in this mail.
Quoted 11 lines
-Hollis
2004-10-13 Hollis Blanchard <[email protected]>
*
include/grub/powerpc/ieee1275/ieee1275.h(abort): Add function prototype.
*kern/powerpc/ieee1275/init.c(grub_machine_init): Callgrub_console_initfirst.
Change the memory range used forgrub_ieee1275_claimandgrub_mm_init_region.
Print an error message if the claim fails.
Looking good Hollis in respect to GCS. There's just one thing:
powerpc/ieee1275/init.c line 63
Quoted 3 lines
powerpc/ieee1275/init.c +3
-0+/* Apple OF 3.1.1 reserves an extra 0x1000 bytes below the load address +* of an ELF file. */ + heap_len = (grub_addr_t ) &_start -0x1000 - heap_start;
Comments are written without extra prefix stars on new lines. Like this:
/* Apple OF 3.1.1 reserves an extra 0x1000 bytes below the load address
of an ELF file. */
Other than that, it looks fine to me. But it's up to the others to accept the patch.
I'm pretty sure Marco could make this little change himself if he chooses to accept the patch.
Best Regards.
~j
Quoted 10 lines · Hollis Blanchard
Ok, this is much simpler than the last patch; it just changes which hardcoded region of memory we use. These are the areas I think we need to watch out for (from memory, so not authoritative):
0-16 KB exception handlers 4-5 MB Old World Mac firmware 8-? MB some older RS/6000 12-20 MB newer RS/6000 / pSeries 20+-32 MB other bits on pSeries, like NVRAM
Quoted 5 lines
Our link base was chosen at 2MB, which is working fine. This patch uses all the memory from the exception handlers (which may or may not be claimed by firmware) to the link base. That should give us plenty of room for the GRUB heap, while also leaving as much as possible open for the OSs to be loaded at.
This is better then what is done now.
Quoted 5 lines
*
kern/powerpc/ieee1275/init.c(grub_machine_init): Callgrub_console_initfirst.
Change the memory range used forgrub_ieee1275_claimandgrub_mm_init_region.
Print an error message if the claim fails.
You forgot to mention that grub/misc.h is included. Can you add "Include <grub/misc.h>." here?
If you make the change that Johan mentioned, it can go in as far as I am concerned.
Thanks,
Marco