summaryrefslogtreecommitdiff
path: root/Kernel/linker.ld
AgeCommit message (Collapse)Author
2021-07-27Kernel: Support loading the kernel at almost arbitrary virtual addressesGunnar Beutner
This enables further work on implementing KASLR by adding relocation support to the pre-kernel and updating the kernel to be less dependent on specific virtual memory layouts.
2021-07-20Kernel: Specify protection flags for ELF load headersGunnar Beutner
These are currently unused by the prekernel and ld used the same flags by default - except for the .ksyms section which was marked as read-write.
2021-07-20Kernel: Use the C preprocessor to avoid two copies of the linker scriptGunnar Beutner
2021-07-18Kernel: Use a different kernel load address for x86_64Liav A
Co-authored-by: Gunnar Beutner <gbeutner@serenityos.org>
2021-07-18Kernel: Introduce basic pre-kernel environmentGunnar Beutner
This implements a simple bootloader that is capable of loading ELF64 kernel images. It does this by using QEMU/GRUB to load the kernel image from disk and pass it to our bootloader as a Multiboot module. The bootloader then parses the ELF image and sets it up appropriately. The kernel's entry point is a C++ function with architecture-native code. Co-authored-by: Liav A <liavalb@gmail.com>
2021-07-16Kernel: Move end_of_kernel_image after the .ksyms sectionGunnar Beutner
Without this we won't be able to detect whether .ksyms overlaps the end of the page table we set up for the kernel image.
2021-07-14Kernel: Make kernel symbols available much earlier in the boot processGunnar Beutner
This adds a new section .ksyms at the end of the linker map, reserves 5MiB for it (which are after end_of_kernel_image so they get re-used once MemoryManager is initialized) and then embeds the symbol map into the kernel binary with objcopy. This also shrinks the .ksyms section to the real size of the symbol file (around 900KiB at the moment). By doing this we can make the symbol map available much earlier in the boot process, i.e. even before VFS is available.
2021-06-19Kernel: Make sure the kernel's ELF PHDRs don't use rwxGunnar Beutner
This doesn't really matter in terms of writability for the kernel text because we set up proper page mappings anyway which prohibit writing to the text segment. However, this makes the profiler happy which previously died when validating the kernel's ELF program headers.
2021-06-17Kernel: Move super_pages section into the bottom 16MBGunnar Beutner
This ensures that pages returned by MM.allocate_supervisor_physical_page() have a physical address that is in the bottom 16MB and can thus be used by the SB16 driver for DMA. Fixes #8092.
2021-03-04Kernel: Define a KERNEL_VIRTUAL_BASE in the linker scriptAndreas Kling
Slightly nicer than saying "0xc0000000" over and over.
2021-02-19Kernel: Add .unmap_after_init section for code we don't need after initAndreas Kling
You can now declare functions with UNMAP_AFTER_INIT and they'll get segregated into a separate kernel section that gets completely unmapped at the end of initialization. This can be used for anything we don't need to call once we've booted into userspace. There are two nice things about this mechanism: - It allows us to free up entire pages of memory for other use. (Note that this patch does not actually make use of the freed pages yet, but in the future we totally could!) - It allows us to get rid of obviously dangerous gadgets like write-to-CR0 and write-to-CR4 which are very useful for an attacker trying to disable SMAP/SMEP/etc. I've also made sure to include a helpful panic message in case you hit a kernel crash because of this protection. :^)
2021-02-14Kernel: Add mechanism to make some memory read-only after init finishesAndreas Kling
You can now use the READONLY_AFTER_INIT macro when declaring a variable and we will put it in a special ".ro_after_init" section in the kernel. Data in that section remains writable during the boot and init process, and is then marked read-only just before launching the SystemServer. This is based on an idea from the Linux kernel. :^)
2021-02-12Kernel: Merge split function and data sections into one during linkingOwen Smith
Also add an assertion to make sure the safemem sections are never discarded by the linker.
2021-01-22Kernel: Move kmalloc heaps and super pages inside .bss segmentJean-Baptiste Boric
The kernel ignored the first 8 MiB of RAM while parsing the memory map because the kmalloc heaps and the super physical pages lived here. Move all that stuff inside the .bss segment so that those memory regions are accounted for, otherwise we risk overwriting boot modules placed next to the kernel.
2021-01-17Kernel: Add safe atomic functionsTom
This allows us to perform atomic operations on potentially unsafe user space pointers.
2020-08-10Kernel: Invoke heap constructors separately early onTom
By having a separate list of constructors for the kernel heap code, we can properly use constructors without re-running them after the heap was already initialized. This solves some problems where values were wiped out because they were overwritten by running their constructors later in the initialization process.
2020-05-14Build: Switch to CMake :^)Sergey Bugaev
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-01-17Kernel: Move kernel above the 3GB virtual address markAndreas Kling
The kernel and its static data structures are no longer identity-mapped in the bottom 8MB of the address space, but instead move above 3GB. The first 8MB above 3GB are pseudo-identity-mapped to the bottom 8MB of the physical address space. But things don't have to stay this way! Thanks to Jesse who made an earlier attempt at this, it was really easy to get device drivers working once the page tables were in place! :^) Fixes #734.
2020-01-17Kernel: Reindent linker scriptAndreas Kling
2020-01-06Kernel: Harden memory mapping of the kernel imageAndreas Kling
We now map the kernel's text and rodata segments read+execute. We also make the data and bss segments non-executable. Thanks to q3k for the idea! :^)
2019-11-23Revert "Kernel: Move Kernel mapping to 0xc0000000"Andreas Kling
This reverts commit bd33c6627394b2166e1419965dd3b2d2dc0c401f. This broke the network card drivers, since they depended on kmalloc addresses being identity-mapped.
2019-11-22Kernel: Move Kernel mapping to 0xc0000000Jesse Buhagiar
The kernel is now no longer identity mapped to the bottom 8MiB of memory, and is now mapped at the higher address of `0xc0000000`. The lower ~1MiB of memory (from GRUB's mmap), however is still identity mapped to provide an easy way for the kernel to get physical pages for things such as DMA etc. These could later be mapped to the higher address too, as I'm not too sure how to go about doing this elegantly without a lot of address subtractions.
2019-11-08Kernel: Removing hardcoded offsets from Memory Managersupercomputer7
Now the kernel page directory and the page tables are located at a safe address, to prevent from paging data colliding with garbage.
2019-11-04Kernel: Reorganize memory layout a bitAndreas Kling
Move the kernel image to the 1 MB physical mark. This prevents it from colliding with stuff like the VGA memory. This was causing us to end up with the BIOS screen contents sneaking into kernel memory sometimes. This patch also bumps the kmalloc heap size from 1 MB to 3 MB. It's not the perfect permanent solution (obviously) but it should get the OOM monkey off our backs for a while.
2019-10-31Kernel: Add bare minimum for global constructors (#707)Andrew Kaster
Add text.startup to the .text block, add .ctors as well. Use them in init.cpp to call global constructors after gtd and idt init. That way any funky constructors should be ok. Also defines some Itanium C++ ABI methods that probably shouldn't be, but without them the linker gets very angry. If the code ever actually tries to use __dso_handle or call __cxa_atexit, there's bigger problems with the kernel. Bit of a hack would be an understatement but hey. It works :)
2019-10-20Kernel: Move Boot/ into Arch/i386/Boot (#667)Tidux
2019-04-01Kernel: Use a multiboot header instead of a convoluted two-part bootloader.Andreas Kling
The old bootloader was hilariously complicated, requiring a floppy disk with the kernel on it, and a hard drive with the file system. This patch removes the floppy disk from the equation and replaces it with a multiboot header. This means the kernel can now be booted with qemu-system-i386 -kernel kernel
2018-10-16Import the "gerbert" kernel I worked on earlier this year.Andreas Kling
It's a lot crappier than I remembered it. It's gonna need a lot of work.