aboutsummaryrefslogtreecommitdiff
path: root/sys/boot/common/load_elf.c
Commit message (Collapse)AuthorAgeFilesLines
* Move sys/boot to stand. Fix all references to new locationWarner Losh2017-11-141-1038/+0
| | | | | | | Sponsored by: Netflix Notes: svn path=/head/; revision=325834
* Don't set the offset when loading the kernel on the arm loader.efi. TheAndrew Turner2016-02-091-1/+6
| | | | | | | | | | | copyin and copyout code handle virtual addresses such that they will take a virtual address and convert it into a valid physical address. It may also mean we fail to boot as the elf files load address could be 0. Sponsored by: ABT Systems Ltd Notes: svn path=/head/; revision=295429
* Fix EFI platform build failuresSteven Hartland2016-02-061-1/+1
| | | | | | | | | | | | | | With warnings now enabled some plaforms where failing due to warnings. * Fix st_size printed as a size_t when its actually an off_t. * Fix pointer conversion in load_elf for some 32bit platforms due to 64bit off in ef. MFC after: 2 days X-MFC-With: Sponsored by: Multiplay Notes: svn path=/head/; revision=295356
* Enable warnings in EFI boot codeSteven Hartland2016-01-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Set WARNS if not set for EFI boot code and fix the issues highlighted by setting it. Most components are set to WARNS level 6 with few being left at lower levels due to the amount of changes needed to fix at higher levels. Error types fixed: * Missing / invalid casts * Missing inner structs * Unused vars * Missing static for internal only funcs * Missing prototypes * Alignment changes * Use of uninitialised vars * Unknown pragma (intrinsic) * Missing types etc due to missing includes * printf formatting types Reviewed by: emaste (in part) MFC after: 2 weeks X-MFC-With: r293268 Sponsored by: Multiplay Differential Revision: https://reviews.freebsd.org/D4839 Notes: svn path=/head/; revision=293724
* An ARM kernel can be loaded at any 2MB boundary, make ubldr aware of that.Ian Lepore2015-05-171-16/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, ubldr would use the virtual addresses in the elf headers by masking off the high bits and assuming the result was a physical address where the kernel should be loaded. That would sometimes discard significant bits of the physical address, but the effects of that were undone by archsw copy code that would find a large block of memory and apply an offset to the source/dest copy addresses. The result was that things were loaded at a different physical address than requested by the higher code layers, but that worked because other adjustments were applied later (such as when jumping to the entry point). Very confusing, and somewhat fragile. Now the archsw copy routines are just simple copies, and instead archsw.arch_loadaddr is implemented to choose a load address. The new routine uses some of the code from the old offset-translation routine to find the largest block of ram, but it excludes ubldr itself from that range, and also excludes If ubldr splits the largest block of ram in two, the kernel is loaded into the bottom of whichever resulting block is larger. As part of eliminating ubldr itself from the ram ranges, export the heap start/end addresses in a pair of new global variables. This change means that the virtual addresses in the arm kernel elf headers now have no meaning at all, except for the entry point address. There is an implicit assumption that the entry point is in the first text page, and that the address in the the header can be turned into an offset by masking it with PAGE_MASK. In the future we can link all arm kernels at a virtual address of 0xC0000000 with no need to use any low-order part of the address to influence where in ram the kernel gets loaded. Notes: svn path=/head/; revision=283035
* Add code to support loading relocatable kernels at offsets that are notNathan Whitehorn2015-01-311-5/+8
| | | | | | | zero. Notes: svn path=/head/; revision=277988
* Add support for booting relocatable kernels on PowerPC.Nathan Whitehorn2015-01-311-19/+27
| | | | Notes: svn path=/head/; revision=277962
* loader: use correct types for parse_modmetadataRoger Pau Monné2015-01-171-4/+4
| | | | | | | | | | | Use the proper types in parse_modmetadata for the p_start and p_end parameters. This was causing problems in the ARM 32bit loader. Sponsored by: Citrix Systems R&D Reported and Tested by: ian Notes: svn path=/head/; revision=277291
* loader: implement multiboot support for Xen Dom0Roger Pau Monné2015-01-151-51/+214
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement a subset of the multiboot specification in order to boot Xen and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot implementation is tailored to boot Xen and FreeBSD Dom0, and it will most surely fail to boot any other multiboot compilant kernel. In order to detect and boot the Xen microkernel, two new file formats are added to the bootloader, multiboot and multiboot_obj. Multiboot support must be tested before regular ELF support, since Xen is a multiboot kernel that also uses ELF. After a multiboot kernel is detected, all the other loaded kernels/modules are parsed by the multiboot_obj format. The layout of the loaded objects in memory is the following; first the Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to long mode by itself), after that the FreeBSD kernel is loaded as a RAW file (Xen will parse and load it using it's internal ELF loader), and finally the metadata and the modules are loaded using the native FreeBSD way. After everything is loaded we jump into Xen's entry point using a small trampoline. The order of the multiboot modules passed to Xen is the following, the first module is the RAW FreeBSD kernel, and the second module is the metadata and the FreeBSD modules. Since Xen will relocate the memory position of the second multiboot module (the one that contains the metadata and native FreeBSD modules), we need to stash the original modulep address inside of the metadata itself in order to recalculate its position once booted. This also means the metadata must come before the loaded modules, so after loading the FreeBSD kernel a portion of memory is reserved in order to place the metadata before booting. In order to tell the loader to boot Xen and then the FreeBSD kernel the following has to be added to the /boot/loader.conf file: xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga" xen_kernel="/boot/xen" The first argument contains the command line that will be passed to the Xen kernel, while the second argument is the path to the Xen kernel itself. This can also be done manually from the loader command line, by for example typing the following set of commands: OK unload OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga OK load kernel OK load zfs OK load if_tap OK load ... OK boot Sponsored by: Citrix Systems R&D Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D517 For the Forth bits: Submitted by: Julien Grall <julien.grall AT citrix.com> Notes: svn path=/head/; revision=277215
* Fix incorrect reading of 32-bit modinfo by 64-bit loaders.Peter Grehan2014-11-111-0/+22
| | | | | | | | | | | | | | | | The various structures in the mod_metadata set of a FreeBSD kernel and modules contain pointers. The FreeBSD loader correctly deals with a mismatch in loader and kernel pointer size (e.g. 32-bit i386/ppc loader, loading 64-bit amd64/ppc64 kernels), but wasn't dealing with the inverse case where a 64-bit loader was loading a 32-bit kernel. Reported by: ktcallbox@gmail.com with a bhyve/i386 and ZFS root install Differential Revision: https://reviews.freebsd.org/D1129 Reviewed by: neel, jhb MFC after: 1 week Notes: svn path=/head/; revision=274407
* Fully support constructors for the purpose of code coverage analysis.Marcel Moolenaar2014-10-201-4/+34
| | | | | | | | | | | | | | | | | | | | This involves: 1. Have the loader pass the start and size of the .ctors section to the kernel in 2 new metadata elements. 2. Have the linker backends look for and record the start and size of the .ctors section in dynamically loaded modules. 3. Have the linker backends call the constructors as part of the final work of initializing preloaded or dynamically loaded modules. Note that LLVM appends the priority of the constructors to the name of the .ctors section. Not so when compiling with GCC. The code currently works for GCC and not for LLVM. Submitted by: Dmitry Mikulin <dmitrym@juniper.net> Obtained from: Juniper Networks, Inc. Notes: svn path=/head/; revision=273334
* Attach the elf section headers to the loaded kernel as metadata, soIan Lepore2013-03-101-0/+2
| | | | | | | | | | | | | | they can easily be used by later post-processing. When searching for a compiled-in fdt blob, use the section headers to get the size and location of the .dynsym section to do a symbol search. This fixes a problem where the search could overshoot the symbol table and wander into the string table. Sometimes that was harmless and sometimes it lead to spurious panic messages about an offset bigger than the module size. Notes: svn path=/head/; revision=248121
* Since ubldr doesn't necessarily load a kernel at the physical address in theIan Lepore2013-03-091-5/+6
| | | | | | | | | | | | | elf headers, mask out the high nibble of that address. This effectly makes the entry point the offset from the load address, and it gets adjusted for the actual load address before jumping to it. Masking the high nibble makes assumptions about memory layout that are true for all the arm platforms we support right now, but it makes me uneasy. This needs to be revisited. Notes: svn path=/head/; revision=248118
* Fix a typo that prevented booting a kernel that had virtual addresses inIan Lepore2013-02-271-1/+1
| | | | | | | the elf headers. Notes: svn path=/head/; revision=247413
* Adjust the arm kernel entry point address properly regardless of whether theIan Lepore2013-02-261-6/+17
| | | | | | | | e_entry field holds a physical or a virtual address. Add a comment block that explains the assumptions being made by the adjustment code. Notes: svn path=/head/; revision=247301
* Fix loading of kernel modules at boot time for powerpc64.Andreas Tobler2012-09-081-3/+3
| | | | | | | | Reported by: Mathias Breuninger MFC after: 1 week Notes: svn path=/head/; revision=240249
* Don't return an error if a kld does not contain any modules (e.g. aJohn Baldwin2012-06-201-1/+1
| | | | | | | | | | kld that only contained a sysctl). The kernel linker allows such modules, so the boot loader should not reject them. MFC after: 2 weeks Notes: svn path=/head/; revision=237338
* Add a version of the FreeBSD bootloader which can run in userland, packagedDoug Rabson2011-06-301-1/+1
| | | | | | | | as a shared library. This is intended to be used by BHyVe to load FreeBSD kernels into new virtual machines. Notes: svn path=/head/; revision=223695
* Add 2 new archsw interfaces:Marcel Moolenaar2011-04-031-9/+10
| | | | | | | | | | | | | | | | | 1. arch_loadaddr - used by platform code to adjust the address at which the object gets loaded. Implement PC98 using this new interface instead of using conditional compilation. For ELF objects the ELF header is passed as the data pointer. For raw files it's the filename. Note that ELF objects are first considered as raw files. 2. arch_loadseg - used by platform code to keep track of actual segments, so that (instruction) caches can be flushed or translations can be created. Both the ELF header as well as the program header are passed to allow platform code to treat the kernel proper differently from any additional modules and to have all the relevant details of the loaded segment (e.g. protection). Notes: svn path=/head/; revision=220311
* Give a bit of a hint of the failure (read != expected) but don't makeEd Maste2010-11-251-1/+1
| | | | | | | | | the error message needlessly more verbose. Discussed with: attilio Notes: svn path=/head/; revision=215811
* Make this printfoutput more verbose.Attilio Rao2010-11-231-1/+2
| | | | | | | | | Sponsored by: Sandvine Incorporated Submitted by: Sandvine Incorporated MFC after: 3 days Notes: svn path=/head/; revision=215758
* Initial support of loader(8) for ARM machines running U-Boot.Rafal Jaworowski2008-10-141-1/+10
| | | | | | | | | | | | | This uses the common U-Boot support lib (sys/boot/uboot, already used on FreeBSD/powerpc), and assumes the underlying firmware has the modern API for stand-alone apps enabled in the config (CONFIG_API). Only netbooting is supported at the moment. Obtained from: Marvell, Semihalf Notes: svn path=/head/; revision=183878
* Add __elfN(relocation_offset). It holds the offset between the virtualMarcel Moolenaar2008-02-231-1/+27
| | | | | | | | | | | | | (link) address and the physical (load) address. Ideally, the mapping between link and load addresses should be abstracted by the copyin(), copyout() and readin() functions, so that we don't have to add kluges in __elfN(loadimage)(). Then, we could also have paged virtual memory for the kernel. This can be important under EFI, where you need to allocate physical memory form the firmware if you want to work in all scenarios. Notes: svn path=/head/; revision=176484
* Unbreak compile with ELF_VERBOSE defined, and fix format warnings.Ruslan Ermilov2006-11-021-3/+4
| | | | Notes: svn path=/head/; revision=163917
* Revert the last change. Masking only 2 MSBs of the virtual addressRuslan Ermilov2006-11-021-1/+1
| | | | | | | | | | | | | | | | to get the physical address doesn't work for all values of KVA_PAGES, while masking 8 MSBs works for all values of KVA_PAGES that are multiple of 4 for non-PAE and 8 for PAE. (This leaves us limited with 12MB for non-PAE kernels and 14MB for PAE kernels.) To get things right, we'd need to subtract the KERNBASE from the virtual address (but KERNBASE is not easy to figure out from here), or have physical addresses set properly in the ELF headers. Discussed with: jhb Notes: svn path=/head/; revision=163914
* Because the BTX mini-kernel now uses flat memory mode and clientsRuslan Ermilov2006-10-291-1/+1
| | | | | | | | | | | | | | | | | | | are no longer limited to a virtual address space of 16 megabytes, only mask high two bits of a virtual address. This allows to load larger kernels (up to 1 gigabyte). Not masking addresses at all was a bad idea on machines with less than >3G of memory -- kernels are linked at 0xc0xxxxxx, and that would attempt to load a kernel at above 3G. By masking only two highest bits we stay within the safe limits while still allowing to boot larger kernels. (This is a safer reimplmentation of sys/boot/i386/boot2/boot.2.c rev. 1.71.) Prodded by: jhb Tested by: nyan (pc98) Notes: svn path=/head/; revision=163765
* Remove more Alpha bits from the boot code including fixing severalJohn Baldwin2006-05-121-1/+1
| | | | | | | stale comments. Notes: svn path=/head/; revision=158467
* Make our ELF64 type definitions match standards. In particular thisMarcel Moolenaar2005-12-181-1/+1
| | | | | | | | | | | | | | | | means: o Remove Elf64_Quarter, o Redefine Elf64_Half to be 16-bit, o Redefine Elf64_Word to be 32-bit, o Add Elf64_Xword and Elf64_Sxword for 64-bit entities, o Use Elf_Size in MI code to abstract the difference between Elf32_Word and Elf64_Word. o Add Elf_Ssize as the signed counterpart of Elf_Size. MFC after: 2 weeks Notes: svn path=/head/; revision=153504
* Separate out the ELF relocation code from the ELF loader, and addIan Dowse2004-08-281-33/+70
| | | | | | | | | | | | better relocation support for the amd64 and i386 platforms. This should not result in any change in functionality, but moves a step towards supporting the relocatable object file modules on amd64. The same hack/trick as load_elf*.c uses is used here to simultaneously support both elf32 and elf64 on amd64 and i386. Notes: svn path=/head/; revision=134458
* Add a few helper functions for zeroing kernel space and readingIan Dowse2004-08-281-37/+11
| | | | | | | from specified file offsets. Make use of these in load_elf.c. Notes: svn path=/head/; revision=134441
* Fixed a misspelling of 0 as NULL.Bruce Evans2004-03-111-1/+1
| | | | Notes: svn path=/head/; revision=126837
* Use __FBSDID().David E. O'Brien2003-08-251-2/+3
| | | | | | | Also some minor style cleanups. Notes: svn path=/head/; revision=119483
* Fix lookup of module metadata on amd64 systems. While this is inPeter Wemm2003-05-121-5/+25
| | | | | | | | | | | common code, the non-trivial part is #ifdef'ed and only executes when loading amd64 kernels. The rest is trivial but needed for the the amd64 case. (Two variables changed from char ** to Elf_Addr). Approved by: re (amd64 "low-risk" stuff) Notes: svn path=/head/; revision=114937
* Enable the i386 loader to load and run an amd64 kernel. If this putsPeter Wemm2003-05-011-53/+64
| | | | | | | | | | | | | | | | | | things over floppy size limits, I can exclude it for release builds or something like that. Most of the changes are to get the load_elf.c file into a seperate elf32_ or elf64_ namespace so that you can have two ELF loaders present at once. Note that for 64 bit kernels, it actually starts up the kernel already in 64 bit mode with paging enabled. This is really easy because we have a known minimum feature set. Of note is that for amd64, we have to pass in the bios int 15 0xe821 memory map because once in long mode, you absolutely cannot make VM86 calls. amd64 does not use 'struct bootinfo' at all. It is a pure loader metadata startup, just like sparc64 and powerpc. Much of the infrastructure to support this was adapted from sparc64. Notes: svn path=/head/; revision=114379
* Libdisk does not need to include <sys/diskslice.h> any more.Poul-Henning Kamp2003-04-041-1/+0
| | | | | | | | | | | | Move the remaining bits of <sys/diskslice.h> to <i386/include/bootinfo.h> Move i386/pc98 specific bits from <sys/reboot.h> to <i386/include/bootinfo.h> as well. Adjust includes in sys/boot accordingly. Notes: svn path=/head/; revision=113083
* Fix module dependency (pre)loading on sparc64 by relocating the variablesJake Burkholder2003-01-211-6/+57
| | | | | | | | | | | read from the raw kld files. Submitted by: Hartmut Brandt <brandt@fokus.gmd.de> PR: 46870 Tested on: alpha (obrien), i386, sparc64 Notes: svn path=/head/; revision=109616
* We don't need bootinfo any more, and sparc64 doesn't have it anyways.David E. O'Brien2002-05-101-1/+0
| | | | Notes: svn path=/head/; revision=96310
* Fix another unsigned long used to index the symbol table which should beJake Burkholder2002-04-091-1/+1
| | | | | | | Elf_Hashelt. Notes: svn path=/head/; revision=94248
* Use the correct elf hash table entry type. This matches a similar fixPeter Wemm2002-04-061-6/+6
| | | | | | | | in the kernel side of things some time ago. The hash table entries are always 32 bits wide, even on 64 bit machines. Notes: svn path=/head/; revision=93922
* Implement the long-awaited module->file cache database. A userlandPeter Wemm2001-09-111-24/+16
| | | | | | | | | | tool (kldxref(8)) keeps a cache of what modules and versions are inside what .ko files. I have tested this on both Alpha and i386. Submitted by: bp Notes: svn path=/head/; revision=83321
* Get rid of some constness warnings.David Malone2001-06-241-6/+7
| | | | Notes: svn path=/head/; revision=78696
* Convert the elf loader to the new linker set layout for elf files.Peter Wemm2001-06-191-6/+7
| | | | | | | | | This should make dependencies at load time work like before. Oops. Noticed by: markm Notes: svn path=/head/; revision=78465
* Fix some of the worst formatting bug (seperate commit)Peter Wemm2001-06-191-2/+4
| | | | Notes: svn path=/head/; revision=78463
* Cleanup warnings. Most of these are signed/unsigned warnings, as well asJohn Baldwin2000-08-031-19/+25
| | | | | | | some added const's. Notes: svn path=/head/; revision=64187
* Remove residual printf.Daniel C. Sobral2000-06-071-1/+0
| | | | | | | Prodded by: msmith Notes: svn path=/head/; revision=61353
* long != int on Alphas.Boris Popov2000-05-121-1/+2
| | | | Notes: svn path=/head/; revision=60432
* Update loader logic to distinguish modules vs. files.Boris Popov2000-05-011-83/+255
| | | | | | | | | | Add support for module metadata. The old way of dependancy handling will be supported for a while. Reviewed by: peter Notes: svn path=/head/; revision=59854
* Fix the loader to handle module dependencies properly. More fixesBoris Popov2000-02-251-39/+8
| | | | | | | | | | will be provided after modmetadata appears in the kernel. Reviewed by: msmith Approved by: jkh Notes: svn path=/head/; revision=57468
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50477
* Enable load of i386 ELF kernels with larger KVA range (e.g. starting atTor Egge1999-02-151-2/+2
| | | | | | | 0xe0100000u or 0xc0100000u instead of the usual 0xf0100000u). Notes: svn path=/head/; revision=44069