Commit Graph

57 Commits

Author SHA1 Message Date
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
Tim Schumacher
20986b7066 Prekernel: Force enable PAE on Intel Pentium M CPUs 2021-10-17 16:15:36 +01:00
Tim Schumacher
e8808b259a Prekernel: Split early boot printing into two subroutines 2021-10-17 16:15:36 +01:00
Tim Schumacher
52621093c7 Kernel: Print CPU check errors by writing to VRAM 2021-10-17 12:25:50 +01:00
Marcin Undak
d14d7ee78b Kernel: Discover initial exception level when booting Aarch64
When booting on RPI3 firmware puts CPU in EL2 mode which is
different from QEMU's default EL3.

I've added logic to discover initial mode at boot
and then act accordingly. This results in Serenity corectly
switching to EL1 on target hardware now.
2021-10-15 17:47:39 +01:00
Marcin Undak
ebf810f9a6 Kernel: Make Aarch64 register variables bit more descriptive 2021-10-15 17:47:39 +01:00
Marcin Undak
2d9fa8146c Kernel: Switch processor to EL1 immediately after boot on Aarch64 2021-10-15 17:47:39 +01:00
Marcin Undak
d6021300d5 Kernel: Move wait_cycles() function to Aarch_asm_utils.S
Just a bit of housekeeping.
2021-10-15 17:47:39 +01:00
Marcin Undak
18eb4a59d6 Kernel: Print current CPU exception level after booting on Aarch64
This is a first step to switch to exception level 1.

This is also my first patch for SerenityOS :)
2021-10-15 17:47:39 +01:00
James Mintram
d92967406a Kernel: Add post build step to generate kernel8.img
Add a postbuild step which creates a raw binary file called kernel8.img
from the Prekernel elf file.
2021-10-13 23:34:29 +01:00
Nico Weber
2c0d329bf6 Kernel: Make aarch64 UART::print_num() print u64s 2021-10-02 21:23:28 +01:00
Nico Weber
bc213ad7a2 Kernel: Add a Timer class for aarch64
For now, this can only query microseconds since boot.

Use this to print a timestamp every second. This busy-loops
until a second has passed. This might be a good first use of
interrupts soon.

qemu used to not implement this timer at some point, but
it seems to work fine even in qemu now (qemu v 5.2.0).
2021-10-02 21:23:28 +01:00
Nico Weber
6c4392bc50 Prekernel: Better datasheet link for RPi3 2021-10-02 02:01:07 +02:00
Nico Weber
94d0562569 Kernel: Make UART::print_num(0) work on aarch64 2021-09-30 15:38:43 +01:00
Nico Weber
d0c1db5efc Kernel: Zero out .bss contents on aarch64
After building and running

     objcopy -O binary Build/aarch64/Kernel/Prekernel/Prekernel \
                       /media/sdcard/kernel8.img

things start booting on an actual RPi4 :^)

(Assuming the sdcard contains RPi firmware, an empty config.txt,
and no other kernel*.img files).
2021-09-30 15:38:43 +01:00
Nico Weber
b0858b2a55 Kernel: Fix a typo in a comment 2021-09-27 10:17:52 +02:00
Nico Weber
4c876e88e0 Kernel: Adjust aarch64 linker script
- .text now starts at 0x80000, where an actual (non-qemu) RPi expects
- use magic section name ".text.first" to make sure the linker script
  puts the kernel entry point at the start of the .text section
- remove a few things from the x86 linker script that aren't needed
  for aarch64 (yet?)
2021-09-27 10:17:52 +02:00
Nico Weber
cbdf4b575d Kernel: Move prekernel linker.ld into Arch subdirectories
This moves Kernel/Prekernel/linker.ld unchanged to
Kernel/Prekernel/Arch/aarch64 and Kernel/Prekernel/Arch/x86.
The aarch64 will change in a future commit.

No behavior change.
2021-09-27 10:17:52 +02:00
Nico Weber
54aabb07f9 Kernel: Add UART class for aarch64 2021-09-26 23:14:01 +00:00
Nico Weber
44c787e88b Kernel: Add Mailbox::set_clock_rate() 2021-09-26 23:14:01 +00:00
Nico Weber
fdc86ddae5 Kernel: Add a GPIO class for aarch64
This allows configuring the alternate pin functions and pin
pull up/down states, which is needed for using the UART.
2021-09-26 11:55:51 +02:00
Nico Weber
697e6ccb89 Kernel: Add a Mailbox class for aarch64
As a demo, query the firmware version. `Meta/serenity.sh gdb aarch64`
can be used to observe that qemu puts 0x548E1 in x0 in response
to this mailbox message.
2021-09-19 17:45:59 +02:00
Nico Weber
d0b9c7a20b Kernel: Add a MMIO class for aarch64
It doesn't do anything yet except figure out the peripheral base
address.

Very likely belongs in Kernel, not Prekernel, eventually.
2021-09-19 17:45:59 +02:00
Nico Weber
3a24eb323f Kernel: Use new halt() for all our halting needs in aarch64 Prekernel 2021-09-19 17:45:59 +02:00
Nico Weber
0319aa315a Kernel: Add __stack_chk_fail to aarch64 Prekernel init
This is needed for some functions with local variables. We'll grow
such a function soon.
2021-09-19 17:45:59 +02:00
Nico Weber
a339b73fc2 Kernel: Don't link Prekernel against kernel_heap
This was added in b5c98ede08, but it looks like a copy-paste
mistake from Kernel/CMakeLists.txt.

Unbreaks building for aarch64.
2021-09-17 17:59:22 +03:00
Andrew Kaster
b5c98ede08 Meta: Switch to a SuperBuild that splits host and target builds
Replace the old logic where we would start with a host build, and swap
all the CMake compiler and target variables underneath it to trick
CMake into building for Serenity after we configured and built the Lagom
code generators.

The SuperBuild creates two ExternalProjects, one for Lagom and one for
Serenity. The Serenity project depends on the install stage for the
Lagom build. The SuperBuild also generates a CMakeToolchain file for the
Serenity build to use that replaces the old toolchain file that was only
used for Ports.

To ensure that code generators are rebuilt when core libraries such as
AK and LibCore are modified, developers will need to direct their manual
`ninja` invocations to the SuperBuild's binary directory instead of the
Serenity binary directory.

This commit includes warning coalescing and option style cleanup for the
affected CMakeLists in the Kernel, top level, and runtime support
libraries. A large part of the cleanup is replacing USE_CLANG_TOOLCHAIN
with the proper CMAKE_CXX_COMPILER_ID variable, which will no longer be
confused by a host clang compiler.
2021-09-15 19:04:52 +04:30
Nico Weber
3c6ad4c7db Kernel: Add a class to wrap aarch64 MIDR_EL1
We'll need part_num() to determine the MMIO address base. It's
0x3F000000 on rpi3 but 0xFE000000 on rpi4.
2021-09-12 17:26:41 +00:00
Nico Weber
2dc02607ed Kernel: Put boot.S first in aarch64 Prekernel source list
The better fix is to have a linker script. We'll need this to set
the entry point to 0x80000 for bare-metal builds anyways. But I'd
like to get some UART output in qemu before I add this (otherwise
I can't check if the bare-metal version does anything), so put
in this temporary kludge for now.
2021-09-12 17:26:41 +00:00
Nico Weber
18dcd7b9c9 Kernel: Define __stack_chk_guard for aarch64 Prekernel
Needed for functions that have local variables.

In time we need to share this between aarch64 and intel, but while
we figure out what exactly the aarch64 Prekernel should do, let's
duplicate this.
2021-09-12 17:26:41 +00:00
Nico Weber
22b2ca7b8e Kernel: Build Prekernel with -fno-threadsafe-statics
Else, function-local statics create calls to
__cxa_guard_acquire / __cxa_guard_release on aarch64, which we don't
(yet?) implement. Since Prekernel is single-threaded, just sidestep
that for now.
2021-09-12 17:26:41 +00:00
Nico Weber
62e0bf852e Kernel: Don't link Prekernel against libsupc++
It isn't needed.

Also, we stopped linking Kernel against it in 67f0c0d5f0. libsupc++
depends on symbols like free() or realloc() which we removed from
Kernel/StdLib.cpp after 67f0c0d5f0 and which don't exist in Prekernel
either.

(It also happens to make the aarc64 link fail in less obvious ways.)
2021-09-08 04:23:17 +00:00
Nico Weber
a8d96df8e0 Kernel: Build MiniStdLib.cpp in aarch64 builds 2021-09-07 20:15:15 +01:00
Nico Weber
208aa05cf3 Kernel: Build UBSanitizer.cpp in aarch64 builds
All these symbols will be needed once we build MiniStdLib.cpp.
2021-09-07 20:15:15 +01:00
Nico Weber
d0b0c45690 Kernel: Remove two unused includes from Prekernel/UBSanitizer.cpp 2021-09-07 20:15:15 +01:00
Nico Weber
62bc238ac3 Kernel: Let aarch64 port call into C++
Put all but the first core into a loop, make room for some stack,
and call init().
2021-09-06 21:57:59 +01:00
Nico Weber
9c5e947e0e Prekernel: Make build on aarch64
Add a dummy Arch/aarch64/boot.S that for now does nothing but
let all processor cores sleep.

For now, none of the actual Prekernel code is built for aarch64.
2021-08-28 21:51:30 +01:00
Nico Weber
da785bd4bd Prekernel: Move boot.S and multiboot.S into an Arch/x86 subfolder 2021-08-28 21:51:30 +01:00
Brian Gianforcaro
665e848576 CMake: Remove Prekernel incompatible options instead of overriding
The pattern of having Prekernel inherit all of the build flags of the
Kernel, and then disabling some flags by adding `-fno-<flag>` options
to then disable those options doesn't work in all scenarios. For example
the ASAN flag `-fasan-shadow-offset=<offset>` has no option to disable
it once it's been passed, so in a future change where this flag is added
we need to be able to disable it cleanly.

The cleaner way is to just allow the Prekernel CMake logic to filter out
the COMPILE_OPTIONS specified for that specific target. This allows us
to remove individual options without trashing all inherited options.
2021-08-25 12:12:59 +02:00
Daniel Bertalan
13e3df41de Meta: Add Clang support to the CMake build scripts 2021-08-08 10:55:36 +02:00
Brian Gianforcaro
7fce0693a5 Prekernel: Disable KASAN, so it has no effect when enabled
I was working on some more KASAN changes and realized the system
no longer links when passing -DENABLE_KERNEL_ADDRESS_SANITIZER=ON.

Prekernel will likely never have KASAN support given it's limited
environment, so just suppress it's usage.
2021-07-30 16:58:09 +02:00
Gunnar Beutner
57417a3d6e Kernel: Support loading the kernel at almost arbitrary virtual addresses
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-27 13:15:16 +02:00
Gunnar Beutner
b10a86d463 Prekernel: Export some multiboot parameters in our own BootInfo struct
This allows us to specify virtual addresses for things the kernel should
access via virtual addresses later on. By doing this we can make the
kernel independent from specific physical addresses.
2021-07-27 13:15:16 +02:00
Gunnar Beutner
3c616ae00f Kernel: Make the kernel independent from specific physical addresses
Previously the kernel relied on a fixed offset between virtual and
physical addresses based on the kernel's load address. This allows us
to specify an independent offset.
2021-07-27 13:15:16 +02:00
Patrick Meyer
83f88df757 Kernel: Add option to build with coverage instrumentation and KCOV
GCC and Clang allow us to inject a call to a function named
__sanitizer_cov_trace_pc on every edge. This function has to be defined
by us. By noting down the caller in that function we can trace the code
we have encountered during execution. Such information is used by
coverage guided fuzzers like AFL and LibFuzzer to determine if a new
input resulted in a new code path. This makes fuzzing much more
effective.

Additionally this adds a basic KCOV implementation. KCOV is an API that
allows user space to request the kernel to start collecting coverage
information for a given user space thread. Furthermore KCOV then exposes
the collected program counters to user space via a BlockDevice which can
be mmaped from user space.

This work is required to add effective support for fuzzing SerenityOS to
the Syzkaller syscall fuzzer. :^) :^)
2021-07-26 17:40:28 +02:00
Gunnar Beutner
412ce31f7f Prekernel: Don't build the prekernel as a PIE image
This is unnecessary because the prekernel is always loaded at a known
base address.
2021-07-23 19:06:51 +02:00
Gunnar Beutner
4fdee56ba3 Prekernel: Make sure to reload CR3 after modifying the page tables 2021-07-20 15:12:19 +02:00
Gunnar Beutner
05fc75f994 Prekernel: Don't wrap around the PTE index improperly
The boot_pd0_pts variable contains more than 512 PTEs so we shouldn't
wrap the index here.
2021-07-20 15:12:19 +02:00
Gunnar Beutner
d29981e4a1 Prekernel: Properly initialize variables 2021-07-20 15:12:19 +02:00