make the linux-ppc packags be in synch with other platforms
[tangerine.git] / arch / common / boot / grub2 / kern / sparc64 / ieee1275 / init.c
blobdbc1fee3e2bd965bb10326ef86c7bf51512524fa
1 /* init.c -- Initialize GRUB on the Ultra Sprac (sparc64). */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2003,2004,2005,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/kernel.h>
21 #include <grub/dl.h>
22 #include <grub/disk.h>
23 #include <grub/mm.h>
24 #include <grub/partition.h>
25 #include <grub/normal.h>
26 #include <grub/fs.h>
27 #include <grub/setjmp.h>
28 #include <grub/env.h>
29 #include <grub/misc.h>
30 #include <grub/time.h>
31 #include <grub/machine/console.h>
32 #include <grub/machine/kernel.h>
33 #include <grub/ieee1275/ofdisk.h>
34 #include <grub/ieee1275/ieee1275.h>
36 /* OpenBoot entry point. */
37 int (*grub_ieee1275_entry_fn) (void *);
38 grub_ieee1275_phandle_t grub_ieee1275_chosen;
39 static grub_uint32_t grub_ieee1275_flags;
40 /* FIXME (sparc64). */
41 static const grub_addr_t grub_heap_start = 0x40000;
42 static grub_addr_t grub_heap_len;
44 void
45 _start (uint64_t r0 __attribute__((unused)),
46 uint64_t r1 __attribute__((unused)),
47 uint64_t r2 __attribute__((unused)),
48 uint64_t r3 __attribute__((unused)),
49 uint64_t r4,
50 uint64_t r5 __attribute__((unused)));
51 void
52 _start (uint64_t r0 __attribute__((unused)),
53 uint64_t r1 __attribute__((unused)),
54 uint64_t r2 __attribute__((unused)),
55 uint64_t r3 __attribute__((unused)),
56 uint64_t r4,
57 uint64_t r5 __attribute__((unused)))
59 grub_ieee1275_entry_fn = (int (*)(void *)) r4;
61 grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);
63 /* Now invoke the main function. */
64 grub_main ();
66 /* Never reached. */
69 void
70 grub_millisleep (grub_uint32_t ms)
72 grub_millisleep_generic (ms);
75 int
76 grub_ieee1275_test_flag (enum grub_ieee1275_flag flag)
78 return (grub_ieee1275_flags & (1 << flag));
81 void
82 grub_ieee1275_set_flag (enum grub_ieee1275_flag flag)
84 grub_ieee1275_flags |= (1 << flag);
87 /* Translate an OF filesystem path (separated by backslashes), into a GRUB
88 path (separated by forward slashes). */
89 static void
90 grub_translate_ieee1275_path (char *filepath)
92 char *backslash;
94 backslash = grub_strchr (filepath, '\\');
95 while (backslash != 0)
97 *backslash = '/';
98 backslash = grub_strchr (filepath, '\\');
102 void
103 grub_machine_set_prefix (void)
105 char bootpath[64]; /* XXX check length */
106 char *filename;
107 char *prefix;
109 if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
110 sizeof (bootpath), 0))
112 /* Should never happen. */
113 grub_printf ("/chosen/bootpath property missing!\n");
114 grub_env_set ("prefix", "");
115 return;
118 /* Transform an OF device path to a GRUB path. */
120 prefix = grub_ieee1275_encode_devname (bootpath);
122 filename = grub_ieee1275_get_filename (bootpath);
123 if (filename)
125 char *newprefix;
126 char *lastslash = grub_strrchr (filename, '\\');
128 /* Truncate at last directory. */
129 if (lastslash)
131 *lastslash = '\0';
132 grub_translate_ieee1275_path (filename);
134 newprefix = grub_malloc (grub_strlen (prefix)
135 + grub_strlen (filename));
136 grub_sprintf (newprefix, "%s%s", prefix, filename);
137 grub_free (prefix);
138 prefix = newprefix;
142 grub_env_set ("prefix", prefix);
144 grub_free (filename);
145 grub_free (prefix);
148 void
149 grub_machine_init (void)
151 char *args;
152 grub_ssize_t length;
154 grub_console_init ();
156 /* FIXME (sparc64). */
157 grub_heap_len = (grub_addr_t) &_start - 0x1000 - grub_heap_start;
159 if (grub_ieee1275_claim (grub_heap_start, grub_heap_len, 0, 0))
160 grub_fatal ("Failed to claim heap at %p, len 0x%x\n", grub_heap_start,
161 grub_heap_len);
162 grub_mm_init_region ((void *) grub_heap_start, grub_heap_len);
164 grub_ofdisk_init ();
166 /* Process commandline. */
167 if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootargs",
168 &length) == 0 &&
169 length > 0)
171 grub_ssize_t i = 0;
173 args = grub_malloc (length);
174 grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", args,
175 length, 0);
177 while (i < length)
179 char *command = &args[i];
180 char *end;
181 char *val;
183 end = grub_strchr (command, ';');
184 if (end == 0)
185 i = length; /* No more commands after this one. */
186 else
188 *end = '\0';
189 i += end - command + 1;
190 while (grub_isspace(args[i]))
191 i++;
194 /* Process command. */
195 val = grub_strchr (command, '=');
196 if (val)
198 *val = '\0';
199 grub_env_set (command, val + 1);
206 void
207 grub_machine_fini (void)
209 grub_ofdisk_fini ();
210 grub_console_fini ();
213 void
214 grub_exit (void)
216 grub_ieee1275_enter ();
219 grub_uint32_t
220 grub_get_rtc (void)
222 grub_uint32_t msecs;
224 if (grub_ieee1275_milliseconds (&msecs))
225 return 0;
227 return msecs;
230 grub_addr_t
231 grub_arch_modules_addr (void)
233 return GRUB_IEEE1275_MODULE_BASE;