Migrate .cvsignore to svn:ignore property
[grub2/phcoder/solaris.git] / loader / ieee1275 / multiboot2.c
blobc253fc938e787bbdee903a843c5b696ecb6c8039
1 /* multiboot.c - boot a multiboot 2 OS image. */
2 /*
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>
24 #include <grub/err.h>
25 #include <grub/elf.h>
26 #include <grub/misc.h>
27 #include <grub/mm.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. */
35 grub_err_t
36 grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr)
38 int rc;
40 rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz);
41 if (rc)
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);
48 return GRUB_ERR_NONE;
51 /* Claim the memory occupied by the multiboot kernel. */
52 grub_err_t
53 grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, UNUSED grub_addr_t *addr)
55 int rc;
57 rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz);
58 if (rc)
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));
66 return GRUB_ERR_NONE;
69 grub_err_t
70 grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr)
72 int rc;
74 /* XXX Will need to map on some firmwares. */
75 rc = grub_ieee1275_claim (0, size, MULTIBOOT2_MOD_ALIGN, addr);
76 if (rc)
77 return grub_error (GRUB_ERR_OUT_OF_MEMORY,
78 "Firmware couldn't allocate memory (size 0x%lx)", size);
80 return GRUB_ERR_NONE;
83 grub_err_t
84 grub_mb2_arch_module_free (grub_addr_t addr, grub_size_t size)
86 grub_ieee1275_release (addr, size);
87 return GRUB_ERR_NONE;
90 grub_err_t
91 grub_mb2_tags_arch_create (void)
93 /* Nothing special. */
94 return GRUB_ERR_NONE;
97 /* Release the memory we claimed from Open Firmware above. */
98 void
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);
115 void
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);
123 #else
124 #error
125 #endif