1 | /*
|
---|
2 | * Copyright (c) 2005 Martin Decky
|
---|
3 | * Copyright (c) 2006 Jakub Jermar
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
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
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
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
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
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
|
---|
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
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 |
|
---|
31 | #include <arch/main.h>
|
---|
32 | #include <arch/arch.h>
|
---|
33 | #include <arch/asm.h>
|
---|
34 | #include <arch/_components.h>
|
---|
35 | #include <halt.h>
|
---|
36 | #include <printf.h>
|
---|
37 | #include <memstr.h>
|
---|
38 | #include <version.h>
|
---|
39 | #include <macros.h>
|
---|
40 | #include <align.h>
|
---|
41 | #include <str.h>
|
---|
42 | #include <errno.h>
|
---|
43 | #include <inflate.h>
|
---|
44 |
|
---|
45 | #define DEFAULT_MEMORY_BASE 0x4000000ULL
|
---|
46 | #define DEFAULT_MEMORY_SIZE 0x4000000ULL
|
---|
47 | #define DEFAULT_LEGACY_IO_BASE 0x00000FFFFC000000ULL
|
---|
48 | #define DEFAULT_LEGACY_IO_SIZE 0x4000000ULL
|
---|
49 |
|
---|
50 | #define DEFAULT_FREQ_SCALE 0x0000000100000001ULL /* 1/1 */
|
---|
51 | #define DEFAULT_SYS_FREQ 100000000ULL /* 100MHz */
|
---|
52 |
|
---|
53 | #define EFI_MEMMAP_FREE_MEM 0
|
---|
54 | #define EFI_MEMMAP_IO 1
|
---|
55 | #define EFI_MEMMAP_IO_PORTS 2
|
---|
56 |
|
---|
57 | static bootinfo_t bootinfo;
|
---|
58 |
|
---|
59 | void bootstrap(void)
|
---|
60 | {
|
---|
61 | version_print();
|
---|
62 |
|
---|
63 | printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
|
---|
64 | printf(" %p|%p: kernel entry point\n", KERNEL_ADDRESS, KERNEL_ADDRESS);
|
---|
65 | printf(" %p|%p: loader entry point\n", LOADER_ADDRESS, LOADER_ADDRESS);
|
---|
66 |
|
---|
67 | size_t i;
|
---|
68 | for (i = 0; i < COMPONENTS; i++)
|
---|
69 | printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
|
---|
70 | components[i].start, components[i].name,
|
---|
71 | components[i].inflated, components[i].size);
|
---|
72 |
|
---|
73 | void *dest[COMPONENTS];
|
---|
74 | size_t top = KERNEL_ADDRESS;
|
---|
75 | size_t cnt = 0;
|
---|
76 | bootinfo.taskmap.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.taskmap.tasks[bootinfo.taskmap.cnt].addr =
|
---|
82 | (void *) top;
|
---|
83 | bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
|
---|
84 | components[i].inflated;
|
---|
85 |
|
---|
86 | str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
|
---|
87 | BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
|
---|
88 |
|
---|
89 | bootinfo.taskmap.cnt++;
|
---|
90 | }
|
---|
91 |
|
---|
92 | dest[i] = (void *) top;
|
---|
93 | top += components[i].inflated;
|
---|
94 | cnt++;
|
---|
95 | }
|
---|
96 |
|
---|
97 | printf("\nInflating components ... ");
|
---|
98 |
|
---|
99 | for (i = cnt; i > 0; i--) {
|
---|
100 | printf("%s ", components[i - 1].name);
|
---|
101 |
|
---|
102 | int err = inflate(components[i - 1].start, components[i - 1].size,
|
---|
103 | dest[i - 1], components[i - 1].inflated);
|
---|
104 |
|
---|
105 | if (err != EOK) {
|
---|
106 | printf("\n%s: Inflating error %d, halting.\n",
|
---|
107 | components[i - 1].name, err);
|
---|
108 | halt();
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | printf(".\n");
|
---|
113 |
|
---|
114 | if (!bootinfo.hello_configured) { /* XXX */
|
---|
115 | /*
|
---|
116 | * Load configuration defaults for simulators.
|
---|
117 | */
|
---|
118 | bootinfo.memmap_items = 0;
|
---|
119 |
|
---|
120 | bootinfo.memmap[bootinfo.memmap_items].base =
|
---|
121 | DEFAULT_MEMORY_BASE;
|
---|
122 | bootinfo.memmap[bootinfo.memmap_items].size =
|
---|
123 | DEFAULT_MEMORY_SIZE;
|
---|
124 | bootinfo.memmap[bootinfo.memmap_items].type =
|
---|
125 | EFI_MEMMAP_FREE_MEM;
|
---|
126 | bootinfo.memmap_items++;
|
---|
127 |
|
---|
128 | bootinfo.memmap[bootinfo.memmap_items].base =
|
---|
129 | DEFAULT_LEGACY_IO_BASE;
|
---|
130 | bootinfo.memmap[bootinfo.memmap_items].size =
|
---|
131 | DEFAULT_LEGACY_IO_SIZE;
|
---|
132 | bootinfo.memmap[bootinfo.memmap_items].type =
|
---|
133 | EFI_MEMMAP_IO_PORTS;
|
---|
134 | bootinfo.memmap_items++;
|
---|
135 |
|
---|
136 | bootinfo.freq_scale = DEFAULT_FREQ_SCALE;
|
---|
137 | bootinfo.sys_freq = DEFAULT_SYS_FREQ;
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | printf("Booting the kernel ...\n");
|
---|
142 | jump_to_kernel(&bootinfo);
|
---|
143 | }
|
---|