source: mainline/boot/arch/sparc64/loader/main.c@ 21d8020

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

make ppc32 OFW usage on par with sparc64, make appropriate modifications elsewhere

  • introduce ofw_tree_walk_by_device_type() to gather all OFW devices of a given type
  • ppc32 uses canonized OFW tree, mac-io and display devices are detected in kernel (not by the boot loader) by means of device type
  • various busses (PCI, EBUS, etc.) stay sparc64 specific for now
  • boot memcpy() is defined in a common way
  • BALLOC_MAX_SIZE is platform-dependent
  • ppc32 and sparc64 boot loaders cleanup (removal of obsolete stuff, data is not passed by global variables if not necessary, etc.)
  • balloc and OFW tree canonizer have now a provision to support different mapping of the data during boot time and kernel run-time
  • OFW tree canonizer uses balloc_rebase() to store pointers suitable for access during kernel run-time (with potentially different memory mapping than during boot time)
  • Property mode set to 100644
File size: 8.5 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 "main.h"
31#include <printf.h>
32#include "asm.h"
33#include "_components.h"
34#include <balloc.h>
35#include <ofw.h>
36#include <ofw_tree.h>
37#include "ofwarch.h"
38#include <align.h>
39#include <macros.h>
40#include <string.h>
41#include <memstr.h>
42
43static bootinfo_t bootinfo;
44static component_t components[COMPONENTS];
45static char *release = STRING(RELEASE);
46
47#ifdef REVISION
48 static char *revision = ", revision " STRING(REVISION);
49#else
50 static char *revision = "";
51#endif
52
53#ifdef TIMESTAMP
54 static char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
55#else
56 static char *timestamp = "";
57#endif
58
59/** UltraSPARC subarchitecture - 1 for US, 3 for US3 */
60static uint8_t subarchitecture;
61
62/**
63 * mask of the MID field inside the ICBUS_CONFIG register shifted by
64 * MID_SHIFT bits to the right
65 */
66static uint16_t mid_mask;
67
68/** Print version information. */
69static void version_print(void)
70{
71 printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n"
72 "Copyright (c) 2006 HelenOS project\n",
73 release, revision, timestamp);
74}
75
76/* the lowest ID (read from the VER register) of some US3 CPU model */
77#define FIRST_US3_CPU 0x14
78
79/* the greatest ID (read from the VER register) of some US3 CPU model */
80#define LAST_US3_CPU 0x19
81
82/* UltraSPARC IIIi processor implementation code */
83#define US_IIIi_CODE 0x15
84
85/**
86 * Sets the global variables "subarchitecture" and "mid_mask" to
87 * correct values.
88 */
89static void detect_subarchitecture(void)
90{
91 uint64_t v;
92 asm volatile (
93 "rdpr %%ver, %0\n"
94 : "=r" (v)
95 );
96
97 v = (v << 16) >> 48;
98 if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) {
99 subarchitecture = SUBARCH_US3;
100 if (v == US_IIIi_CODE)
101 mid_mask = (1 << 5) - 1;
102 else
103 mid_mask = (1 << 10) - 1;
104 } else if (v < FIRST_US3_CPU) {
105 subarchitecture = SUBARCH_US;
106 mid_mask = (1 << 5) - 1;
107 } else
108 printf("\nThis CPU is not supported by HelenOS.");
109}
110
111void bootstrap(void)
112{
113 void *base = (void *) KERNEL_VIRTUAL_ADDRESS;
114 void *balloc_base;
115 unsigned int top = 0;
116 unsigned int i;
117 unsigned int j;
118
119 version_print();
120
121 detect_subarchitecture();
122 init_components(components);
123
124 if (!ofw_get_physmem_start(&bootinfo.physmem_start)) {
125 printf("Error: unable to get start of physical memory.\n");
126 halt();
127 }
128
129 if (!ofw_memmap(&bootinfo.memmap)) {
130 printf("Error: unable to get memory map, halting.\n");
131 halt();
132 }
133
134 if (bootinfo.memmap.total == 0) {
135 printf("Error: no memory detected, halting.\n");
136 halt();
137 }
138
139 /*
140 * SILO for some reason adds 0x400000 and subtracts
141 * bootinfo.physmem_start to/from silo_ramdisk_image.
142 * We just need plain physical address so we fix it up.
143 */
144 if (silo_ramdisk_image) {
145 silo_ramdisk_image += bootinfo.physmem_start;
146 silo_ramdisk_image -= 0x400000;
147
148 /* Install 1:1 mapping for the RAM disk. */
149 if (ofw_map((void *) ((uintptr_t) silo_ramdisk_image),
150 (void *) ((uintptr_t) silo_ramdisk_image),
151 silo_ramdisk_size, -1) != 0) {
152 printf("Failed to map RAM disk.\n");
153 halt();
154 }
155 }
156
157 printf("\nMemory statistics (total %d MB, starting at %P)\n",
158 bootinfo.memmap.total >> 20, bootinfo.physmem_start);
159 printf(" %P: kernel entry point\n", KERNEL_VIRTUAL_ADDRESS);
160 printf(" %P: boot info structure\n", &bootinfo);
161
162 /*
163 * Figure out destination address for each component.
164 * In this phase, we don't copy the components yet because we want to
165 * to be careful not to overwrite anything, especially the components
166 * which haven't been copied yet.
167 */
168 bootinfo.taskmap.count = 0;
169 for (i = 0; i < COMPONENTS; i++) {
170 printf(" %P: %s image (size %d bytes)\n", components[i].start,
171 components[i].name, components[i].size);
172 top = ALIGN_UP(top, PAGE_SIZE);
173 if (i > 0) {
174 if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
175 printf("Skipping superfluous components.\n");
176 break;
177 }
178
179 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
180 base + top;
181 bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
182 components[i].size;
183 strncpy(bootinfo.taskmap.tasks[
184 bootinfo.taskmap.count].name, components[i].name,
185 BOOTINFO_TASK_NAME_BUFLEN);
186 bootinfo.taskmap.count++;
187 }
188 top += components[i].size;
189 }
190
191 /* Do not consider RAM disk */
192 j = bootinfo.taskmap.count - 1;
193
194 if (silo_ramdisk_image) {
195 /* Treat the RAM disk as the last bootinfo task. */
196 if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
197 printf("Skipping RAM disk.\n");
198 goto skip_ramdisk;
199 }
200
201 top = ALIGN_UP(top, PAGE_SIZE);
202 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
203 base + top;
204 bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
205 silo_ramdisk_size;
206 bootinfo.taskmap.count++;
207 printf("\nCopying RAM disk...");
208
209 /*
210 * Claim and map the whole ramdisk as it may exceed the area
211 * given to us by SILO.
212 */
213 (void) ofw_claim_phys(base + top, silo_ramdisk_size);
214 (void) ofw_map(bootinfo.physmem_start + base + top, base + top,
215 silo_ramdisk_size, -1);
216 memmove(base + top, (void *) ((uintptr_t) silo_ramdisk_image),
217 silo_ramdisk_size);
218
219 printf("done.\n");
220 top += silo_ramdisk_size;
221 }
222skip_ramdisk:
223
224 /*
225 * Now we can proceed to copy the components. We do it in reverse order
226 * so that we don't overwrite anything even if the components overlap
227 * with base.
228 */
229 printf("\nCopying tasks...");
230 for (i = COMPONENTS - 1; i > 0; i--, j--) {
231 printf("%s ", components[i].name);
232
233 /*
234 * At this point, we claim the physical memory that we are
235 * going to use. We should be safe in case of the virtual
236 * address space because the OpenFirmware, according to its
237 * SPARC binding, should restrict its use of virtual memory
238 * to addresses from [0xffd00000; 0xffefffff] and
239 * [0xfe000000; 0xfeffffff].
240 *
241 * XXX We don't map this piece of memory. We simply rely on
242 * SILO to have it done for us already in this case.
243 */
244 (void) ofw_claim_phys(bootinfo.physmem_start +
245 bootinfo.taskmap.tasks[j].addr,
246 ALIGN_UP(components[i].size, PAGE_SIZE));
247
248 memcpy((void *) bootinfo.taskmap.tasks[j].addr,
249 components[i].start, components[i].size);
250
251 }
252 printf(".\n");
253
254 printf("\nCopying kernel...");
255 (void) ofw_claim_phys(bootinfo.physmem_start + base,
256 ALIGN_UP(components[0].size, PAGE_SIZE));
257 memcpy(base, components[0].start, components[0].size);
258 printf("done.\n");
259
260 /*
261 * Claim and map the physical memory for the boot allocator.
262 * Initialize the boot allocator.
263 */
264 balloc_base = base + ALIGN_UP(top, PAGE_SIZE);
265 (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base,
266 BALLOC_MAX_SIZE);
267 (void) ofw_map(bootinfo.physmem_start + balloc_base, balloc_base,
268 BALLOC_MAX_SIZE, -1);
269 balloc_init(&bootinfo.ballocs, (uintptr_t) balloc_base,
270 (uintptr_t) balloc_base);
271
272 printf("\nCanonizing OpenFirmware device tree...");
273 bootinfo.ofw_root = ofw_tree_build();
274 printf("done.\n");
275
276#ifdef CONFIG_AP
277 printf("\nChecking for secondary processors...");
278 if (!ofw_cpu(mid_mask, bootinfo.physmem_start))
279 printf("Error: unable to get CPU properties\n");
280 printf("done.\n");
281#endif
282
283 ofw_setup_palette();
284
285 printf("\nBooting the kernel...\n");
286 jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS,
287 bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo,
288 sizeof(bootinfo), subarchitecture);
289}
Note: See TracBrowser for help on using the repository browser.