Commit Graph

504 Commits

Author SHA1 Message Date
Liav A
89a8920764 Kernel: Untie PS2 mouse and keyboard devices from i8042 implementation
To ensure actual PS2 code is not tied to the i8042 code, we make them
separated in the following ways:
- PS2KeyboardDevice and PS2MouseDevice classes are no longer inheriting
  from the IRQHandler class. Instead we have specific IRQHandler derived
  class for the i8042 controller implementation, which is used to ensure
  that we don't end up mixing PS2 code with low-level interrupt handling
  functionality. In the future this means that we could add a driver for
  other PS2 controllers that might have only one interrupt handler but
  multiple PS2 devices are attached, therefore, making it easier to put
  the right propagation flow from the controller driver all the way to
  the HID core code.
- A simple abstraction layer is added between the PS2 command set which
  devices could use and the actual implementation low-level commands.
  This means that the code in PS2MouseDevice and PS2KeyboardDevice
  classes is no longer tied to i8042 implementation-specific commands,
  so now these objects could send PS2 commands to their PS2 controller
  and get a PS2Response which abstracts the given response too.
2023-06-21 05:02:09 -06:00
Jelle Raaijmakers
2133bae1a4 Kernel: Move AC'97 to its own subdirectory 2023-06-21 12:26:32 +02:00
Liav A
d550b09871 Kernel: Move PC BIOS-related code to the x86_64 architecture directory
All code that is related to PC BIOS should not be in the Kernel/Firmware
directory as this directory is for abstracted and platform-agnostic code
like ACPI (and device tree parsing in the future).

This fixes a problem with the aarch64 architecure, as these machines
don't have any PC-BIOS in them so actually trying to access these memory
locations (EBDA, BIOS ROM) does not make any sense, as they're specific
to x86 machines only.
2023-06-19 23:49:00 +02:00
Liav A
5fd975da8f Kernel: Move MultiProcessor parsing code to the Arch/x86_64 directory
This code is very x86-specific, because Intel introduced the actual
MultiProcessor specification back in 1993, qouted here as a proof:

"The MP specification covers PC/AT-compatible MP platform designs based
on Intel processor architectures and Advanced Programmable Interrupt
Controller (APIC) architectures"
2023-06-19 23:49:00 +02:00
Liav A
428afca32b Kernel/ACPI: Make most of StaticParsing methods to be platform-agnostic
Most of the ACPI static parsing methods (methods that can be called
without initializing a full AML parser) are not tied to any specific
platform or CPU architecture.

The only method that is platform-specific is the one that finds the RSDP
structure. Thus, each CPU architecture/platform needs to implement it.
This means that now aarch64 can implement its own method to find the
ACPI RSDP structure, which would be hooked into the rest of the ACPI
code elegantly, but for now I just added a FIXME and that method returns
empty value of Optional<PhysicalAddress>.
2023-06-19 23:49:00 +02:00
MacDue
063efe9cf8 Kernel: Set kernel stack alignment to 8-bytes
This is already assumed by most of the assembly in the kernel, setting
this is just making it explicit (and may save some stack).
2023-06-19 21:59:35 +02:00
Liav A
9ee098b119 Kernel: Move all Graphics-related code into Devices/GPU directory
Like the HID, Audio and Storage subsystem, the Graphics subsystem (which
handles GPUs technically) exposes unix device files (typically in /dev).
To ensure consistency across the repository, move all related files to a
new directory under Kernel/Devices called "GPU".

Also remove the redundant "GPU" word from the VirtIO driver directory,
and the word "Graphics" from GraphicsManagement.{h,cpp} filenames.
2023-06-06 00:40:32 +02:00
Ben Wiederhake
3d6b838df3 LibPartition: Migrate from DeprecatedFile to File
The implemented cloning mechanism should be sound:
- If a PartitionTable is passed a File with
  ShouldCloseFileDescriptor::Yes, then it will keep it alive until the
  PartitionTable is destroyed.
- If a PartitionTable is passed a File with
  ShouldCloseFileDescriptor::No, then the caller has to ensure that the
  file descriptor remains alive.
If the caller is EBRPartitionTable, the same consideration holds.
If the caller is PartitionEditor::PartitionModel, this is satisfied by
keeping an OwnPtr<Core::File> around which is the originally opened
file.

Therefore, we never leak any fds, and never access a Core::File or fd
after destroying it.
2023-06-05 14:50:09 +02:00
Liav A
59cab85002 Kernel: Rename Syscall.cpp => Syscalls/SyscallHandler.cpp 2023-06-04 21:32:34 +02:00
Liav A
927926b924 Kernel: Move Performance-measurement code to the Tasks subdirectory 2023-06-04 21:32:34 +02:00
Liav A
b88c1d90e1 Kernel: Move TimerQueue code to the Time subdirectory 2023-06-04 21:32:34 +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
f1cbfc5a6e Kernel: Move task-crash related code to the Tasks subdirectory 2023-06-04 21:32:34 +02:00
Liav A
ee0ccdaebe Kernel: Move Credentials.{cpp,h} to the Security subdirectory 2023-06-04 21:32:34 +02:00
Liav A
64af4953c2 Kernel: Move UBSanitizer and AddressSanitizer to Security subdirectory 2023-06-04 21:32:34 +02:00
Liav A
490856453d Kernel: Move Random.{h,cpp} code to Security subdirectory 2023-06-04 21:32:34 +02:00
Liav A
1b04726c85 Kernel: Move all tasks-related code to the Tasks subdirectory 2023-06-04 21:32:34 +02:00
Liav A
788022d5d1 Kernel: Move Jail code to a new subdirectory 2023-06-04 21:32:34 +02:00
Liav A
500b7b08d6 Kernel: Move the Storage directory to be a new directory under Devices
The Storage subsystem, like the Audio and HID subsystems, exposes Unix
device files (for example, in the /dev directory). To ensure consistency
across the repository, we should make the Storage subsystem to reside in
the Kernel/Devices directory like the two other mentioned subsystems.
2023-06-02 11:04:37 +02:00
Daniel Bertalan
7987bf5b92 Kernel/aarch64: Add RPi/MMIO.cpp to SOURCES_RUNNING_WITHOUT_MMU
Otherwise, `MMIO::MMIO` will fault on the RPi 3 due to accessing
`__stack_chk_guard` before the kernel is mapped into high memory.
2023-05-28 05:05:09 -06:00
Liav A
4617c05a08 Kernel: Move a bunch of generic devices code into new subdirectory 2023-05-19 21:49:21 +02:00
Daniel Bertalan
c460b84ebe Kernel: Add character device driver for the RPi "mini UART" (UART1)
While the PL011-based UART0 is currently reserved for the kernel
console, UART1 is free to be exposed to the userspace as `/dev/ttyS0`.
This will be used as the stdout of `run-tests-and-shutdown.sh` when
testing the AArch64 kernel.
2023-05-17 01:32:43 -06:00
Daniel Bertalan
d9c557d0b4 Kernel: Add RPi Watchdog and use it for system shutdown
The Raspberry Pi hardware doesn't support a proper software-initiated
shutdown, so this instead uses the watchdog to reboot to a special
partition which the firmware interprets as an immediate halt on
shutdown. When running under Qemu, this causes the emulator to exit.
2023-05-17 01:32:43 -06:00
Daniel Bertalan
555d301e3b Kernel: Unify x86-64 and AArch64 __panic implementation
We now have everything in the AArch64 kernel to be able to use the full
`__panic` implementation, so we can share the code with x86-64.

I have kept `__assertion_failed` separate for now, as the x86-64 version
directly executes inline assembly, thus `Kernel/Arch/aarch64/Panic.cpp`
could not be removed.
2023-05-17 01:32:43 -06:00
Andrew Kaster
baeee0effe Kernel: Restore kernel8.img for aarch64 build
This was erroneously deleted in 420952a433
2023-05-16 09:47:37 +02:00
Liav A
420952a433 Kernel/aarch64: Remove drawing of logo on the framebuffer during init
This logo was actually used as a first sign of life in the very early
days of the aarch64 port.
Now that we boot into the graphical mode of the system just fine there's
no need to keep this.
2023-05-13 07:56:00 +02:00
Pankaj Raghav
feb48cbc7c Kernel: Introduce PCIIRQHandler
PCIIRQHandler is a generic IRQ handler that the device driver can
inherit to use either Pin or MSI(x) based interrupt mechanism.

The PCIIRQHandler can do what the existing IRQHandler can do for pin
based interrupts but also deal with MSI based interrupts. We can
hopefully convert all the PCI based devices to use this handler so that
MSI(x) can be used.
2023-05-07 21:16:41 +02:00
Pankaj Raghav
f0b6eb6932 Kernel: Implement helpers to manipulate MSI(x) data structures
MSIx table entry is used to program interrupt vectors and it is
architecture specific. Add helper functions declaration in
Arch/PCIMSI.h. The definition of the function is placed in the
respective arch specific code.
2023-05-07 21:16:41 +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
Liav A
6c4a47d916 Kernel: Remove redundant HID name from all associated files 2023-04-09 18:11:37 +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
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
Marco Cutecchia
5fe6c6fc24 Kernel: Add support for SD host controllers on the PCI bus 2023-04-02 12:43:17 -06:00
Jelle Raaijmakers
dd8fa73da1 Kernel: Add support for Intel HDA
This is an implementation that tries to follow the spec as closely as
possible, and works with Qemu's Intel HDA and some bare metal HDA
controllers out there. Compiling with `INTEL_HDA_DEBUG=on` will provide
a lot of detailed information that could help us getting this to work
on more bare metal controllers as well :^)

Output format is limited to `i16` samples for now.
2023-03-25 21:27:03 +01:00
Marco Cutecchia
36c5afdfb2 Revert "Revert "Kernel/Storage: Remove the ramdisk implementation""
This reverts commit 187723776a.

This was reverted because it was needed until the aarch64 port
got an SD card driver

Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00: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
Liav A
59a76b1279 Kernel: Remove 2 duplicated listings of cpp files in CMakeLists.txt file 2023-03-25 08:46:54 +00: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
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
Liav A
ac4829cc50 Kernel/IntelGraphics: Move PLL handling code to a different file
Dealing with the specific details of how to program a PLL should be done
in a separate file to ensure we can easily expand it to support future
generations of the Intel graphics device.
2023-02-19 15:01:01 -07:00
Liav A
2def16a3d2 Kernel/Graphics: Introduce the IntelDisplayConnectorGroup class
In the real world, graphics hardware tend to have multiple display
connectors. However, usually the connectors share one register space but
still keeping different PLL timings and display lanes.
This new class should represent a group of multiple display connectors
working together in the same Intel graphics adapter. This opens an
opportunity to abstract the interface so we could support future Intel
iGPU generations.

This is also a preparation before the driver can support newer devices
and utilize their capabilities.
The mentioned preparation is applied in a these aspects:
1. The code is splitted into more classes to adjust to future expansion.
2 classes are introduced: IntelDisplayPlane and IntelDisplayTranscoder,
so the IntelDisplayPlane controls the plane registers and second class
controls the pipeline (transcoder, encoder) registers. On gen4 it's not
really useful because there are probably one plane and one encoder to
care about, but in future generations, there are likely to be multiple
transcoders and planes to accommodate multi head support.
2. The set_edid_bytes method in the DisplayConnector class can now be
told to not assume the provided EDID bytes are always invalid. Therefore
it can refrain from printing error messages if this flag parameter is
true. This is useful for supporting real hardware situation when on boot
not all ports are connected to a monitor, which can result in floating
bus condition (essentially all the bytes we read are 0xFF).
3. An IntelNativeDisplayConnector could now be set to flag other types
of connections such as eDP (embedded DisplayPort), Analog output, etc.
This is important because on the Intel gen4 graphics we could assume to
have one analog output connector, but on future generations this is very
likely to not be the case, as there might be no VGA outputs, but rather
only an eDP connector which is converted to VGA by a design choice of
the motherboard manufacturer.
4. Add ConnectorIndex to IntelNativeDisplayConnector class - Currently
this is used to verify we always handle the correct connector when doing
modesetting.
Later, it will be used to locate special settings needed when handling
connector requests.
5. Prepare to support more types of display planes. For example, the
Intel Skylake register set for display planes is a bit different, so
let's ensure we can properly support it in the near future.
2023-02-19 15:01:01 -07:00
Liav A
61f4914d6e Kernel+Userland: Add constants subdirectory at /sys/kernel directory
This subdirectory is meant to hold all constant data related to the
kernel. This means that this data is never meant to updated and is
relevant from system boot to system shutdown.
Move the inodes of "load_base", "cmdline" and "system_mode" to that
directory. All nodes under this new subdirectory are generated during
boot, and therefore don't require calling kmalloc each time we need to
read them. Locking is also not necessary, because these nodes and their
data are completely static once being generated.
2023-02-19 13:47:11 +01: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
Ollrogge
361df6eff8 AK: Add conversion functions for packed DOS time format
This also adjusts the FATFS code to use the new functions and removes
the now redundant old conversion functions.
2023-02-12 13:13:15 -07:00
konrad
84e8d5f418 Kernel: Remove old ‘main id register accessorʼ for Aarch64 2023-02-10 11:51:47 -07:00
Liav A
ab27fce86f AK: Add a new method to propagate errno while printing errors in Kernel
This new method is meant to be used in both userspace and kernel code.
The idea is to allow printing of a verbose message and then returning an
errno code which is the proper mechanism for kernel code because we
should almost always assume that such error will be propagated back to
userspace in some way, so the userspace code could reasonably decode it.

For userspace code however, this new method is meant to be a simple
wrapper for Error::from_string_view, because for most invocations, it's
much more useful to have a verbose & literal error than a errno code, so
we simply ignore that errno code completely in such context.
2023-02-10 09:14:20 +00:00