1 | /*
|
---|
2 | * Copyright (c) 2005 Martin Decky
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <arch/main.h>
|
---|
30 | #include <arch/arch.h>
|
---|
31 | #include <arch/asm.h>
|
---|
32 | #include <arch/_components.h>
|
---|
33 | #include <halt.h>
|
---|
34 | #include <printf.h>
|
---|
35 | #include <memstr.h>
|
---|
36 | #include <version.h>
|
---|
37 | #include <macros.h>
|
---|
38 | #include <align.h>
|
---|
39 | #include <str.h>
|
---|
40 | #include <errno.h>
|
---|
41 | #include <inflate.h>
|
---|
42 |
|
---|
43 | #define TOP2ADDR(top) (((void *) PA2KA(BOOT_OFFSET)) + (top))
|
---|
44 |
|
---|
45 | static bootinfo_t *bootinfo = (bootinfo_t *) PA2KA(BOOTINFO_OFFSET);
|
---|
46 | static uint32_t *cpumap = (uint32_t *) PA2KA(CPUMAP_OFFSET);
|
---|
47 |
|
---|
48 | void bootstrap(void)
|
---|
49 | {
|
---|
50 | version_print();
|
---|
51 |
|
---|
52 | printf("\nMemory statistics\n");
|
---|
53 | printf(" %p|%p: CPU map\n", (void *) PA2KA(CPUMAP_OFFSET),
|
---|
54 | (void *) CPUMAP_OFFSET);
|
---|
55 | printf(" %p|%p: bootstrap stack\n", (void *) PA2KA(STACK_OFFSET),
|
---|
56 | (void *) STACK_OFFSET);
|
---|
57 | printf(" %p|%p: boot info structure\n",
|
---|
58 | (void *) PA2KA(BOOTINFO_OFFSET), (void *) BOOTINFO_OFFSET);
|
---|
59 | printf(" %p|%p: kernel entry point\n", (void *) PA2KA(BOOT_OFFSET),
|
---|
60 | (void *) BOOT_OFFSET);
|
---|
61 | printf(" %p|%p: bootloader entry point\n",
|
---|
62 | (void *) PA2KA(LOADER_OFFSET), (void *) LOADER_OFFSET);
|
---|
63 |
|
---|
64 | size_t i;
|
---|
65 | for (i = 0; i < COMPONENTS; i++)
|
---|
66 | printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].start,
|
---|
67 | (uintptr_t) components[i].start >= PA2KSEG(0) ?
|
---|
68 | (void *) KSEG2PA(components[i].start) :
|
---|
69 | (void *) KA2PA(components[i].start),
|
---|
70 | components[i].name, components[i].inflated,
|
---|
71 | components[i].size);
|
---|
72 |
|
---|
73 | void *dest[COMPONENTS];
|
---|
74 | size_t top = 0;
|
---|
75 | size_t cnt = 0;
|
---|
76 | bootinfo->cnt = 0;
|
---|
77 | for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
|
---|
78 | top = ALIGN_UP(top, PAGE_SIZE);
|
---|
79 |
|
---|
80 | if (i > 0) {
|
---|
81 | bootinfo->tasks[bootinfo->cnt].addr = TOP2ADDR(top);
|
---|
82 | bootinfo->tasks[bootinfo->cnt].size = components[i].inflated;
|
---|
83 |
|
---|
84 | str_cpy(bootinfo->tasks[bootinfo->cnt].name,
|
---|
85 | BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
|
---|
86 |
|
---|
87 | bootinfo->cnt++;
|
---|
88 | }
|
---|
89 |
|
---|
90 | dest[i] = TOP2ADDR(top);
|
---|
91 | top += components[i].inflated;
|
---|
92 | cnt++;
|
---|
93 | }
|
---|
94 |
|
---|
95 | printf("\nInflating components ... ");
|
---|
96 |
|
---|
97 | for (i = cnt; i > 0; i--) {
|
---|
98 | #ifdef MACHINE_msim
|
---|
99 | void *tail = dest[i - 1] + components[i].inflated;
|
---|
100 | if (tail >= ((void *) PA2KA(LOADER_OFFSET))) {
|
---|
101 | printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
|
---|
102 | components[i].name, tail, (void *) PA2KA(LOADER_OFFSET));
|
---|
103 | halt();
|
---|
104 | }
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | printf("%s ", components[i - 1].name);
|
---|
108 |
|
---|
109 | int err = inflate(components[i - 1].start, components[i - 1].size,
|
---|
110 | dest[i - 1], components[i - 1].inflated);
|
---|
111 |
|
---|
112 | if (err != EOK) {
|
---|
113 | printf("\n%s: Inflating error %d, halting.\n",
|
---|
114 | components[i - 1].name, err);
|
---|
115 | halt();
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | printf(".\n");
|
---|
120 |
|
---|
121 | printf("Copying CPU map ... \n");
|
---|
122 |
|
---|
123 | bootinfo->cpumap = 0;
|
---|
124 | for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
|
---|
125 | if (cpumap[i] != 0)
|
---|
126 | bootinfo->cpumap |= (1 << i);
|
---|
127 | }
|
---|
128 |
|
---|
129 | printf("Booting the kernel ... \n");
|
---|
130 | jump_to_kernel((void *) PA2KA(BOOT_OFFSET), bootinfo);
|
---|
131 | }
|
---|