Commit Graph

984 Commits

Author SHA1 Message Date
Liav A
d76c08c9b0 Kernel: Introduce a new super class called HIDController
Use the new class in HID code, because all other HID device controllers
will be using this class as their parent class.

Hence, we no longer keep a reference to any PS/2 device in HIDManagement
and rely on HIDController derived classes to do this for us.

It also means that we removed another instance of a LockRefPtr, which
is designated to be removed and is replaced by the better pattern of
SpinlockProtected<RefPtr<>> instead.
2023-04-09 18:11:37 +02:00
Liav A
6c4a47d916 Kernel: Remove redundant HID name from all associated files 2023-04-09 18:11:37 +02:00
Brian Gianforcaro
e891f13c84 Kernel: Fix compilation of aarch64/RPi/Framebuffer.cpp
The definitions were being defined already by `BootInfo.h` and that was
being included here via transitive includes. The extern definitions of
the variables do not have the `READONLY_AFTER_INIT` attribute in
`BootInfo.h`. This causes conflicting definitions of the same variable.

The `READONLY_AFTER_INIT` specifier is not needed for extern variables
as it only effects their linkage, not their actual use, so just use the
versions in `BootInfo.h` instead of re-declaring.
2023-04-08 19:16:35 -07:00
Liav A
b87747fa64 Kernel: Fix typo in the FramebufferGetPitchMboxMessage name 2023-04-07 10:43:45 +02:00
Timon Kruiper
2b6c44852c Kernel/aarch64: Actually remove Arch/aarch64/init.cpp
The idea was to remove this file in bd2011406, but that did not actually
happen. Let's actually remove it.
2023-04-06 22:06:03 +03:00
Timon Kruiper
ec765544a5 Kernel/aarch64: Add getters/setters in RegisterState and ThreadRegisters
Specifically this commit implements two setters set_userspace_sp and
set_ip in RegisterState.h, and also adds a stack pointer getter (sp) in
ThreadRegisters.h. Contributed by konrad, thanks for that.
2023-04-06 21:19:58 +03:00
Timon Kruiper
36362b9679 Kernel/aarch64: Implement copying of kernel regs into ptrace regs
And also vice versa. Contributed by konrad, thanks for that.
2023-04-06 21:19:58 +03:00
Timon Kruiper
200e91cd7f Kernel+LibC: Modify aarch64's __mcontext to store registers in an array
This commit also removes the unnecessary ifdefs from
sys/arch/aarch64/regs.h. Contributed by konrad, thanks for that.
2023-04-06 21:19:58 +03:00
Timon Kruiper
6a8581855d Kernel/aarch64: Flush entire TLB cache when changing TTBR0_EL1
Setting the page table base register (ttbr0_el1) is not enough, and will
not flush the TLB caches, in contrary with x86_64 where setting the CR3
register will actually flush the caches. This commit adds the necessary
code to properly flush the TLB caches when context switching. This
commit also changes Processor::flush_tlb_local to use the vmalle1
variant, as previously we would be flushing the tlb's of all the cores
in the inner-shareable domain.
2023-04-06 21:19:58 +03:00
Idan Horowitz
003989e1b0 Kernel: Store a pointer to the owner process in PageDirectory
This replaces the previous owning address space pointer. This commit
should not change any of the existing functionality, but it lays down
the groundwork needed to let us properly access the region table under
the address space spinlock during page fault handling.
2023-04-06 20:30:03 +03:00
Andreas Kling
a098266ff5 Kernel: Simplify Process factory functions
- Instead of taking the first new thread as an out-parameter, we now
  bundle the process and its first thread in a struct and use that
  as the return value.

- Make all Process factory functions return ErrorOr. Use this to convert
  some places to more TRY().

- Drop the "try_" prefix on Process factory functions.
2023-04-04 10:33:42 +02:00
Caoimhe
3f69ef86c2 Kernel/aarch64: Implement Processor::time_spent_idle() 2023-04-04 10:30:09 +02:00
Timon Kruiper
bd2011406e Kernel: Merge x86_64 and aarch64 init.cpp files 2023-04-03 20:01:28 -06:00
Timon Kruiper
c31dc82b17 Kernel: Move deferred call code into separate DeferredCallPool class
This allows us to share this code between the x86_64 and aarch64 build.
2023-04-03 20:01:28 -06:00
Timon Kruiper
1f68ac600c Kernel/aarch64: Correctly implement Processor::leave_critical 2023-04-03 20:01:28 -06:00
Timon Kruiper
14d20618f1 Kernel/aarch64: Move query_firmware_version into RPi::Mailbox
This is for the upcoming commit that merges the x86_64 and aarch64
init.cpp files.
2023-04-03 20:01:28 -06:00
Timon Kruiper
2613ac4cb4 Kernel/aarch64: Move logo drawing and initializing into RPi::Framebuffer
This is for a upcoming commit that merges the x86_64 and aarch64
init.cpp files.
2023-04-03 20:01:28 -06:00
Timon Kruiper
05b9eb7feb Kernel/aarch64: Rename Processor::install to Processor::early_initialize
Also pass the cpu number to Processor::initialize. This way the init
code can be shared between the x86_64 and aarch64 build.
2023-04-03 20:01:28 -06:00
Idan Horowitz
402c9e5e23 Kernel: Implement Processor::assume_context for AArch64
With this implemented sys$execve should be fully working on AArch64.
2023-04-03 02:59:37 -06:00
Idan Horowitz
0dc5c49938 Kernel: Call exit_trap in AArch64 restore_context_and_eret
This matches x86_64's behaviour in common_trap_exit. (called from
thread_context_first_enter)
Currently thread_context_first_enter is only called when creating new
processes from scratch, in which case this doesn't change the actual
behaviour. But once thread_context_first_enter is called as part of
execve support, this will ensure the Thread's m_current_trap is set
correctly to the new trap frame.
2023-04-03 02:59:37 -06:00
Idan Horowitz
a349570a04 Kernel: Abstract Processor::assume_context flags using InterruptsState
The details of the specific interrupt bits that must be turned on are
irrelevant to the sys$execve implementation. Abstract it away to the
Processor implementations using the InterruptsState enum.
2023-04-03 02:59:37 -06:00
Idan Horowitz
6ad8f4bb11 Kernel: Stop overwriting AArch64 link register in forked processes
Forked processes already have an existing value for the link register,
which we can't overwrite. But since they're forked the original link
register value that points to exit_kernel_thread was already saved
somewhere on the stack, so it's ok not to set it.
2023-04-03 02:59:37 -06:00
Marco Cutecchia
d09852642c Revert "Kernel/aarch64: Embed disk image into kernel binary"
This reverts commit 3b65fd64fc.

This is no longer needed as we don't use the ramdisk anymore

Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia
c91db6ec97 Kernel: Add an SD card driver for the aarch64 port
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia
bb8092d6a1 Kernel: Allow enabling high level detection on GPIOs
Co-authored-by: Timon Kruiper <timonkruiper@gmail.com>
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia
28acf25035 Kernel: Use u64 instead of int for the bitfields of CPACR_EL1
This fixes the Clang build of the aarch64 port
2023-03-25 16:50:36 +00:00
Pankaj Raghav
b204da94b0 Kernel/Storage: Use NonnullRefPtr for storage controllers
Storage controllers are initialized during init and are never modified.
NonnullRefPtr can be safely used instead of the NonnullLockRefPtr. This
also fixes one of the UB issue that was there when using an NVMe device
because of NonnullLockRefPtr.

We can add proper locking when we need to modify the storage controllers
after init.
2023-03-15 11:25:59 +01:00
Liav A
633006926f Kernel: Make the Jails' internal design a lot more sane
This is done with 2 major steps:
1. Remove JailManagement singleton and use a structure that resembles
    what we have with the Process object. This is required later for the
    second step in this commit, but on its own, is a major change that
    removes this clunky singleton that had no real usage by itself.
2. Use IntrusiveLists to keep references to Process objects in the same
    Jail so it will be much more straightforward to iterate on this kind
    of objects when needed. Previously we locked the entire Process list
    and we did a simple pointer comparison to check if the checked
    Process we iterate on is in the same Jail or not, which required
    taking multiple Spinlocks in a very clumsy and heavyweight way.
2023-03-12 10:21:59 -06:00
Julian Offenhäuser
c705afa43a Kernel: Fix variable shadowing issue in PCIIDELegacyModeController
In this specific else case, primary_base_io_window would not be assigned
in the outer scope, leading to a crash immediately after.
2023-03-11 06:06:01 -07:00
Andreas Kling
7369d0ab5f Kernel: Stop using NonnullLockRefPtrVector 2023-03-06 23:46:36 +01:00
Liav A
5416a37fde Kernel: Remove heuristics for detecting malformed malloc memory access
I never saw these kind of messages in any debug session I had, and it
helps us to remove an include to LibC/mallocdefs.h file.
2023-03-01 19:36:53 -07:00
Liav A
c56e1c5378 Kernel/FileSystem: Simplify the ProcFS significantly
Since the ProcFS doesn't hold many global objects within it, the need
for a fully-structured design of backing components and a registry like
with the SysFS is no longer true.

To acommodate this, let's remove all backing store and components of the
ProcFS, so now it resembles what we had in the early days of ProcFS in
the project - a mostly-static filesystem, with very small amount of
kmalloc allocations needed.
We still use the inode index mechanism to understand the role of each
inode, but this is done in a much "static"ier way than before.
2023-02-24 22:14:18 +01:00
Timon Kruiper
13f5aa81e3 Kernel/aarch64: Disable memory access alignment check
Even though we currently build all of Userland and the Kernel with the
-mstrict-align flag, the compiler will still emit unaligned memory
accesses. To work around this, we disable the check for now. See
https://github.com/SerenityOS/serenity/issues/17516 for the relevant
issue.
2023-02-18 19:17:21 +01:00
Timon Kruiper
5d587ea562 Kernel/aarch64: Call handle_crash on unknown exceptions
This is useful for debugging, as it will now print out a userspace
backtrace, and optionally also dump the memory regions of the process.
2023-02-18 19:17:21 +01:00
Andrew Kaster
3a01573350 Revert "Kernel: Migrate ‘main id registerʼ access in Aarch64 MMIO"
This patch needed more review than it got.

This reverts commit a6526cd90c.
2023-02-17 11:29:33 -07:00
Andrew Kaster
aac122ab17 Revert "Kernel: Remove old ‘main id register accessorʼ for Aarch64"
This patch needed more review than it got.

This reverts commit 84e8d5f418.
2023-02-17 11:29:33 -07:00
Ben Wiederhake
9a7b3c145f Everywhere: Change all XXX into FIXME or remove as appropriate 2023-02-15 23:33:25 +01:00
Timon Kruiper
cfd73e5d9f Kernel/aarch64: Implement Thread Local Storage
This commit adds Processor::set_thread_specific_data, and this function
is used to factor out architecture specific implementation of setting
the thread specific data. This function is implemented for
aarch64 and x86_64, and the callsites are changed to use this function
instead.
2023-02-15 22:53:19 +01:00
Timon Kruiper
7d0917f50b Kernel/aarch64: Remove tpidr_el0 from RegisterState
In the next commit, this register will be populated by directly writing
to it, instead of using the RegisterState mechanism.
2023-02-15 22:53:19 +01:00
Timon Kruiper
a98c0c3e51 Kernel/aarch64: Add implementations for safe_memset and safe_strnlen
They currently do not actually implement a safe memset or safe strnlen,
but this initial implementation works fine for now.
2023-02-15 22:53:19 +01:00
Timon Kruiper
d1eec20773 Kernel/aarch64: Implement storing and restoring floating-point registers 2023-02-15 22:53:19 +01:00
Timon Kruiper
e57d35ff53 Kernel/aarch64: Do not trap floating-point instructions
This requires setting the FPEN field of the Architectural Feature Access
Control Register (CPACR_EL1) to 0b11.
2023-02-15 22:53:19 +01:00
Timon Kruiper
d5262a540c Kernel/aarch64: Handle SVC exception by calling syscall_handler
The SVC (supervisor call) instruction is used in userland to do
syscalls, and this commit adds the handling of syscalls to
Interrupts.cpp.
2023-02-15 22:53:19 +01:00
konrad
84e8d5f418 Kernel: Remove old ‘main id register accessorʼ for Aarch64 2023-02-10 11:51:47 -07:00
konrad
a6526cd90c Kernel: Migrate ‘main id registerʼ access in Aarch64 MMIO 2023-02-10 11:51:47 -07:00
konrad
d6c620dc4f Kernel: Provide better types in MIDR register accessor for Aarch64
This avoids unnecessary and-masks during reading.
2023-02-10 11:51:47 -07:00
Timon Kruiper
0f3e1668bb Kernel/aarch64: Execute first userspace process
This adds the necessary code to init.cpp to be able to execute the first
userspace process. To do this, first the filesystem code is initialized,
which will use the ramdisk embedded into the kernel image. Then the
first userspace process, /bin/SystemServer is executed. :^)

The ramdisk code is used as it is useful for the bring-up of the aarch64
port, however once the kernel has support for better ram-based
filesystems, the ramdisk code will be removed again.
2023-02-08 18:19:48 +00:00
Timon Kruiper
3b65fd64fc Kernel/aarch64: Embed disk image into kernel binary
This allows us to actually boot to userspace in the next commit! :^)
2023-02-08 18:19:48 +00:00
Timon Kruiper
da89cd948f Kernel/aarch64: Do not dump register state on every page fault
This became very spammy, and is not needed anymore since we now
correctly handle page faults.
2023-02-08 18:19:48 +00:00
Timon Kruiper
3106a72a72 Kernel/aarch64: Make register dump output a bit nicer 2023-02-08 18:19:48 +00:00
Timon Kruiper
cf5b02e3a4 Kernel/aarch64: Dump ESR_EL1 in dump_registers and remove backtracing 2023-02-08 18:19:48 +00:00
Timon Kruiper
3611427ce2 Kernel/aarch64: Return correct values from RegisterState accessors 2023-02-08 18:19:48 +00:00
Timon Kruiper
5781d58fe8 Kernel/aarch64: Implement set_exec_state in ThreadRegisters
This sets up the correct ThreadRegisters state when a process is
exec'ed, which happens when the first userspace application is executed.
Also changes Processor.cpp to get the stack pointer from the
ThreadRegisters.
2023-02-08 18:19:48 +00:00
Timon Kruiper
8960662e57 Kernel/aarch64: Set exception origin mode to SP_EL0 for userspace thread 2023-02-08 18:19:48 +00:00
Timon Kruiper
3f05748c0c Kernel/aarch64: Store Saved Program Status Register in ThreadRegisters
This allows us to set the Mode field of the Saved Program Status
Register (EL1) to EL0t when a userspace process is created.
2023-02-08 18:19:48 +00:00
Timon Kruiper
816076f71a Kernel: Share CrashHandler.cpp between aarch64 and x86_64
This file contains no architecture specific code, so can be moved to the
Kernel/ directory, and thus shared between aarch64 and x86_64.
2023-02-08 18:19:48 +00:00
Timon Kruiper
7ba9bc6338 Kernel/aarch64: Remove static from dump_registers
This allows the function to be called from other translation units, in
particular this allows the CrashHandler.cpp file to be shared between
aarch64 and x86_64.
2023-02-08 18:19:48 +00:00
Timon Kruiper
5cb37038a3 Kernel/aarch64: Set kernel_load_base and correctly calculate symbol addr
Setting the kernel_load_base variable caused backtracking to regress, so
to have proper backtracing the calculation of the symbol address in
KSyms.cpp needs to keep into account that the aarch64 kernel is linked
at a high virtual memory address.
2023-02-08 18:19:48 +00:00
Timon Kruiper
c7802cef25 Kernel/aarch64: Handle exceptions from lower exception level (EL)
When we execute in userspace, the exception level is EL0, so to handle
exceptions, such as interrupts, and syscalls, we need to add handlers to
vector_table.S. For now we only support running userspace applications
in AArch64 mode, so this commit only adds the handlers for that mode.
2023-02-08 18:19:48 +00:00
Timon Kruiper
7be7324287 Kernel/aarch64: Set correct ExecutionMode of PageFault
Adds a helper to aarch64/Registers.h to factor out the exception class
encoding.
2023-02-08 18:19:48 +00:00
Timon Kruiper
ecf45e191e Kernel/aarch64: Handle instruction aborts
To detect instruction aborts, a helper to Registers.h is added, and used
in Interrupts.cpp. Additionally, the PageFault class gets a setter to
set the PageFaults m_is_instruction_fetch bool, and is also used in
Interrupts.cpp.
2023-02-08 18:19:48 +00:00
Timon Kruiper
163e3ac90b Kernel/aarch64: Set Access Permission EL0 bit for userspace mappings
This bit was not set, which was causing Permission Faults when executing
in userspace.
2023-02-08 18:19:48 +00:00
Agustin Gianni
bfbb4bcd9b Kernel: Remove trap based syscall handling
This patch removes the x86 mechanism for calling syscalls, favoring
the more modern syscall instruction. It also moves architecture
dependent code from functions that are meant to be architecture
agnostic therefore paving the way for adding more architectures.
2023-02-02 01:52:52 -07:00
Timon Kruiper
b941bd55d9 Kernel: Add Syscalls/execve.cpp to aarch64 build 2023-01-27 20:47:08 +00:00
Timon Kruiper
1fbf562e7e Kernel: Add ThreadRegisters::set_exec_state and use it in execve.cpp
Using this abstraction it is possible to compile this file for aarch64.
2023-01-27 20:47:08 +00:00
Timon Kruiper
171a8ca478 Kernel/aarch64: Implement Processor::platform_string() 2023-01-27 20:47:08 +00:00
Timon Kruiper
a146a19636 Kernel: Make Syscalls/ptrace.cpp buildable for aarch64 2023-01-27 20:47:08 +00:00
Timon Kruiper
cab725cdfb Kernel/aarch64: Implement set_return_reg and capture_syscall_params 2023-01-27 20:47:08 +00:00
Timon Kruiper
293ece6fad Kernel/aarch64: Add stub for copy_ptrace_registers_into_kernel_registers 2023-01-27 20:47:08 +00:00
Sam Atkins
3cbc0fdbb0 Kernel: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00:00
Timon Kruiper
2896d7796d Kernel/aarch64: Set Access Permission (writable bit) on PageTableEntry
This will cause page faults to be generated. Since the previous commits
introduced the handling of page faults, we can now actually correctly
handle page faults.
2023-01-27 11:41:43 +01:00
Timon Kruiper
1d58663298 Kernel/aarch64: Implement switching page directories
The code in PageDirectory.cpp now keeps track of the registered page
directories, and actually sets the TTBR0_EL1 to the page table base of
the currently executing thread. When context switching, we now also
change the TTBR0_EL1 to the page table base of the thread that we
context switch into.
2023-01-27 11:41:43 +01:00
Timon Kruiper
1f30a5e4d9 Kernel/aarch64: Store and initialize TTBR0_EL1 in ThreadRegisters 2023-01-27 11:41:43 +01:00
Timon Kruiper
9e90932bfb Kernel/aarch64: Add helper to get the current TTBR0_EL1 2023-01-27 11:41:43 +01:00
Timon Kruiper
d9946c8e89 Kernel/aarch64: Keep track of root page table and kernel directory table 2023-01-27 11:41:43 +01:00
Timon Kruiper
697c5ca5e5 Kernel: Move Memory/PageDirectory.{cpp,h} to arch-specific directory
The handling of page tables is very architecture specific, so belongs
in the Arch directory. Some parts were already architecture-specific,
however this commit moves the rest of the PageDirectory class into the
Arch directory.

While we're here the aarch64/PageDirectory.{h,cpp} files are updated to
be aarch64 specific, by renaming some members and removing x86_64
specific code.
2023-01-27 11:41:43 +01:00
Timon Kruiper
55d756a813 Kernel/aarch64: Implement initial page fault handling
The shared code is moved to a common PageFault.cpp file.
2023-01-27 11:41:43 +01:00
Timon Kruiper
a532d28905 Kernel/aarch64: Add stub for handle_safe_access_fault 2023-01-27 11:41:43 +01:00
Timon Kruiper
ade27fa6b9 Kernel: Refactor PageFault for use in the aarch64 port
The class used to look at the x86_64 specific exception code to figure
out what kind of page fault happend, however this refactor allows
aarch64 to use the same class.
2023-01-27 11:41:43 +01:00
Timon Kruiper
fb10774862 Kernel: Factor our PreviousMode into RegisterState::previous_mode
Various places in the kernel were manually checking the cs register for
x86_64, however to share this with aarch64 a function in RegisterState
is added, and the call-sites are updated. While we're here the
PreviousMode enum is renamed to ExecutionMode.
2023-01-27 11:41:43 +01:00
Timon Kruiper
247109cee6 Kernel/aarch64: Execute kernel with SP_EL1 instead of SP_EL0
Until now the kernel was always executing with SP_EL0, as this made the
initial dropping to EL1 a bit easier. This commit changes this behaviour
to use the corresponding SP_ELx for each exception level.

To make sure that the execution of the C++ code can continue, the
current stack pointer is copied into the corresponding SP_ELx just
before dropping an exception level.
2023-01-27 11:41:43 +01:00
Timon Kruiper
05659debd1 Kernel/aarch64: Move exception handler to Interrupts.cpp
Also dump the registers in a nicer format.
2023-01-27 11:41:43 +01:00
Liav A
1f9d3a3523 Kernel/PCI: Hold a reference to DeviceIdentifier in the Device class
There are now 2 separate classes for almost the same object type:
- EnumerableDeviceIdentifier, which is used in the enumeration code for
  all PCI host controller classes. This is allowed to be moved and
  copied, as it doesn't support ref-counting.
- DeviceIdentifier, which inherits from EnumerableDeviceIdentifier. This
  class uses ref-counting, and is not allowed to be copied. It has a
  spinlock member in its structure to allow safely executing complicated
  IO sequences on a PCI device and its space configuration.
  There's a static method that allows a quick conversion from
  EnumerableDeviceIdentifier to DeviceIdentifier while creating a
  NonnullRefPtr out of it.

The reason for doing this is for the sake of integrity and reliablity of
the system in 2 places:
- Ensure that "complicated" tasks that rely on manipulating PCI device
  registers are done in a safe manner. For example, determining a PCI
  BAR space size requires multiple read and writes to the same register,
  and if another CPU tries to do something else with our selected
  register, then the result will be a catastrophe.
- Allow the PCI API to have a united form around a shared object which
  actually holds much more data than the PCI::Address structure. This is
  fundamental if we want to do certain types of optimizations, and be
  able to support more features of the PCI bus in the foreseeable
  future.

This patch already has several implications:
- All PCI::Device(s) hold a reference to a DeviceIdentifier structure
  being given originally from the PCI::Access singleton. This means that
  all instances of DeviceIdentifier structures are located in one place,
  and all references are pointing to that location. This ensures that
  locking the operation spinlock will take effect in all the appropriate
  places.
- We no longer support adding PCI host controllers and then immediately
  allow for enumerating it with a lambda function. It was found that
  this method is extremely broken and too much complicated to work
  reliably with the new paradigm being introduced in this patch. This
  means that for Volume Management Devices (Intel VMD devices), we
  simply first enumerate the PCI bus for such devices in the storage
  code, and if we find a device, we attach it in the PCI::Access method
  which will scan for devices behind that bridge and will add new
  DeviceIdentifier(s) objects to its internal Vector. Afterwards, we
  just continue as usual with scanning for actual storage controllers,
  so we will find a corresponding NVMe controllers if there were any
  behind that VMD bridge.
2023-01-26 23:04:26 +01:00
konrad
95c469ca4c Kernel: Move Aarch64 MMU debug message into memory manager initializer
Doing so unifies startup debug messages visually.
2023-01-25 23:17:36 +01:00
konrad
e1c50b83e1 Kernel: Use RDSEED assembly snippet to seed RNG on Aarch64
There’s similar RDRAND register (encoded as ‘s3_3_c2_c4_0ʼ) to be
added if needed. RNG CPU feature on Aarch64 guarantees existence of both
RDSEED and RDRAND registers simultaneously—in contrast to x86-64, where
respective instructions are independent of each other.
2023-01-25 23:17:36 +01:00
konrad
7c8e61f4d1 Kernel: Unify x86-64 assembly snippets naming for RDSEED & RDRAND 2023-01-25 23:17:36 +01:00
Timon Kruiper
c4a3af12fc Kernel/aarch64: Change base address of the kernel to 0x2000000000
This is the same address that the x86_64 kernel runs at, and allows us
to run the kernel at a high virtual memory address. Since we now run
completely in high virtual memory, we can also unmap the identity
mapping. Additionally some changes in MMU.cpp are required to
successfully boot.
2023-01-24 14:54:44 +00:00
Timon Kruiper
3bc122fcef Kernel/aarch64: Ensure global variable accesses work without MMU enabled
Since we link the kernel at a high virtual memory address, the addresses
of global variables are also at virtual addresses. To be able to access
them without the MMU enabled, we have to subtract the
KERNEL_MAPPING_BASE.
2023-01-24 14:54:44 +00:00
Timon Kruiper
ebdb899d3d Kernel/aarch64: Add pre_init function for that sets up the CPU and MMU
This is a separate file that behaves similar to the Prekernel for
x86_64, and makes sure the CPU is dropped to EL1, the MMU is enabled,
and makes sure the CPU is running in high virtual memory. This code then
jumps to the usual init function of the kernel.
2023-01-24 14:54:44 +00:00
Timon Kruiper
5db32ecbe1 Kernel/aarch64: Access MMIO using mapping in high virtual memory
This ensures that we can unmap the identity mapping of the kernel in
physical memory.
2023-01-24 14:54:44 +00:00
Timon Kruiper
91d0451999 Kernel/aarch64: Use relative addressing in boot.S
As the kernel is now linked at high address in virtual memory, we cannot
use absolute addresses as they refer to high addresses in virtual
memory. At this point in the boot process we are still running with the
MMU off, so we have to make sure the accesses are using physical memory
addresses.
2023-01-24 14:54:44 +00:00
Timon Kruiper
a581cae4d4 Kernel/aarch64: Add function to MMU.cpp to unmap identity mapping
This function will be used once the kernel runs in high virtual memory
to unmap the identity mapping as userspace will later on use this memory
range instead.
2023-01-24 14:54:44 +00:00
Timon Kruiper
150c52e420 Kernel/aarch64: Add {panic,dbgln}_without_mmu
And use it the code that will be part of the early boot process.

The PANIC macro and dbgln functions cannot be used as it accesses global
variables, which in the early boot process do not work, since the MMU is
not yet enabled.
2023-01-24 14:54:44 +00:00
Timon Kruiper
69c49b3d00 Kernel/aarch64: Map kernel and MMIO in high virtual memory
In the upcoming commits, we'll change the kernel to run at a virtual
address in high memory. This commit prepares for that by making sure the
kernel and mmio are mapped into high virtual memory.
2023-01-24 14:54:44 +00:00
Jelle Raaijmakers
2428ba3832 Kernel: Remove dbgln when unregistering an unhandled x86_64 interrupt
A lot of interrupt numbers are initialized with the unhandled interrupt
handler. Whenever a new handler is registered on one of these
interrupts, the old handler is unregistered first. Let's not be verbose
about this since it is perfectly normal.
2023-01-20 15:22:42 +01:00
Jelle Raaijmakers
5f85f1abaa Kernel: Simplify (un)registering interrupt logic
Lose a level of indentation and remove a superfluous `handler_slot`
check.
2023-01-20 15:22:42 +01:00
konrad
78d6de2ec1 Kernel: Make a slightly better demo for Aarch64 multiprocessing 2023-01-18 22:58:42 +01:00
konrad
5791072280 Kernel: Detect Aarch64 virtual address bit width with CPU ID registers 2023-01-18 22:58:42 +01:00
konrad
401fc6afae Kernel: Detect Aarch64 physical address bit width with CPU ID registers 2023-01-18 22:58:42 +01:00
konrad
66c65f6e2c Kernel: Add and use accessors to read from Aarch64 CPU ID registers
Following registers accessors are updated and put in use:
* ID_AA64ISAR0_EL1, Instruction Set Attribute Register 0

Accessors for following registers are added and put in use:
* ID_AA64ISAR1_EL1, Instruction Set Attribute Register 1
* ID_AA64ISAR2_EL1, Instruction Set Attribute Register 2
* ID_AA64MMFR1_EL1, AArch64 Memory Model Feature Register 1
* ID_AA64MMFR2_EL1, AArch64 Memory Model Feature Register 2
* ID_AA64MMFR3_EL1, AArch64 Memory Model Feature Register 3
* ID_AA64MMFR4_EL1, AArch64 Memory Model Feature Register 4
* ID_AA64PFR0_EL1, AArch64 Processor Feature Register 0
* ID_AA64PFR1_EL1, AArch64 Processor Feature Register 1
* ID_AA64PFR2_EL1, AArch64 Processor Feature Register 2
* ID_AA64ZFR0_EL1, AArch64 SVE Feature ID register 0
* ID_AA64SMFR0_EL1, AArch64 SME Feature ID register 0
* ID_AA64DFR0_EL1, AArch64 Debug Feature Register 0
* ID_AA64DFR1_EL1, AArch64 Debug Feature Register 1

Additionally, there are few CPU features detected with
* TCR_EL1, Translation Control Register

but detection mechanism using it (for LPA/LPA2) is probably wrong as
this is control register, not a id register, and needs further work.

Finally, following registers are provided. Former one is already used,
while latter is given for future use:
* MIDR_EL1, Main ID Register
* AIDR_EL1, Auxiliary ID Register
2023-01-18 22:58:42 +01:00
konrad
6979cf230e Kernel: Print Aarch64 CPU features during CPU initialization 2023-01-18 22:58:42 +01:00
konrad
a8e9591bac Kernel: Split Aarch64 CPU setup into two stages
Former aims to bring the processor itself into desired state,
while latter allows for additional initialization with heap available.
2023-01-18 22:58:42 +01:00
konrad
97dce5d001 Kernel: Add Aarch64 CPU feature detection 2023-01-18 22:58:42 +01:00
konrad
0f81fb03f2 Kernel: Introduce stages in Aarch64 CPU initialization phase
Dropping to each exception level is now more explicit.
2023-01-18 22:58:42 +01:00
konrad
c08f059340 Kernel: Add CPUFeature enumeration for Aarch64 CPUs
Also, enumeration name & description mappings are provided along.
2023-01-18 22:58:42 +01:00
konrad
823aab8296 Kernel: Use a descriptive name for x86-64 cpu_feature_to_string_view
Settled for `cpu_feature_to_name` as that naming is more descriptive
and similarly named `cpu_feature_to_description` function will be
provided for Aarch64.
2023-01-18 22:58:42 +01:00
Liav A
3d87445c82 Kernel: Restore setting i8042 scan code set to scan code set 2 sequence
This seems to work perfectly OK on my ICH7 test machine and also it
works on QEMU, so it is probably OK to restore this.
This will ensure we always get scan code set 1 input, because we enable
scan code set 2 and PS/2 translation on the first (keyboard) port.
2023-01-06 11:09:56 +01:00
Liav A
0f7cc468b2 Kernel: Make i8042 controller initialization sequence more robust
The setting of scan code set sequence is removed, as it's buggy and
could lead the controller to fail immediately when doing self-test
afterwards. We will restore it when we understand how to do so safely.

Allow the user to determine a preferred detection path with a new kernel
command line argument. The defualt option is to check i8042 presence
with an ACPI check and if necessary - an "aggressive" test to determine
i8042 existence in the system.
Also, keep the i8042 controller pointer on the stack, so don't assign
m_i8042_controller member pointer if it does not exist.
2023-01-06 11:09:56 +01:00
Ben Wiederhake
c25bef59aa Kernel: Repair build for aarch64
This broke in 6fd478b6ce due to
insufficient testing on my part. Sorry!
2023-01-05 19:47:07 +01:00
Nico Weber
7f4680a377 Kernel/aarch64: Remove counterproductive volatile
Should not be needed, and triggers -Wvolatile in gcc.
See discussion on #16790.
2023-01-05 19:45:27 +01:00
Evan Smal
288a73ea0e Kernel: Add dmesgln_pci logging for Kernel::PCI
A virtual method named device_name() was added to
Kernel::PCI to support logging the PCI::Device name
and address using dmesgln_pci. Previously, PCI::Device
did not store the device name.

All devices inheriting from PCI::Device now use dmesgln_pci where
they previously used dmesgln.
2023-01-05 01:44:19 +01:00
Ben Wiederhake
65b420f996 Everywhere: Remove unused includes of AK/Memory.h
These instances were detected by searching for files that include
AK/Memory.h, but don't match the regex:

\\b(fast_u32_copy|fast_u32_fill|secure_zero|timing_safe_compare)\\b

This regex is pessimistic, so there might be more files that don't
actually use any memory function.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Ben Wiederhake
f07847e099 Everywhere: Remove unused includes of AK/Concepts.h
These instances were detected by searching for files that include
AK/Concepts.h, but don't match the regex:

\\b(AnyString|Arithmetic|ArrayLike|DerivedFrom|Enum|FallibleFunction|Flo
atingPoint|Fundamental|HashCompatible|Indexable|Integral|IterableContain
er|IteratorFunction|IteratorPairWith|OneOf|OneOfIgnoringCV|SameAs|Signed
|SpecializationOf|Unsigned|VoidFunction)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use any concepts.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Ben Wiederhake
c2a900b853 Everywhere: Remove unused includes of AK/StdLibExtras.h
These instances were detected by searching for files that include
AK/StdLibExtras.h, but don't match the regex:

\\b(abs|AK_REPLACED_STD_NAMESPACE|array_size|ceil_div|clamp|exchange|for
ward|is_constant_evaluated|is_power_of_two|max|min|mix|move|_RawPtr|RawP
tr|round_up_to_power_of_two|swap|to_underlying)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use any "extra stdlib" functions.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Ben Wiederhake
6fd478b6ce Everywhere: Remove unused includes of AK/Format.h
These instances were detected by searching for files that include
AK/Format.h, but don't match the regex:

\\b(CheckedFormatString|critical_dmesgln|dbgln|dbgln_if|dmesgln|FormatBu
ilder|__FormatIfSupported|FormatIfSupported|FormatParser|FormatString|Fo
rmattable|Formatter|__format_value|HasFormatter|max_format_arguments|out
|outln|set_debug_enabled|StandardFormatter|TypeErasedFormatParams|TypeEr
asedParameter|VariadicFormatParams|v_critical_dmesgln|vdbgln|vdmesgln|vf
ormat|vout|warn|warnln|warnln_if)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use any formatting functions.

Observe that this revealed that Userland/Libraries/LibC/signal.cpp is
missing an include.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
kleines Filmröllchen
a6a439243f Kernel: Turn lock ranks into template parameters
This step would ideally not have been necessary (increases amount of
refactoring and templates necessary, which in turn increases build
times), but it gives us a couple of nice properties:
- SpinlockProtected inside Singleton (a very common combination) can now
  obtain any lock rank just via the template parameter. It was not
  previously possible to do this with SingletonInstanceCreator magic.
- SpinlockProtected's lock rank is now mandatory; this is the majority
  of cases and allows us to see where we're still missing proper ranks.
- The type already informs us what lock rank a lock has, which aids code
  readability and (possibly, if gdb cooperates) lock mismatch debugging.
- The rank of a lock can no longer be dynamic, which is not something we
  wanted in the first place (or made use of). Locks randomly changing
  their rank sounds like a disaster waiting to happen.
- In some places, we might be able to statically check that locks are
  taken in the right order (with the right lock rank checking
  implementation) as rank information is fully statically known.

This refactoring even more exposes the fact that Mutex has no lock rank
capabilites, which is not fixed here.
2023-01-02 18:15:27 -05:00
Ben Wiederhake
3334cf675a AK+Kernel: Eliminate UB (signed overflow) from days_since_epoch 2023-01-02 16:19:35 -05:00
Ben Wiederhake
a8391d5a60 Everywhere: Remove unused includes of AK/Array.h
These instances were detected by searching for files that include
Array.h, but don't match the regex:
\\b(Array(?!\.h>)|iota_array|integer_sequence_generate_array)\\b
These are the three symbols defined by Array.h.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:08:35 +00:00
Liav A
cf3b75e2e6 Kernel: Propagate properly errors from PCI IDE Controller initialization 2023-01-02 04:59:23 -07:00
Liav A
735aa01b58 Kernel: Remove stale detect_disks method from PCI IDE controller class 2023-01-02 04:59:23 -07:00
Andreas Kling
1b4baaed56 Kernel/x86_64: *Restore* interrupt flag in page fault handler
If a page fault occurs while interrupts are disabled, we were wrongly
enabling interrupts right away in the page fault handler.

Instead, we should only do this if interrupts were enabled when the
page fault occurred.
2023-01-01 15:14:35 +01:00
kleines Filmröllchen
5d00e21852 Kernel/aarch64: Implement wait_cycles as a pause loop
The hand-written assembly does not compile under Clang due to register
size mismatches. Using a loop is slower (~6 instructions on O2 as
opposed to 2 with hand-written assembly), but using the pause
instruction makes this more efficient even under TCG.
2022-12-30 08:32:46 -07:00
kleines Filmröllchen
984348ed0d Kernel/aarch64: Implement Processor::pause and Processor::wait_check
For pause we use isb sy which will put the processor to sleep while the
pipeline is being flushed. This instruction is also used by Rust in spin
loops and found to be more efficient, as well as being a rough
equivalent to the x86 pause instruction which we also use here.

For wait_check we use yield, which is a hinted nop that is faster to
execute, and I leave a FIXME for processing SMP messages once we support
SMP.

These two changes probably make spin loops work on aarch64 :^)
2022-12-30 08:32:46 -07:00
kleines Filmröllchen
4d475588bb Kernel/aarch64: Declare TrapFrame as struct
Clang doesn't like misdeclaring classes and structs.
2022-12-30 08:32:46 -07:00
Timon Kruiper
e9b4e07b0a Kernel/aarch64: Start and initialize Scheduler and run multiple threads
This commit changes the init.cpp file to start and initialize the
Scheduler, and actually runs init_stage2. To show that it actually
works, another thread is spawned and executed simultaneously, by context
switching between the two!
2022-12-29 19:32:20 -07:00
Timon Kruiper
a5e98d3644 Kernel/aarch64: Add implementation of Processor::switch_context
This initial implementation makes it possible to actually context switch
between different kernel threads! :^)
2022-12-29 19:32:20 -07:00
Timon Kruiper
0b95d8cd24 Kernel/aarch64: Implement thread_context_first_enter
This requires two new functions, context_first_init and
restore_context_and_eret. With this code in place, we are now running
the first idle thread! :^)
2022-12-29 19:32:20 -07:00
Timon Kruiper
262309d9bf Kernel/aarch64: Implement Processor::initialize_context_switching
This changes the stack pointer to the initial_thread stack pointer, and
pushes two pointers onto the stack that point to the initial_thread. The
function then jumps to the ip of the initial_thread, which will be
thread_context_first_enter, and hangs there because that function is not
yet implemented.
2022-12-29 19:32:20 -07:00
Timon Kruiper
892f81b01a Kernel/aarch64: Add initial implementation of Processor::init_context
This does not handle everything correctly yet, such as setting the
correct state for running userspace applications, however this should be
enough to get kernel scheduling to work.
2022-12-29 19:32:20 -07:00
Timon Kruiper
9554e5ca48 Kernel/aarch64: Add Saved Program Status Register EL1 (SPSR_EL1) 2022-12-29 19:32:20 -07:00
Timon Kruiper
fb803e8025 Kernel/aarch64: Stub Processor::smp_wake_n_idle_processors 2022-12-29 19:32:20 -07:00
Timon Kruiper
1da84c2a2c Kernel: Factor out setting Thread entry function
This adds ThreadRegisters::set_entry_function, and also implements it
for aarch64.
2022-12-29 19:32:20 -07:00
Timon Kruiper
a6f78b895f Kernel/aarch64: Stub Processor::clean_fpu_state() instead of crashing
Also print a message to the debug output, such that developers know that
the current implementation is not actually correct.
2022-12-29 19:32:20 -07:00
Timon Kruiper
a3cbaa3449 Kernel: Move ThreadRegisters into arch-specific directory
These are architecture-specific anyway, so they belong in the Arch
directory. This commit also adds ThreadRegisters::set_initial_state to
factor out the logic in Thread.cpp.
2022-12-29 19:32:20 -07:00
Timon Kruiper
5a5fa10046 Kernel/aarch64: Add FIXME debug messages to PageDirectory
These are added to make clear that the current memory situation in the
aarch64 kernel is not complete yet.
2022-12-29 19:32:20 -07:00
Timon Kruiper
21deb603de Kernel/aarch64: Implement stub for asm_signal_trampoline
This get us further into the boot process, since Process::initialize
does not crash anymore.
2022-12-29 19:32:20 -07:00
Timon Kruiper
1cc06b9985 Kernel/aarch64: Correctly implement Processor::is_initialized() 2022-12-29 19:32:20 -07:00
Timon Kruiper
27b384e073 Kernel/aarch64: Remove copy constructor from Processor
I can't think of a reason why copying the Processor class makes sense,
so lets make sure it's not possible to do it by accident by declaring
the copy constructor as deleted.
2022-12-29 19:32:20 -07:00
Timon Kruiper
fbfe669f6d Kernel/aarch64: Implement Processor::{clear,restore}_critical() 2022-12-29 19:32:20 -07:00
Timon Kruiper
993b7495ba Kernel/aarch64: Implement Processor::check_invoke_scheduler() 2022-12-29 19:32:20 -07:00
Timon Kruiper
f6f43fd65e Kernel: Add Processor::wait_for_interrupt and use it in Scheduler
This removes the x86 specific hlt instruction from the scheduler, and
allows us to run the scheduler code for aarch64 by implementing
Processor::wait_for_interrupt for aarch64.
2022-12-29 19:32:20 -07:00
Timon Kruiper
f232133f65 Kernel/aarch64: Implement Processor::{enter,exit}_trap
And use them in interrupt handling.
2022-12-29 19:32:20 -07:00
Timon Kruiper
ee883b839c Kernel/aarch64: Implement dbgput{str,char} in kprintf.cpp
Also changes the implementation of kernelearlyputstr to call
kernelputstr, to deduplicate some logic.
2022-12-29 19:32:20 -07:00
Timon Kruiper
b991cff60f Kernel/aarch64: Add function to convert DFSC to StringView
This is useful for debugging, when hitting a data abort.
2022-12-29 19:32:20 -07:00
Timon Kruiper
ac788a2c8e Kernel: Remove duplicate Processor::restore_in_critical
There is already Processor::restore_critical, which does exactly the
same thing.
2022-12-29 19:32:20 -07:00
Timon Kruiper
b18a7297c5 Kernel: Move ScopedCritical.cpp to Kernel base directory
This file does not contain any architecture specific implementations,
so we can move it to the Kernel base directory. Also update the relevant
include paths.
2022-12-29 19:32:20 -07:00
Timon Kruiper
496a3cdcd3 Kernel/aarch64: Fix typo in RegisterState.h
We are actually storing tpidr_el0, as can be seen in vector_table.S, but
the RegisterState.h incorrectly had tpidr_el1. This will probably save
some annoying debugging later on.
2022-12-29 19:32:20 -07:00
Andreas Kling
fb09661420 Kernel: Add missing Random.h include in x86_64/Processor.cpp 2022-12-28 11:53:41 +01:00
Andreas Kling
7b9ea3efde Kernel+Userland: Remove uses of the __i386__ compiler macro 2022-12-28 11:53:41 +01: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