Print this page
12195 acpidump failed under EFI
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/dboot/dboot_elfload.c
+++ new/usr/src/uts/i86pc/dboot/dboot_elfload.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 +/*
28 + * Copyright 2020 Joyent, Inc.
29 + */
27 30
28 31 #include <sys/types.h>
29 32 #include <sys/inttypes.h>
30 33 #include <sys/systm.h>
31 34 #include <sys/elf.h>
32 35 #include <sys/elf_notes.h>
33 36
34 37 #include <util/memcpy.h>
35 38
36 39 #include "dboot_xboot.h"
37 40 #include "dboot_elfload.h"
38 41 #include "dboot_printf.h"
39 42
40 43 static caddr_t elf_file = 0;
41 44
42 45 #define PGETBYTES(offset) ((void *)(elf_file + (offset)))
43 46
44 47 static void *
45 48 getehdr(void)
46 49 {
47 50 uchar_t *ident;
48 51 void *hdr = NULL;
49 52
50 53 ident = PGETBYTES(0);
51 54 if (ident == NULL)
52 55 dboot_panic("Cannot read kernel ELF header");
53 56
54 57 if (ident[EI_MAG0] != ELFMAG0 || ident[EI_MAG1] != ELFMAG1 ||
55 58 ident[EI_MAG2] != ELFMAG2 || ident[EI_MAG3] != ELFMAG3)
56 59 dboot_panic("not an ELF file!");
57 60
58 61 if (ident[EI_CLASS] == ELFCLASS32)
59 62 hdr = PGETBYTES(0);
60 63 else if (ident[EI_CLASS] == ELFCLASS64)
61 64 hdr = PGETBYTES(0);
62 65 else
63 66 dboot_panic("Unknown ELF class");
64 67
65 68 return (hdr);
66 69 }
67 70
68 71
69 72 /*
70 73 * parse the elf file for program information
71 74 */
72 75 int
73 76 dboot_elfload64(uintptr_t file_image)
74 77 {
75 78 Elf64_Ehdr *eh;
76 79 Elf64_Phdr *phdr;
77 80 Elf64_Shdr *shdr;
78 81 caddr_t allphdrs, sechdrs;
79 82 int i;
80 83 paddr_t src;
81 84 paddr_t dst;
82 85 paddr_t next_addr;
83 86
84 87 elf_file = (caddr_t)file_image;
85 88
86 89 allphdrs = NULL;
87 90
88 91 eh = getehdr();
89 92 if (eh == NULL)
90 93 dboot_panic("getehdr() failed");
91 94
92 95 if (eh->e_type != ET_EXEC)
93 96 dboot_panic("not ET_EXEC, e_type = 0x%x", eh->e_type);
94 97
95 98 if (eh->e_phnum == 0 || eh->e_phoff == 0)
96 99 dboot_panic("no program headers");
97 100
98 101 /*
99 102 * Get the program headers.
100 103 */
101 104 allphdrs = PGETBYTES(eh->e_phoff);
102 105 if (allphdrs == NULL)
103 106 dboot_panic("Failed to get program headers e_phnum = %d",
104 107 eh->e_phnum);
105 108
106 109 /*
107 110 * Get the section headers.
108 111 */
109 112 sechdrs = PGETBYTES(eh->e_shoff);
110 113 if (sechdrs == NULL)
111 114 dboot_panic("Failed to get section headers e_shnum = %d",
112 115 eh->e_shnum);
113 116
114 117 /*
115 118 * Next look for interesting program headers.
116 119 */
117 120 for (i = 0; i < eh->e_phnum; i++) {
118 121 /*LINTED [ELF program header alignment]*/
119 122 phdr = (Elf64_Phdr *)(allphdrs + eh->e_phentsize * i);
120 123
121 124 /*
122 125 * Dynamically-linked executable.
123 126 * Complain.
124 127 */
125 128 if (phdr->p_type == PT_INTERP) {
126 129 dboot_printf("warning: PT_INTERP section\n");
127 130 continue;
128 131 }
129 132
130 133 /*
131 134 * at this point we only care about PT_LOAD segments
132 135 */
133 136 if (phdr->p_type != PT_LOAD)
134 137 continue;
135 138
136 139 if (phdr->p_flags == (PF_R | PF_W) && phdr->p_vaddr == 0) {
137 140 dboot_printf("warning: krtld reloc info?\n");
138 141 continue;
139 142 }
140 143
141 144 /*
142 145 * If memory size is zero just ignore this header.
143 146 */
144 147 if (phdr->p_memsz == 0)
145 148 continue;
146 149
147 150 /*
148 151 * If load address 1:1 then ignore this header.
149 152 */
150 153 if (phdr->p_paddr == phdr->p_vaddr) {
151 154 if (prom_debug)
152 155 dboot_printf("Skipping PT_LOAD segment for "
153 156 "paddr = 0x%lx\n", (ulong_t)phdr->p_paddr);
154 157 continue;
155 158 }
156 159
157 160 /*
158 161 * copy the data to kernel area
159 162 */
160 163 if (phdr->p_paddr != FOUR_MEG && phdr->p_paddr != 2 * FOUR_MEG)
161 164 dboot_panic("Bad paddr for kernel nucleus segment");
162 165 src = (uintptr_t)PGETBYTES(phdr->p_offset);
163 166 dst = ktext_phys + phdr->p_paddr - FOUR_MEG;
164 167 if (prom_debug)
165 168 dboot_printf("copying %ld bytes from ELF offset 0x%lx "
166 169 "to physaddr 0x%lx (va=0x%lx)\n",
167 170 (ulong_t)phdr->p_filesz, (ulong_t)phdr->p_offset,
168 171 (ulong_t)dst, (ulong_t)phdr->p_vaddr);
169 172 (void) memcpy((void *)(uintptr_t)dst,
170 173 (void *)(uintptr_t)src, (size_t)phdr->p_filesz);
171 174
172 175 next_addr = dst + phdr->p_filesz;
173 176 }
174 177
↓ open down ↓ |
138 lines elided |
↑ open up ↑ |
175 178
176 179 /*
177 180 * Next look for bss
178 181 */
179 182 for (i = 0; i < eh->e_shnum; i++) {
180 183 shdr = (Elf64_Shdr *)(sechdrs + eh->e_shentsize * i);
181 184
182 185 /* zero out bss */
183 186 if (shdr->sh_type == SHT_NOBITS) {
184 187 if (prom_debug)
185 - dboot_printf("zeroing BSS %lu bytes from "
188 + dboot_printf("zeroing BSS %ld bytes from "
186 189 "physaddr 0x%" PRIx64
187 190 " (end=0x%" PRIx64 ")\n",
188 191 (ulong_t)shdr->sh_size,
189 192 next_addr,
190 193 next_addr + shdr->sh_size);
191 194 (void) memset((void *)(uintptr_t)next_addr, 0,
192 195 shdr->sh_size);
193 196 break;
194 197 }
195 198 }
196 199
197 200 /*
198 201 * Ignore the intepreter (or should we die if there is one??)
199 202 */
200 203 return (0);
201 204 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX