1 /* multiboot.c - boot a multiboot 2 OS image. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2007 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <multiboot2.h>
21 #include <grub/loader.h>
22 #include <grub/ieee1275/ieee1275.h>
23 #include <grub/multiboot2.h>
26 #include <grub/misc.h>
28 #include <grub/machine/kernel.h>
29 #include <grub/machine/loader.h>
31 typedef void (*kernel_entry_t
) (unsigned long, void *, int (void *),
32 unsigned long, unsigned long);
34 /* Claim the memory occupied by the multiboot kernel. */
36 grub_mb2_arch_elf32_hook (Elf32_Phdr
*phdr
, UNUSED grub_addr_t
*addr
)
40 rc
= grub_claimmap (phdr
->p_paddr
, phdr
->p_memsz
);
42 return grub_error(GRUB_ERR_OUT_OF_MEMORY
, "Couldn't claim %x - %x",
43 phdr
->p_paddr
, phdr
->p_paddr
+ phdr
->p_memsz
);
45 grub_dprintf ("loader", "Loading segment at 0x%x - 0x%x\n", phdr
->p_paddr
,
46 phdr
->p_paddr
+ phdr
->p_memsz
);
51 /* Claim the memory occupied by the multiboot kernel. */
53 grub_mb2_arch_elf64_hook (Elf64_Phdr
*phdr
, UNUSED grub_addr_t
*addr
)
57 rc
= grub_claimmap (phdr
->p_paddr
, phdr
->p_memsz
);
59 return grub_error(GRUB_ERR_OUT_OF_MEMORY
, "Couldn't claim 0x%lx - 0x%lx",
60 phdr
->p_paddr
, phdr
->p_paddr
+ phdr
->p_memsz
);
62 grub_dprintf ("loader", "Loading segment at 0x%lx - 0x%lx\n",
63 (unsigned long) phdr
->p_paddr
,
64 (unsigned long) (phdr
->p_paddr
+ phdr
->p_memsz
));
70 grub_mb2_arch_module_alloc (grub_size_t size
, grub_addr_t
*addr
)
74 /* XXX Will need to map on some firmwares. */
75 rc
= grub_ieee1275_claim (0, size
, MULTIBOOT2_MOD_ALIGN
, addr
);
77 return grub_error (GRUB_ERR_OUT_OF_MEMORY
,
78 "Firmware couldn't allocate memory (size 0x%lx)", size
);
84 grub_mb2_arch_module_free (grub_addr_t addr
, grub_size_t size
)
86 grub_ieee1275_release (addr
, size
);
91 grub_mb2_tags_arch_create (void)
93 /* Nothing special. */
97 /* Release the memory we claimed from Open Firmware above. */
99 grub_mb2_arch_unload (struct multiboot_tag_header
*tags
)
101 struct multiboot_tag_header
*tag
;
103 /* Free all module memory in the tag list. */
104 for_each_tag (tag
, tags
)
106 if (tag
->key
== MULTIBOOT2_TAG_MODULE
)
108 struct multiboot_tag_module
*module
=
109 (struct multiboot_tag_module
*) tag
;
110 grub_ieee1275_release (module
->addr
, module
->size
);
116 grub_mb2_arch_boot (grub_addr_t entry_addr
, void *tags
)
118 #if defined(__powerpc__)
119 kernel_entry_t entry
= (kernel_entry_t
) entry_addr
;
120 entry (MULTIBOOT2_BOOTLOADER_MAGIC
, tags
, grub_ieee1275_entry_fn
, 0, 0);
121 #elif defined(__i386__)
122 grub_multiboot2_real_boot (entry_addr
, tags
);