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