Rev 3582 | Rev 3664 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1018 | decky | 1 | /* |
2071 | jermar | 2 | * Copyright (c) 2005 Martin Decky |
3 | * Copyright (c) 2006 Jakub Jermar |
||
1018 | decky | 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" |
||
1764 | jermar | 31 | #include <printf.h> |
1018 | decky | 32 | #include "asm.h" |
1685 | decky | 33 | #include "_components.h" |
1894 | jermar | 34 | #include <balloc.h> |
1782 | jermar | 35 | #include <ofw.h> |
1894 | jermar | 36 | #include <ofw_tree.h> |
1837 | jermar | 37 | #include "ofwarch.h" |
1789 | jermar | 38 | #include <align.h> |
3492 | rimsky | 39 | #include <string.h> |
1018 | decky | 40 | |
1782 | jermar | 41 | bootinfo_t bootinfo; |
3582 | rimsky | 42 | |
43 | /** UltraSPARC subarchitecture - 1 for US, 3 for US3 */ |
||
44 | uint8_t subarchitecture; |
||
45 | |||
1972 | jermar | 46 | component_t components[COMPONENTS]; |
1782 | jermar | 47 | |
1997 | decky | 48 | char *release = RELEASE; |
49 | |||
50 | #ifdef REVISION |
||
51 | char *revision = ", revision " REVISION; |
||
52 | #else |
||
53 | char *revision = ""; |
||
54 | #endif |
||
55 | |||
56 | #ifdef TIMESTAMP |
||
57 | char *timestamp = "\nBuilt on " TIMESTAMP; |
||
58 | #else |
||
59 | char *timestamp = ""; |
||
60 | #endif |
||
61 | |||
62 | /** Print version information. */ |
||
63 | static void version_print(void) |
||
64 | { |
||
3397 | rimsky | 65 | printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n" |
66 | "Copyright (c) 2006 HelenOS project\n", |
||
67 | release, revision, timestamp); |
||
1997 | decky | 68 | } |
69 | |||
3618 | rimsky | 70 | /* the lowest ID (read from the VER register) of some US3 CPU model */ |
3582 | rimsky | 71 | #define FIRST_US3_CPU 0x14 |
3618 | rimsky | 72 | |
73 | /* the greatest ID (read from the VER register) of some US3 CPU model */ |
||
3582 | rimsky | 74 | #define LAST_US3_CPU 0x19 |
3618 | rimsky | 75 | |
76 | /** |
||
77 | * Sets the global variable "subarchitecture" to the correct value. |
||
78 | */ |
||
3582 | rimsky | 79 | static void detect_subarchitecture(void) |
80 | { |
||
81 | uint64_t v; |
||
82 | asm volatile ("rdpr %%ver, %0\n" : "=r" (v)); |
||
83 | |||
84 | v = (v << 16) >> 48; |
||
85 | if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) { |
||
86 | subarchitecture = SUBARCH_US3; |
||
87 | } else if (v < FIRST_US3_CPU) { |
||
88 | subarchitecture = SUBARCH_US; |
||
89 | } |
||
90 | } |
||
91 | |||
1018 | decky | 92 | void bootstrap(void) |
93 | { |
||
3492 | rimsky | 94 | void *base = (void *) KERNEL_VIRTUAL_ADDRESS; |
95 | void *balloc_base; |
||
96 | unsigned int top = 0; |
||
97 | int i, j; |
||
98 | |||
1997 | decky | 99 | version_print(); |
1972 | jermar | 100 | |
3582 | rimsky | 101 | detect_subarchitecture(); |
1685 | decky | 102 | init_components(components); |
1782 | jermar | 103 | |
1978 | jermar | 104 | if (!ofw_get_physmem_start(&bootinfo.physmem_start)) { |
105 | printf("Error: unable to get start of physical memory.\n"); |
||
106 | halt(); |
||
107 | } |
||
108 | |||
1789 | jermar | 109 | if (!ofw_memmap(&bootinfo.memmap)) { |
110 | printf("Error: unable to get memory map, halting.\n"); |
||
111 | halt(); |
||
112 | } |
||
3502 | rimsky | 113 | |
1789 | jermar | 114 | if (bootinfo.memmap.total == 0) { |
115 | printf("Error: no memory detected, halting.\n"); |
||
116 | halt(); |
||
117 | } |
||
3397 | rimsky | 118 | |
119 | /* |
||
120 | * SILO for some reason adds 0x400000 and subtracts |
||
121 | * bootinfo.physmem_start to/from silo_ramdisk_image. |
||
122 | * We just need plain physical address so we fix it up. |
||
123 | */ |
||
124 | if (silo_ramdisk_image) { |
||
125 | silo_ramdisk_image += bootinfo.physmem_start; |
||
126 | silo_ramdisk_image -= 0x400000; |
||
3492 | rimsky | 127 | /* Install 1:1 mapping for the ramdisk. */ |
128 | if (ofw_map((void *)((uintptr_t)silo_ramdisk_image), |
||
129 | (void *)((uintptr_t)silo_ramdisk_image), |
||
130 | silo_ramdisk_size, -1) != 0) { |
||
131 | printf("Failed to map ramdisk.\n"); |
||
132 | halt(); |
||
133 | } |
||
3397 | rimsky | 134 | } |
1789 | jermar | 135 | |
1899 | jermar | 136 | printf("\nSystem info\n"); |
1978 | jermar | 137 | printf(" memory: %dM starting at %P\n", |
3397 | rimsky | 138 | bootinfo.memmap.total >> 20, bootinfo.physmem_start); |
1789 | jermar | 139 | |
1685 | decky | 140 | printf("\nMemory statistics\n"); |
1789 | jermar | 141 | printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS); |
142 | printf(" %P: boot info structure\n", &bootinfo); |
||
1685 | decky | 143 | |
3492 | rimsky | 144 | /* |
145 | * Figure out destination address for each component. |
||
146 | * In this phase, we don't copy the components yet because we want to |
||
147 | * to be careful not to overwrite anything, especially the components |
||
148 | * which haven't been copied yet. |
||
149 | */ |
||
150 | bootinfo.taskmap.count = 0; |
||
151 | for (i = 0; i < COMPONENTS; i++) { |
||
1978 | jermar | 152 | printf(" %P: %s image (size %d bytes)\n", components[i].start, |
2250 | jermar | 153 | components[i].name, components[i].size); |
3492 | rimsky | 154 | top = ALIGN_UP(top, PAGE_SIZE); |
155 | if (i > 0) { |
||
156 | if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { |
||
157 | printf("Skipping superfluous components.\n"); |
||
158 | break; |
||
159 | } |
||
160 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
||
161 | base + top; |
||
162 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
||
163 | components[i].size; |
||
164 | bootinfo.taskmap.count++; |
||
165 | } |
||
166 | top += components[i].size; |
||
167 | } |
||
1782 | jermar | 168 | |
3492 | rimsky | 169 | j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */ |
1894 | jermar | 170 | |
3492 | rimsky | 171 | if (silo_ramdisk_image) { |
172 | /* Treat the ramdisk as the last bootinfo task. */ |
||
173 | if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { |
||
174 | printf("Skipping ramdisk.\n"); |
||
175 | goto skip_ramdisk; |
||
176 | } |
||
1685 | decky | 177 | top = ALIGN_UP(top, PAGE_SIZE); |
3492 | rimsky | 178 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
179 | base + top; |
||
180 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
||
181 | silo_ramdisk_size; |
||
182 | bootinfo.taskmap.count++; |
||
183 | printf("\nCopying ramdisk..."); |
||
184 | /* |
||
185 | * Claim and map the whole ramdisk as it may exceed the area |
||
186 | * given to us by SILO. |
||
187 | */ |
||
188 | (void) ofw_claim_phys(base + top, silo_ramdisk_size); |
||
189 | (void) ofw_map(base + top, base + top, silo_ramdisk_size, -1); |
||
190 | memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image), |
||
191 | silo_ramdisk_size); |
||
192 | printf("done.\n"); |
||
193 | top += silo_ramdisk_size; |
||
194 | } |
||
195 | skip_ramdisk: |
||
2250 | jermar | 196 | |
3492 | rimsky | 197 | /* |
198 | * Now we can proceed to copy the components. We do it in reverse order |
||
199 | * so that we don't overwrite anything even if the components overlap |
||
200 | * with base. |
||
201 | */ |
||
202 | printf("\nCopying bootinfo tasks\n"); |
||
203 | for (i = COMPONENTS - 1; i > 0; i--, j--) { |
||
204 | printf(" %s...", components[i].name); |
||
205 | |||
2250 | jermar | 206 | /* |
207 | * At this point, we claim the physical memory that we are |
||
208 | * going to use. We should be safe in case of the virtual |
||
209 | * address space because the OpenFirmware, according to its |
||
210 | * SPARC binding, should restrict its use of virtual memory |
||
211 | * to addresses from [0xffd00000; 0xffefffff] and |
||
212 | * [0xfe000000; 0xfeffffff]. |
||
3492 | rimsky | 213 | * |
214 | * XXX We don't map this piece of memory. We simply rely on |
||
215 | * SILO to have it done for us already in this case. |
||
2250 | jermar | 216 | */ |
3492 | rimsky | 217 | (void) ofw_claim_phys(bootinfo.physmem_start + |
218 | bootinfo.taskmap.tasks[j].addr, |
||
2250 | jermar | 219 | ALIGN_UP(components[i].size, PAGE_SIZE)); |
220 | |||
3492 | rimsky | 221 | memcpy((void *)bootinfo.taskmap.tasks[j].addr, |
222 | components[i].start, components[i].size); |
||
1685 | decky | 223 | printf("done.\n"); |
1018 | decky | 224 | } |
1782 | jermar | 225 | |
3492 | rimsky | 226 | printf("\nCopying kernel..."); |
227 | (void) ofw_claim_phys(bootinfo.physmem_start + base, |
||
228 | ALIGN_UP(components[0].size, PAGE_SIZE)); |
||
229 | memcpy(base, components[0].start, components[0].size); |
||
230 | printf("done.\n"); |
||
231 | |||
2250 | jermar | 232 | /* |
3492 | rimsky | 233 | * Claim and map the physical memory for the boot allocator. |
2250 | jermar | 234 | * Initialize the boot allocator. |
235 | */ |
||
3492 | rimsky | 236 | balloc_base = base + ALIGN_UP(top, PAGE_SIZE); |
237 | (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base, |
||
238 | BALLOC_MAX_SIZE); |
||
239 | (void) ofw_map(balloc_base, balloc_base, BALLOC_MAX_SIZE, -1); |
||
240 | balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base); |
||
1894 | jermar | 241 | |
242 | printf("\nCanonizing OpenFirmware device tree..."); |
||
243 | bootinfo.ofw_root = ofw_tree_build(); |
||
244 | printf("done.\n"); |
||
245 | |||
1979 | jermar | 246 | #ifdef CONFIG_SMP |
1899 | jermar | 247 | printf("\nChecking for secondary processors..."); |
248 | if (!ofw_cpu()) |
||
1978 | jermar | 249 | printf("Error: unable to get CPU properties\n"); |
1899 | jermar | 250 | printf("done.\n"); |
1979 | jermar | 251 | #endif |
1899 | jermar | 252 | |
1018 | decky | 253 | printf("\nBooting the kernel...\n"); |
1978 | jermar | 254 | jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS, |
2250 | jermar | 255 | bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, |
256 | sizeof(bootinfo)); |
||
1018 | decky | 257 | } |
2250 | jermar | 258 |