Subversion Repositories HelenOS

Rev

Rev 3743 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3743 Rev 3770
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
component_t components[COMPONENTS];
43
component_t components[COMPONENTS];
44
 
44
 
45
char *release = RELEASE;
45
char *release = RELEASE;
46
 
46
 
47
#ifdef REVISION
47
#ifdef REVISION
48
    char *revision = ", revision " REVISION;
48
    char *revision = ", revision " REVISION;
49
#else
49
#else
50
    char *revision = "";
50
    char *revision = "";
51
#endif
51
#endif
52
 
52
 
53
#ifdef TIMESTAMP
53
#ifdef TIMESTAMP
54
    char *timestamp = "\nBuilt on " TIMESTAMP;
54
    char *timestamp = "\nBuilt on " TIMESTAMP;
55
#else
55
#else
56
    char *timestamp = "";
56
    char *timestamp = "";
57
#endif
57
#endif
58
 
58
 
59
/** UltraSPARC subarchitecture - 1 for US, 3 for US3, 0 for other */
59
/** UltraSPARC subarchitecture - 1 for US, 3 for US3, 0 for other */
60
uint8_t subarchitecture = 0;
60
uint8_t subarchitecture = 0;
61
 
61
 
62
/**
62
/**
63
 * mask of the MID field inside the ICBUS_CONFIG register shifted by
63
 * mask of the MID field inside the ICBUS_CONFIG register shifted by
64
 * MID_SHIFT bits to the right
64
 * MID_SHIFT bits to the right
65
 */
65
 */
66
uint16_t mid_mask;
66
uint16_t mid_mask;
67
 
67
 
68
/** Print version information. */
68
/** Print version information. */
69
static void version_print(void)
69
static void version_print(void)
70
{
70
{
71
    printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n"
71
    printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n"
72
        "Copyright (c) 2006 HelenOS project\n",
72
        "Copyright (c) 2006 HelenOS project\n",
73
        release, revision, timestamp);
73
        release, revision, timestamp);
74
}
74
}
75
 
75
 
76
/* the lowest ID (read from the VER register) of some US3 CPU model */
76
/* the lowest ID (read from the VER register) of some US3 CPU model */
77
#define FIRST_US3_CPU   0x14
77
#define FIRST_US3_CPU   0x14
78
 
78
 
79
/* the greatest ID (read from the VER register) of some US3 CPU model */
79
/* the greatest ID (read from the VER register) of some US3 CPU model */
80
#define LAST_US3_CPU    0x19
80
#define LAST_US3_CPU    0x19
81
 
81
 
82
/* UltraSPARC IIIi processor implementation code */
82
/* UltraSPARC IIIi processor implementation code */
83
#define US_IIIi_CODE    0x15
83
#define US_IIIi_CODE    0x15
84
 
84
 
85
/* max. length of the "compatible" property of the root node */
85
/* max. length of the "compatible" property of the root node */
86
#define COMPATIBLE_PROP_MAXLEN  64
86
#define COMPATIBLE_PROP_MAXLEN  64
87
 
87
 
88
/*
88
/*
89
 * HelenOS bootloader will use these constants to distinguish particular
89
 * HelenOS bootloader will use these constants to distinguish particular
90
 * UltraSPARC architectures
90
 * UltraSPARC architectures
91
 */
91
 */
92
#define COMPATIBLE_SUN4U    10
92
#define COMPATIBLE_SUN4U    10
93
#define COMPATIBLE_SUN4V    20
93
#define COMPATIBLE_SUN4V    20
94
 
94
 
95
/** US architecture. COMPATIBLE_SUN4U for sun4v, COMPATIBLE_SUN4V for sun4u */
95
/** US architecture. COMPATIBLE_SUN4U for sun4v, COMPATIBLE_SUN4V for sun4u */
96
static uint8_t architecture;
96
static uint8_t architecture;
97
 
97
 
98
/**
98
/**
99
 * Detects the UltraSPARC architecture (sun4u and sun4v currently supported)
99
 * Detects the UltraSPARC architecture (sun4u and sun4v currently supported)
100
 * by inspecting the property called "compatible" in the OBP root node.
100
 * by inspecting the property called "compatible" in the OBP root node.
101
 */
101
 */
102
static void detect_architecture(void)
102
static void detect_architecture(void)
103
{
103
{
104
    phandle root = ofw_find_device("/");
104
    phandle root = ofw_find_device("/");
105
    char compatible[COMPATIBLE_PROP_MAXLEN];
105
    char compatible[COMPATIBLE_PROP_MAXLEN];
106
 
106
 
107
    if (ofw_get_property(root, "compatible", compatible,
107
    if (ofw_get_property(root, "compatible", compatible,
108
            COMPATIBLE_PROP_MAXLEN) <= 0) {
108
            COMPATIBLE_PROP_MAXLEN) <= 0) {
109
        printf("Unable to determine architecture, default: sun4u.\n");
109
        printf("Unable to determine architecture, default: sun4u.\n");
110
        architecture = COMPATIBLE_SUN4U;
110
        architecture = COMPATIBLE_SUN4U;
111
        return;
111
        return;
112
    }
112
    }
113
 
113
 
114
    if (strcmp(compatible, "sun4v") == 0) {
114
    if (strcmp(compatible, "sun4v") == 0) {
115
        architecture = COMPATIBLE_SUN4V;
115
        architecture = COMPATIBLE_SUN4V;
116
    } else {
116
    } else {
117
        /*
117
        /*
118
         * As not all sun4u machines have "sun4u" in their "compatible"
118
         * As not all sun4u machines have "sun4u" in their "compatible"
119
         * OBP property (e.g. Serengeti's OBP "compatible" property is
119
         * OBP property (e.g. Serengeti's OBP "compatible" property is
120
         * "SUNW,Serengeti"), we will by default fallback to sun4u if
120
         * "SUNW,Serengeti"), we will by default fallback to sun4u if
121
         * an unknown value of the "compatible" property is encountered.
121
         * an unknown value of the "compatible" property is encountered.
122
         */
122
         */
123
        architecture = COMPATIBLE_SUN4U;
123
        architecture = COMPATIBLE_SUN4U;
124
    }
124
    }
125
}
125
}
126
 
126
 
127
/**
127
/**
128
 * Detects the subarchitecture (US, US3) of the sun4u
128
 * Detects the subarchitecture (US, US3) of the sun4u
129
 * processor. Sets the global variables "subarchitecture" and "mid_mask" to
129
 * processor. Sets the global variables "subarchitecture" and "mid_mask" to
130
 * correct values.
130
 * correct values.
131
 */
131
 */
132
static void detect_subarchitecture(void)
132
static void detect_subarchitecture(void)
133
{
133
{
134
    uint64_t v;
134
    uint64_t v;
135
    asm volatile ("rdpr %%ver, %0\n" : "=r" (v));
135
    asm volatile ("rdpr %%ver, %0\n" : "=r" (v));
136
   
136
   
137
    v = (v << 16) >> 48;
137
    v = (v << 16) >> 48;
138
    if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) {
138
    if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) {
139
        subarchitecture = SUBARCH_US3;
139
        subarchitecture = SUBARCH_US3;
140
        if (v == US_IIIi_CODE)
140
        if (v == US_IIIi_CODE)
141
            mid_mask = (1 << 5) - 1;
141
            mid_mask = (1 << 5) - 1;
142
        else
142
        else
143
            mid_mask = (1 << 10) - 1;
143
            mid_mask = (1 << 10) - 1;
144
    } else if (v < FIRST_US3_CPU) {
144
    } else if (v < FIRST_US3_CPU) {
145
        subarchitecture = SUBARCH_US;
145
        subarchitecture = SUBARCH_US;
146
        mid_mask = (1 << 5) - 1;
146
        mid_mask = (1 << 5) - 1;
147
    } else {
147
    } else {
148
        printf("\nThis CPU is not supported by HelenOS.");
148
        printf("\nThis CPU is not supported by HelenOS.");
149
    }
149
    }
150
}
150
}
151
 
151
 
152
/**
152
/**
153
 * Performs sun4u-specific initialization. The components are expected
153
 * Performs sun4u-specific initialization. The components are expected
154
 * to be already copied and boot allocator initialized.
154
 * to be already copied and boot allocator initialized.
-
 
155
 *
-
 
156
 * @param base  kernel base virtual address
-
 
157
 * @param top   virtual address above which the boot allocator
-
 
158
 *      can make allocations
155
 */
159
 */
156
static void bootstrap_sun4u(void)
160
static void bootstrap_sun4u(void *base, unsigned int top)
157
{
161
{
-
 
162
    void *balloc_base;
-
 
163
 
-
 
164
    /*
-
 
165
     * Claim and map the physical memory for the boot allocator.
-
 
166
     * Initialize the boot allocator.
-
 
167
     */
-
 
168
    balloc_base = base + ALIGN_UP(top, PAGE_SIZE);
-
 
169
    (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base,
-
 
170
        BALLOC_MAX_SIZE);
-
 
171
    (void) ofw_map(balloc_base, balloc_base, BALLOC_MAX_SIZE, -1);
-
 
172
    balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base);
-
 
173
 
158
    printf("\nCanonizing OpenFirmware device tree...");
174
    printf("\nCanonizing OpenFirmware device tree...");
159
    bootinfo.ofw_root = ofw_tree_build();
175
    bootinfo.ofw_root = ofw_tree_build();
160
    printf("done.\n");
176
    printf("done.\n");
161
 
177
 
162
    detect_subarchitecture();
178
    detect_subarchitecture();
163
 
179
 
164
#ifdef CONFIG_SMP
180
#ifdef CONFIG_SMP
165
    printf("\nChecking for secondary processors...");
181
    printf("\nChecking for secondary processors...");
166
    if (!ofw_cpu())
182
    if (!ofw_cpu())
167
        printf("Error: unable to get CPU properties\n");
183
        printf("Error: unable to get CPU properties\n");
168
    printf("done.\n");
184
    printf("done.\n");
169
#endif
185
#endif
170
 
186
 
171
    setup_palette();
187
    setup_palette();
172
}
188
}
173
 
189
 
174
/**
190
/**
175
 * Performs sun4v-specific initialization. The components are expected
191
 * Performs sun4v-specific initialization. The components are expected
176
 * to be already copied and boot allocator initialized.
192
 * to be already copied and boot allocator initialized.
177
 */
193
 */
178
static void bootstrap_sun4v(void)
194
static void bootstrap_sun4v(void)
179
{
195
{
-
 
196
    /*
-
 
197
     * When SILO booted, the OBP had established a virtual to physical
-
 
198
     * memory mapping. This mapping is not an identity (because the
-
 
199
     * physical memory starts on non-zero address) - this is not
-
 
200
     * surprising. But! The mapping even does not map virtual address
-
 
201
     * 0 onto the starting address of the physical memory, but onto an
-
 
202
     * address which is 0x400000 bytes higher. The reason is that the
-
 
203
     * OBP had already used the memory just at the beginning of the
-
 
204
     * physical memory, so that memory cannot be used by SILO (nor
-
 
205
     * bootloader). As for now, we solve it by a nasty workaround:
-
 
206
     * we pretend that the physical memory starts 0x400000 bytes further
-
 
207
     * than it actually does (and hence pretend that the physical memory
-
 
208
     * is 0x400000 bytes smaller). Of course, the value 0x400000 will most
-
 
209
     * probably depend on the machine and OBP version (the workaround now
-
 
210
     * works on Simics). A solution would be to inspect the "available"
-
 
211
     * property of the "/memory" node to find out which parts of memory
-
 
212
     * are used by OBP and redesign the algorithm of copying
-
 
213
     * kernel/init tasks/ramdisk from the bootable image to memory
-
 
214
     * (which we must do anyway because of issues with claiming the memory
-
 
215
     * on Serengeti).
-
 
216
     */
-
 
217
    bootinfo.physmem_start += 0x400000;
-
 
218
    bootinfo.memmap.zones[0].start += 0x400000;
-
 
219
    bootinfo.memmap.zones[0].size -= 0x400000;
180
}
220
}
181
 
221
 
182
void bootstrap(void)
222
void bootstrap(void)
183
{
223
{
184
    void *base = (void *) KERNEL_VIRTUAL_ADDRESS;
224
    void *base = (void *) KERNEL_VIRTUAL_ADDRESS;
185
    void *balloc_base;
-
 
186
    unsigned int top = 0;
225
    unsigned int top = 0;
187
    int i, j;
226
    int i, j;
188
 
227
 
189
    detect_architecture();
228
    detect_architecture();
190
    init_components(components);
229
    init_components(components);
191
 
230
 
192
    if (!ofw_get_physmem_start(&bootinfo.physmem_start)) {
231
    if (!ofw_get_physmem_start(&bootinfo.physmem_start)) {
193
        printf("Error: unable to get start of physical memory.\n");
232
        printf("Error: unable to get start of physical memory.\n");
194
        halt();
233
        halt();
195
    }
234
    }
196
 
235
 
197
    if (!ofw_memmap(&bootinfo.memmap)) {
236
    if (!ofw_memmap(&bootinfo.memmap)) {
198
        printf("Error: unable to get memory map, halting.\n");
237
        printf("Error: unable to get memory map, halting.\n");
199
        halt();
238
        halt();
200
    }
239
    }
201
 
240
 
202
    if (bootinfo.memmap.total == 0) {
241
    if (bootinfo.memmap.total == 0) {
203
        printf("Error: no memory detected, halting.\n");
242
        printf("Error: no memory detected, halting.\n");
204
        halt();
243
        halt();
205
    }
244
    }
206
 
245
 
207
    /*
246
    /*
208
     * SILO for some reason adds 0x400000 and subtracts
247
     * SILO for some reason adds 0x400000 and subtracts
209
     * bootinfo.physmem_start to/from silo_ramdisk_image.
248
     * bootinfo.physmem_start to/from silo_ramdisk_image.
210
     * We just need plain physical address so we fix it up.
249
     * We just need plain physical address so we fix it up.
211
     */
250
     */
212
    if (silo_ramdisk_image) {
251
    if (silo_ramdisk_image) {
213
        silo_ramdisk_image += bootinfo.physmem_start;
252
        silo_ramdisk_image += bootinfo.physmem_start;
214
        silo_ramdisk_image -= 0x400000;
253
        silo_ramdisk_image -= 0x400000;
215
        /* Install 1:1 mapping for the ramdisk. */
254
        /* Install 1:1 mapping for the ramdisk. */
216
        if (ofw_map((void *)((uintptr_t)silo_ramdisk_image),
255
        if (ofw_map((void *)((uintptr_t)silo_ramdisk_image),
217
            (void *)((uintptr_t)silo_ramdisk_image),
256
            (void *)((uintptr_t)silo_ramdisk_image),
218
            silo_ramdisk_size, -1) != 0) {
257
            silo_ramdisk_size, -1) != 0) {
219
            printf("Failed to map ramdisk.\n");
258
            printf("Failed to map ramdisk.\n");
220
            halt();
259
            halt();
221
        }
260
        }
222
    }
261
    }
223
   
262
   
224
    printf("\nSystem info\n");
263
    printf("\nSystem info\n");
225
    printf(" memory: %dM starting at %P\n",
264
    printf(" memory: %dM starting at %P\n",
226
        bootinfo.memmap.total >> 20, bootinfo.physmem_start);
265
        bootinfo.memmap.total >> 20, bootinfo.physmem_start);
227
 
266
 
228
    printf("\nMemory statistics\n");
267
    printf("\nMemory statistics\n");
229
    printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS);
268
    printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS);
230
    printf(" %P: boot info structure\n", &bootinfo);
269
    printf(" %P: boot info structure\n", &bootinfo);
231
   
270
   
232
    /*
271
    /*
233
     * Figure out destination address for each component.
272
     * Figure out destination address for each component.
234
     * In this phase, we don't copy the components yet because we want to
273
     * In this phase, we don't copy the components yet because we want to
235
     * to be careful not to overwrite anything, especially the components
274
     * to be careful not to overwrite anything, especially the components
236
     * which haven't been copied yet.
275
     * which haven't been copied yet.
237
     */
276
     */
238
    bootinfo.taskmap.count = 0;
277
    bootinfo.taskmap.count = 0;
239
    for (i = 0; i < COMPONENTS; i++) {
278
    for (i = 0; i < COMPONENTS; i++) {
240
        printf(" %P: %s image (size %d bytes)\n", components[i].start,
279
        printf(" %P: %s image (size %d bytes)\n", components[i].start,
241
            components[i].name, components[i].size);
280
            components[i].name, components[i].size);
242
        top = ALIGN_UP(top, PAGE_SIZE);
281
        top = ALIGN_UP(top, PAGE_SIZE);
243
        if (i > 0) {
282
        if (i > 0) {
244
            if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
283
            if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
245
                printf("Skipping superfluous components.\n");
284
                printf("Skipping superfluous components.\n");
246
                break;
285
                break;
247
            }
286
            }
248
            bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
287
            bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
249
                base + top;
288
                base + top;
250
            bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
289
            bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
251
                components[i].size;
290
                components[i].size;
252
            bootinfo.taskmap.count++;
291
            bootinfo.taskmap.count++;
253
        }
292
        }
254
        top += components[i].size;
293
        top += components[i].size;
255
    }
294
    }
256
 
295
 
257
    j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */
296
    j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */
258
 
297
 
259
    if (silo_ramdisk_image) {
298
    if (silo_ramdisk_image) {
260
        /* Treat the ramdisk as the last bootinfo task. */
299
        /* Treat the ramdisk as the last bootinfo task. */
261
        if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
300
        if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
262
            printf("Skipping ramdisk.\n");
301
            printf("Skipping ramdisk.\n");
263
            goto skip_ramdisk;
302
            goto skip_ramdisk;
264
        }
303
        }
265
        top = ALIGN_UP(top, PAGE_SIZE);
304
        top = ALIGN_UP(top, PAGE_SIZE);
266
        bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
305
        bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
267
            base + top;
306
            base + top;
268
        bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
307
        bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
269
            silo_ramdisk_size;
308
            silo_ramdisk_size;
270
        bootinfo.taskmap.count++;
309
        bootinfo.taskmap.count++;
271
        printf("\nCopying ramdisk...");
310
        printf("\nCopying ramdisk...");
272
        /*
311
        /*
273
         * Claim and map the whole ramdisk as it may exceed the area
312
         * Claim and map the whole ramdisk as it may exceed the area
274
         * given to us by SILO.
313
         * given to us by SILO.
275
         */
314
         */
276
        (void) ofw_claim_phys(base + top, silo_ramdisk_size);
315
        (void) ofw_claim_phys(base + top, silo_ramdisk_size);
277
        (void) ofw_map(base + top, base + top, silo_ramdisk_size, -1);
316
        (void) ofw_map(base + top, base + top, silo_ramdisk_size, -1);
278
        memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image),
317
        memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image),
279
            silo_ramdisk_size);
318
            silo_ramdisk_size);
280
        printf("done.\n");
319
        printf("done.\n");
281
        top += silo_ramdisk_size;
320
        top += silo_ramdisk_size;
282
    }
321
    }
283
skip_ramdisk:
322
skip_ramdisk:
284
 
323
 
285
    /*
324
    /*
286
     * Now we can proceed to copy the components. We do it in reverse order
325
     * Now we can proceed to copy the components. We do it in reverse order
287
     * so that we don't overwrite anything even if the components overlap
326
     * so that we don't overwrite anything even if the components overlap
288
     * with base.
327
     * with base.
289
     */
328
     */
290
    printf("\nCopying bootinfo tasks\n");
329
    printf("\nCopying bootinfo tasks\n");
291
    for (i = COMPONENTS - 1; i > 0; i--, j--) {
330
    for (i = COMPONENTS - 1; i > 0; i--, j--) {
292
        printf(" %s...", components[i].name);
331
        printf(" %s...", components[i].name);
293
 
332
 
294
        /*
333
        /*
295
         * At this point, we claim the physical memory that we are
334
         * At this point, we claim the physical memory that we are
296
         * going to use. We should be safe in case of the virtual
335
         * going to use. We should be safe in case of the virtual
297
         * address space because the OpenFirmware, according to its
336
         * address space because the OpenFirmware, according to its
298
         * SPARC binding, should restrict its use of virtual memory
337
         * SPARC binding, should restrict its use of virtual memory
299
         * to addresses from [0xffd00000; 0xffefffff] and
338
         * to addresses from [0xffd00000; 0xffefffff] and
300
         * [0xfe000000; 0xfeffffff].
339
         * [0xfe000000; 0xfeffffff].
301
         *
340
         *
302
         * XXX We don't map this piece of memory. We simply rely on
341
         * XXX We don't map this piece of memory. We simply rely on
303
         *     SILO to have it done for us already in this case.
342
         *     SILO to have it done for us already in this case.
304
         */
343
         */
305
        (void) ofw_claim_phys(bootinfo.physmem_start +
344
        (void) ofw_claim_phys(bootinfo.physmem_start +
306
            bootinfo.taskmap.tasks[j].addr,
345
            bootinfo.taskmap.tasks[j].addr,
307
            ALIGN_UP(components[i].size, PAGE_SIZE));
346
            ALIGN_UP(components[i].size, PAGE_SIZE));
308
           
347
           
309
        memcpy((void *)bootinfo.taskmap.tasks[j].addr,
348
        memcpy((void *)bootinfo.taskmap.tasks[j].addr,
310
            components[i].start, components[i].size);
349
            components[i].start, components[i].size);
311
        printf("done.\n");
350
        printf("done.\n");
312
    }
351
    }
313
 
352
 
314
    printf("\nCopying kernel...");
353
    printf("\nCopying kernel...");
315
    (void) ofw_claim_phys(bootinfo.physmem_start + base,
354
    (void) ofw_claim_phys(bootinfo.physmem_start + base,
316
        ALIGN_UP(components[0].size, PAGE_SIZE));
355
        ALIGN_UP(components[0].size, PAGE_SIZE));
317
    memcpy(base, components[0].start, components[0].size);
356
    memcpy(base, components[0].start, components[0].size);
318
    printf("done.\n");
357
    printf("done.\n");
319
 
358
 
320
    /*
-
 
321
     * Claim and map the physical memory for the boot allocator.
-
 
322
     * Initialize the boot allocator.
-
 
323
     */
-
 
324
    balloc_base = base + ALIGN_UP(top, PAGE_SIZE);
-
 
325
    (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base,
-
 
326
        BALLOC_MAX_SIZE);
-
 
327
    (void) ofw_map(balloc_base, balloc_base, BALLOC_MAX_SIZE, -1);
-
 
328
    balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base);
-
 
329
 
-
 
330
    /* perform architecture-specific initialization */
359
    /* perform architecture-specific initialization */
331
    if (architecture == COMPATIBLE_SUN4U) {
360
    if (architecture == COMPATIBLE_SUN4U) {
332
        bootstrap_sun4u();
361
        bootstrap_sun4u(base, top);
333
    } else if (architecture == COMPATIBLE_SUN4V) {
362
    } else if (architecture == COMPATIBLE_SUN4V) {
334
        bootstrap_sun4v();
363
        bootstrap_sun4v();
335
    } else {
364
    } else {
336
        printf("Unknown architecture.\n");
365
        printf("Unknown architecture.\n");
337
        halt();
366
        halt();
338
    }
367
    }
339
 
368
 
340
    printf("\nBooting the kernel...\n");
369
    printf("\nBooting the kernel...\n");
341
    jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS,
370
    jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS,
342
        bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo,
371
        bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo,
343
        sizeof(bootinfo));
372
        sizeof(bootinfo));
344
}
373
}
345
 
374
 
346
 
375