source: mainline/boot/arch/sparc64/src/main.c@ 4039c77

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4039c77 was 4872160, checked in by Martin Decky <martin@…>, 16 years ago

new boot infrastructure

  • more code and metadata unification
  • import of up-to-date implementations from the kernel
  • the boot loaders should behave more similarly on all platforms
  • support for deflate compressed (LZ77) boot components
    • this again allows feasible boot images to be created on mips32
  • IA64 is still not booting
    • the broken forked GNU EFI library has been removed, a replacement of the functionality is on its way
  • Property mode set to 100644
File size: 9.1 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * Copyright (c) 2006 Jakub Jermar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <arch/main.h>
31#include <arch/arch.h>
32#include <arch/asm.h>
33#include <arch/ofw.h>
34#include <arch/_components.h>
35#include <genarch/ofw.h>
36#include <genarch/ofw_tree.h>
37#include <halt.h>
38#include <printf.h>
39#include <memstr.h>
40#include <version.h>
41#include <macros.h>
42#include <align.h>
43#include <str.h>
44#include <errno.h>
45#include <inflate.h>
46
47/* The lowest ID (read from the VER register) of some US3 CPU model */
48#define FIRST_US3_CPU 0x14
49
50/* The greatest ID (read from the VER register) of some US3 CPU model */
51#define LAST_US3_CPU 0x19
52
53/* UltraSPARC IIIi processor implementation code */
54#define US_IIIi_CODE 0x15
55
56#define OBP_BIAS 0x400000
57
58#define BALLOC_MAX_SIZE 131072
59
60#define TOP2ADDR(top) (((void *) KERNEL_ADDRESS) + (top))
61
62/** UltraSPARC architecture */
63static uint8_t arch;
64
65/** UltraSPARC subarchitecture */
66static uint8_t subarch;
67
68/** Mask of the MID field inside the ICBUS_CONFIG register
69 *
70 * Shifted by MID_SHIFT bits to the right
71 *
72 */
73static uint16_t mid_mask;
74
75static bootinfo_t bootinfo;
76
77/** Detect the UltraSPARC architecture
78 *
79 * Detection is done by inspecting the property called "compatible"
80 * in the OBP root node. Currently sun4u and sun4v are supported.
81 * Set global variable "arch" to the correct value.
82 *
83 */
84static void arch_detect(void)
85{
86 phandle root = ofw_find_device("/");
87 char compatible[OFW_TREE_PROPERTY_MAX_VALUELEN];
88
89 if (ofw_get_property(root, "compatible", compatible,
90 OFW_TREE_PROPERTY_MAX_VALUELEN) <= 0) {
91 printf("Warning: Unable to determine architecture, assuming sun4u.\n");
92 arch = ARCH_SUN4U;
93 return;
94 }
95
96 if (str_cmp(compatible, "sun4v") != 0) {
97 /*
98 * As not all sun4u machines have "sun4u" in their "compatible"
99 * OBP property (e.g. Serengeti's OBP "compatible" property is
100 * "SUNW,Serengeti"), we will by default fallback to sun4u if
101 * an unknown value of the "compatible" property is encountered.
102 */
103 printf("Warning: Unknown architecture, assuming sun4u.\n");
104 arch = ARCH_SUN4U;
105 } else
106 arch = ARCH_SUN4V;
107}
108
109
110/** Detect the subarchitecture (US, US3) of sun4u
111 *
112 * Set the global variables "subarch" and "mid_mask" to
113 * correct values.
114 *
115 */
116static void sun4u_subarch_detect(void)
117{
118 uint64_t ver;
119 asm volatile (
120 "rdpr %%ver, %[ver]\n"
121 : [ver] "=r" (ver)
122 );
123
124 ver = (ver << 16) >> 48;
125
126 if ((ver >= FIRST_US3_CPU) && (ver <= LAST_US3_CPU)) {
127 subarch = SUBARCH_US3;
128
129 if (ver == US_IIIi_CODE)
130 mid_mask = (1 << 5) - 1;
131 else
132 mid_mask = (1 << 10) - 1;
133
134 } else if (ver < FIRST_US3_CPU) {
135 subarch = SUBARCH_US;
136 mid_mask = (1 << 5) - 1;
137 } else {
138 printf("Warning: This CPU is not supported.");
139 subarch = SUBARCH_UNKNOWN;
140 }
141}
142
143/** Perform sun4u-specific SMP initialization.
144 *
145 */
146static void sun4u_smp(void)
147{
148#ifdef CONFIG_AP
149 printf("Checking for secondary processors ...\n");
150 ofw_cpu(mid_mask, bootinfo.physmem_start);
151#endif
152}
153
154/** Perform sun4v-specific fixups.
155 *
156 */
157static void sun4v_fixups(void)
158{
159 /*
160 * When SILO booted, the OBP had established a virtual to physical
161 * memory mapping. This mapping is not an identity since the
162 * physical memory starts at non-zero address.
163 *
164 * However, the mapping even does not map virtual address 0
165 * onto the starting address of the physical memory, but onto an
166 * address which is 0x400000 (OBP_BIAS) bytes higher.
167 *
168 * The reason is that the OBP had already used the memory just
169 * at the beginning of the physical memory. Thus that memory cannot
170 * be used by SILO (nor the bootloader).
171 *
172 * So far, we solve it by a nasty workaround:
173 *
174 * We pretend that the physical memory starts 0x400000 (OBP_BIAS)
175 * bytes further than it actually does (and hence pretend that the
176 * physical memory is 0x400000 bytes smaller). Of course, the value
177 * 0x400000 will most probably depend on the machine and OBP version
178 * (the workaround works on Simics).
179 *
180 * A proper solution would be to inspect the "available" property
181 * of the "/memory" node to find out which parts of memory
182 * are used by OBP and redesign the algorithm of copying
183 * kernel/init tasks/ramdisk from the bootable image to memory
184 * (which we must do anyway because of issues with claiming the memory
185 * on Serengeti).
186 *
187 */
188 bootinfo.physmem_start += OBP_BIAS;
189 bootinfo.memmap.zones[0].start += OBP_BIAS;
190 bootinfo.memmap.zones[0].size -= OBP_BIAS;
191}
192
193void bootstrap(void)
194{
195 version_print();
196
197 arch_detect();
198 if (arch == ARCH_SUN4U)
199 sun4u_subarch_detect();
200 else
201 subarch = SUBARCH_UNKNOWN;
202
203 bootinfo.physmem_start = ofw_get_physmem_start();
204 ofw_memmap(&bootinfo.memmap);
205
206 void *bootinfo_pa = ofw_translate(&bootinfo);
207 void *loader_address_pa = ofw_translate((void *) LOADER_ADDRESS);
208
209 printf("\nMemory statistics (total %llu MB, starting at %p)\n",
210 bootinfo.memmap.total >> 20, bootinfo.physmem_start);
211 printf(" %p|%p: boot info structure\n", &bootinfo, bootinfo_pa);
212 printf(" %p|%p: kernel entry point\n", KERNEL_ADDRESS, KERNEL_ADDRESS);
213 printf(" %p|%p: loader entry pount\n", LOADER_ADDRESS, loader_address_pa);
214
215 size_t i;
216 for (i = 0; i < COMPONENTS; i++)
217 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
218 ofw_translate(components[i].start), components[i].name,
219 components[i].inflated, components[i].size);
220
221 void *dest[COMPONENTS];
222 size_t top = KERNEL_ADDRESS;
223 size_t cnt = 0;
224 bootinfo.taskmap.cnt = 0;
225 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
226 top = ALIGN_UP(top, PAGE_SIZE);
227
228 if (i > 0) {
229 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
230 (void *) top;
231 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
232 components[i].inflated;
233
234 str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
235 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
236
237 bootinfo.taskmap.cnt++;
238 }
239
240 dest[i] = (void *) top;
241 top += components[i].inflated;
242 cnt++;
243 }
244
245 printf("\nInflating components ... ");
246
247 for (i = cnt; i > 0; i--) {
248 printf("%s ", components[i - 1].name);
249
250 /*
251 * At this point, we claim the physical memory that we are
252 * going to use. We should be safe in case of the virtual
253 * address space because the OpenFirmware, according to its
254 * SPARC binding, should restrict its use of virtual memory
255 * to addresses from [0xffd00000; 0xffefffff] and
256 * [0xfe000000; 0xfeffffff].
257 *
258 * We don't map this piece of memory. We simply rely on
259 * SILO to have it done for us already in this case.
260 *
261 * XXX SILO only maps 8 MB for us here. We should improve
262 * this code to be totally independent on the behavior
263 * of SILO.
264 *
265 */
266 ofw_claim_phys(bootinfo.physmem_start + dest[i - 1],
267 ALIGN_UP(components[i - 1].inflated, PAGE_SIZE));
268
269 int err = inflate(components[i - 1].start, components[i - 1].size,
270 dest[i - 1], components[i - 1].inflated);
271
272 if (err != EOK) {
273 printf("\n%s: Inflating error %d, halting.\n",
274 components[i - 1].name, err);
275 halt();
276 }
277 }
278
279 printf(".\n");
280
281 /*
282 * Claim and map the physical memory for the boot allocator.
283 * Initialize the boot allocator.
284 */
285 printf("Setting up boot allocator ...\n");
286 void *balloc_base = (void *) ALIGN_UP(top, PAGE_SIZE);
287 ofw_claim_phys(bootinfo.physmem_start + balloc_base, BALLOC_MAX_SIZE);
288 ofw_map(bootinfo.physmem_start + balloc_base, balloc_base,
289 BALLOC_MAX_SIZE, -1);
290 balloc_init(&bootinfo.ballocs, balloc_base, (uintptr_t) balloc_base,
291 BALLOC_MAX_SIZE);
292
293 printf("Setting up screens ...\n");
294 ofw_setup_screens();
295
296 printf("Canonizing OpenFirmware device tree ...\n");
297 bootinfo.ofw_root = ofw_tree_build();
298
299 if (arch == ARCH_SUN4U)
300 sun4u_smp();
301
302 if (arch == ARCH_SUN4V)
303 sun4v_fixups();
304
305 printf("Booting the kernel ...\n");
306 ofw_quiesce();
307 jump_to_kernel((void *) KERNEL_ADDRESS, &bootinfo, subarch,
308 bootinfo.physmem_start | BSP_PROCESSOR);
309}
Note: See TracBrowser for help on using the repository browser.