source: mainline/boot/arch/ia64/src/main.c@ 09ab0a9a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 09ab0a9a was 09ab0a9a, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix vertical spacing with new Ccheck revision.

  • Property mode set to 100644
File size: 6.3 KB
RevLine 
[807102ca]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#include <arch/main.h>
[bbe4828]31#include <arch/types.h>
[807102ca]32#include <arch/arch.h>
33#include <arch/asm.h>
[bbe4828]34#include <genarch/efi.h>
[26fb118a]35#include <arch/sal.h>
[699f3bc]36#include <arch/pal.h>
[807102ca]37#include <halt.h>
38#include <printf.h>
39#include <memstr.h>
40#include <version.h>
41#include <macros.h>
42#include <align.h>
43#include <str.h>
44#include <errno.h>
45#include <inflate.h>
[4646710]46#include "../../components.h"
[807102ca]47
48#define DEFAULT_MEMORY_BASE 0x4000000ULL
[dbb3552]49#define DEFAULT_MEMORY_SIZE (256 * 1024 * 1024)
[807102ca]50#define DEFAULT_LEGACY_IO_BASE 0x00000FFFFC000000ULL
51#define DEFAULT_LEGACY_IO_SIZE 0x4000000ULL
52
53#define DEFAULT_FREQ_SCALE 0x0000000100000001ULL /* 1/1 */
54#define DEFAULT_SYS_FREQ 100000000ULL /* 100MHz */
55
[bbe4828]56#define MEMMAP_FREE_MEM 0
57#define MEMMAP_IO 1
58#define MEMMAP_IO_PORTS 2
59
60extern boot_param_t *bootpar;
[807102ca]61
62static bootinfo_t bootinfo;
63
[bbe4828]64static void read_efi_memmap(void)
65{
66 memmap_item_t *memmap = bootinfo.memmap;
67 size_t items = 0;
[a35b458]68
[bbe4828]69 if (!bootpar) {
70 /* Fake-up a memory map for simulators. */
71 memmap[items].base = DEFAULT_MEMORY_BASE;
72 memmap[items].size = DEFAULT_MEMORY_SIZE;
73 memmap[items].type = MEMMAP_FREE_MEM;
74 items++;
75
76 memmap[items].base = DEFAULT_LEGACY_IO_BASE;
77 memmap[items].size = DEFAULT_LEGACY_IO_SIZE;
78 memmap[items].type = MEMMAP_IO_PORTS;
[4646710]79 items++;
[bbe4828]80 } else {
81 char *cur, *mm_base = (char *) bootpar->efi_memmap;
82 size_t mm_size = bootpar->efi_memmap_sz;
83 size_t md_size = bootpar->efi_memdesc_sz;
[a35b458]84
[bbe4828]85 /*
86 * Walk the EFI memory map using the V1 memory descriptor
87 * format. The actual memory descriptor can use newer format,
88 * but it must always be backwards compatible with the V1
89 * format.
90 */
91 for (cur = mm_base;
92 (cur < mm_base + (mm_size - md_size)) &&
93 (items < MEMMAP_ITEMS);
94 cur += md_size) {
95 efi_v1_memdesc_t *md = (efi_v1_memdesc_t *) cur;
96
97 switch ((efi_memory_type_t) md->type) {
98 case EFI_CONVENTIONAL_MEMORY:
99 memmap[items].type = MEMMAP_FREE_MEM;
100 break;
101 case EFI_MEMORY_MAPPED_IO:
102 memmap[items].type = MEMMAP_IO;
103 break;
104 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
105 memmap[items].type = MEMMAP_IO_PORTS;
106 break;
107 default:
108 continue;
109 }
[a35b458]110
[bbe4828]111 memmap[items].base = md->phys_start;
112 memmap[items].size = md->pages * EFI_PAGE_SIZE;
113 items++;
114 }
115 }
[a35b458]116
[bbe4828]117 bootinfo.memmap_items = items;
118}
119
[577fe9b6]120static void read_pal_configuration(void)
121{
122 if (bootpar) {
[699f3bc]123 bootinfo.freq_scale = pal_proc_freq_ratio();
[577fe9b6]124 } else {
125 /* Configure default values for simulators. */
126 bootinfo.freq_scale = DEFAULT_FREQ_SCALE;
127 }
128}
129
[bbe4828]130static void read_sal_configuration(void)
131{
[26fb118a]132 if (bootpar && bootpar->efi_system_table) {
133 efi_guid_t sal_guid = SAL_SYSTEM_TABLE_GUID;
134 sal_system_table_header_t *sal_st;
[a35b458]135
[26fb118a]136 sal_st = efi_vendor_table_find(
137 (efi_system_table_t *) bootpar->efi_system_table, sal_guid);
138
139 sal_system_table_parse(sal_st);
[a35b458]140
[577fe9b6]141 bootinfo.sys_freq = sal_base_clock_frequency();
[bbe4828]142 } else {
[26fb118a]143 /* Configure default values for simulators. */
[bbe4828]144 bootinfo.sys_freq = DEFAULT_SYS_FREQ;
145 }
146}
147
[807102ca]148void bootstrap(void)
149{
150 version_print();
[a35b458]151
[807102ca]152 printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
[7e752b2]153 printf(" %p|%p: kernel entry point\n",
154 (void *) KERNEL_ADDRESS, (void *) KERNEL_ADDRESS);
155 printf(" %p|%p: loader entry point\n",
156 (void *) LOADER_ADDRESS, (void *) LOADER_ADDRESS);
[a35b458]157
[807102ca]158 size_t i;
159 for (i = 0; i < COMPONENTS; i++)
[4646710]160 printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
161 components[i].addr, components[i].name,
[807102ca]162 components[i].inflated, components[i].size);
[a35b458]163
[807102ca]164 void *dest[COMPONENTS];
165 size_t top = KERNEL_ADDRESS;
166 size_t cnt = 0;
167 bootinfo.taskmap.cnt = 0;
168 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
169 top = ALIGN_UP(top, PAGE_SIZE);
[a35b458]170
[807102ca]171 if (i > 0) {
172 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
173 (void *) top;
174 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
175 components[i].inflated;
[a35b458]176
[807102ca]177 str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
178 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
[a35b458]179
[807102ca]180 bootinfo.taskmap.cnt++;
181 }
[a35b458]182
[807102ca]183 dest[i] = (void *) top;
184 top += components[i].inflated;
185 cnt++;
186 }
[a35b458]187
[807102ca]188 printf("\nInflating components ... ");
[a35b458]189
[bb1b44e]190 /*
191 * We will use the next available address for a copy of each component to
192 * make sure that inflate() works with disjunctive memory regions.
193 */
194 top = ALIGN_UP(top, PAGE_SIZE);
195
[807102ca]196 for (i = cnt; i > 0; i--) {
197 printf("%s ", components[i - 1].name);
[a35b458]198
[bb1b44e]199 /*
200 * Copy the component to a location which is guaranteed not to
201 * overlap with the destination for inflate().
202 */
[4646710]203 memmove((void *) top, components[i - 1].addr, components[i - 1].size);
[a35b458]204
[bb1b44e]205 int err = inflate((void *) top, components[i - 1].size,
[807102ca]206 dest[i - 1], components[i - 1].inflated);
[a35b458]207
[807102ca]208 if (err != EOK) {
209 printf("\n%s: Inflating error %d, halting.\n",
210 components[i - 1].name, err);
211 halt();
212 }
213 }
[a35b458]214
[807102ca]215 printf(".\n");
216
[bbe4828]217 read_efi_memmap();
218 read_sal_configuration();
[577fe9b6]219 read_pal_configuration();
[a35b458]220
[807102ca]221 printf("Booting the kernel ...\n");
222 jump_to_kernel(&bootinfo);
223}
Note: See TracBrowser for help on using the repository browser.