Commit graph

105 commits

Author SHA1 Message Date
Daniel Bertalan 45d81dceed Everywhere: Replace ElfW(type) macro usage with Elf_type
This works around a `clang-format-17` bug which caused certain usages to
be misformatted and fail to compile.

Fixes #8315
2023-12-01 10:02:39 +02:00
Vladimir Serbinenko 10d4bbd133 Prekernel: Fix wrong and misleading comment
Comment speaks about MULTIBOOT_MEMORY_INFO but those fields are actually
about aout kludge.
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko 19cede9b3b Prekernel: Load multiboot values before loading kernel
This makes sure we don't clobber multiboot structure before we need it
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko d13609a607 Prekernel: Support kernel preloaded at high address
Loaders try to put modules as low as reasonable but on
EFI often "reasonable" is much higher than on BIOS. As
a result target can be easily higher than source.

Then we have 2 problems:
* memmove compares virtual address and since target
  is mapped higher it ends up going backwards which
  is wrong if target is physically below source
* order of copying of sections must be inverted if
  target is below source
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko 982ce17927 Prekernel: Map entire 4GiB space
Prekernel code currently assumes that mapping until MAX_KERNEL_SIZE
is enough to make the modules accessible. GRUB tries to load as low
as possible but higher than 1 MiB. Hence this is usually true.
However on EFI some ranges may already be used by boot services and
GRUB tries to avoid them if possible. This pushes modules higher.
The simplest solution is to map entire 4 GiB space.
As an additional benefit it makes the framebuffer accessible that
can be used for the debugging.
2023-10-03 16:19:03 -06:00
implicitfield 5dfe2eb389 Everywhere: Resolve conflicts with LibC and libc++
Since https://reviews.llvm.org/D131441, libc++ must be included before
LibC. As clang includes libc++ as one of the system includes, LibC
must be included after those, and the only correct way to do that is
to install LibC's headers into the sysroot.

Targets that don't link with LibC yet require its headers for one
reason or another must add install_libc_headers as a dependency to
ensure that the correct headers have been (re)installed into the
sysroot.

LibC/stddef.h has been dropped since the built-in stddef.h receives
a higher include priority.

In addition, string.h and wchar.h must
define __CORRECT_ISO_CPP_STRING_H_PROTO and
_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS respectively in order to tell
libc++ to not try to define methods implemented by LibC.
2023-06-27 12:40:38 +02:00
implicitfield 79adeb626b LibC+LibELF: Move ELF definitions from LibC to LibELF
This is needed to avoid including LibC headers in Lagom builds.
Unfortunately, we cannot rely on the build machine to provide a
fully POSIX-compatible ELF header for Lagom builds, so we have to
use our own.
2023-06-27 12:40:38 +02:00
Liav A 8f21420a1d Kernel: Move all boot-related code to the new Boot subdirectory 2023-06-04 21:32:34 +02:00
Liav A 7c0540a229 Everywhere: Move global Kernel pattern code to Kernel/Library directory
This has KString, KBuffer, DoubleBuffer, KBufferBuilder, IOWindow,
UserOrKernelBuffer and ScopedCritical classes being moved to the
Kernel/Library subdirectory.

Also, move the panic and assertions handling code to that directory.
2023-06-04 21:32:34 +02:00
Liav A aaa1de7878 Kernel: Move {Virtual,Physical}Address classes to the Memory directory 2023-06-04 21:32:34 +02:00
Tim Schumacher 9ab598af49 Revert "Kernel/x86: Bake the Prekernel and the Kernel into one image"
Some hardware/software configurations crash KVM as soon as we try to
start Serenity. The exact cause is currently unknown, so just fully
revert it for now.

This reverts commit 897c4e5145.
2023-04-28 23:24:19 +02:00
Liav A 897c4e5145 Kernel/x86: Bake the Prekernel and the Kernel into one image
The new baked image is a Prekernel and a Kernel baked together now, so
essentially we no longer need to pass the Prekernel as -kernel and the
actual  kernel image as -initrd to QEMU, leaving the option to pass an
actual initrd or initramfs module later on with multiboot.
2023-04-28 09:23:30 +02:00
konrad 7c8e61f4d1 Kernel: Unify x86-64 assembly snippets naming for RDSEED & RDRAND 2023-01-25 23:17:36 +01:00
Timon Kruiper 33581d5c44 Kernel: Add KERNEL_MAPPING_BASE to Sections.h and use it in Prekernel 2023-01-24 14:54:44 +00:00
Liav A 91db482ad3 Kernel: Reorganize Arch/x86 directory to Arch/x86_64 after i686 removal
No functional change.
2022-12-28 11:53:41 +01:00
Liav A 5ff318cf3a Kernel: Remove i686 support 2022-12-28 11:53:41 +01:00
Keegan Saunders 89b23c473a LibC: Use uintptr_t for __stack_chk_guard
We used size_t, which is a type that is guarenteed to be large
enough to hold an array index, but uintptr_t is designed to be used
to hold pointer values, which is the case of stack guards.
2022-11-29 11:04:21 +01:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Idan Horowitz f9c6f37bac Kernel: Add a 'disable_kaslr' kernel command line parameter
This parameter can be used to disable the KASLR mechanism.
2022-03-24 23:36:56 +00:00
Idan Horowitz f0166efe8c Kernel: Use the whole kernel PD range when randomizing the KASLR offset
Now that we reclaim the memory range that is created by KASLR before
the start of the kernel image, there's no need to be conservative with
the KASLR offset.
2022-03-23 19:49:49 +02:00
Idan Horowitz e18632660f Kernel: Use the pre-image kernel memory range introduced by KASLR
This ensures we don't just waste the memory range between the default
base load address and the actual load address that was shifted by the
KASLR offset.
2022-03-22 16:46:51 +01:00
Idan Horowitz d850e483f7 Kernel: Keep kernel base load address 2 MiB aligned
This requirement comes from the fact the Prekernel mapping logic only
uses 2 MiB pages.
This unfortunately reduces the bits of entropy in kernel addresses from
16 bits to 7, but it could be further improved in the future by making
the Prekernel mapping logic a bit more dynamic.
2022-03-22 16:46:51 +01:00
Andreas Kling b6e767f953 Kernel: Disable KASLR on i686
The 32-bit CI runners don't seem to happy with KASLR, so let's make it
x86-64 only for now.
2022-03-22 02:47:27 +01:00
Idan Horowitz 1ad0e05ea1 Kernel: Add an extremely primitive version of KASLR
This initial (and very basic) implementation of KASLR simply randomizes
the kernel base VA in the 256 MiB range following the default load base.
2022-03-21 23:33:42 +01:00
Jakub V. Flasar 6d2c298b66 Kernel: Move aarch64 Prekernel into Kernel
As there is no need for a Prekernel on aarch64, the Prekernel code was
moved into Kernel itself. The functionality remains the same.

SERENITY_KERNEL_AND_INITRD in run.sh specifies a kernel and an inital
ramdisk to be used by the emulator. This is needed because aarch64
does not need a Prekernel and the other ones do.
2022-03-12 14:54:12 -08:00
Lenny Maiorani c6acf64558 Kernel: Change static constexpr variables to constexpr where possible
Function-local `static constexpr` variables can be `constexpr`. This
can reduce memory consumption, binary size, and offer additional
compiler optimizations.

These changes result in a stripped x86_64 kernel binary size reduction
of 592 bytes.
2022-02-09 21:04:51 +00:00
Andreas Kling e86ab57078 AK+Kernel+LibSanitizer: Store "ubsan-is-deadly" flag as Atomic<bool> 2022-02-03 16:11:26 +01:00
Jesse Buhagiar 5b7682b352 Prekernel: Handle synchronous EL1 exceptions in C++ on aarch64
We now have a mechanism to save the current CPU context to the stack,
and then pass that to the C++ common exception handler.
2022-01-24 06:57:59 +00:00
Jesse Buhagiar 547322fb95 Prekernel: Install EL1 vector table at boot on aarch64
We now have a function to install a (currently default) vector
table, meaning that any exceptions (or interrupts for that matter)
will be caught by the processor and routed to one of the vectors
inside the table.
2022-01-24 06:57:59 +00:00
Jesse Buhagiar 28e36a70d6 Prekernel: Implement print_hex UART function on aarch64
This allows us to print a hex number to the serial
terminal.
2022-01-24 06:57:59 +00:00
mjz19910 10ec98dd38 Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
Tom 6a4d06e739 Kernel: Only use multiboot framebuffer details if present
We should only look at the framebuffer structure members if the
MULTIBOOT_INFO_FRAMEBUFFER_INFO bit is set in the flags field.

Also add some logging if we ignored the fbdev command line argument
due to either not having a framebuffer provided by the bootloader, or
because we don't support the framebuffer format.
2022-01-06 22:34:11 +01:00
Daniel Bertalan 9b90f1fed5 Kernel: Do not do integer to pointer conversion in constexpr functions
Creating pointers from arbitrary values is not a valid thing to do in
constexpr functions. Furthermore, this functions is always called with
runtime values anyways, so there's no use in having it be constexpr.
Instead, make it ALWAYS_INLINE.
2021-12-04 11:59:59 -08:00
James Mintram f7c0cdcc19 Kernel: Use peripheral addresses returned from MMIO to map prekernel mem 2021-11-28 22:01:21 -08:00
James Mintram 4e9777243e Kernel: Refactor prekernel MMU to use a bump allocator 2021-11-28 22:01:21 -08:00
James Mintram 4a4a3193f8 Kernel: Rename Aarch64Asm -> ASM_wrapper and add Aarch64::Asm namespace 2021-11-28 22:01:21 -08:00
James Mintram 34709c8d39 Kernel: Rename Aarch64Registers -> Registers and add Aarch64 namespace 2021-11-28 22:01:21 -08:00
James Mintram 271b9b8da3 Kernel: Set up and activate the MMU in the aarch64 perkernel 2021-11-28 22:01:21 -08:00
James Mintram c2d7e200eb Kernel: Move common aarch64 asm functions into kernel folder and NS 2021-11-28 22:01:21 -08:00
James Mintram 68b5d00f42 Kernel: Split prekernel exception level code into its own file 2021-11-28 22:01:21 -08:00
James Mintram 18f1530c84 Kernel: Change prekernel to use shared SP across Exception Levels 2021-11-28 22:01:21 -08:00
James Mintram 5a75bd31b0 Kernel: Replace inline asm with typesafe static member functions 2021-11-28 22:01:21 -08:00
James Mintram 4bc5936a57 Kernel: Remove unused header from Aarch64_asm_utils 2021-11-28 22:01:21 -08:00
Marcin Undak 588ba72fe7 Kernel: Draw picture on screen when booting Raspberry Pi 2021-10-31 12:35:53 +01:00
Marcin Undak e7141c4230 Kernel: Add very simple PPM parser for Aarch64
This is much simpler and more embeddable version than libGFX one.
Solely purpose is to draw initial boot logo on screen before kernel
is even booted.
2021-10-31 12:35:53 +01:00
Marcin Undak dbb61620be Kernel: Add Framebuffer class for Raspberry Pi
It initializes framebuffer and exposes access to its properties.
2021-10-31 12:35:53 +01:00
Marcin Undak 3cc5752a69 Kernel: Refactor Aarch64 MailBox class
The goal was to reduce common setup of messages. Changes:
* MailBox turned into singleton to follow existing patterns
* Removed device specific messages from MailBox requiring
  clients to know the details instead
* Created base Message class which clients should deriver from

It really simplify the usage for more complicated message queues
like framebuffer setup - see followup commits.
2021-10-31 12:35:53 +01:00
Marcin Undak 82a73b8499 Kernel: Add temporary debug printing utilities for Aarch64
Added dbgln() and warnln() debug functions to help bootstraping.
Eventually they are going to be replaced by AK/Format.h implementation.
2021-10-31 12:35:53 +01:00
Daniel Bertalan 06fc64be13 Toolchain+Meta: Update LLVM version to 13.0.0
This commit updates the Clang toolchain's version to 13.0.0, which comes
with better C++20 support and improved handling of new features by
clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our
Clang binaries will only be 2-4% slower than if we dynamically linked
them, but we save hundreds of megabytes of disk space.

The `BuildClang.sh` script has been reworked to build the entire
toolchain in just three steps: one for the compiler, one for GNU
binutils, and one for the runtime libraries. This reduces the complexity
of the build script, and will allow us to modify the CI configuration to
only rebuild the libraries when our libc headers change.

Most of the compile flags have been moved out to a separate CMake cache
file, similarly to how the Android and Fuchsia toolchains are
implemented within the LLVM repo. This provides a nicer interface than
the heaps of command-line arguments.

We no longer build separate toolchains for each architecture, as the
same Clang binary can compile code for multiple targets.

The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in
this commit. Clang happily accepts an `i686-pc-serenity` target triple,
which matches what our GCC toolchain accepts.
2021-10-17 17:09:58 +01:00
Daniel Bertalan a8fefd89cd Everywhere: Make some symbols __attribute__((used)) for LTO
With these changes, the userland builds correctly with Clang's ThinLTO
enabled.
2021-10-17 17:09:58 +01:00