Commit Graph

107 Commits

Author SHA1 Message Date
Timon Kruiper
47af812a23 Kernel/aarch64: Implement VERIFY_INTERRUPTS_{ENABLED, DISABLED}
This requires to stub `Process::all_instances()`.
2022-08-26 12:51:57 +02:00
Timon Kruiper
026f37b031 Kernel: Move Spinlock functions back to arch independent Locking folder
Now that the Spinlock code is not dependent on architectural specific
code anymore, we can move it back to the Locking folder. This also means
that the Spinlock implemenation is now used for the aarch64 kernel.
2022-08-26 12:51:57 +02:00
Timon Kruiper
c9118de5a6 Kernel/aarch64: Implement critical section related functions 2022-08-26 12:51:57 +02:00
Timon Kruiper
e8aff0c1c8 Kernel: Use InterruptsState in Spinlock code
This commit updates the lock function from Spinlock and
RecursiveSpinlock to return the InterruptsState of the processor,
instead of the processor flags. The unlock functions would only look at
the interrupt flag of the processor flags, so we now use the
InterruptsState enum to clarify the intent, and such that we can use the
same Spinlock code for the aarch64 build.

To not break the build, all the call sites are updated aswell.
2022-08-26 12:51:57 +02:00
Timon Kruiper
c1b0d254fd Kernel/aarch64: Add stubs for Mutex::lock and Mutex::unlock
Also add the g_scheduler_lock to the Dummy.cpp. This makes the aarch64
build succeeded again.
2022-08-26 12:51:57 +02:00
Timon Kruiper
d62bd3c635 Kernel/aarch64: Properly initialize T0SZ and T1SZ fields in TCR_EL1
By default these 2 fields were zero, which made it rely on
implementation defined behavior whether these fields internally would be
set to the correct value. The ARM processor in the Raspberry PI (and
QEMU 6.x) would actually fixup these values, whereas QEMU 7.x now does
not do that anymore, and a translation fault would be generated instead.

For more context see the relevant QEMU issue:
 - https://gitlab.com/qemu-project/qemu/-/issues/1157

Fixes #14856
2022-08-23 09:23:27 -04:00
Andreas Kling
11eee67b85 Kernel: Make self-contained locking smart pointers their own classes
Until now, our kernel has reimplemented a number of AK classes to
provide automatic internal locking:

- RefPtr
- NonnullRefPtr
- WeakPtr
- Weakable

This patch renames the Kernel classes so that they can coexist with
the original AK classes:

- RefPtr => LockRefPtr
- NonnullRefPtr => NonnullLockRefPtr
- WeakPtr => LockWeakPtr
- Weakable => LockWeakable

The goal here is to eventually get rid of the Lock* classes in favor of
using external locking.
2022-08-20 17:20:43 +02:00
Andreas Kling
e475263113 AK+Kernel: Add AK::AtomicRefCounted and use everywhere in the kernel
Instead of having two separate implementations of AK::RefCounted, one
for userspace and one for kernelspace, there is now RefCounted and
AtomicRefCounted.
2022-08-20 17:15:52 +02:00
Filiph Sandström
99ae4fa161 Kernel: Move TrapFrame into its own header on aarch64 2022-08-14 09:44:48 +01:00
Filiph Sandström
c14047034b Kernel: Remove leftover reference to prekernel on aarch64
This commit essentially just renames `init_prekernel_page_tables` to
`init_page_tables`.
2022-08-10 15:20:56 -04:00
Timon Kruiper
c92e68da38 Kernel: Rounding size of bss to be a multiple of 8 for aarch64 linker.ld
This fixes a bug where the bss was not completely zeroed out. This bug
showed up when running the aarch64 Kernel baremetal on a Raspberry Pi.
2022-08-06 14:00:54 +01:00
Timon Kruiper
22aea9f659 Kernel: Add logic to RPi UART driver to emit CR when encountering LF
This makes sure that the debug message are properly aligned when running
the kernel bare-metal on a Raspberry Pi. While we are here, also move
the function out of line.
2022-08-06 14:00:54 +01:00
Filiph Sandström
bac4bdc5d2 Kernel: Fix incorrect return type on aarch64
InterruptController's model incorrectly returned a char[] instead
of a StringView.
2022-07-25 16:01:46 +01:00
Liav A
1c499e75bd Kernel+Userland: Remove supervisor pages concept
There's no real value in separating physical pages to supervisor and
user types, so let's remove the concept and just let everyone to use
"user" physical pages which can be allocated from any PhysicalRegion
we want to use. Later on, we will remove the "user" prefix as this
prefix is not needed anymore.
2022-07-14 23:27:46 +02:00
Timon Kruiper
1072d523e2 Kernel: Initialize and use interrupts in the aarch64 Kernel
Now that everything is in place, we can actually use interrupts in the
aarch64 Kernel build. :^)
2022-06-02 13:14:12 +01:00
Timon Kruiper
dab6dbe893 Kernel: Add interrupt support to aarch64 RPi Timer driver
Since we can now build and use the IRQHandler class, we can implement
interrupt support for the Timer in the aarch64 build.
2022-06-02 13:14:12 +01:00
Timon Kruiper
8b77c61e7d Kernel: Use AK::NeverDestroyed<Timer> to store the timer class
For an upcoming change to support interrupts in this driver, this class
has to inherit from IRQHandler. That in turn will make this class
virtual, which will then actually call the destructor of the class. We
don't want this to happen, thus we have to wrap the class in a
AK::NeverDestroyed.
2022-06-02 13:14:12 +01:00
Timon Kruiper
a0b0c4e723 Kernel: Make RPi Timer::set_clock_rate static
This allows it to be called in UART without calling the Timer
constructor. This in turn allows the UART to be used before interrupts
are enabled.
2022-06-02 13:14:12 +01:00
Timon Kruiper
3cf8d3361e Kernel: Add support for handling interrupts on aarch64
There is currently some code duplication between the aarch64
implementation and the x86 one, but this initial implementation works
for now. :^)
2022-06-02 13:14:12 +01:00
Timon Kruiper
c959344c00 Kernel: Add simple implementation for InterruptManagement on aarch64
This class currently hardcodes the use of the Raspberry Pi interrupt
controller.
2022-06-02 13:14:12 +01:00
Timon Kruiper
5eac2b9f33 Kernel: Add driver for interrupt controller on the Raspberry Pi
This implements the simpler IRQController class and adds a
pending_interrupts() function to the class.
2022-06-02 13:14:12 +01:00
Timon Kruiper
f085903f62 Kernel: Move IRQController and InterruptManagement to Arch directory
These 2 classes currently contain much code that is x86(_64) specific.
Move them to the architecture specific directory. This also allows for a
simpler implementation for aarch64.
2022-06-02 13:14:12 +01:00
Timon Kruiper
63ee2781fb Kernel: Put Raspberry Pi devices into RPi namespace
This makes it clear in the code that these drivers are specific for the
Raspberry Pi devices.
2022-06-02 13:14:12 +01:00
Timon Kruiper
77f24056e0 Kernel: Disable interrupts when halting the aarch64 processor
This will actually halt the processor.
2022-06-02 13:14:12 +01:00
Timon Kruiper
cbe1717181 Kernel: Rename idt_init() to initialize_interrupts()
Also move the function out of the x86/Interrupts.h file into the generic
Interrupts.h file and add a stub for aarch64.
2022-06-02 13:14:12 +01:00
Timon Kruiper
d631a3daf6 Kernel: Add Interrupts/IRQHandler.cpp to the aarch64 build
This requires a few stubs such that the compiler won't complain.
2022-06-02 13:14:12 +01:00
Timon Kruiper
9413fe9fe5 Kernel: Add interrupt related functions to Processor class
This adds {enable, disable}_interrupts() and are_interrupts_enabled()
to the Processor class, and also implements them for x86(_64) and
aarch64.
2022-06-02 13:14:12 +01:00
Timon Kruiper
80be5f8044 Kernel: Add DAIF system register to aarch64 registers
This register can be used to check whether the 4 different types of
interrupts are masked. A different variant can be used to set/clear
specific interrupt bits.
2022-06-02 13:14:12 +01:00
Timon Kruiper
2fd5e9f729 Kernel: Add GenericInterruptHandler.cpp to aarch64 build
This requires us to add an Interrupts.h file in the Kernel/Arch
directory, which includes the architecture specific files.

The commit also stubs out the functions to be able to compile the
aarch64 Kernel.
2022-06-02 13:14:12 +01:00
SeekingBlues
df8df947f6 Kernel: Do not include AK/Platform.h in mcontext headers
Including signal.h would cause several ports to fail on build,
because it would end up including AK/Platform.h through these
mcontext headers. This is problematic because AK/Platform.h defines
several macros with very common names, such as `NAKED` (breaks radare2),
and `NO_SANITIZE_ADDRESS` and `ALWAYS_INLINE` (breaks ruby).
2022-05-30 21:39:41 +02:00
Timon Kruiper
1461a7601d Kernel: Report value of ESR_EL1 when exception happens on aarch64 2022-05-21 20:23:32 +01:00
Timon Kruiper
2c05afaa7b Kernel: Add Exception Syndrome Register to aarch64 Registers.h
This allows us to print more information about what kind of exception
happend.
2022-05-21 20:23:32 +01:00
Timon Kruiper
e43fdcc77e Kernel: Add more exception handlers for aarch64 Kernel
The aarch64 Kernel runs with SP_EL0, thus exceptions that happen can now
be handled.
2022-05-21 20:23:32 +01:00
Timon Kruiper
06432719fd Kernel: Set up initial exception stack when going into EL1 on aarch64
When an exception is triggered on aarch64, the processor always switches
to the exception stack which is defined by the SP_EL1 register.
2022-05-21 20:23:32 +01:00
Timon Kruiper
9f730fab8d Kernel: Add alignment specifier to aarch64 register definitions
When disabling UBSAN, the compiler would complain that the constraints
of the inline assembly could not be met. By adding the alignas specifier
the compiler can now determine that the struct can be passed into a
register, and thus the constraints are met.
2022-05-21 20:23:32 +01:00
Timon Kruiper
18cad73b01 Kernel: Put code in the aarch64 init.cpp file into the Kernel namespace 2022-05-12 23:14:05 +02:00
Timon Kruiper
9282e0db16 Kernel: Move __assertion_failed to aarch64/Panic.cpp
This is for an upcoming change to add the Kernel namespace to the
init.cpp file.
2022-05-12 23:14:05 +02:00
Timon Kruiper
1f3977b303 Kernel: Remove Prekernel namespace in the aarch64 Kernel
Now that we merged all the Prekernel files into the Kernel files, we can
get rid of the Prekernel namespace as well.
2022-05-12 23:14:05 +02:00
Timon Kruiper
c96a3f0c48 Kernel: Move the aarch64 boot.S out of the Prekernel directory 2022-05-12 23:14:05 +02:00
Timon Kruiper
e88cd338f1 Kernel: Move Prekernel{CPU, Exceptions}.cpp out of Prekernel directory
This lets us delete the Prekernel.h file, and gets us closer to deleting
the Prekernel from the aarch64 Kernel.
2022-05-12 23:14:05 +02:00
Timon Kruiper
e7c5fd978b Kernel: Move Prekernel assembly utils to aarch64/ASM_wrapper.h
By moving these functions to the ASM_wrapper.h file, we can get rid of
another Prekernel file.
2022-05-12 23:14:05 +02:00
Timon Kruiper
e80d8d697c Kernel: Replace Prekernel::halt with Processor::halt in aarch64 build
This allows us to get rid of one more Prekernel file.
2022-05-12 23:14:05 +02:00
Timon Kruiper
c515e1341a Kernel: Add initial implementation of Processor in aarch64
Instead of storing the current Processor into a core local register, we
currently just store it into a global, since we don't support SMP for
aarch64 anyway. This simplifies the initial implementation.
2022-05-09 21:12:56 +02:00
Timon Kruiper
ed4bfaed12 Kernel: Call the constructors in the aarch64 init function
Now that we have separated the kmalloc.cpp constructors into a separate
library, we can actually call the constructors in the init function.
2022-05-09 21:12:56 +02:00
Timon Kruiper
d449fef606 Kernel: Reorder sections in aarch64 linker script to save space
By putting the NOLOAD sections (.bss and .super_pages) at the end of the
ELF file, objcopy does not have to insert a lot of zeros to make sure
that the .ksyms section is at the right place in memory. Now the .ksyms
section comes before the two NOLOAD sections. This shrinks the
kernel8.img with 6MB, from 8.3M to 2.3M. :^)
2022-05-09 21:12:56 +02:00
Timon Kruiper
a1b352fdc0 Kernel: Add some mission sections to the aarch64 linker script
The sections did end up in the ELF file, however they weren't
explicitely mentioned in the linker.ld script. In the future, we can add
the --orphan-handling=error flag to the linker options, which will
enforce that the sections used in the sources files also are mentioned
in the linker script.
2022-05-09 21:12:56 +02:00
Timon Kruiper
2cf36a1ca2 Kernel: Panic when an assertion is failed in aarch64 Kernel
This in turn makes sure that we get a nice backtrace when an assertion
failed, or when a VERIFY_NOT_REACHED() is hit.
2022-05-03 21:53:36 +02:00
Timon Kruiper
771d0719ea Kernel: Remove unused aarch64 Prekernel::panic() function 2022-05-03 21:53:36 +02:00
Timon Kruiper
f8e4eecbfb Kernel: Replace calls to Prekernel::panic() with PANIC macro on aarch64 2022-05-03 21:53:36 +02:00
Timon Kruiper
e81e1fa9c8 Kernel: Implement __panic() for the aarch64 Kernel
Now that dump_backtrace() works, we can actually print a helpful
backtrace when the Kernel panics.
2022-05-03 21:53:36 +02:00