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 <grub/loader.h>
21 #include <grub/ieee1275/ieee1275.h>
22 #include <grub/multiboot2.h>
23 #include <multiboot2.h>
26 #include <grub/misc.h>
28 #include <grub/machine/kernel.h>
29 #include <grub/machine/loader.h>
31 #include <grub/cpu/multiboot.h>
34 typedef void (*kernel_entry_t
) (unsigned long, void *, int (void *),
35 unsigned long, unsigned long);
37 /* Claim the memory occupied by the multiboot kernel. */
39 grub_mb2_arch_elf32_hook (Elf32_Phdr
*phdr
, UNUSED grub_addr_t
*addr
,
44 if (phdr
->p_type
!= PT_LOAD
)
51 rc
= grub_claimmap (phdr
->p_paddr
, phdr
->p_memsz
);
53 return grub_error(GRUB_ERR_OUT_OF_MEMORY
, "Couldn't claim %x - %x",
54 phdr
->p_paddr
, phdr
->p_paddr
+ phdr
->p_memsz
);
56 grub_dprintf ("loader", "Loading segment at 0x%x - 0x%x\n", phdr
->p_paddr
,
57 phdr
->p_paddr
+ phdr
->p_memsz
);
62 /* Claim the memory occupied by the multiboot kernel. */
64 grub_mb2_arch_elf64_hook (Elf64_Phdr
*phdr
, UNUSED grub_addr_t
*addr
,
69 if (phdr
->p_type
!= PT_LOAD
)
76 rc
= grub_claimmap (phdr
->p_paddr
, phdr
->p_memsz
);
78 return grub_error(GRUB_ERR_OUT_OF_MEMORY
, "Couldn't claim 0x%lx - 0x%lx",
79 phdr
->p_paddr
, phdr
->p_paddr
+ phdr
->p_memsz
);
81 grub_dprintf ("loader", "Loading segment at 0x%lx - 0x%lx\n",
82 (unsigned long) phdr
->p_paddr
,
83 (unsigned long) (phdr
->p_paddr
+ phdr
->p_memsz
));
89 grub_mb2_arch_module_alloc (grub_size_t size
, grub_addr_t
*addr
)
93 /* XXX Will need to map on some firmwares. */
94 rc
= grub_ieee1275_claim (0, size
, MULTIBOOT2_MOD_ALIGN
, addr
);
96 return grub_error (GRUB_ERR_OUT_OF_MEMORY
,
97 "Firmware couldn't allocate memory (size 0x%lx)", size
);
103 grub_mb2_arch_module_free (grub_addr_t addr
, grub_size_t size
)
105 grub_ieee1275_release (addr
, size
);
106 return GRUB_ERR_NONE
;
110 grub_mb2_tags_arch_create (void)
112 /* Nothing special. */
113 return GRUB_ERR_NONE
;
116 /* Release the memory we claimed from Open Firmware above. */
118 grub_mb2_arch_unload (struct multiboot_tag_header
*tags
)
120 struct multiboot_tag_header
*tag
;
122 /* Free all module memory in the tag list. */
123 for_each_tag (tag
, tags
)
125 if (tag
->key
== MULTIBOOT2_TAG_MODULE
)
127 struct multiboot_tag_module
*module
=
128 (struct multiboot_tag_module
*) tag
;
129 grub_ieee1275_release (module
->addr
, module
->size
);
135 grub_mb2_arch_boot (grub_addr_t entry_addr
, void *tags
)
137 #if defined(__powerpc__)
138 kernel_entry_t entry
= (kernel_entry_t
) entry_addr
;
139 entry (MULTIBOOT2_BOOTLOADER_MAGIC
, tags
, grub_ieee1275_entry_fn
, 0, 0);
140 #elif defined(__i386__)
141 grub_multiboot2_real_boot (entry_addr
, tags
);