MCPcopy Create free account
hub / github.com/F-Stack/f-stack / load_kernel

Function load_kernel

freebsd/mips/mips/elf_trampoline.c:104–208  ·  view source on GitHub ↗

* Relocate PT_LOAD segements of kernel ELF image to their respective * virtual addresses and return entry point */

Source from the content-addressed store, hash-verified

102 * virtual addresses and return entry point
103 */
104void *
105load_kernel(void * kstart)
106{
107#if ELFSIZE == 64
108 Elf64_Ehdr *eh;
109 Elf64_Phdr phdr[64] /* XXX */;
110 Elf64_Shdr shdr[64] /* XXX */;
111#else
112 Elf32_Ehdr *eh;
113 Elf32_Phdr phdr[64] /* XXX */;
114 Elf32_Shdr shdr[64] /* XXX */;
115#endif
116 int i, j;
117 void *entry_point;
118 vm_offset_t loadend = 0;
119 intptr_t lastaddr;
120 int symtabindex = -1;
121 int symstrindex = -1;
122 Elf_Size tmp;
123
124#if ELFSIZE == 64
125 eh = (Elf64_Ehdr *)kstart;
126#else
127 eh = (Elf32_Ehdr *)kstart;
128#endif
129 entry_point = mkptr(eh->e_entry);
130 memcpy(phdr, (void *)(kstart + eh->e_phoff),
131 eh->e_phnum * sizeof(phdr[0]));
132
133 memcpy(shdr, (void *)(kstart + eh->e_shoff),
134 sizeof(*shdr) * eh->e_shnum);
135
136 if (eh->e_shnum * eh->e_shentsize != 0 && eh->e_shoff != 0) {
137 for (i = 0; i < eh->e_shnum; i++) {
138 if (shdr[i].sh_type == SHT_SYMTAB) {
139 /*
140 * XXX: check if .symtab is in PT_LOAD?
141 */
142 if (shdr[i].sh_offset != 0 &&
143 shdr[i].sh_size != 0) {
144 symtabindex = i;
145 symstrindex = shdr[i].sh_link;
146 }
147 }
148 }
149 }
150
151 /*
152 * Copy loadable segments
153 */
154 for (i = 0; i < eh->e_phnum; i++) {
155 volatile char c;
156
157 if (phdr[i].p_type != PT_LOAD)
158 continue;
159
160 memcpy(mkptr(phdr[i].p_vaddr),
161 (void*)(kstart + phdr[i].p_offset), phdr[i].p_filesz);

Callers 1

_startCFunction · 0.85

Calls 2

bzeroFunction · 0.85
memcpyFunction · 0.70

Tested by

no test coverage detected