Commit graph

47 commits

Author SHA1 Message Date
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
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
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 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 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 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
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 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
Sam Atkins 3cbc0fdbb0 Kernel: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00: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 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
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 7c8e61f4d1 Kernel: Unify x86-64 assembly snippets naming for RDSEED & RDRAND 2023-01-25 23:17:36 +01: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 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
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
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
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
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 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 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 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
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
Hendiadyoin1 7ca3d413f7 Kernel: Pull apart CPU.h
This does not add any functional changes
2021-06-24 00:38:23 +02:00
Linus Groh 2b0c361d04 Everywhere: Fix a bunch of typos 2021-04-18 10:30:03 +02:00
Hendiadyoin1 ce4f43a192 Kernel::x86_64: Re-copy boot.S and add longmode in
Now we should have the posibility to run in longmode, after enabling it
in the gdt
2021-03-21 09:35:23 +01:00
Hendiadyoin1 0d934fc991 Kernel::CPU: Move headers into common directory
Alot of code is shared between i386/i686/x86 and x86_64
and a lot probably will be used for compatability modes.
So we start by moving the headers into one Directory.
We will probalby be able to move some cpp files aswell.
2021-03-21 09:35:23 +01:00
Hendiadyoin1 5a8cc07485 Kernel: Add TSS64 and Desciptor for 64-bit 2021-03-21 09:35:23 +01:00
Andreas Kling adb2e6be5f Kernel: Make the kernel compile & link for x86_64
It's now possible to build the whole kernel with an x86_64 toolchain.
There's no bootstrap code so it doesn't work yet (obviously.)
2021-03-04 18:25:01 +01:00