Subversion Repositories HelenOS

Rev

Rev 2787 | Rev 3684 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2787 Rev 3425
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 <string.h>
39
 
40
 
40
bootinfo_t bootinfo;
41
bootinfo_t bootinfo;
41
component_t components[COMPONENTS];
42
component_t components[COMPONENTS];
42
 
43
 
43
char *release = RELEASE;
44
char *release = RELEASE;
Line 55... Line 56...
55
#endif
56
#endif
56
 
57
 
57
/** Print version information. */
58
/** Print version information. */
58
static void version_print(void)
59
static void version_print(void)
59
{
60
{
60
    printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\nCopyright (c) 2006 HelenOS project\n", release, revision, timestamp);
61
    printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n"
-
 
62
        "Copyright (c) 2006 HelenOS project\n",
-
 
63
        release, revision, timestamp);
61
}
64
}
62
 
65
 
63
void bootstrap(void)
66
void bootstrap(void)
64
{
67
{
-
 
68
    void *base = (void *) KERNEL_VIRTUAL_ADDRESS;
-
 
69
    void *balloc_base;
-
 
70
    unsigned int top = 0;
-
 
71
    int i, j;
-
 
72
 
65
    version_print();
73
    version_print();
66
   
74
   
67
    init_components(components);
75
    init_components(components);
68
 
76
 
69
    if (!ofw_get_physmem_start(&bootinfo.physmem_start)) {
77
    if (!ofw_get_physmem_start(&bootinfo.physmem_start)) {
Line 78... Line 86...
78
   
86
   
79
    if (bootinfo.memmap.total == 0) {
87
    if (bootinfo.memmap.total == 0) {
80
        printf("Error: no memory detected, halting.\n");
88
        printf("Error: no memory detected, halting.\n");
81
        halt();
89
        halt();
82
    }
90
    }
-
 
91
 
-
 
92
    /*
-
 
93
     * SILO for some reason adds 0x400000 and subtracts
-
 
94
     * bootinfo.physmem_start to/from silo_ramdisk_image.
-
 
95
     * We just need plain physical address so we fix it up.
-
 
96
     */
-
 
97
    if (silo_ramdisk_image) {
-
 
98
        silo_ramdisk_image += bootinfo.physmem_start;
-
 
99
        silo_ramdisk_image -= 0x400000;
-
 
100
        /* Install 1:1 mapping for the ramdisk. */
-
 
101
        if (ofw_map((void *)((uintptr_t)silo_ramdisk_image),
-
 
102
            (void *)((uintptr_t)silo_ramdisk_image),
-
 
103
            silo_ramdisk_size, -1) != 0) {
-
 
104
            printf("Failed to map ramdisk.\n");
-
 
105
            halt();
-
 
106
        }
-
 
107
    }
83
   
108
   
84
    printf("\nSystem info\n");
109
    printf("\nSystem info\n");
85
    printf(" memory: %dM starting at %P\n",
110
    printf(" memory: %dM starting at %P\n",
86
        bootinfo.memmap.total >> 20, bootinfo.physmem_start);
111
        bootinfo.memmap.total >> 20, bootinfo.physmem_start);
87
 
112
 
88
    printf("\nMemory statistics\n");
113
    printf("\nMemory statistics\n");
89
    printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS);
114
    printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS);
90
    printf(" %P: boot info structure\n", &bootinfo);
115
    printf(" %P: boot info structure\n", &bootinfo);
91
   
116
   
-
 
117
    /*
-
 
118
     * Figure out destination address for each component.
-
 
119
     * In this phase, we don't copy the components yet because we want to
-
 
120
     * to be careful not to overwrite anything, especially the components
-
 
121
     * which haven't been copied yet.
-
 
122
     */
92
    unsigned int i;
123
    bootinfo.taskmap.count = 0;
93
    for (i = 0; i < COMPONENTS; i++)
124
    for (i = 0; i < COMPONENTS; i++) {
94
        printf(" %P: %s image (size %d bytes)\n", components[i].start,
125
        printf(" %P: %s image (size %d bytes)\n", components[i].start,
95
            components[i].name, components[i].size);
126
            components[i].name, components[i].size);
-
 
127
        top = ALIGN_UP(top, PAGE_SIZE);
-
 
128
        if (i > 0) {
-
 
129
            if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
-
 
130
                printf("Skipping superfluous components.\n");
-
 
131
                break;
-
 
132
            }
-
 
133
            bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
-
 
134
                base + top;
-
 
135
            bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
-
 
136
                components[i].size;
-
 
137
            bootinfo.taskmap.count++;
-
 
138
        }
-
 
139
        top += components[i].size;
-
 
140
    }
96
 
141
 
97
    void * base = (void *) KERNEL_VIRTUAL_ADDRESS;
142
    j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */
98
    unsigned int top = 0;
-
 
99
 
143
 
100
    printf("\nCopying components\n");
144
    if (silo_ramdisk_image) {
-
 
145
        /* Treat the ramdisk as the last bootinfo task. */
101
    bootinfo.taskmap.count = 0;
146
        if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
102
    for (i = 0; i < COMPONENTS; i++) {
147
            printf("Skipping ramdisk.\n");
103
        printf(" %s...", components[i].name);
148
            goto skip_ramdisk;
-
 
149
        }
104
        top = ALIGN_UP(top, PAGE_SIZE);
150
        top = ALIGN_UP(top, PAGE_SIZE);
-
 
151
        bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
-
 
152
            base + top;
-
 
153
        bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
-
 
154
            silo_ramdisk_size;
-
 
155
        bootinfo.taskmap.count++;
-
 
156
        printf("\nCopying ramdisk...");
-
 
157
        /*
-
 
158
         * Claim and map the whole ramdisk as it may exceed the area
-
 
159
         * given to us by SILO.
-
 
160
         */
-
 
161
        (void) ofw_claim_phys(base + top, silo_ramdisk_size);
-
 
162
        (void) ofw_map(base + top, base + top, silo_ramdisk_size, -1);
-
 
163
        memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image),
-
 
164
            silo_ramdisk_size);
-
 
165
        printf("done.\n");
-
 
166
        top += silo_ramdisk_size;
-
 
167
    }
-
 
168
skip_ramdisk:
-
 
169
 
-
 
170
    /*
-
 
171
     * Now we can proceed to copy the components. We do it in reverse order
-
 
172
     * so that we don't overwrite anything even if the components overlap
-
 
173
     * with base.
-
 
174
     */
-
 
175
    printf("\nCopying bootinfo tasks\n");
-
 
176
    for (i = COMPONENTS - 1; i > 0; i--, j--) {
-
 
177
        printf(" %s...", components[i].name);
105
 
178
 
106
        /*
179
        /*
107
         * At this point, we claim the physical memory that we are
180
         * At this point, we claim the physical memory that we are
108
         * going to use. We should be safe in case of the virtual
181
         * going to use. We should be safe in case of the virtual
109
         * address space because the OpenFirmware, according to its
182
         * address space because the OpenFirmware, according to its
110
         * SPARC binding, should restrict its use of virtual memory
183
         * SPARC binding, should restrict its use of virtual memory
111
         * to addresses from [0xffd00000; 0xffefffff] and
184
         * to addresses from [0xffd00000; 0xffefffff] and
112
         * [0xfe000000; 0xfeffffff].
185
         * [0xfe000000; 0xfeffffff].
-
 
186
         *
-
 
187
         * XXX We don't map this piece of memory. We simply rely on
-
 
188
         *     SILO to have it done for us already in this case.
113
         */
189
         */
114
        (void) ofw_claim_phys(bootinfo.physmem_start + base + top,
190
        (void) ofw_claim_phys(bootinfo.physmem_start +
-
 
191
            bootinfo.taskmap.tasks[j].addr,
115
            ALIGN_UP(components[i].size, PAGE_SIZE));
192
            ALIGN_UP(components[i].size, PAGE_SIZE));
116
           
193
           
117
        memcpy(base + top, components[i].start, components[i].size);
-
 
118
        if (i > 0) {
-
 
119
            bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
194
        memcpy((void *)bootinfo.taskmap.tasks[j].addr,
120
                base + top;
-
 
121
            bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
-
 
122
                components[i].size;
195
            components[i].start, components[i].size);
123
            bootinfo.taskmap.count++;
-
 
124
        }
-
 
125
        top += components[i].size;
-
 
126
        printf("done.\n");
196
        printf("done.\n");
127
    }
197
    }
128
 
198
 
-
 
199
    printf("\nCopying kernel...");
-
 
200
    (void) ofw_claim_phys(bootinfo.physmem_start + base,
-
 
201
        ALIGN_UP(components[0].size, PAGE_SIZE));
-
 
202
    memcpy(base, components[0].start, components[0].size);
-
 
203
    printf("done.\n");
-
 
204
 
129
    /*
205
    /*
130
     * Claim the physical memory for the boot allocator.
206
     * Claim and map the physical memory for the boot allocator.
131
     * Initialize the boot allocator.
207
     * Initialize the boot allocator.
132
     */
208
     */
-
 
209
    balloc_base = base + ALIGN_UP(top, PAGE_SIZE);
133
    (void) ofw_claim_phys(bootinfo.physmem_start +
210
    (void) ofw_claim_phys(bootinfo.physmem_start + balloc_base,
-
 
211
        BALLOC_MAX_SIZE);
134
        base + ALIGN_UP(top, PAGE_SIZE), BALLOC_MAX_SIZE);
212
    (void) ofw_map(balloc_base, balloc_base, BALLOC_MAX_SIZE, -1);
135
    balloc_init(&bootinfo.ballocs, ALIGN_UP(((uintptr_t) base) + top,
213
    balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base);
136
        PAGE_SIZE));
-
 
137
 
214
 
138
    printf("\nCanonizing OpenFirmware device tree...");
215
    printf("\nCanonizing OpenFirmware device tree...");
139
    bootinfo.ofw_root = ofw_tree_build();
216
    bootinfo.ofw_root = ofw_tree_build();
140
    printf("done.\n");
217
    printf("done.\n");
141
 
218