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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f7734012 was f7734012, checked in by Jiri Svoboda <jirik.svoboda@…>, 17 years ago

Init-task names for sparc64 (that's the final one, whew).

  • Property mode set to 100644
File size: 8.4 KB
RevLine 
[b7b5f83]1/*
[df4ed85]2 * Copyright (c) 2005 Martin Decky
3 * Copyright (c) 2006 Jakub Jermar
[b7b5f83]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"
[61e90dd]34#include <balloc.h>
[822b64e]35#include <ofw.h>
[61e90dd]36#include <ofw_tree.h>
[b4fa652]37#include "ofwarch.h"
[63cda71]38#include <align.h>
[fa024ce]39#include <macros.h>
[dac629e]40#include <string.h>
[b7b5f83]41
[822b64e]42bootinfo_t bootinfo;
[965dc18]43
[1b43a04]44component_t components[COMPONENTS];
[822b64e]45
[fa024ce]46char *release = STRING(RELEASE);
[aca95f6b]47
48#ifdef REVISION
[fa024ce]49 char *revision = ", revision " STRING(REVISION);
[aca95f6b]50#else
51 char *revision = "";
52#endif
53
54#ifdef TIMESTAMP
[fa024ce]55 char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
[aca95f6b]56#else
57 char *timestamp = "";
58#endif
59
[965dc18]60/** UltraSPARC subarchitecture - 1 for US, 3 for US3 */
61uint8_t subarchitecture;
62
63/**
64 * mask of the MID field inside the ICBUS_CONFIG register shifted by
65 * MID_SHIFT bits to the right
66 */
67uint16_t mid_mask;
68
[aca95f6b]69/** Print version information. */
70static void version_print(void)
71{
[a9ddab2]72 printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n"
73 "Copyright (c) 2006 HelenOS project\n",
74 release, revision, timestamp);
[aca95f6b]75}
76
[965dc18]77/* the lowest ID (read from the VER register) of some US3 CPU model */
78#define FIRST_US3_CPU 0x14
79
80/* the greatest ID (read from the VER register) of some US3 CPU model */
81#define LAST_US3_CPU 0x19
82
83/* UltraSPARC IIIi processor implementation code */
84#define US_IIIi_CODE 0x15
85
86/**
87 * Sets the global variables "subarchitecture" and "mid_mask" to
88 * correct values.
89 */
90static void detect_subarchitecture(void)
91{
92 uint64_t v;
93 asm volatile ("rdpr %%ver, %0\n" : "=r" (v));
94
95 v = (v << 16) >> 48;
96 if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) {
97 subarchitecture = SUBARCH_US3;
98 if (v == US_IIIi_CODE)
99 mid_mask = (1 << 5) - 1;
100 else
101 mid_mask = (1 << 10) - 1;
102 } else if (v < FIRST_US3_CPU) {
103 subarchitecture = SUBARCH_US;
104 mid_mask = (1 << 5) - 1;
105 } else {
106 printf("\nThis CPU is not supported by HelenOS.");
107 }
108}
109
[b7b5f83]110void bootstrap(void)
111{
[27518e4]112 void *base = (void *) KERNEL_VIRTUAL_ADDRESS;
113 void *balloc_base;
114 unsigned int top = 0;
115 int i, j;
116
[aca95f6b]117 version_print();
[1b43a04]118
[965dc18]119 detect_subarchitecture();
[b7b5f83]120 init_components(components);
[822b64e]121
[f2ea5d8]122 if (!ofw_get_physmem_start(&bootinfo.physmem_start)) {
123 printf("Error: unable to get start of physical memory.\n");
124 halt();
125 }
126
[63cda71]127 if (!ofw_memmap(&bootinfo.memmap)) {
128 printf("Error: unable to get memory map, halting.\n");
129 halt();
130 }
[965dc18]131
[63cda71]132 if (bootinfo.memmap.total == 0) {
133 printf("Error: no memory detected, halting.\n");
134 halt();
135 }
[a9ddab2]136
137 /*
138 * SILO for some reason adds 0x400000 and subtracts
139 * bootinfo.physmem_start to/from silo_ramdisk_image.
140 * We just need plain physical address so we fix it up.
141 */
142 if (silo_ramdisk_image) {
143 silo_ramdisk_image += bootinfo.physmem_start;
144 silo_ramdisk_image -= 0x400000;
[27518e4]145 /* Install 1:1 mapping for the ramdisk. */
[6196dae]146 if (ofw_map((void *)((uintptr_t) silo_ramdisk_image),
147 (void *)((uintptr_t) silo_ramdisk_image),
[27518e4]148 silo_ramdisk_size, -1) != 0) {
149 printf("Failed to map ramdisk.\n");
150 halt();
151 }
[a9ddab2]152 }
[63cda71]153
[45b26dad]154 printf("\nSystem info\n");
[f2ea5d8]155 printf(" memory: %dM starting at %P\n",
[a9ddab2]156 bootinfo.memmap.total >> 20, bootinfo.physmem_start);
[63cda71]157
[b7b5f83]158 printf("\nMemory statistics\n");
[63cda71]159 printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS);
160 printf(" %P: boot info structure\n", &bootinfo);
[b7b5f83]161
[27518e4]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++) {
[f2ea5d8]170 printf(" %P: %s image (size %d bytes)\n", components[i].start,
[95b47c82]171 components[i].name, components[i].size);
[27518e4]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 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
179 base + top;
180 bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
181 components[i].size;
[f7734012]182 strncpy(bootinfo.taskmap.tasks[
183 bootinfo.taskmap.count].name, components[i].name,
184 BOOTINFO_TASK_NAME_BUFLEN);
[27518e4]185 bootinfo.taskmap.count++;
186 }
187 top += components[i].size;
188 }
[822b64e]189
[27518e4]190 j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */
[61e90dd]191
[27518e4]192 if (silo_ramdisk_image) {
193 /* Treat the ramdisk as the last bootinfo task. */
194 if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
195 printf("Skipping ramdisk.\n");
196 goto skip_ramdisk;
197 }
[b7b5f83]198 top = ALIGN_UP(top, PAGE_SIZE);
[27518e4]199 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
200 base + top;
201 bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
202 silo_ramdisk_size;
203 bootinfo.taskmap.count++;
204 printf("\nCopying ramdisk...");
205 /*
206 * Claim and map the whole ramdisk as it may exceed the area
207 * given to us by SILO.
208 */
209 (void) ofw_claim_phys(base + top, silo_ramdisk_size);
[6196dae]210 (void) ofw_map(bootinfo.physmem_start + base + top, base + top,
211 silo_ramdisk_size, -1);
[dac629e]212 memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image),
[27518e4]213 silo_ramdisk_size);
214 printf("done.\n");
215 top += silo_ramdisk_size;
216 }
217skip_ramdisk:
218
219 /*
220 * Now we can proceed to copy the components. We do it in reverse order
221 * so that we don't overwrite anything even if the components overlap
222 * with base.
223 */
224 printf("\nCopying bootinfo tasks\n");
225 for (i = COMPONENTS - 1; i > 0; i--, j--) {
226 printf(" %s...", components[i].name);
[95b47c82]227
228 /*
229 * At this point, we claim the physical memory that we are
230 * going to use. We should be safe in case of the virtual
231 * address space because the OpenFirmware, according to its
232 * SPARC binding, should restrict its use of virtual memory
233 * to addresses from [0xffd00000; 0xffefffff] and
234 * [0xfe000000; 0xfeffffff].
[27518e4]235 *
236 * XXX We don't map this piece of memory. We simply rely on
237 * SILO to have it done for us already in this case.
[95b47c82]238 */
[27518e4]239 (void) ofw_claim_phys(bootinfo.physmem_start +
240 bootinfo.taskmap.tasks[j].addr,
[95b47c82]241 ALIGN_UP(components[i].size, PAGE_SIZE));
242
[27518e4]243 memcpy((void *)bootinfo.taskmap.tasks[j].addr,
244 components[i].start, components[i].size);
[b7b5f83]245 printf("done.\n");
246 }
[822b64e]247
[27518e4]248 printf("\nCopying kernel...");
249 (void) ofw_claim_phys(bootinfo.physmem_start + base,
250 ALIGN_UP(components[0].size, PAGE_SIZE));
251 memcpy(base, components[0].start, components[0].size);
252 printf("done.\n");
253
[95b47c82]254 /*
[27518e4]255 * Claim and map the physical memory for the boot allocator.
[95b47c82]256 * Initialize the boot allocator.
257 */
[27518e4]258 balloc_base = base + ALIGN_UP(top, PAGE_SIZE);
259 (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base,
260 BALLOC_MAX_SIZE);
[6196dae]261 (void) ofw_map(bootinfo.physmem_start + balloc_base, balloc_base,
262 BALLOC_MAX_SIZE, -1);
[27518e4]263 balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base);
[61e90dd]264
265 printf("\nCanonizing OpenFirmware device tree...");
266 bootinfo.ofw_root = ofw_tree_build();
267 printf("done.\n");
268
[48c3d50]269#ifdef CONFIG_AP
[45b26dad]270 printf("\nChecking for secondary processors...");
271 if (!ofw_cpu())
[f2ea5d8]272 printf("Error: unable to get CPU properties\n");
[45b26dad]273 printf("done.\n");
[f18cc64]274#endif
[45b26dad]275
[fd375a8d]276 ofw_setup_palette();
[2b1f860]277
[b7b5f83]278 printf("\nBooting the kernel...\n");
[f2ea5d8]279 jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS,
[95b47c82]280 bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo,
281 sizeof(bootinfo));
[b7b5f83]282}
Note: See TracBrowser for help on using the repository browser.