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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e8d3165e was e8d3165e, checked in by Jakub Jermar <jakub@…>, 6 years ago

Treat additional region types as available memory

In order for the ia64 loader to find the memory map area occupied by the
kernel (a.k.a. ram_end), it needs to consider additioanl region types
which also denote available memory (after the call to ExitBootServices).
These are: EfiLoaderCode, EfiLoaderData, EfiBootServicesCode and
EfiBootServicesData. Without this the memory map is incomplete and
contains a big hole that covers the entire area of the loaded image. The
loader then cannot find ram_end and the boot fails. The memory map also
needs to be compacted so that adjacent regions of the same type are not
too small for a successful boot.

  • Property mode set to 100644
File size: 6.1 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>
[63a045c]45#include <payload.h>
[cfdeedc]46#include <kernel.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;
[e8d3165e]96 memmap_item_t *o = NULL;
97
98 if (items)
99 o = &memmap[items - 1];
[bbe4828]100
101 switch ((efi_memory_type_t) md->type) {
[e8d3165e]102 case EFI_LOADER_CODE:
103 case EFI_LOADER_DATA:
104 case EFI_BOOT_SERVICES_CODE:
105 case EFI_BOOT_SERVICES_DATA:
[bbe4828]106 case EFI_CONVENTIONAL_MEMORY:
[e8d3165e]107 if (o && o->type == MEMMAP_FREE_MEM &&
108 o->base + o->size == md->phys_start) {
109 o->size += md->pages * EFI_PAGE_SIZE;
110 continue;
111 }
[bbe4828]112 memmap[items].type = MEMMAP_FREE_MEM;
113 break;
114 case EFI_MEMORY_MAPPED_IO:
115 memmap[items].type = MEMMAP_IO;
116 break;
117 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
118 memmap[items].type = MEMMAP_IO_PORTS;
119 break;
120 default:
121 continue;
122 }
[a35b458]123
[bbe4828]124 memmap[items].base = md->phys_start;
125 memmap[items].size = md->pages * EFI_PAGE_SIZE;
126 items++;
127 }
128 }
[a35b458]129
[bbe4828]130 bootinfo.memmap_items = items;
131}
132
[577fe9b6]133static void read_pal_configuration(void)
134{
135 if (bootpar) {
[699f3bc]136 bootinfo.freq_scale = pal_proc_freq_ratio();
[577fe9b6]137 } else {
138 /* Configure default values for simulators. */
139 bootinfo.freq_scale = DEFAULT_FREQ_SCALE;
140 }
141}
142
[bbe4828]143static void read_sal_configuration(void)
144{
[26fb118a]145 if (bootpar && bootpar->efi_system_table) {
146 efi_guid_t sal_guid = SAL_SYSTEM_TABLE_GUID;
147 sal_system_table_header_t *sal_st;
[a35b458]148
[26fb118a]149 sal_st = efi_vendor_table_find(
150 (efi_system_table_t *) bootpar->efi_system_table, sal_guid);
151
152 sal_system_table_parse(sal_st);
[a35b458]153
[577fe9b6]154 bootinfo.sys_freq = sal_base_clock_frequency();
[bbe4828]155 } else {
[26fb118a]156 /* Configure default values for simulators. */
[bbe4828]157 bootinfo.sys_freq = DEFAULT_SYS_FREQ;
158 }
159}
160
[807102ca]161void bootstrap(void)
162{
163 version_print();
[a35b458]164
[63a045c]165 printf("Boot loader: %p -> %p\n", loader_start, loader_end);
[807102ca]166 printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
[7e752b2]167 printf(" %p|%p: kernel entry point\n",
168 (void *) KERNEL_ADDRESS, (void *) KERNEL_ADDRESS);
169 printf(" %p|%p: loader entry point\n",
170 (void *) LOADER_ADDRESS, (void *) LOADER_ADDRESS);
[a35b458]171
[63a045c]172 read_efi_memmap();
173 read_sal_configuration();
174 read_pal_configuration();
[a35b458]175
[63a045c]176 uint8_t *kernel_start = (uint8_t *) KERNEL_ADDRESS;
177 uint8_t *ram_end = NULL;
[a35b458]178
[63a045c]179 /* Find the end of the memory area occupied by the kernel. */
180 for (unsigned i = 0; i < bootinfo.memmap_items; i++) {
181 memmap_item_t m = bootinfo.memmap[i];
182 if (m.type == MEMMAP_FREE_MEM &&
183 m.base <= (uintptr_t) kernel_start &&
184 m.base + m.size > (uintptr_t) kernel_start) {
185 ram_end = (uint8_t *) (m.base + m.size);
[807102ca]186 }
187 }
[a35b458]188
[63a045c]189 if (ram_end == NULL) {
190 printf("Memory map doesn't contain usable area at kernel's address.\n");
191 halt();
192 }
[807102ca]193
[63a045c]194 // FIXME: Correct kernel's logical address.
195 extract_payload(&bootinfo.taskmap, kernel_start, ram_end,
196 (uintptr_t) kernel_start, NULL);
[a35b458]197
[cfdeedc]198 uintptr_t entry = check_kernel(kernel_start);
199
200 // FIXME: kernel's entry point is linked at a different address than
201 // where it is run from.
202 entry = entry - KERNEL_VADDRESS + KERNEL_ADDRESS;
203
204 printf("Booting the kernel at %p...\n", (void *) entry);
205 jump_to_kernel(&bootinfo, (void *) entry);
[807102ca]206}
Note: See TracBrowser for help on using the repository browser.