source: mainline/boot/arch/ppc32/src/main.c@ 06e2209

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

do not use ofw_quiesce() (it can actually make more harm than good)
fix the order of arguments passed from the bootloader to kernel on sparc64 (this fixes booting on machines with non-zero physical address start)
remove separate cache.S, use the code directly in start.S

  • Property mode set to 100644
File size: 5.4 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 <arch/main.h>
30#include <arch/arch.h>
31#include <arch/asm.h>
32#include <arch/_components.h>
33#include <genarch/ofw.h>
34#include <genarch/ofw_tree.h>
35#include <halt.h>
36#include <printf.h>
37#include <memstr.h>
38#include <version.h>
39#include <macros.h>
40#include <align.h>
41#include <str.h>
42#include <errno.h>
43#include <inflate.h>
44
45#define BALLOC_MAX_SIZE 131072
46
47static bootinfo_t bootinfo;
48
49static void check_overlap(const char *dest, void *phys, size_t pages)
50{
51 if ((pages << PAGE_WIDTH) > (uintptr_t) phys) {
52 printf("Error: Image (%u pages) overlaps %s at %p, halting.\n",
53 pages, dest, phys);
54 halt();
55 }
56}
57
58void bootstrap(void)
59{
60 version_print();
61 ofw_memmap(&bootinfo.memmap);
62
63 void *bootinfo_pa = ofw_translate(&bootinfo);
64 void *real_mode_pa = ofw_translate(&real_mode);
65 void *loader_address_pa = ofw_translate((void *) LOADER_ADDRESS);
66
67 printf("\nMemory statistics (total %llu MB)\n", bootinfo.memmap.total >> 20);
68 printf(" %p|%p: real mode trampoline\n", &real_mode, real_mode_pa);
69 printf(" %p|%p: boot info structure\n", &bootinfo, bootinfo_pa);
70 printf(" %p|%p: kernel entry point\n", PA2KA(BOOT_OFFSET), BOOT_OFFSET);
71 printf(" %p|%p: loader entry point\n", LOADER_ADDRESS, loader_address_pa);
72
73 size_t i;
74 for (i = 0; i < COMPONENTS; i++)
75 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
76 ofw_translate(components[i].start), components[i].name,
77 components[i].inflated, components[i].size);
78
79 size_t dest[COMPONENTS];
80 size_t top = 0;
81 size_t cnt = 0;
82 bootinfo.taskmap.cnt = 0;
83 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
84 top = ALIGN_UP(top, PAGE_SIZE);
85
86 if (i > 0) {
87 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
88 (void *) PA2KA(top);
89 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
90 components[i].inflated;
91
92 str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
93 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
94
95 bootinfo.taskmap.cnt++;
96 }
97
98 dest[i] = top;
99 top += components[i].inflated;
100 cnt++;
101 }
102
103 void *balloc_base;
104 void *balloc_base_pa;
105 ofw_alloc("boot allocator area", &balloc_base, &balloc_base_pa,
106 BALLOC_MAX_SIZE, loader_address_pa);
107 printf(" %p|%p: boot allocator area\n", balloc_base, balloc_base_pa);
108
109 void *inflate_base;
110 void *inflate_base_pa;
111 ofw_alloc("inflate area", &inflate_base, &inflate_base_pa, top,
112 loader_address_pa);
113 printf(" %p|%p: inflate area\n", inflate_base, inflate_base_pa);
114
115 uintptr_t balloc_start = ALIGN_UP(top, PAGE_SIZE);
116 size_t pages = (balloc_start + ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE))
117 >> PAGE_WIDTH;
118 void *transtable;
119 void *transtable_pa;
120 ofw_alloc("translate table", &transtable, &transtable_pa,
121 pages * sizeof(void *), loader_address_pa);
122 printf(" %p|%p: translate table\n", transtable, transtable_pa);
123
124 check_overlap("boot allocator area", balloc_base_pa, pages);
125 check_overlap("inflate area", inflate_base_pa, pages);
126 check_overlap("translate table", transtable_pa, pages);
127
128 printf("\nInflating components ... ");
129
130 for (i = cnt; i > 0; i--) {
131 printf("%s ", components[i - 1].name);
132
133 int err = inflate(components[i - 1].start, components[i - 1].size,
134 inflate_base + dest[i - 1], components[i - 1].inflated);
135
136 if (err != EOK) {
137 printf("\n%s: Inflating error %d, halting.\n",
138 components[i - 1].name, err);
139 halt();
140 }
141 }
142
143 printf(".\n");
144
145 printf("Setting up boot allocator ...\n");
146 balloc_init(&bootinfo.ballocs, balloc_base, PA2KA(balloc_start),
147 BALLOC_MAX_SIZE);
148
149 printf("Setting up screens ...\n");
150 ofw_setup_screens();
151
152 printf("Canonizing OpenFirmware device tree ...\n");
153 bootinfo.ofw_root = ofw_tree_build();
154
155 printf("Setting up translate table ...\n");
156 for (i = 0; i < pages; i++) {
157 uintptr_t off = i << PAGE_WIDTH;
158 void *phys;
159
160 if (off < balloc_start)
161 phys = ofw_translate(inflate_base + off);
162 else
163 phys = ofw_translate(balloc_base + off - balloc_start);
164
165 ((void **) transtable)[i] = phys;
166 }
167
168 printf("Booting the kernel...\n");
169 jump_to_kernel(bootinfo_pa, transtable_pa, pages, real_mode_pa);
170}
Note: See TracBrowser for help on using the repository browser.