source: rtems/c/src/lib/libbsp/sparc64/shared/helenos/boot/sparc64/loader/main.c @ 566a1806

4.115
Last change on this file since 566a1806 was 566a1806, checked in by Joel Sherrill <joel.sherrill@…>, on 06/17/10 at 16:20:46

2010-06-17 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, Makefile.am, acinclude.m4, configure.ac, shared/asm/asm.S, shared/clock/ckinit.c, shared/console/conscfg.c, shared/helenos/LICENSE, shared/helenos/README, shared/helenos/boot/genarch/balloc.c, shared/helenos/boot/genarch/ofw.c, shared/helenos/boot/genarch/ofw_tree.c, shared/helenos/boot/generic/string.c, shared/helenos/boot/include/align.h, shared/helenos/boot/include/balloc.h, shared/helenos/boot/include/gentypes.h, shared/helenos/boot/include/main.h, shared/helenos/boot/include/ofw.h, shared/helenos/boot/include/ofw_tree.h, shared/helenos/boot/include/ofwarch.h, shared/helenos/boot/include/register.h, shared/helenos/boot/include/stack.h, shared/helenos/boot/include/types.h, shared/helenos/boot/sparc64/loader/main.c, shared/helenos/boot/sparc64/loader/ofwarch.c, shared/helenos/boot/sparc64/loader/ofwasm.S, shared/helenos/kernel/genarch/include/ofw/ofw_tree.h, shared/helenos/kernel/generic/include/align.h, shared/helenos/kernel/sparc64/include/arch.h, shared/helenos/kernel/sparc64/include/boot.h, shared/helenos/kernel/sparc64/include/regdef.h, shared/helenos/kernel/sparc64/include/stack.h, shared/helenos/kernel/sparc64/include/mm/cache_spec.h, shared/helenos/kernel/sparc64/include/mm/frame.h, shared/helenos/kernel/sparc64/include/mm/mmu.h, shared/helenos/kernel/sparc64/include/mm/page.h, shared/helenos/kernel/sparc64/include/mm/tlb.h, shared/helenos/kernel/sparc64/include/mm/tte.h, shared/helenos/kernel/sparc64/include/mm/sun4u/frame.h, shared/helenos/kernel/sparc64/include/mm/sun4u/mmu.h, shared/helenos/kernel/sparc64/include/mm/sun4u/page.h, shared/helenos/kernel/sparc64/include/mm/sun4u/tlb.h, shared/helenos/kernel/sparc64/include/mm/sun4u/tte.h, shared/helenos/kernel/sparc64/include/sun4u/arch.h, shared/helenos/kernel/sparc64/src/cache.S, shared/helenos/kernel/sparc64/src/sun4u/takemmu.S, shared/include/asm.h, shared/include/traptable.h, shared/start/start.S, shared/start/trap_table.S, shared/startup/bspgetworkarea.c, shared/startup/bspstart.c, shared/startup/linkcmds, shared/startup/setvec.c: New files.
  • Property mode set to 100644
File size: 12.7 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/*
31 * $Id$
32 *
33 * Modifications are made to switch to using printk rather than printf,
34 * and to remove portions of the HelenOS bootstrap process that are
35 * unnecessary on RTEMS.  The removed code is elided with #if 0 ... #endif
36 * blocks.
37 *
38 * Removes some header files. Adds back some missing defines.
39 */
40
41#define RTEMS
42
43#include <bsp.h>
44#include <rtems/bspIo.h>
45
46#include <boot/main.h>
47#include <boot/balloc.h>
48#include <boot/ofw.h>
49#include <boot/ofw_tree.h>
50#include <boot/ofwarch.h>
51#include <boot/align.h>
52
53#if 0
54#include "asm.h"
55#include <printf.h>
56#include "_components.h"
57#include <macros.h>
58#include <string.h>
59#include <memstr.h>
60#endif
61
62#include <asm.h>
63
64#define PAGE_WIDTH  14
65#define PAGE_SIZE   (1 << PAGE_WIDTH)
66
67static bootinfo_t bootinfo;
68#if 0
69static component_t components[COMPONENTS];
70static char *release = STRING(RELEASE);
71
72#ifdef REVISION
73        static char *revision = ", revision " STRING(REVISION);
74#else
75        static char *revision = "";
76#endif
77
78#ifdef TIMESTAMP
79        static char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
80#else
81        static char *timestamp = "";
82#endif
83#endif
84
85#if 0
86/** UltraSPARC subarchitecture - 1 for US, 3 for US3, 0 for other */
87static uint8_t subarchitecture = 0;
88#endif
89
90#if 0
91/**
92 * mask of the MID field inside the ICBUS_CONFIG register shifted by
93 * MID_SHIFT bits to the right
94 */
95static uint16_t mid_mask;
96#endif
97
98#if 0
99/** Print version information. */
100static void version_print(void)
101{
102        printk("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n"
103            "Copyright (c) 2006 HelenOS project\n",
104            release, revision, timestamp);
105}
106#endif
107
108/* the lowest ID (read from the VER register) of some US3 CPU model */
109#define FIRST_US3_CPU  0x14
110
111/* the greatest ID (read from the VER register) of some US3 CPU model */
112#define LAST_US3_CPU   0x19
113
114/* UltraSPARC IIIi processor implementation code */
115#define US_IIIi_CODE   0x15
116
117/* max. length of the "compatible" property of the root node */
118#define COMPATIBLE_PROP_MAXLEN  64
119
120/*
121 * HelenOS bootloader will use these constants to distinguish particular
122 * UltraSPARC architectures
123 */
124#define COMPATIBLE_SUN4U        10
125#define COMPATIBLE_SUN4V        20
126
127/** US architecture. COMPATIBLE_SUN4U for sun4v, COMPATIBLE_SUN4V for sun4u */
128static uint8_t architecture;
129
130/**
131 * Detects the UltraSPARC architecture (sun4u and sun4v currently supported)
132 * by inspecting the property called "compatible" in the OBP root node.
133 */
134static void detect_architecture(void)
135{
136        phandle root = ofw_find_device("/");
137        char compatible[COMPATIBLE_PROP_MAXLEN];
138
139        if (ofw_get_property(root, "compatible", compatible,
140                        COMPATIBLE_PROP_MAXLEN) <= 0) {
141                printk("Unable to determine architecture, default: sun4u.\n");
142                architecture = COMPATIBLE_SUN4U;
143                return;
144        }
145
146        if (strcmp(compatible, "sun4v") == 0) {
147                architecture = COMPATIBLE_SUN4V;
148        } else {
149                /*
150                 * As not all sun4u machines have "sun4u" in their "compatible"
151                 * OBP property (e.g. Serengeti's OBP "compatible" property is
152                 * "SUNW,Serengeti"), we will by default fallback to sun4u if
153                 * an unknown value of the "compatible" property is encountered.
154                 */
155                architecture = COMPATIBLE_SUN4U;
156        }
157}
158
159#if 0
160/**
161 * Detects the subarchitecture (US, US3) of the sun4u
162 * processor. Sets the global variables "subarchitecture" and "mid_mask" to
163 * correct values.
164 */
165static void detect_subarchitecture(void)
166{
167        uint64_t v;
168        asm volatile (
169                "rdpr %%ver, %0\n"
170                : "=r" (v)
171        );
172       
173        v = (v << 16) >> 48;
174        if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) {
175                subarchitecture = SUBARCH_US3;
176                if (v == US_IIIi_CODE)
177                        mid_mask = (1 << 5) - 1;
178                else
179                        mid_mask = (1 << 10) - 1;
180        } else if (v < FIRST_US3_CPU) {
181                subarchitecture = SUBARCH_US;
182                mid_mask = (1 << 5) - 1;
183        } else
184                printk("\nThis CPU is not supported by HelenOS.");
185}
186#endif
187
188#if 0
189/**
190 * Performs sun4u-specific initialization. The components are expected
191 * to be already copied and boot allocator initialized.
192 *
193 * @param base  kernel base virtual address
194 * @param top   virtual address above which the boot allocator
195 *              can make allocations
196 */
197static void bootstrap_sun4u(void *base, unsigned int top)
198{
199        void *balloc_base;
200        /*
201         * Claim and map the physical memory for the boot allocator.
202         * Initialize the boot allocator.
203         */
204        balloc_base = base + ALIGN_UP(top, PAGE_SIZE);
205        (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base,
206            BALLOC_MAX_SIZE);
207        (void) ofw_map(bootinfo.physmem_start + balloc_base, balloc_base,
208            BALLOC_MAX_SIZE, -1);
209        balloc_init(&bootinfo.ballocs, (uintptr_t) balloc_base,
210            (uintptr_t) balloc_base);
211#if 0   
212        printf("Setting up screens...");
213        ofw_setup_screens();
214        printf("done.\n");
215#endif
216#if 0
217        printf("Canonizing OpenFirmware device tree...");
218#endif
219        bootinfo.ofw_root = ofw_tree_build();
220#if 0
221        printf("done.\n");
222#endif
223#if 0
224#ifdef CONFIG_AP
225        printf("Checking for secondary processors...");
226        if (!ofw_cpu(mid_mask, bootinfo.physmem_start))
227                printf("Error: unable to get CPU properties\n");
228        printf("done.\n");
229#endif
230#endif
231}
232#endif
233
234#if 0
235/**
236 *  * Performs sun4v-specific initialization. The components are expected
237 *   * to be already copied and boot allocator initialized.
238 *    */
239static void bootstrap_sun4v(void)
240{
241        /*
242         * When SILO booted, the OBP had established a virtual to physical
243         * memory mapping. This mapping is not an identity (because the
244         * physical memory starts on non-zero address) - this is not
245         * surprising. But! The mapping even does not map virtual address
246         * 0 onto the starting address of the physical memory, but onto an
247         * address which is 0x400000 bytes higher. The reason is that the
248         * OBP had already used the memory just at the beginning of the
249         * physical memory, so that memory cannot be used by SILO (nor
250         * bootloader). As for now, we solve it by a nasty workaround:
251         * we pretend that the physical memory starts 0x400000 bytes further
252         * than it actually does (and hence pretend that the physical memory
253         * is 0x400000 bytes smaller). Of course, the value 0x400000 will most
254         * probably depend on the machine and OBP version (the workaround now
255         * works on Simics). A solution would be to inspect the "available"
256         * property of the "/memory" node to find out which parts of memory
257         * are used by OBP and redesign the algorithm of copying
258         * kernel/init tasks/ramdisk from the bootable image to memory
259         * (which we must do anyway because of issues with claiming the memory
260         * on Serengeti).
261         */
262        bootinfo.physmem_start += 0x400000;
263        bootinfo.memmap.zones[0].start += 0x400000;
264        bootinfo.memmap.zones[0].size -= 0x400000;
265#if 0
266        printf("The sun4v init finished.");
267#endif
268}
269#endif
270
271void bootstrap(void)
272{
273#if 0
274        void *base = (void *) KERNEL_VIRTUAL_ADDRESS;
275        unsigned int top = 0;
276        unsigned int i;
277        unsigned int j;
278#endif
279
280  detect_architecture();
281#if 0
282        init_components(components);
283#endif
284       
285        if (!ofw_get_physmem_start(&bootinfo.physmem_start)) {
286                printk("Error: unable to get start of physical memory.\n");
287                halt();
288        }
289       
290        if (!ofw_memmap(&bootinfo.memmap)) {
291                printk("Error: unable to get memory map, halting.\n");
292                halt();
293        }
294       
295        if (bootinfo.memmap.total == 0) {
296                printk("Error: no memory detected, halting.\n");
297                halt();
298        }
299       
300        /*
301         * SILO for some reason adds 0x400000 and subtracts
302         * bootinfo.physmem_start to/from silo_ramdisk_image.
303         * We just need plain physical address so we fix it up.
304         */
305        if (silo_ramdisk_image) {
306                silo_ramdisk_image += bootinfo.physmem_start;
307                silo_ramdisk_image -= 0x400000;
308               
309                /* Install 1:1 mapping for the RAM disk. */
310                if (ofw_map((void *) ((uintptr_t) silo_ramdisk_image),
311                    (void *) ((uintptr_t) silo_ramdisk_image),
312                    silo_ramdisk_size, -1) != 0) {
313                        printk("Failed to map RAM disk.\n");
314                        halt();
315                }
316        }
317       
318  printk("\nMemory statistics (total %d MB, starting at %x)\n",
319            bootinfo.memmap.total >> 20, bootinfo.physmem_start);
320        printk(" %x: kernel entry point\n", KERNEL_VIRTUAL_ADDRESS);
321        printk(" %x: boot info structure\n", &bootinfo);
322
323#if 0
324        /*
325         * Figure out destination address for each component.
326         * In this phase, we don't copy the components yet because we want to
327         * to be careful not to overwrite anything, especially the components
328         * which haven't been copied yet.
329         */
330        bootinfo.taskmap.count = 0;
331        for (i = 0; i < COMPONENTS; i++) {
332                printf(" %P: %s image (size %d bytes)\n", components[i].start,
333                    components[i].name, components[i].size);
334                top = ALIGN_UP(top, PAGE_SIZE);
335                if (i > 0) {
336                        if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
337                                printf("Skipping superfluous components.\n");
338                                break;
339                        }
340                       
341                        bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
342                            base + top;
343                        bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
344                            components[i].size;
345                        strncpy(bootinfo.taskmap.tasks[
346                            bootinfo.taskmap.count].name, components[i].name,
347                            BOOTINFO_TASK_NAME_BUFLEN);
348                        bootinfo.taskmap.count++;
349                }
350                top += components[i].size;
351        }
352       
353        printf("\n");
354
355        /* Do not consider RAM disk */
356        j = bootinfo.taskmap.count - 1;
357       
358        if (silo_ramdisk_image) {
359                /* Treat the RAM disk as the last bootinfo task. */
360                if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
361                        printf("Skipping RAM disk.\n");
362                        goto skip_ramdisk;
363                }
364               
365                top = ALIGN_UP(top, PAGE_SIZE);
366                bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
367                    base + top;
368                bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
369                    silo_ramdisk_size;
370                bootinfo.taskmap.count++;
371                printf("Copying RAM disk...");
372               
373                /*
374                 * Claim and map the whole ramdisk as it may exceed the area
375                 * given to us by SILO.
376                 */
377                (void) ofw_claim_phys(base + top, silo_ramdisk_size);
378                (void) ofw_map(bootinfo.physmem_start + base + top, base + top,
379                    silo_ramdisk_size, -1);
380                memmove(base + top, (void *) ((uintptr_t) silo_ramdisk_image),
381                    silo_ramdisk_size);
382               
383                printf("done.\n");
384                top += silo_ramdisk_size;
385        }
386skip_ramdisk:
387       
388        /*
389         * Now we can proceed to copy the components. We do it in reverse order
390         * so that we don't overwrite anything even if the components overlap
391         * with base.
392         */
393        printf("Copying tasks...");
394        for (i = COMPONENTS - 1; i > 0; i--, j--) {
395                printf("%s ", components[i].name);
396               
397                /*
398                 * At this point, we claim the physical memory that we are
399                 * going to use. We should be safe in case of the virtual
400                 * address space because the OpenFirmware, according to its
401                 * SPARC binding, should restrict its use of virtual memory
402                 * to addresses from [0xffd00000; 0xffefffff] and
403                 * [0xfe000000; 0xfeffffff].
404                 *
405                 * XXX We don't map this piece of memory. We simply rely on
406                 *     SILO to have it done for us already in this case.
407                 */
408                (void) ofw_claim_phys(bootinfo.physmem_start +
409                    bootinfo.taskmap.tasks[j].addr,
410                    ALIGN_UP(components[i].size, PAGE_SIZE));
411               
412                memcpy((void *) bootinfo.taskmap.tasks[j].addr,
413                    components[i].start, components[i].size);
414               
415        }
416        printf(".\n");
417       
418        printf("Copying kernel...");
419        (void) ofw_claim_phys(bootinfo.physmem_start + base,
420            ALIGN_UP(components[0].size, PAGE_SIZE));
421        memcpy(base, components[0].start, components[0].size);
422        printf("done.\n");
423       
424        /* perform architecture-specific initialization */
425        if (architecture == COMPATIBLE_SUN4U) {
426                bootstrap_sun4u(base, top);
427        } else if (architecture == COMPATIBLE_SUN4V) {
428                bootstrap_sun4v();
429        } else {
430                printf("Unknown architecture.\n");
431                halt();
432        }
433       
434        printf("Booting the kernel...\n");
435        jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS,
436            bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo,
437            sizeof(bootinfo), subarchitecture);
438#endif
439}
Note: See TracBrowser for help on using the repository browser.