1 |
/* main.c - the kernel main routine */ |
/* main.c - the kernel main routine */ |
2 |
/* |
/* |
3 |
* GRUB -- GRand Unified Bootloader |
* GRUB -- GRand Unified Bootloader |
4 |
* Copyright (C) 2002, 2003 Free Software Foundation, Inc. |
* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. |
5 |
* |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
29 |
#include <grub/device.h> |
#include <grub/device.h> |
30 |
#include <grub/env.h> |
#include <grub/env.h> |
31 |
|
|
|
/* Return the end of the core image. */ |
|
|
grub_addr_t |
|
|
grub_get_end_addr (void) |
|
|
{ |
|
|
return grub_total_module_size + grub_end_addr; |
|
|
} |
|
|
|
|
32 |
/* Load all modules in core. */ |
/* Load all modules in core. */ |
33 |
static void |
static void |
34 |
grub_load_modules (void) |
grub_load_modules (void) |
35 |
{ |
{ |
36 |
|
struct grub_module_info *modinfo; |
37 |
struct grub_module_header *header; |
struct grub_module_header *header; |
38 |
|
grub_addr_t modbase; |
39 |
|
|
40 |
|
modbase = grub_arch_modules_addr (); |
41 |
|
modinfo = (struct grub_module_info *) modbase; |
42 |
|
|
43 |
|
/* Check if there are any modules. */ |
44 |
|
if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC) |
45 |
|
return; |
46 |
|
|
47 |
for (header = (struct grub_module_header *) grub_end_addr; |
for (header = (struct grub_module_header *) (modbase + modinfo->offset); |
48 |
header < (struct grub_module_header *) grub_get_end_addr (); |
header < (struct grub_module_header *) (modbase + modinfo->size); |
49 |
header = (struct grub_module_header *) ((char *) header + header->size)) |
header = (struct grub_module_header *) ((char *) header + header->size)) |
50 |
{ |
{ |
51 |
if (! grub_dl_load_core ((char *) header + header->offset, |
if (! grub_dl_load_core ((char *) header + header->offset, |
52 |
(header->size - header->offset))) |
(header->size - header->offset))) |
53 |
grub_fatal ("%s", grub_errmsg); |
grub_fatal ("%s", grub_errmsg); |
54 |
} |
} |
|
} |
|
55 |
|
|
56 |
/* Add the region where modules reside into dynamic memory. */ |
/* Add the region where modules reside into dynamic memory. */ |
57 |
static void |
grub_mm_init_region ((void *) modinfo, modinfo->size); |
|
grub_add_unused_region (void) |
|
|
{ |
|
|
if (grub_total_module_size) |
|
|
grub_mm_init_region ((void *) grub_end_addr, grub_total_module_size); |
|
58 |
} |
} |
59 |
|
|
60 |
/* Set the root device according to the dl prefix. */ |
/* Set the root device according to the dl prefix. */ |
108 |
/* Load pre-loaded modules and free the space. */ |
/* Load pre-loaded modules and free the space. */ |
109 |
grub_register_exported_symbols (); |
grub_register_exported_symbols (); |
110 |
grub_load_modules (); |
grub_load_modules (); |
|
grub_add_unused_region (); |
|
111 |
|
|
112 |
/* Load the normal mode module. */ |
/* Load the normal mode module. */ |
113 |
grub_load_normal_mode (); |
grub_load_normal_mode (); |