Date: Fri, 17 May 2002 16:32:39 -0700 (PDT) From: Jake Burkholder <jake@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 11459 for review Message-ID: <200205172332.g4HNWdU24448@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=11459 Change 11459 by jake@jake_sparc64 on 2002/05/17 16:32:15 Inline the load function. Affected files ... ... //depot/projects/sparc64/sys/boot/sparc64/boot1/boot1.c#5 edit Differences ... ==== //depot/projects/sparc64/sys/boot/sparc64/boot1/boot1.c#5 (text+ko) ==== @@ -347,6 +347,10 @@ main(int ac, char **av) { const char *path; + Elf64_Ehdr eh; + Elf64_Phdr ph; + caddr_t p; + ino_t ino; int i; path = _PATH_LOADER; @@ -369,10 +373,29 @@ " Boot loader: %s\n", bootpath, path); if (mount(bootpath) == -1) - panic("mount"); - - load(path); - return (1); + panic("main: can't mount %s", bootpath); + if ((ino = lookup(path)) == 0) + panic("main: file %s not found", path); + if (fsread(ino, &eh, sizeof(eh)) != sizeof(eh)) + panic("main: can't read elf header"); + if (!IS_ELF(eh)) + panic("main: not an elf file"); + for (i = 0; i < eh.e_phnum; i++) { + fs_off = eh.e_phoff + i * eh.e_phentsize; + if (fsread(ino, &ph, sizeof(ph)) != sizeof(ph)) + panic("main: can't read program header %d", i); + if (ph.p_type != PT_LOAD) + continue; + fs_off = ph.p_offset; + p = (caddr_t)ph.p_vaddr; + if (fsread(ino, p, ph.p_filesz) != ph.p_filesz) + panic("main: can't read contents of section %d", i); + if (ph.p_filesz != ph.p_memsz) + bzero(p + ph.p_filesz, ph.p_memsz - ph.p_filesz); + } + ofw_close(bootdev); + (*(void (*)())eh.e_entry)(0, 0, 0, 0, ofw); + panic("main"); } static void @@ -411,48 +434,6 @@ return (0); } -static void -load(const char *fname) -{ - Elf64_Ehdr eh; - Elf64_Phdr ph; - caddr_t p; - ino_t ino; - int i; - - if ((ino = lookup(fname)) == 0) { - printf("File %s not found\n", fname); - return; - } - if (fsread(ino, &eh, sizeof(eh)) != sizeof(eh)) { - printf("Can't read elf header\n"); - return; - } - if (!IS_ELF(eh)) { - printf("Not an ELF file\n"); - return; - } - for (i = 0; i < eh.e_phnum; i++) { - fs_off = eh.e_phoff + i * eh.e_phentsize; - if (fsread(ino, &ph, sizeof(ph)) != sizeof(ph)) { - printf("Can't read program header %d\n", i); - return; - } - if (ph.p_type != PT_LOAD) - continue; - fs_off = ph.p_offset; - p = (caddr_t)ph.p_vaddr; - if (fsread(ino, p, ph.p_filesz) != ph.p_filesz) { - printf("Can't read content of section %d\n", i); - return; - } - if (ph.p_filesz != ph.p_memsz) - bzero(p + ph.p_filesz, ph.p_memsz - ph.p_filesz); - } - ofw_close(bootdev); - (*(void (*)(int, int, int, int, ofwfp_t))eh.e_entry)(0, 0, 0, 0, ofw); -} - static ino_t lookup(const char *path) { To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200205172332.g4HNWdU24448>