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_millisleep (grub_uint32_t ms
)
72 grub_millisleep_generic (ms
);
76 grub_ieee1275_test_flag (enum grub_ieee1275_flag flag
)
78 return (grub_ieee1275_flags
& (1 << flag
));
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). */
90 grub_translate_ieee1275_path (char *filepath
)
94 backslash
= grub_strchr (filepath
, '\\');
95 while (backslash
!= 0)
98 backslash
= grub_strchr (filepath
, '\\');
103 grub_machine_set_prefix (void)
105 char bootpath
[64]; /* XXX check length */
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", "");
118 /* Transform an OF device path to a GRUB path. */
120 prefix
= grub_ieee1275_encode_devname (bootpath
);
122 filename
= grub_ieee1275_get_filename (bootpath
);
126 char *lastslash
= grub_strrchr (filename
, '\\');
128 /* Truncate at last directory. */
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
);
142 grub_env_set ("prefix", prefix
);
144 grub_free (filename
);
149 grub_machine_init (void)
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
,
162 grub_mm_init_region ((void *) grub_heap_start
, grub_heap_len
);
166 /* Process commandline. */
167 if (grub_ieee1275_get_property_length (grub_ieee1275_chosen
, "bootargs",
173 args
= grub_malloc (length
);
174 grub_ieee1275_get_property (grub_ieee1275_chosen
, "bootargs", args
,
179 char *command
= &args
[i
];
183 end
= grub_strchr (command
, ';');
185 i
= length
; /* No more commands after this one. */
189 i
+= end
- command
+ 1;
190 while (grub_isspace(args
[i
]))
194 /* Process command. */
195 val
= grub_strchr (command
, '=');
199 grub_env_set (command
, val
+ 1);
207 grub_machine_fini (void)
210 grub_console_fini ();
216 grub_ieee1275_enter ();
224 if (grub_ieee1275_milliseconds (&msecs
))
231 grub_arch_modules_addr (void)
233 return GRUB_IEEE1275_MODULE_BASE
;