Commit graph

7607 commits

Author SHA1 Message Date
Gunnar Beutner 69efded562 Kernel: Add more stubs needed for Thread.cpp 2022-10-16 17:35:37 +02:00
Gunnar Beutner 1e3edb3b76 Kernel: Don't directly include <Kernel/Arch/x86/TrapFrame.h>
This adds a new arch-independent header which in turn includes the
correct header for the build architecture.
2022-10-16 17:35:37 +02:00
Gunnar Beutner 918fdf9e2c Kernel: Add VALIDATE_IS_AARCH64 guard macro 2022-10-16 17:35:37 +02:00
Gunnar Beutner dfee6f73d2 Kernel: Replace VERIFY_NOT_REACHED with TODO_AARCH64
This makes it easier to differentiate between cases where certain
functionality is not implemented vs. cases where a code location
should really be unreachable.
2022-10-16 17:35:37 +02:00
Liav A 462802ef0c Kernel/SysFS: Expose file size of ACPI tables in /sys/firmware/acpi
It costs us nothing, and some utilities (such as the known file utility)
rely on the exposed file size (after doing lstat on it), to show
anything useful besides saying the file is "empty".
2022-10-16 17:26:35 +02:00
Liav A 11a5f2c508 Kernel: Initialize primitive class member of ACPISysFSComponent to zero 2022-10-16 17:26:35 +02:00
Brian Gianforcaro 2079728a74 Kernel: Add formal Processor::verify_no_spinlocks_held() API
In a few places we check `!Processor::in_critical()` to validate
that the current processor doesn't hold any kernel spinlocks.

Instead lets provide it a first class name for readability.
I'll also be adding more of these, so I would rather add more
usages of a nice API instead of this implicit/assumed logic.
2022-10-16 02:29:14 -06:00
Liav A 40f35558b5 Kernel: Remove unused /proc/devices node
This node is not used anymore, so let's remove it.
2022-10-16 02:24:43 -06:00
Gunnar Beutner afa9060012 Kernel: Fix build error on AARCH64
This currently fails with:

error: #pragma once in main file [-Werror]
2022-10-15 06:01:45 +00:00
Undefine 135ca3fa1b Kernel: Add support for the FAT32 filesystem
This commit adds read-only support for the FAT32 filesystem. It also
includes support for long file names.
2022-10-14 18:36:40 -06:00
Liav A 7520acd4eb Kernel: Move Scheduler current time method to the TimeManagement code 2022-10-14 14:13:51 +02:00
Liav A 3651d9701e Kernel: Abstract platform-specific current time methods from Scheduler
This change ensures that the scheduler doesn't depend on a platform
specific or arch-specific code when it initializes itself, but rather we
ensure that in compile-time we will generate the appropriate code to
find the correct arch-specific current time methods.
2022-10-14 14:13:51 +02:00
kleines Filmröllchen 4c7eef874d Kernel: Read version and git commit hash from baked-in version info
... instead of hard-coding it in the uname syscall.
2022-10-14 13:45:33 +02:00
kleines Filmröllchen 7e11b9a276 Kernel: Move sys$uname to use TypedTransfer
This should equate to roughly the same code but improve typechecking.
2022-10-14 13:45:33 +02:00
kleines Filmröllchen 7c05eed487 Kernel: Bake version information into the Kernel
This is done by generating a Kernel/Version.h header with major version,
minor version, and git hash.
2022-10-14 13:45:33 +02:00
Gunnar Beutner 70f4d943be Kernel+LibC: Add registers for AARCH64 in __mcontext 2022-10-14 13:01:13 +02:00
Gunnar Beutner b7555419f1 Kernel: Remove -nodefaultlibs compiler options
This was necessary until a few months ago because of b0rked toolchain
options.
2022-10-14 13:01:13 +02:00
Gunnar Beutner 5921df75b6 Kernel: Implement userspace support for syscalls on AARCH64
There are no guarantees that the final syscall API will look like this
but at least for now this lets us compile the userland binaries.
2022-10-14 13:01:13 +02:00
Timon Kruiper 50e74de279 Kernel: Add StdLib.cpp and UserOrKernelBuffer.cpp to aarch64 build
Also remove UserOrKernelBuffer::{read, write} and __stack_chk_fail from
Dummy.cpp and init.cpp respectively.
2022-10-13 11:26:46 +02:00
Markus Pfeifenberger 0cfcac7900 Kernel: Only use the TSC when it is invariant 2022-10-12 00:32:23 -06:00
minus cf48200e7b Kernel: Make the ACPI DSDT table accessible
Expose the DSDT table in ACPI::Parser and in
/sys/firmware/acpi as a first little step toward
interpreting the AML bytecode from ACPI.
2022-10-12 00:11:36 -06:00
Andrew Kaster 828441852f Everywhere: Replace uses of __serenity__ with AK_OS_SERENITY
Now that we have OS macros for essentially every supported OS, let's try
to use them everywhere.
2022-10-10 12:23:12 +02:00
Liav A f07e0180d6 Kernel: Don't truncate physical memory space PDE pointers
For some odd reason we used to return PhysicalPtr for a page_table_base
result, but when setting it we accepted only a 32 bit value, so we
truncated valid 64 bit addresses into 32 bit addresses by doing that.
With this commit being applied, now PageDirectories can be located
beyond the 4 GiB barrier.

This was found by sin-ack, therefore he should be credited with this fix
appropriately with Co-authored-by sign.

Co-authored-by: sin-ack <sin-ack@users.noreply.github.com>
2022-10-09 09:58:08 -06:00
Tim Schumacher d72a3b5959 Kernel: Do not mark .ro_after_init as NOLOAD
There is no particular reason why this section should be marked as
`NOBITS` (as it might very well include initialized values), and it
resolves 90% of the mismatches between the input and output sections,
which LLD now warns about when linking.
2022-10-09 10:20:19 +02:00
Nico Weber 2af028132a AK+Everywhere: Add AK_COMPILER_{GCC,CLANG} and use them most places
Doesn't use them in libc headers so that those don't have to pull in
AK/Platform.h.

AK_COMPILER_GCC is set _only_ for gcc, not for clang too. (__GNUC__ is
defined in clang builds as well.) Using AK_COMPILER_GCC simplifies
things some.

AK_COMPILER_CLANG isn't as much of a win, other than that it's
consistent with AK_COMPILER_GCC.
2022-10-04 23:35:07 +01:00
Timothy Flynn 97d15e9b8f Kernel: Do not require 'proc' promise in getsid() and getpgid()
These only require 'stdio' according to:
https://man.openbsd.org/pledge.2
2022-10-03 13:48:03 +02:00
Liav A 4e0f85432a Kernel/Storage: Remove the ramdisk implementation
Nobody uses this because the x86 prekernel environment is corrupting the
ramdisk image prior to running the actual kernel. In the future we can
ensure that the prekernel doesn't corrupt the ramdisk if we want to
bring support back. In addition to that, we could just use a RAM based
filesystem to load whatever is needed like in Linux, without the need of
additional filesystem driver.

For the mentioned corruption problem, look at issue #9893.
2022-10-03 11:12:35 +02:00
Liav A 66bde66f49 Kernel/aarch64: Use adopt_lock_ref to instantiate an InterruptController 2022-10-01 19:36:04 +02:00
Timon Kruiper 779a1d1232 Kernel/aarch64: Get framebuffer data from BootFramebufferConsole
The BootFramebufferConsole class maps the framebuffer using the
MemoryManager, so to be able to draw the logo, we need to get this
mapped framebuffer. This commit adds a unsafe API for that.
2022-10-01 14:09:01 +02:00
Timon Kruiper 15b818cd57 Kernel/aarch64: Remove specific aarch64 code in BootFramebufferConsole
The MemoryManager now works, so we can use the same code as on x86 to
map the framebuffer. Since it uses the MemoryManager, the initialization
of the BootFramebufferConsole has to happen after the MemoryManager is
working.
2022-10-01 14:09:01 +02:00
Timon Kruiper 57b1369475 Kernel/aarch64: Put correct memory size in multiboot_mmap
Also enable the MMU earlier in the boot process.
2022-10-01 14:09:01 +02:00
Timon Kruiper c2e410195a Kernel/aarch64: Set up pointer to kernel page directory
The MemoryManager uses this pointer to adds its newly created page
tables to the kernel page directory.
2022-10-01 14:09:01 +02:00
Timon Kruiper 96f73c9289 Kernel/aarch64: Set up quickmap infrastructure in initial page tables
With this change the quickmap related functions in MemoryManager
actually work. :^)
2022-10-01 14:09:01 +02:00
Timon Kruiper a62732ee2f Kernel/aarch64: Only identity map kernel image, instead of all of RAM
For the initial page tables we only need to identity map the kernel
image, the rest of the memory will be managed by the MemoryManager. The
linker script is updated to get the kernel image start and end
addresses.
2022-10-01 14:09:01 +02:00
Timon Kruiper cdf59c86ac Kernel: Make PageDirectory.h architecture specific
The page table and page directory formats are architecture specific, so
move the headers into the Arch directory. Also move the aarch64 page
table constants from aarch64/MMU.cpp to aarch64/PageDirectory.h.
2022-10-01 14:09:01 +02:00
Timon Kruiper ad5e8bbb4f Kernel: Add ability to dump backtrace from provided frame pointer
When an exception happens it is sometimes hard to figure out where
exactly the exception happened, so use the frame pointer of the trap
frame to print a backtrace.
2022-10-01 14:09:01 +02:00
Timon Kruiper 57901a6f62 Kernel/aarch64: Implement tlb flushing
This initial implementation flushes the complete tlb cache. A FIXME is
added to implement the partial tlb flushing.
2022-10-01 14:09:01 +02:00
Timon Kruiper 424a974e01 Kernel: Don't reserve Low Memory (0-1MB) on non-x86 architectures
This memory is only reserved on x86(-64) and is usable on other
architectures.
2022-10-01 14:09:01 +02:00
Timon Kruiper 1b60126d93 Kernel/aarch64: Stub Inode::{read,write}_bytes
Recent changes caused the build to fail for aarch64, with these
functions stubbed it builds again.
2022-10-01 14:09:01 +02:00
Nico Weber b0c0ebc543 Kernel: Fix a comment typo 2022-09-30 20:09:26 -07:00
Liav A 3cf6ac1b3f Kernel: Fix typo in comment in Ext2FileSystem::read_bytes_locked method 2022-09-26 20:13:13 +01:00
Liav A 0a793a7fa3 Kernel/FileSystem: Remove the locking of a Inode mutex in InodeVMObjects
We no longer require to lock the m_inode_lock in the SharedInodeVMObject
code as the methods write_bytes and read_bytes of the Inode class do
this for us now.
2022-09-26 22:06:10 +03:00
Liav A 60b088b89a Kernel: Send SIGBUS to threads that use after valid Inode mmaped range
According to Dr. POSIX, we should allow to call mmap on inodes even on
ranges that currently don't map to any actual data. Trying to read or
write to those ranges should result in SIGBUS being sent to the thread
that did violating memory access.

To implement this restriction, we simply check if the result of
read_bytes on an Inode returns 0, which means we have nothing valid to
map to the program, hence it should receive a SIGBUS in that case.
2022-09-26 20:00:34 +03:00
Idan Horowitz 04b1d32b70 Kernel: Stop using 'int's for indices in interrupt handling 2022-09-25 16:52:56 +03:00
Idan Horowitz 6f6211c5e6 Kernel: Simplify InterruptManagement::switch_to_pic_mode()
Since switch_to_pic_mode is only called if no IOAPIC is available,
there's no need to try and and find it and disable it.
2022-09-25 16:52:56 +03:00
Idan Horowitz 9abbeff79f Kernel: Store IRQControllers in NonnullRefPtrs instead of RefPtrs
These are always non-null, so there's no point in storing them in a
nullable container.
2022-09-25 16:52:56 +03:00
Idan Horowitz 176989d811 Kernel: Use InterruptManagement::m_interrupt_controllers::append()
There's no need to reinvent the wheel.
2022-09-25 16:52:56 +03:00
Idan Horowitz 746bf12ac4 Kernel: Remove unused InterruptManagement::m_smp_enabled 2022-09-25 16:52:56 +03:00
Liav A d5b97eb41e Kernel+Userland: Provide bytes count for a DisplayConnector framebuffer
This value will be used later on by WindowServer to reject resolutions
that will request a mapping that will overflow the hardware framebuffer
max length.
2022-09-24 15:38:56 +01:00
kleines Filmröllchen 1a7d6508e3 Kernel: By default, don't dump regions when a userspace crash happens
There is the DUMP_REGIONS_ON_CRASH debug macro which re-enables this
(old) behavior.
2022-09-24 14:22:09 +02:00
Liav A 6e26e9fb29 Revert "Kernel: Send SIGBUS to threads that use after valid Inode mmaped range"
This reverts commit 0c675192c9.
2022-09-24 13:49:40 +02:00
Liav A 05ba034000 Kernel: Introduce the IOWindow class
This class is intended to replace all IOAddress usages in the Kernel
codebase altogether. The idea is to ensure IO can be done in
arch-specific manner that is determined mostly in compile-time, but to
still be able to use most of the Kernel code in non-x86 builds. Specific
devices that rely on x86-specific IO instructions are already placed in
the Arch/x86 directory and are omitted for non-x86 builds.

The reason this works so well is the fact that x86 IO space acts in a
similar fashion to the traditional memory space being available in most
CPU architectures - the x86 IO space is essentially just an array of
bytes like the physical memory address space, but requires x86 IO
instructions to load and store data. Therefore, many devices allow host
software to interact with the hardware registers in both ways, with a
noticeable trend even in the modern x86 hardware to move away from the
old x86 IO space to exclusively using memory-mapped IO.

Therefore, the IOWindow class encapsulates both methods for x86 builds.
The idea is to allow PCI devices to be used in either way in x86 builds,
so when trying to map an IOWindow on a PCI BAR, the Kernel will try to
find the proper method being declared with the PCI BAR flags.
For old PCI hardware on non-x86 builds this might turn into a problem as
we can't use port mapped IO, so the Kernel will gracefully fail with
ENOTSUP error code if that's the case, as there's really nothing we can
do within such case.

For general IO, the read{8,16,32} and write{8,16,32} methods are
available as a convenient API for other places in the Kernel. There are
simply no direct 64-bit IO API methods yet, as it's not needed right now
and is not considered to be Arch-agnostic too - the x86 IO space doesn't
support generating 64 bit cycle on IO bus and instead requires two 2
32-bit accesses. If for whatever reason it appears to be necessary to do
IO in such manner, it could probably be added with some neat tricks to
do so. It is recommended to use Memory::TypedMapping struct if direct 64
bit IO is actually needed.
2022-09-23 17:22:15 +01:00
Liav A 6bafbd64e2 Kernel/Memory: Introduce a method to allocate TypedMapping on the heap
This will be used later on to allocate such structure on the heap when
it is necessary to do so.
2022-09-23 17:22:15 +01:00
Liav A fe2bd8e3dd Kernel: Move x86-specific timer code handling to Arch/x86/Time directory
The APICTimer, HPET and RTC (the RTC timer is in the context of the PC
RTC here) are timers that exist only in x86 platforms, therefore, we
move the handling code and the initialization code to the Arch/x86/Time
directory. Other related code patterns in the TimeManagement singleton
and in the Random.cpp file are guarded with #ifdef to ensure they are
only compiled for x86 builds.
2022-09-23 17:22:15 +01:00
Liav A 48f3d762af Kernel/Graphics: Move x86-specific support for VGA to Arch/x86 directory
The new VGAIOArbiter class is now responsible to conduct x86-specific
instructions to control VGA hardware from the old ISA ports. This allows
us to ensure the GraphicsManagement code doesn't use x86-specific code,
thus allowing it to be compiled within non-x86 kernel builds.
2022-09-23 17:22:15 +01:00
Liav A 37ed1b28fa Kernel: Ensure proper locking when mutating boot console cursor
The BootFramebufferConsole highly depends on using the m_lock spinlock,
therefore setting and changing the cursor state should be done under
that spinlock too to avoid crashing.
2022-09-20 20:51:03 +01:00
Liav A 0a5416a87a Kernel: Mark Console::{hide,show}_cursor methods protected
Only the Console code in the Graphics directory should be able to call
on these methods. The set_cursor method stays public as VirtualConsole
uses that method to change the cursor position.
2022-09-20 20:51:03 +01:00
Liav A 252c92d565 Kernel/Graphics: Introduce support for QEMU isa-vga device
This device is supposed to be used in microvm and ISA-PC machine types,
and we assume that if we are able to probe for the QEMU BGA version of
0xB0C5, then we have an existing ISA Bochs VGA adapter to utilize.
To ensure we don't instantiate the driver for non isa-vga devices, we
try to ensure that PCI is disabled because hardware IO test probe failed
so we can be sure that we use this special handling code only in the
QEMU microvm and ISA-PC machine types. Unfortunately, this means that if
for some reason the isa-vga device is attached for the i440FX or Q35
machine types, we simply are not able to drive the device in such setups
at all.

To determine the amount of VRAM being available, we read VBE register at
offset 0xA. That register holds the amount of VRAM divided by 64K, so we
need to multiply the value in our code to use the actual VRAM size value
again.

The isa-vga device requires us to hardcode the framebuffer physical
address to 0xE0000000, and that address is not expected to change in the
future as many other projects rely on the isa-vga framebuffer to be
present at that physical memory address.
2022-09-20 19:05:13 +01:00
Liav A b28202e356 Kernel/PCI: Consider ACPI MCFG existence in IO probe test
We should aim to reliably determine if PCI hardware exists or not, and
we should consider the ACPI MCFG table in that test. Although it is
unusual to see an hardware setup where the PCI host bridge does not
respond to x86 IO instructions, it is expected to happen at least on the
QEMU microvm machine type as the host bridge only responds to memory
mapped IO requests. Therefore, we first test if ACPI is enabled, and we
try to use it to fetch the MCFG table. Later on we could also add FDT
parsing as part of the PCI IO test which would be useful for the QEMU
microvm machine type.
2022-09-20 19:05:13 +01:00
Liav A 02a980ee54 Kernel/Graphics: Always ensure a console is set when initialization ends
We use a ScopeGuard to ensure we always set a console of some sort if we
exit early from the initialization sequence in the GraphicsManagement
code. We do so to ensure we can boot into text mode console in an ISA-PC
machine type, because earlier we failed with an assertion due to not
setting any console for VirtualConsole to use.
2022-09-20 19:05:13 +01:00
Liav A 48730ff8ec Kernel/Storage: Force PIO mode for ISA IDE controllers
ISA IDE controllers don't support Bus-master DMA as this feature is only
available for PCI IDE controllers. Therefore, don't try to use DMA mode
for such hardware.
2022-09-20 19:05:13 +01:00
Liav A 76aace6f19 Kernel: Move x86-specific init sequence code to the x86/Arch directory
The code in init.cpp is specific to the x86 initialization sequence, so
move it to the Arch/x86 directory in the same fashion like the aarch64
pattern.
2022-09-20 18:43:05 +01:00
Liav A 1b7b360ca1 Kernel: Move x86-specific IRQ controller code to Arch/x86 directory
The PIC and APIC code are specific to x86 platforms, so move them out of
the general Interrupts directory to Arch/x86/common/Interrupts directory
instead.
2022-09-20 18:43:05 +01:00
Liav A aeef1c52bc Kernel: Move PCI IDE driver code to the Arch/x86 directory
That code heavily relies on x86-specific instructions, and while other
CPU architectures and platforms can have PCI IDE controllers, currently
we don't support those, so this code is a special case which needs to be
in the Arch/x86 directory.
In the future it could be put back to the original place when we make it
more generic and suitable for other platforms.
2022-09-20 18:43:05 +01:00
Liav A 8d6da9863f Kernel: Move x86 Bochs VBE code to the Arch/x86 directory
To do this, we make the QEMUDisplayConnector class more standalone so it
does not need to inherit from the BochsDisplayConnector class.
2022-09-20 18:43:05 +01:00
Liav A c50a81e93e Kernel: Move x86-specific HID code to the Arch/x86 directory
The i8042 controller with its attached devices, the PS2 keyboard and
mouse, rely on x86-specific IO instructions to work. Therefore, move
them to the Arch/x86 directory to make it easier to omit the handling
code of these devices.
2022-09-20 18:43:05 +01:00
Liav A 948be9674a Kernel: Don't compile ISA IDE controller code in non-x86 builds
The ISA IDE controller code makes sense to be compiled in a x86 build as
it relies on access to the x86 IO space. For other architectures, we can
just omit the code as there's no way we can use that code again.
To ensure we can omit the code easily, we move it to the Arch/x86
directory.
2022-09-20 18:43:05 +01:00
Liav A bb6f61ee5d Kernel/PCI: Convert PCI BAR number to a strong typed enum class 2022-09-20 18:43:05 +01:00
Liav A f510c0ba04 Kernel: Remove stale includes of x86 IO header file
The AHCI code doesn't rely on x86 IO at all as it only uses memory
mapped IO so we can simply remove the header.

We also simply don't use x86 IO in the Intel graphics driver, so we can
simply remove the include of the x86 IO header there too.

Everything else was a bunch of stale includes to the x86 IO header and
are actually not necessary, so let's remove them to make it easier to
compile non-x86 Kernel builds.
2022-09-20 18:43:05 +01:00
Liav A 485d4e01ed Kernel: Move VMWare backdoor communication code to the x86 directory
The VMWare backdoor handling code involves many x86-specific
instructions and therefore should be in the Arch/x86 directory. This
ensures we can easily omit the code in compile-time for non-x86 builds.
2022-09-20 18:43:05 +01:00
Liav A e39086f2c6 Kernel: Move PCI initialization x86-specific code to the arch directory
It seems more correct to let each platform to define its own sequence of
initialization of the PCI bus, so let's remove the #if flags and just
put the entire Initializer.cpp file in the appropriate code directory.
2022-09-20 18:43:05 +01:00
Liav A 5576151e68 Kernel: Don't blindly compile Bochs debug output code in ConsoleDevice
Only use the Bochs debug output if we compile a x86 build since bochs
debug output relies on x86 specific instructions.

We also remove the CONSOLE_OUT_TO_BOCHS_DEBUG_PORT flag as we always
compile bochs debug output for x86 builds and we always want to include
the bochs debug output capability as it is very handy and doesn't hurt
bare metal hardware or do any other problem besides taking a small
amount of CPU cycles.
2022-09-20 18:43:05 +01:00
Liav A fdef8d0d37 Kernel: Move PCSpeaker code to the x86-specific architecture directory
The PCSpeaker code is specific to x86 platforms, thus it makes sense to
put in the Arch/x86 subdirectory.
2022-09-20 18:43:05 +01:00
Liav A 1596ee241f Kernel/PCI: Move IO based HostBridge code to x86 arch-specific directory
The simple PCI::HostBridge class implements access to the PCI
configuration space by using x86 IO instructions. Therefore, it should
be put in the Arch/x86/PCI directory so it can be easily omitted for
non-x86 builds.
2022-09-20 18:43:05 +01:00
Liav A a02c9c9569 Kernel: Abstract platform-specific serial port access from kprintf
kprintf should not really care about the hardware-specific details of
each UART or serial port out there, so instead of using x86 specific
instructions, let's ensure that we will compile only the relevant code
for debug output for a targeted-specific platform.
2022-09-20 18:43:05 +01:00
Liav A d5ee03ef5b Kernel/x86: Move RTC and CMOS code to x86 arch-specific subdirectory
The RTC and CMOS are currently only supported for x86 platforms and use
specific x86 instructions to produce only certain x86 plaform operations
and results, therefore, we move them to the Arch/x86 specific directory.
2022-09-20 18:43:05 +01:00
Liav A e740d959df Kernel: Move CMOS code to the Kernel namespace 2022-09-20 18:43:05 +01:00
Liav A 84fbab6803 Kernel: Move IO delay code to x86 architecture subdirectory
Many code patterns and hardware procedures rely on reliable delay in the
microseconds granularity, and since they are using such delays which are
valid cases, but should not rely on x86 specific code, we allow to
determine in compile time the proper platform-specific code to use to
invoke such delays.
2022-09-20 18:43:05 +01:00
Liav A cac72259d0 Kernel: Put the RTC code in the Kernel namespace
We only use the RTC code in the Kernel, so it doesn't make sense to make
the RTC namespace outside of it. In addition to that, we will need later
on to use the RTC in an x86 specific manner and this will help us to use
this code in such fashion.
2022-09-20 18:43:05 +01:00
Liav A 16428e4d4c Kernel: Convert NVMe code includes to absolute paths 2022-09-20 18:43:05 +01:00
Liav A 9252a892bb Kernel: Abstracts x86 reboot and shutdown specific methods
We move QEMU and VirtualBox shutdown sequences to a separate file, as
well as moving the i8042 reboot code sequence too to another file.

This allows us to abstract specific methods from the power state node
code of the SysFS filesystem, to allow other architectures to put their
methods there too in the future.
2022-09-20 18:43:05 +01:00
Liav A 0a220a413f Kernel/PCI: Don't use x86 initialization methods in non-x86 builds
Using the IO address space is only relevant for x86 machines, so let's
not compile instructions to access the PCI configuration space when we
don't target x86 platforms.
2022-09-20 18:43:05 +01:00
Liav A 4555cac639 Kernel: Move QEMU shutdown code to the x86 subdirectory
QEMU VM shutdown code is really x86 specific, so let's ensure we only
use it when compiling a Kernel for x86 machines.
2022-09-20 18:43:05 +01:00
Ben Wiederhake 55d78ca40d Kernel: Replace KString::must_create, fix init_args 2022-09-18 18:47:34 -07:00
Ben Wiederhake f11a69aafb Kernel: Fix misplaced #include in ATA/Definitions.h 2022-09-18 18:30:05 -07:00
Ben Wiederhake c214d31c5e Everywhere: Fix order of includes and #pragma once 2022-09-18 18:30:05 -07:00
Ben Wiederhake 87eac0e424 Kernel: Add missing include in API
This remained undetected for a long time as HeaderCheck is disabled by
default. This commit makes the following file compile again:

    // file: compile_me.cpp
    #include <Kernel/API/POSIX/ucontext.h>
    // That's it, this was enough to cause a compilation error.
2022-09-18 13:27:24 -04:00
b14ckcat 3452cbd1ed Kernel/USB: Hotplug multiple USB device crash hotfix 2022-09-17 17:11:13 +02:00
Liav A 0c675192c9 Kernel: Send SIGBUS to threads that use after valid Inode mmaped range
According to Dr. POSIX, we should allow to call mmap on inodes even on
ranges that currently don't map to any actual data. Trying to read or
write to those ranges should result in SIGBUS being sent to the thread
that did violating memory access.
2022-09-16 14:55:45 +03:00
Liav A 3ad0e1a1d5 Kernel: Handle mmap requests on zero-length data file inodes safely 2022-09-16 14:55:45 +03:00
Liav A c88cc8557f Kernel/FileSystem: Make Inode::{write,read}_bytes methods non-virtual
We make these methods non-virtual because we want to ensure we properly
enforce locking of the m_inode_lock mutex. Also, for write operations,
we want to call prepare_to_write_data before the actual write. The
previous design required us to ensure the callers do that at various
places which lead to hard-to-find bugs. By moving everything to a place
where we call prepare_to_write_data only once, we eliminate a possibilty
of forgeting to call it on some code path in the kernel.
2022-09-16 14:55:45 +03:00
Liav A 4f4717e351 Kernel/FileSystem: Mark ext2 inode block list non-const
The block list required a bit of work, and now the only method being
declared const to bypass its const-iness is the read_bytes method that
calls a new method called compute_block_list_with_exclusive_locking that
takes care of proper locking before trying to update the block list data
of the ext2 inode.
2022-09-16 14:55:45 +03:00
Liav A 843bd43c5b Kernel/FileSystem: Mark ext2 inode lookup cache non-const
For the lookup cache, no method being declared const tried to modify it,
so it was easy to drop the mutable declaration on the HashMap member.
2022-09-16 14:55:45 +03:00
Tim Schumacher 8763dbcccc Everywhere: Remove a bunch of dead write-only variables
LLVM 15 now warns (and thus errors) about this, and there is really no
point in keeping them.
2022-09-16 05:39:28 +00:00
Brian Gianforcaro d0a1775369 Everywhere: Fix a variety of typos
Spelling fixes found by `codespell`.
2022-09-14 04:46:49 +00:00
Andreas Kling 2cc947ede4 Kernel: Use correct timestamp in sys$utimens()
We were mixing up the nanosecond and second parts of the timestamps.

Regressed in 280694bb46.
2022-09-13 17:03:31 +02:00
Filiph Sandström 7e1e208d08 Kernel: Add basic aarch64 support to MemoryManager
FIXME: There's still a lot to do like for example, port `quickmap_page`.
This does however get us further into the boot process than before.
2022-09-12 00:56:44 +01:00
Filiph Sandström 14fe03569a Kernel: Add support for displaying critical output on aarch64 2022-09-12 00:56:44 +01:00
Filiph Sandström 3b331a83e2 Kernel: Include CommandLine as a part of aarch64 2022-09-12 00:56:44 +01:00
Filiph Sandström fcd1cf4e1b Kernel: Include DeviceManagement as a part of aarch64 2022-09-12 00:56:44 +01:00
demostanis c56cbf8027 CMake: Quote all CMAKE_COMMAND occurences
Building might fail if the cmake command path contains
whitespace. See https://stackoverflow.com/a/35853080.
2022-09-02 23:34:47 +01:00
Tim Schumacher 5e11a512d6 Kernel: Buffer an entire region when generating coredumps
This allows us to unlock the region tree lock early, to avoid keeping
the lock while we are doing IO.
2022-08-31 16:28:47 +02:00
Tim Schumacher 32a03cffeb Kernel: Work using copies of specific region data during a coredump
This limits our interaction with the "real" region tree (and therefore
its lock) to the time where we actually read from the user address
space.
2022-08-31 16:28:47 +02:00
Liav A 2c84466ad8 Kernel/Storage: Introduce new boot device addressing modes
Before of this patch, we supported two methods to address a boot device:
1. Specifying root=/dev/hdXY, where X is a-z letter which corresponds to
a boot device, and Y as number from 1 to 16, to indicate the partition
number, which can be omitted to instruct the kernel to use a raw device
rather than a partition on a raw device.
2. Specifying root=PARTUUID: with a GUID string of a GUID partition. In
case of existing storage device with GPT partitions, this is most likely
the safest option to ensure booting from persistent storage.

While option 2 is more advanced and reliable, the first option has 2
caveats:
1. The string prefix "/dev/hd" doesn't mean anything beside a convention
on Linux installations, that was taken into use in Serenity. In Serenity
we don't mount DevTmpFS before we mount the boot device on /, so the
kernel doesn't really access /dev anyway, so this convention is only a
big misleading relic that can easily make the user to assume we access
/dev early on boot.
2. This convention although resemble the simple linux convention, is
quite limited in specifying a correct boot device across hardware setup
changes, so option 2 was recommended to ensure the system is always
bootable.

With these caveats in mind, this commit tries to fix the problem with
adding more addressing options as well as to remove the first option
being mentioned above of addressing.
To sum it up, there are 4 addressing options:
1. Hardware relative address - Each instance of StorageController is
assigned with a index number relative to the type of hardware it handles
which makes it possible to address storage devices with a prefix of the
commandset ("ata" for ATA, "nvme" for NVMe, "ramdisk" for Plain memory),
and then the number for the parent controller relative hardware index,
another number LUN target_id, and a third number for LUN disk_id.
2. LUN address - Similar to the previous option, but instead we rely on
the parent controller absolute index for the first number.
3. Block device major and minor numbers - by specifying the major and
minor numbers, the kernel can simply try to get the corresponding block
device and use it as the boot device.
4. GUID string, in the same fashion like before, so the user use the
"PARTUUID:" string prefix and add the GUID of the GPT partition.

For the new address modes 1 and 2, the user can choose to also specify a
partition out of the selected boot device. To do that, the user needs to
append the semicolon character and then add the string "partX" where X
is to be changed for the partition number. We start counting from 0, and
therefore the first partition number is 0 and not 1 in the kernel boot
argument.
2022-08-30 00:50:15 +01:00
b14ckcat 550b3c7330 Kernel/USB: Rework UHCI interrupt transfer schedule
This reworks the way the UHCI schedule is set up to handle interrupt
transfers, creating 11 queue heads each assigned a different
period/latency, so that interrupt transfers can be linked into the
schedule with their specified period more easily.
2022-08-28 13:40:07 +02:00
b14ckcat 4a3a0ac19e Kernel/USB: Rework queued transfer schedule
Modifies the way the UHCI schedule is set up & modified to allow for
multiple transfers of the same type, from one or more devices, to be
queued up and handled simultaneously.
2022-08-28 13:40:07 +02:00
Idan Horowitz 12300b7d0b Kernel: Dump OOM debug info after releasing the MM global data lock
Otherwise we would be holding the MM global data lock and the Process
address space locks in reversed order to the rest of the system, which
can lead to deadlocks.
2022-08-27 21:54:13 +03:00
Idan Horowitz 4ce326205e Kernel: Stop verifying interrupts are disabled in Process::for_each
This is a left-over from back when we didn't have any locking on the
global Process list, nor did we have SMP support, so this acted as some
kind of locking mechanism. We now have proper locks around the Process
list, so this is no longer relevant.
2022-08-27 21:54:13 +03:00
Skye Sprung eca85f2050 Kernel: Changed serial debug functions and variables for readability
Change the name of set_serial_debug(bool on_or_off) to
set_serial_debug_enabled(bool desired_state). This is to make the names
more expressive and less unclear as to what the function does, as it
only sets the enabled state.
Likewise, change the name of get_serial_debug() to
is_serial_debug_enabled() in order to make clear from the name that
this is simply the state of s_serial_debug_enabled.
Change the name of serial_debug to s_serial_debug_enabled since this is
a static bool describing this state.
Finally, change the signature of set_serial_debug_enabled to return a
bool, as this is more logical and understandable.
2022-08-27 19:42:52 +01:00
Tim Schumacher 8ba6e96d05 Kernel: Reorganize and colorize the scheduler thread list dump 2022-08-26 13:07:07 +02:00
Tim Schumacher 2bf5052608 Kernel: Show more (b)locking info when dumping the process list 2022-08-26 13:07:07 +02:00
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 6432f3eee8 Kernel: Add enum InterruptsState and helper functions
This commit adds the concept of an InterruptsState to the kernel. This
will be used to make the Spinlock code architecture independent. A new
Processor.cpp file is added such that we don't have to duplicate the
code.
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
Andreas Kling a3b2b20782 Kernel: Remove global MM lock in favor of SpinlockProtected
Globally shared MemoryManager state is now kept in a GlobalData struct
and wrapped in SpinlockProtected.

A small set of members are left outside the GlobalData struct as they
are only set during boot initialization, and then remain constant.
This allows us to access those members without taking any locks.
2022-08-26 01:04:51 +02:00
Andreas Kling 2c72d495a3 Kernel: Use RefPtr instead of LockRefPtr for PhysicalPage
I believe this to be safe, as the main thing that LockRefPtr provides
over RefPtr is safe copying from a shared LockRefPtr instance. I've
inspected the uses of RefPtr<PhysicalPage> and it seems they're all
guarded by external locking. Some of it is less obvious, but this is
an area where we're making continuous headway.
2022-08-24 18:35:41 +02:00
Andreas Kling 5a804b9a1d Kernel: Make PhysicalPage::ref() use relaxed memory order
When incrementing a reference count, it should be sufficient to use
relaxed ordering. Note that unref() still uses acquire-release.
2022-08-24 18:35:41 +02:00
Andreas Kling 0dd88fd836 Kernel: Remove unnecessary forward declaration of s_mm_lock 2022-08-24 14:57:51 +02:00
Andreas Kling ac3ea277aa Kernel: Don't take MM lock in ~PageDirectory()
We don't need the MM lock to unregister a PageDirectory from the CR3
map. This is already protected by the CR3 map's own lock.
2022-08-24 14:57:51 +02:00
Andreas Kling 5beed613ca Kernel: Don't take MM lock in MemoryManager::dump_kernel_regions()
We have to hold the region tree lock while dumping its regions anyway,
and taking the MM lock here was unnecessary.
2022-08-24 14:57:51 +02:00
Andreas Kling 05156cac94 Kernel: Don't take MM lock in MemoryManager::enter_address_space()
We're not accessing any of the MM members here. Also remove some
redundant code to update CR3, since it calls activate_page_directory()
which does exactly the same thing.
2022-08-24 14:57:51 +02:00
Andreas Kling 2607a6a4bd Kernel: Update comment about what the MM lock protects 2022-08-24 14:57:51 +02:00
Andreas Kling da24a937f5 Kernel: Don't wrap AddressSpace's RegionTree in SpinlockProtected
Now that AddressSpace itself is always SpinlockProtected, we don't
need to also wrap the RegionTree. Whoever has the AddressSpace locked
is free to poke around its tree.
2022-08-24 14:57:51 +02:00
Andreas Kling d3e8eb5918 Kernel: Make file-backed memory regions remember description permissions
This allows sys$mprotect() to honor the original readable & writable
flags of the open file description as they were at the point we did the
original sys$mmap().

IIUC, this is what Dr. POSIX wants us to do:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/mprotect.html

Also, remove the bogus and racy "W^X" checking we did against mappings
based on their current inode metadata. If we want to do this, we can do
it properly. For now, it was not only racy, but also did blocking I/O
while holding a spinlock.
2022-08-24 14:57:51 +02:00
Andreas Kling 30861daa93 Kernel: Simplify the File memory-mapping API
Before this change, we had File::mmap() which did all the work of
setting up a VMObject, and then creating a Region in the current
process's address space.

This patch simplifies the interface by removing the region part.
Files now only have to return a suitable VMObject from
vmobject_for_mmap(), and then sys$mmap() itself will take care of
actually mapping it into the address space.

This fixes an issue where we'd try to block on I/O (for inode metadata
lookup) while holding the address space spinlock. It also reduces time
spent holding the address space lock.
2022-08-24 14:57:51 +02:00
Andreas Kling cf16b2c8e6 Kernel: Wrap process address spaces in SpinlockProtected
This forces anyone who wants to look into and/or manipulate an address
space to lock it. And this replaces the previous, more flimsy, manual
spinlock use.

Note that pointers *into* the address space are not safe to use after
you unlock the space. We've got many issues like this, and we'll have
to track those down as wlel.
2022-08-24 14:57:51 +02:00
Andreas Kling d6ef18f587 Kernel: Don't hog the MM lock while unmapping regions
We were holding the MM lock across all of the region unmapping code.
This was previously necessary since the quickmaps used during unmapping
required holding the MM lock.

Now that it's no longer necessary, we can leave the MM lock alone here.
2022-08-24 14:57:51 +02:00
Andreas Kling dc9d2c1b10 Kernel: Wrap RegionTree objects in SpinlockProtected
This makes locking them much more straightforward, and we can remove
a bunch of confusing use of AddressSpace::m_lock. That lock will also
be converted to use of SpinlockProtected in a subsequent patch.
2022-08-24 14:57:51 +02:00
James Bellamy 9c1ee8cbd1 Kernel: Remove big lock from sys$socket
With the implementation of the credentials object the socket syscall no
longer needs the big lock.
2022-08-23 20:29:50 +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
Samuel Bowman 91574ed677 Kernel: Fix boot profiling
Boot profiling was previously broken due to init_stage2() passing the
event mask to sys$profiling_enable() via kernel pointer, but a user
pointer is expected.

To fix this, I added Process::profiling_enable() as an alternative to
Process::sys$profiling_enable which takes a u64 rather than a
Userspace<u64 const*>. It's a bit of a hack, but it works.
2022-08-23 11:48:50 +02:00
Anthony Iacono ec3d8a7a18 Kernel: Remove unused Process::in_group() 2022-08-23 01:01:48 +02:00
Andreas Kling 434d77cd43 Kernel/ProcFS: Silently ignore attempts to update ProcFS timestamps
We have to override Inode::update_timestamps() for ProcFS inodes,
otherwise we'll get the default behavior of erroring with ENOTIMPL.
2022-08-23 01:00:40 +02:00
Andreas Kling 5307e1bf01 Kernel/SysFS: Silently ignore attempts to update SysFS timestamps
We have to override Inode::update_timestamps() for SysFS inodes,
otherwise we'll get the default behavior of erroring with ENOTIMPL.
2022-08-23 00:55:41 +02:00
Andreas Kling 4c081e0479 Kernel/x86: Protect the CR3->PD map with a spinlock
This can be accessed from multiple CPUs at the same time, so relying on
the interrupt flag is clearly insufficient.
2022-08-22 17:56:03 +02:00
Andreas Kling 6cd3695761 Kernel: Stop taking MM lock while using regular quickmaps
You're still required to disable interrupts though, as the mappings are
per-CPU. This exposed the fact that our CR3 lookup map is insufficiently
protected (but we'll address that in a separate commit.)
2022-08-22 17:56:03 +02:00
Andreas Kling c8375c51ff Kernel: Stop taking MM lock while using PD/PT quickmaps
This is no longer required as these quickmaps are now per-CPU. :^)
2022-08-22 17:56:03 +02:00
Andreas Kling a838fdfd88 Kernel: Make the page table quickmaps per-CPU
While the "regular" quickmap (used to temporarily map a physical page
at a known address for quick access) has been per-CPU for a while,
we also have the PD (page directory) and PT (page table) quickmaps
used by the memory management code to edit page tables. These have been
global, which meant that SMP systems had to keep fighting over them.

This patch makes *all* quickmaps per-CPU. We reserve virtual addresses
for up to 64 CPUs worth of quickmaps for now.

Note that all quickmaps are still protected by the MM lock, and we'll
have to fix that too, before seeing any real throughput improvements.
2022-08-22 17:56:03 +02:00
Andreas Kling 930dedfbd8 Kernel: Make sys$utime() and sys$utimensat() not take the big lock 2022-08-22 17:56:03 +02:00
Andreas Kling 280694bb46 Kernel: Update atime/ctime/mtime timestamps atomically
Instead of having three separate APIs (one for each timestamp),
there's now only Inode::update_timestamps() and it takes 3x optional
timestamps. The non-empty timestamps are updated while holding the inode
mutex, and the outside world no longer has to look at intermediate
timestamp states.
2022-08-22 17:56:03 +02:00
Andreas Kling 35b2e9c663 Kernel: Make sys$mknod() not take the big lock 2022-08-22 17:56:03 +02:00
Anthony Iacono f86b671de2 Kernel: Use Process::credentials() and remove user ID/group ID helpers
Move away from using the group ID/user ID helpers in the process to
allow for us to take advantage of the immutable credentials instead.
2022-08-22 12:46:32 +02:00
Andreas Kling 42435ce5e4 Kernel: Make sys$recvfrom() with MSG_DONTWAIT not so racy
Instead of temporary changing the open file description's "blocking"
flag while doing a non-waiting recvfrom, we instead plumb the currently
wanted blocking behavior all the way through to the underlying socket.
2022-08-21 16:45:42 +02:00
Andreas Kling 8997c6a4d1 Kernel: Make Socket::connect() take credentials as input 2022-08-21 16:35:03 +02:00
Andreas Kling 51318d51a4 Kernel: Make Socket::bind() take credentials as input 2022-08-21 16:33:09 +02:00
Andreas Kling 8d0bd3f225 Kernel: Make LocalSocket do chown/chmod through VFS
This ensures that all the permissions checks are made against the
provided credentials. Previously we were just calling through directly
to the inode setters, which did no security checks!
2022-08-21 16:22:34 +02:00
Andreas Kling dbe182f1c6 Kernel: Make Inode::resolve_as_link() take credentials as input 2022-08-21 16:17:13 +02:00