Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / common / boot / grub2 / kern / sparc64 / ieee1275 / init.c
blob57ffc389808fdc801660faec444893039a1b3dcb
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 int
70 grub_ieee1275_test_flag (enum grub_ieee1275_flag flag)
72 return (grub_ieee1275_flags & (1 << flag));
75 void
76 grub_ieee1275_set_flag (enum grub_ieee1275_flag flag)
78 grub_ieee1275_flags |= (1 << flag);
81 /* Translate an OF filesystem path (separated by backslashes), into a GRUB
82 path (separated by forward slashes). */
83 static void
84 grub_translate_ieee1275_path (char *filepath)
86 char *backslash;
88 backslash = grub_strchr (filepath, '\\');
89 while (backslash != 0)
91 *backslash = '/';
92 backslash = grub_strchr (filepath, '\\');
96 void
97 grub_machine_set_prefix (void)
99 char bootpath[64]; /* XXX check length */
100 char *filename;
101 char *prefix;
103 if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
104 sizeof (bootpath), 0))
106 /* Should never happen. */
107 grub_printf ("/chosen/bootpath property missing!\n");
108 grub_env_set ("prefix", "");
109 return;
112 /* Transform an OF device path to a GRUB path. */
114 prefix = grub_ieee1275_encode_devname (bootpath);
116 filename = grub_ieee1275_get_filename (bootpath);
117 if (filename)
119 char *newprefix;
120 char *lastslash = grub_strrchr (filename, '\\');
122 /* Truncate at last directory. */
123 if (lastslash)
125 *lastslash = '\0';
126 grub_translate_ieee1275_path (filename);
128 newprefix = grub_malloc (grub_strlen (prefix)
129 + grub_strlen (filename));
130 grub_sprintf (newprefix, "%s%s", prefix, filename);
131 grub_free (prefix);
132 prefix = newprefix;
136 grub_env_set ("prefix", prefix);
138 grub_free (filename);
139 grub_free (prefix);
142 grub_uint64_t ieee1275_get_time_ms (void);
144 void
145 grub_machine_init (void)
147 char *args;
148 grub_ssize_t length;
150 grub_console_init ();
152 /* FIXME (sparc64). */
153 grub_heap_len = (grub_addr_t) &_start - 0x1000 - grub_heap_start;
155 if (grub_ieee1275_claim (grub_heap_start, grub_heap_len, 0, 0))
156 grub_fatal ("Failed to claim heap at %p, len 0x%x\n", grub_heap_start,
157 grub_heap_len);
158 grub_mm_init_region ((void *) grub_heap_start, grub_heap_len);
160 grub_ofdisk_init ();
162 /* Process commandline. */
163 if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootargs",
164 &length) == 0 &&
165 length > 0)
167 grub_ssize_t i = 0;
169 args = grub_malloc (length);
170 grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", args,
171 length, 0);
173 while (i < length)
175 char *command = &args[i];
176 char *end;
177 char *val;
179 end = grub_strchr (command, ';');
180 if (end == 0)
181 i = length; /* No more commands after this one. */
182 else
184 *end = '\0';
185 i += end - command + 1;
186 while (grub_isspace(args[i]))
187 i++;
190 /* Process command. */
191 val = grub_strchr (command, '=');
192 if (val)
194 *val = '\0';
195 grub_env_set (command, val + 1);
200 grub_install_get_time_ms (ieee1275_get_time_ms);
203 void
204 grub_machine_fini (void)
206 grub_ofdisk_fini ();
207 grub_console_fini ();
210 void
211 grub_exit (void)
213 grub_ieee1275_enter ();
216 grub_uint64_t
217 ieee1275_get_time_ms (void)
219 return grub_get_rtc ();
222 grub_uint32_t
223 grub_get_rtc (void)
225 grub_uint32_t msecs;
227 if (grub_ieee1275_milliseconds (&msecs))
228 return 0;
230 return msecs;
233 grub_addr_t
234 grub_arch_modules_addr (void)
236 return GRUB_IEEE1275_MODULE_BASE;