1 /* init.c -- Initialize GRUB on the Ultra Sprac (sparc64). */
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>
22 #include <grub/disk.h>
24 #include <grub/partition.h>
25 #include <grub/normal.h>
27 #include <grub/setjmp.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
;
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
)),
50 uint64_t r5
__attribute__((unused
)));
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
)),
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. */
70 grub_ieee1275_test_flag (enum grub_ieee1275_flag flag
)
72 return (grub_ieee1275_flags
& (1 << flag
));
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). */
84 grub_translate_ieee1275_path (char *filepath
)
88 backslash
= grub_strchr (filepath
, '\\');
89 while (backslash
!= 0)
92 backslash
= grub_strchr (filepath
, '\\');
97 grub_machine_set_prefix (void)
99 char bootpath
[64]; /* XXX check length */
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", "");
112 /* Transform an OF device path to a GRUB path. */
114 prefix
= grub_ieee1275_encode_devname (bootpath
);
116 filename
= grub_ieee1275_get_filename (bootpath
);
120 char *lastslash
= grub_strrchr (filename
, '\\');
122 /* Truncate at last directory. */
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
);
136 grub_env_set ("prefix", prefix
);
138 grub_free (filename
);
142 grub_uint64_t
ieee1275_get_time_ms (void);
145 grub_machine_init (void)
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
,
158 grub_mm_init_region ((void *) grub_heap_start
, grub_heap_len
);
162 /* Process commandline. */
163 if (grub_ieee1275_get_property_length (grub_ieee1275_chosen
, "bootargs",
169 args
= grub_malloc (length
);
170 grub_ieee1275_get_property (grub_ieee1275_chosen
, "bootargs", args
,
175 char *command
= &args
[i
];
179 end
= grub_strchr (command
, ';');
181 i
= length
; /* No more commands after this one. */
185 i
+= end
- command
+ 1;
186 while (grub_isspace(args
[i
]))
190 /* Process command. */
191 val
= grub_strchr (command
, '=');
195 grub_env_set (command
, val
+ 1);
200 grub_install_get_time_ms (ieee1275_get_time_ms
);
204 grub_machine_fini (void)
207 grub_console_fini ();
213 grub_ieee1275_enter ();
217 ieee1275_get_time_ms (void)
219 return grub_get_rtc ();
227 if (grub_ieee1275_milliseconds (&msecs
))
234 grub_arch_modules_addr (void)
236 return GRUB_IEEE1275_MODULE_BASE
;