Commit graph

7480 commits

Author SHA1 Message Date
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