1
/* init.c -- Initialize GRUB on the newworld mac (PPC). */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
6
* 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
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program 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 this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#include <grub/kernel.h>
23
#include <grub/disk.h>
25
#include <grub/partition.h>
26
#include <grub/normal.h>
28
#include <grub/setjmp.h>
30
#include <grub/misc.h>
31
#include <grub/machine/console.h>
32
#include <grub/machine/time.h>
33
#include <grub/machine/kernel.h>
34
#include <grub/ieee1275/ofdisk.h>
35
#include <grub/ieee1275/ieee1275.h>
37
/* Apple OF 1.0.5 reserves 0x0 to 0x4000 for the exception handlers. */
38
static const grub_addr_t grub_heap_start = 0x4000;
39
static grub_addr_t grub_heap_len;
44
/* Trap to Open Firmware. */
50
/* Translate an OF filesystem path (separated by backslashes), into a GRUB
51
path (separated by forward slashes). */
53
grub_translate_ieee1275_path (char *filepath)
57
backslash = grub_strchr (filepath, '\\');
58
while (backslash != 0)
61
backslash = grub_strchr (filepath, '\\');
66
grub_set_prefix (void)
68
char bootpath[64]; /* XXX check length */
72
if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath,
73
sizeof (bootpath), 0))
75
/* Should never happen. */
76
grub_printf ("/chosen/bootpath property missing!\n");
77
grub_env_set ("prefix", "");
81
/* Transform an OF device path to a GRUB path. */
83
prefix = grub_ieee1275_encode_devname (bootpath);
85
filename = grub_ieee1275_get_filename (bootpath);
89
char *lastslash = grub_strrchr (filename, '\\');
91
/* Truncate at last directory. */
95
grub_translate_ieee1275_path (filename);
97
newprefix = grub_malloc (grub_strlen (prefix)
98
+ grub_strlen (filename));
99
grub_sprintf (newprefix, "%s%s", prefix, filename);
105
grub_env_set ("prefix", prefix);
107
grub_free (filename);
112
grub_machine_init (void)
115
grub_ieee1275_phandle_t chosen;
119
grub_console_init ();
121
/* Apple OF 3.1.1 reserves an extra 0x1000 bytes below the load address
123
grub_heap_len = (grub_addr_t) &_start - 0x1000 - grub_heap_start;
125
if (grub_ieee1275_claim (grub_heap_start, grub_heap_len, 0, 0))
127
grub_printf ("Failed to claim heap at 0x%x, len 0x%x\n", grub_heap_start,
131
grub_mm_init_region ((void *) grub_heap_start, grub_heap_len);
137
/* Process commandline. */
138
grub_ieee1275_finddevice ("/chosen", &chosen);
139
if (grub_ieee1275_get_property (chosen, "bootargs", &args,
140
sizeof args, &actual) == 0
147
char *command = &args[i];
151
end = grub_strchr (command, ';');
153
i = actual; /* No more commands after this one. */
157
i += end - command + 1;
158
while (grub_isspace(args[i]))
162
/* Process command. */
163
val = grub_strchr (command, '=');
167
grub_env_set (command, val + 1);
174
grub_machine_fini (void)
177
grub_console_fini ();
189
grub_uint32_t msecs = 0;
191
grub_ieee1275_milliseconds (&msecs);
197
grub_arch_modules_addr (void)
199
return GRUB_IEEE1275_MODULE_BASE;