Rev 3582 | Rev 3664 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3582 | Rev 3618 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2005 Martin Decky |
2 | * Copyright (c) 2005 Martin Decky |
3 | * Copyright (c) 2006 Jakub Jermar |
3 | * Copyright (c) 2006 Jakub Jermar |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | #include "main.h" |
30 | #include "main.h" |
31 | #include <printf.h> |
31 | #include <printf.h> |
32 | #include "asm.h" |
32 | #include "asm.h" |
33 | #include "_components.h" |
33 | #include "_components.h" |
34 | #include <balloc.h> |
34 | #include <balloc.h> |
35 | #include <ofw.h> |
35 | #include <ofw.h> |
36 | #include <ofw_tree.h> |
36 | #include <ofw_tree.h> |
37 | #include "ofwarch.h" |
37 | #include "ofwarch.h" |
38 | #include <align.h> |
38 | #include <align.h> |
39 | #include <string.h> |
39 | #include <string.h> |
40 | 40 | ||
41 | bootinfo_t bootinfo; |
41 | bootinfo_t bootinfo; |
42 | 42 | ||
43 | /** UltraSPARC subarchitecture - 1 for US, 3 for US3 */ |
43 | /** UltraSPARC subarchitecture - 1 for US, 3 for US3 */ |
44 | uint8_t subarchitecture; |
44 | uint8_t subarchitecture; |
45 | 45 | ||
46 | component_t components[COMPONENTS]; |
46 | component_t components[COMPONENTS]; |
47 | 47 | ||
48 | char *release = RELEASE; |
48 | char *release = RELEASE; |
49 | 49 | ||
50 | #ifdef REVISION |
50 | #ifdef REVISION |
51 | char *revision = ", revision " REVISION; |
51 | char *revision = ", revision " REVISION; |
52 | #else |
52 | #else |
53 | char *revision = ""; |
53 | char *revision = ""; |
54 | #endif |
54 | #endif |
55 | 55 | ||
56 | #ifdef TIMESTAMP |
56 | #ifdef TIMESTAMP |
57 | char *timestamp = "\nBuilt on " TIMESTAMP; |
57 | char *timestamp = "\nBuilt on " TIMESTAMP; |
58 | #else |
58 | #else |
59 | char *timestamp = ""; |
59 | char *timestamp = ""; |
60 | #endif |
60 | #endif |
61 | 61 | ||
62 | /** Print version information. */ |
62 | /** Print version information. */ |
63 | static void version_print(void) |
63 | static void version_print(void) |
64 | { |
64 | { |
65 | printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n" |
65 | printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n" |
66 | "Copyright (c) 2006 HelenOS project\n", |
66 | "Copyright (c) 2006 HelenOS project\n", |
67 | release, revision, timestamp); |
67 | release, revision, timestamp); |
68 | } |
68 | } |
69 | 69 | ||
- | 70 | /* the lowest ID (read from the VER register) of some US3 CPU model */ |
|
70 | #define FIRST_US3_CPU 0x14 |
71 | #define FIRST_US3_CPU 0x14 |
- | 72 | ||
- | 73 | /* the greatest ID (read from the VER register) of some US3 CPU model */ |
|
71 | #define LAST_US3_CPU 0x19 |
74 | #define LAST_US3_CPU 0x19 |
- | 75 | ||
- | 76 | /** |
|
- | 77 | * Sets the global variable "subarchitecture" to the correct value. |
|
- | 78 | */ |
|
72 | static void detect_subarchitecture(void) |
79 | static void detect_subarchitecture(void) |
73 | { |
80 | { |
74 | uint64_t v; |
81 | uint64_t v; |
75 | asm volatile ("rdpr %%ver, %0\n" : "=r" (v)); |
82 | asm volatile ("rdpr %%ver, %0\n" : "=r" (v)); |
76 | 83 | ||
77 | v = (v << 16) >> 48; |
84 | v = (v << 16) >> 48; |
78 | if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) { |
85 | if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) { |
79 | subarchitecture = SUBARCH_US3; |
86 | subarchitecture = SUBARCH_US3; |
80 | } else if (v < FIRST_US3_CPU) { |
87 | } else if (v < FIRST_US3_CPU) { |
81 | subarchitecture = SUBARCH_US; |
88 | subarchitecture = SUBARCH_US; |
82 | } |
89 | } |
83 | } |
90 | } |
84 | 91 | ||
85 | void bootstrap(void) |
92 | void bootstrap(void) |
86 | { |
93 | { |
87 | void *base = (void *) KERNEL_VIRTUAL_ADDRESS; |
94 | void *base = (void *) KERNEL_VIRTUAL_ADDRESS; |
88 | void *balloc_base; |
95 | void *balloc_base; |
89 | unsigned int top = 0; |
96 | unsigned int top = 0; |
90 | int i, j; |
97 | int i, j; |
91 | 98 | ||
92 | version_print(); |
99 | version_print(); |
93 | 100 | ||
94 | detect_subarchitecture(); |
101 | detect_subarchitecture(); |
95 | init_components(components); |
102 | init_components(components); |
96 | 103 | ||
97 | if (!ofw_get_physmem_start(&bootinfo.physmem_start)) { |
104 | if (!ofw_get_physmem_start(&bootinfo.physmem_start)) { |
98 | printf("Error: unable to get start of physical memory.\n"); |
105 | printf("Error: unable to get start of physical memory.\n"); |
99 | halt(); |
106 | halt(); |
100 | } |
107 | } |
101 | 108 | ||
102 | if (!ofw_memmap(&bootinfo.memmap)) { |
109 | if (!ofw_memmap(&bootinfo.memmap)) { |
103 | printf("Error: unable to get memory map, halting.\n"); |
110 | printf("Error: unable to get memory map, halting.\n"); |
104 | halt(); |
111 | halt(); |
105 | } |
112 | } |
106 | 113 | ||
107 | if (bootinfo.memmap.total == 0) { |
114 | if (bootinfo.memmap.total == 0) { |
108 | printf("Error: no memory detected, halting.\n"); |
115 | printf("Error: no memory detected, halting.\n"); |
109 | halt(); |
116 | halt(); |
110 | } |
117 | } |
111 | 118 | ||
112 | /* |
119 | /* |
113 | * SILO for some reason adds 0x400000 and subtracts |
120 | * SILO for some reason adds 0x400000 and subtracts |
114 | * bootinfo.physmem_start to/from silo_ramdisk_image. |
121 | * bootinfo.physmem_start to/from silo_ramdisk_image. |
115 | * We just need plain physical address so we fix it up. |
122 | * We just need plain physical address so we fix it up. |
116 | */ |
123 | */ |
117 | if (silo_ramdisk_image) { |
124 | if (silo_ramdisk_image) { |
118 | silo_ramdisk_image += bootinfo.physmem_start; |
125 | silo_ramdisk_image += bootinfo.physmem_start; |
119 | silo_ramdisk_image -= 0x400000; |
126 | silo_ramdisk_image -= 0x400000; |
120 | /* Install 1:1 mapping for the ramdisk. */ |
127 | /* Install 1:1 mapping for the ramdisk. */ |
121 | if (ofw_map((void *)((uintptr_t)silo_ramdisk_image), |
128 | if (ofw_map((void *)((uintptr_t)silo_ramdisk_image), |
122 | (void *)((uintptr_t)silo_ramdisk_image), |
129 | (void *)((uintptr_t)silo_ramdisk_image), |
123 | silo_ramdisk_size, -1) != 0) { |
130 | silo_ramdisk_size, -1) != 0) { |
124 | printf("Failed to map ramdisk.\n"); |
131 | printf("Failed to map ramdisk.\n"); |
125 | halt(); |
132 | halt(); |
126 | } |
133 | } |
127 | } |
134 | } |
128 | 135 | ||
129 | printf("\nSystem info\n"); |
136 | printf("\nSystem info\n"); |
130 | printf(" memory: %dM starting at %P\n", |
137 | printf(" memory: %dM starting at %P\n", |
131 | bootinfo.memmap.total >> 20, bootinfo.physmem_start); |
138 | bootinfo.memmap.total >> 20, bootinfo.physmem_start); |
132 | 139 | ||
133 | printf("\nMemory statistics\n"); |
140 | printf("\nMemory statistics\n"); |
134 | printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS); |
141 | printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS); |
135 | printf(" %P: boot info structure\n", &bootinfo); |
142 | printf(" %P: boot info structure\n", &bootinfo); |
136 | 143 | ||
137 | /* |
144 | /* |
138 | * Figure out destination address for each component. |
145 | * Figure out destination address for each component. |
139 | * In this phase, we don't copy the components yet because we want to |
146 | * In this phase, we don't copy the components yet because we want to |
140 | * to be careful not to overwrite anything, especially the components |
147 | * to be careful not to overwrite anything, especially the components |
141 | * which haven't been copied yet. |
148 | * which haven't been copied yet. |
142 | */ |
149 | */ |
143 | bootinfo.taskmap.count = 0; |
150 | bootinfo.taskmap.count = 0; |
144 | for (i = 0; i < COMPONENTS; i++) { |
151 | for (i = 0; i < COMPONENTS; i++) { |
145 | printf(" %P: %s image (size %d bytes)\n", components[i].start, |
152 | printf(" %P: %s image (size %d bytes)\n", components[i].start, |
146 | components[i].name, components[i].size); |
153 | components[i].name, components[i].size); |
147 | top = ALIGN_UP(top, PAGE_SIZE); |
154 | top = ALIGN_UP(top, PAGE_SIZE); |
148 | if (i > 0) { |
155 | if (i > 0) { |
149 | if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { |
156 | if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { |
150 | printf("Skipping superfluous components.\n"); |
157 | printf("Skipping superfluous components.\n"); |
151 | break; |
158 | break; |
152 | } |
159 | } |
153 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
160 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
154 | base + top; |
161 | base + top; |
155 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
162 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
156 | components[i].size; |
163 | components[i].size; |
157 | bootinfo.taskmap.count++; |
164 | bootinfo.taskmap.count++; |
158 | } |
165 | } |
159 | top += components[i].size; |
166 | top += components[i].size; |
160 | } |
167 | } |
161 | 168 | ||
162 | j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */ |
169 | j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */ |
163 | 170 | ||
164 | if (silo_ramdisk_image) { |
171 | if (silo_ramdisk_image) { |
165 | /* Treat the ramdisk as the last bootinfo task. */ |
172 | /* Treat the ramdisk as the last bootinfo task. */ |
166 | if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { |
173 | if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { |
167 | printf("Skipping ramdisk.\n"); |
174 | printf("Skipping ramdisk.\n"); |
168 | goto skip_ramdisk; |
175 | goto skip_ramdisk; |
169 | } |
176 | } |
170 | top = ALIGN_UP(top, PAGE_SIZE); |
177 | top = ALIGN_UP(top, PAGE_SIZE); |
171 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
178 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
172 | base + top; |
179 | base + top; |
173 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
180 | bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
174 | silo_ramdisk_size; |
181 | silo_ramdisk_size; |
175 | bootinfo.taskmap.count++; |
182 | bootinfo.taskmap.count++; |
176 | printf("\nCopying ramdisk..."); |
183 | printf("\nCopying ramdisk..."); |
177 | /* |
184 | /* |
178 | * Claim and map the whole ramdisk as it may exceed the area |
185 | * Claim and map the whole ramdisk as it may exceed the area |
179 | * given to us by SILO. |
186 | * given to us by SILO. |
180 | */ |
187 | */ |
181 | (void) ofw_claim_phys(base + top, silo_ramdisk_size); |
188 | (void) ofw_claim_phys(base + top, silo_ramdisk_size); |
182 | (void) ofw_map(base + top, base + top, silo_ramdisk_size, -1); |
189 | (void) ofw_map(base + top, base + top, silo_ramdisk_size, -1); |
183 | memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image), |
190 | memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image), |
184 | silo_ramdisk_size); |
191 | silo_ramdisk_size); |
185 | printf("done.\n"); |
192 | printf("done.\n"); |
186 | top += silo_ramdisk_size; |
193 | top += silo_ramdisk_size; |
187 | } |
194 | } |
188 | skip_ramdisk: |
195 | skip_ramdisk: |
189 | 196 | ||
190 | /* |
197 | /* |
191 | * Now we can proceed to copy the components. We do it in reverse order |
198 | * Now we can proceed to copy the components. We do it in reverse order |
192 | * so that we don't overwrite anything even if the components overlap |
199 | * so that we don't overwrite anything even if the components overlap |
193 | * with base. |
200 | * with base. |
194 | */ |
201 | */ |
195 | printf("\nCopying bootinfo tasks\n"); |
202 | printf("\nCopying bootinfo tasks\n"); |
196 | for (i = COMPONENTS - 1; i > 0; i--, j--) { |
203 | for (i = COMPONENTS - 1; i > 0; i--, j--) { |
197 | printf(" %s...", components[i].name); |
204 | printf(" %s...", components[i].name); |
198 | 205 | ||
199 | /* |
206 | /* |
200 | * At this point, we claim the physical memory that we are |
207 | * At this point, we claim the physical memory that we are |
201 | * going to use. We should be safe in case of the virtual |
208 | * going to use. We should be safe in case of the virtual |
202 | * address space because the OpenFirmware, according to its |
209 | * address space because the OpenFirmware, according to its |
203 | * SPARC binding, should restrict its use of virtual memory |
210 | * SPARC binding, should restrict its use of virtual memory |
204 | * to addresses from [0xffd00000; 0xffefffff] and |
211 | * to addresses from [0xffd00000; 0xffefffff] and |
205 | * [0xfe000000; 0xfeffffff]. |
212 | * [0xfe000000; 0xfeffffff]. |
206 | * |
213 | * |
207 | * XXX We don't map this piece of memory. We simply rely on |
214 | * XXX We don't map this piece of memory. We simply rely on |
208 | * SILO to have it done for us already in this case. |
215 | * SILO to have it done for us already in this case. |
209 | */ |
216 | */ |
210 | (void) ofw_claim_phys(bootinfo.physmem_start + |
217 | (void) ofw_claim_phys(bootinfo.physmem_start + |
211 | bootinfo.taskmap.tasks[j].addr, |
218 | bootinfo.taskmap.tasks[j].addr, |
212 | ALIGN_UP(components[i].size, PAGE_SIZE)); |
219 | ALIGN_UP(components[i].size, PAGE_SIZE)); |
213 | 220 | ||
214 | memcpy((void *)bootinfo.taskmap.tasks[j].addr, |
221 | memcpy((void *)bootinfo.taskmap.tasks[j].addr, |
215 | components[i].start, components[i].size); |
222 | components[i].start, components[i].size); |
216 | printf("done.\n"); |
223 | printf("done.\n"); |
217 | } |
224 | } |
218 | 225 | ||
219 | printf("\nCopying kernel..."); |
226 | printf("\nCopying kernel..."); |
220 | (void) ofw_claim_phys(bootinfo.physmem_start + base, |
227 | (void) ofw_claim_phys(bootinfo.physmem_start + base, |
221 | ALIGN_UP(components[0].size, PAGE_SIZE)); |
228 | ALIGN_UP(components[0].size, PAGE_SIZE)); |
222 | memcpy(base, components[0].start, components[0].size); |
229 | memcpy(base, components[0].start, components[0].size); |
223 | printf("done.\n"); |
230 | printf("done.\n"); |
224 | 231 | ||
225 | /* |
232 | /* |
226 | * Claim and map the physical memory for the boot allocator. |
233 | * Claim and map the physical memory for the boot allocator. |
227 | * Initialize the boot allocator. |
234 | * Initialize the boot allocator. |
228 | */ |
235 | */ |
229 | balloc_base = base + ALIGN_UP(top, PAGE_SIZE); |
236 | balloc_base = base + ALIGN_UP(top, PAGE_SIZE); |
230 | (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base, |
237 | (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base, |
231 | BALLOC_MAX_SIZE); |
238 | BALLOC_MAX_SIZE); |
232 | (void) ofw_map(balloc_base, balloc_base, BALLOC_MAX_SIZE, -1); |
239 | (void) ofw_map(balloc_base, balloc_base, BALLOC_MAX_SIZE, -1); |
233 | balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base); |
240 | balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base); |
234 | 241 | ||
235 | printf("\nCanonizing OpenFirmware device tree..."); |
242 | printf("\nCanonizing OpenFirmware device tree..."); |
236 | bootinfo.ofw_root = ofw_tree_build(); |
243 | bootinfo.ofw_root = ofw_tree_build(); |
237 | printf("done.\n"); |
244 | printf("done.\n"); |
238 | 245 | ||
239 | #ifdef CONFIG_SMP |
246 | #ifdef CONFIG_SMP |
240 | printf("\nChecking for secondary processors..."); |
247 | printf("\nChecking for secondary processors..."); |
241 | if (!ofw_cpu()) |
248 | if (!ofw_cpu()) |
242 | printf("Error: unable to get CPU properties\n"); |
249 | printf("Error: unable to get CPU properties\n"); |
243 | printf("done.\n"); |
250 | printf("done.\n"); |
244 | #endif |
251 | #endif |
245 | 252 | ||
246 | printf("\nBooting the kernel...\n"); |
253 | printf("\nBooting the kernel...\n"); |
247 | jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS, |
254 | jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS, |
248 | bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, |
255 | bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, |
249 | sizeof(bootinfo)); |
256 | sizeof(bootinfo)); |
250 | } |
257 | } |
251 | 258 | ||
252 | 259 |