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

5
Last change on this file since 5e899b5 was 5e899b5, checked in by Joel Sherrill <joel@…>, on 04/24/17 at 01:35:05

sparc64/shared/helenos/boot/sparc64/loader/main.c: Fix printf() format warning

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