source: mainline/boot/arch/ppc32/loader/main.c@ 177e4ea

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

initialize and setup all displays which can be detected in OFW tree (not only stdin)
reduce the number of newlines during boot (speedups especially in simulators)

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <printf.h>
30#include <ofw.h>
31#include <align.h>
32#include <macros.h>
33#include <string.h>
34#include "main.h"
35#include "asm.h"
36#include "_components.h"
37
38static bootinfo_t bootinfo;
39static component_t components[COMPONENTS];
40static char *release = STRING(RELEASE);
41
42#ifdef REVISION
43 static char *revision = ", revision " STRING(REVISION);
44#else
45 static char *revision = "";
46#endif
47
48#ifdef TIMESTAMP
49 static char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
50#else
51 static char *timestamp = "";
52#endif
53
54/** Print version information. */
55static void version_print(void)
56{
57 printf("HelenOS PPC32 Bootloader\nRelease %s%s%s\n"
58 "Copyright (c) 2006 HelenOS project\n\n",
59 release, revision, timestamp);
60}
61
62static void check_align(const void *addr, const char *desc)
63{
64 if ((uintptr_t) addr % PAGE_SIZE != 0) {
65 printf("Error: %s not on page boundary, halting.\n", desc);
66 halt();
67 }
68}
69
70static void check_overlap(const void *pa, const char *desc, const uintptr_t top)
71{
72 if ((uintptr_t) pa + PAGE_SIZE < top) {
73 printf("Error: %s overlaps destination physical area\n", desc);
74 halt();
75 }
76}
77
78void bootstrap(void)
79{
80 version_print();
81 init_components(components);
82
83 if (!ofw_memmap(&bootinfo.memmap)) {
84 printf("Error: Unable to get memory map, halting.\n");
85 halt();
86 }
87
88 if (bootinfo.memmap.total == 0) {
89 printf("Error: No memory detected, halting.\n");
90 halt();
91 }
92
93 check_align(&real_mode, "bootstrap trampoline");
94 check_align(trans, "translation table");
95 check_align(balloc_base, "boot allocations");
96
97 unsigned int i;
98 for (i = 0; i < COMPONENTS; i++)
99 check_align(components[i].start, components[i].name);
100
101 void *bootinfo_pa = ofw_translate(&bootinfo);
102 void *real_mode_pa = ofw_translate(&real_mode);
103 void *trans_pa = ofw_translate(trans);
104 void *balloc_base_pa = ofw_translate(balloc_base);
105
106 printf("Memory statistics (total %d MB)\n", bootinfo.memmap.total >> 20);
107 printf(" %L: boot info structure (physical %L)\n", &bootinfo, bootinfo_pa);
108 printf(" %L: bootstrap trampoline (physical %L)\n", &real_mode, real_mode_pa);
109 printf(" %L: translation table (physical %L)\n", trans, trans_pa);
110 printf(" %L: boot allocations (physical %L)\n", balloc_base, balloc_base_pa);
111 for (i = 0; i < COMPONENTS; i++)
112 printf(" %L: %s image (size %d bytes)\n", components[i].start, components[i].name, components[i].size);
113
114 uintptr_t top = 0;
115 for (i = 0; i < COMPONENTS; i++)
116 top += ALIGN_UP(components[i].size, PAGE_SIZE);
117 top += ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE);
118
119 if (top >= TRANS_SIZE * PAGE_SIZE) {
120 printf("Error: boot image is too large\n");
121 halt();
122 }
123
124 check_overlap(bootinfo_pa, "boot info", top);
125 check_overlap(real_mode_pa, "bootstrap trampoline", top);
126 check_overlap(trans_pa, "translation table", top);
127
128 unsigned int pages = ALIGN_UP(KERNEL_SIZE, PAGE_SIZE) >> PAGE_WIDTH;
129
130 for (i = 0; i < pages; i++) {
131 void *pa = ofw_translate(KERNEL_START + (i << PAGE_WIDTH));
132 check_overlap(pa, "kernel", top);
133 trans[i] = (uintptr_t) pa;
134 }
135
136 bootinfo.taskmap.count = 0;
137 for (i = 1; i < COMPONENTS; i++) {
138 if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
139 printf("\nSkipping superfluous components.\n");
140 break;
141 }
142
143 unsigned int component_pages = ALIGN_UP(components[i].size, PAGE_SIZE) >> PAGE_WIDTH;
144 unsigned int j;
145
146 for (j = 0; j < component_pages; j++) {
147 void *pa = ofw_translate(components[i].start + (j << PAGE_WIDTH));
148 check_overlap(pa, components[i].name, top);
149 trans[pages + j] = (uintptr_t) pa;
150 if (j == 0) {
151
152 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) PA2KA(pages << PAGE_WIDTH);
153 bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = components[i].size;
154 strncpy(bootinfo.taskmap.tasks[bootinfo.taskmap.count].name,
155 components[i].name, BOOTINFO_TASK_NAME_BUFLEN);
156
157 bootinfo.taskmap.count++;
158 }
159 }
160
161 pages += component_pages;
162 }
163
164 uintptr_t balloc_kernel_base = PA2KA(pages << PAGE_WIDTH);
165 unsigned int balloc_pages = ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE) >> PAGE_WIDTH;
166 for (i = 0; i < balloc_pages; i++) {
167 void *pa = ofw_translate(balloc_base + (i << PAGE_WIDTH));
168 check_overlap(pa, "boot allocations", top);
169 trans[pages + i] = (uintptr_t) pa;
170 }
171
172 pages += balloc_pages;
173
174 printf("Setting up screens...");
175 ofw_setup_screens();
176 printf("done.\n");
177
178 balloc_init(&bootinfo.ballocs, (uintptr_t) balloc_base, balloc_kernel_base);
179 printf("\nCanonizing OpenFirmware device tree...");
180 bootinfo.ofw_root = ofw_tree_build();
181 printf("done.\n");
182
183 printf("Booting the kernel...\n");
184 jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa);
185}
Note: See TracBrowser for help on using the repository browser.