Commit graph

8638 commits

Author SHA1 Message Date
Sönke Holz b363abb082 Kernel/aarch64: Explicitly allow float instrs in {load,store}_fpu_state
LLVM 18 otherwise throws errors, as we use '-mgeneral-regs-only' in the
kernel.
The functions had to be moved into a .S, as there is no
'-mno-general-regs-only' and also no nice way to remove
'-mgeneral-regs-only' for a single .cpp file.
2024-04-30 06:32:58 -06:00
Idan Horowitz dfa2c98497 Kernel: Support the RISC-V PLIC
By supporting the RISC-V PLIC (Platform-Level Interrupt Controller)
we can now handle device (external) interrupts.
2024-04-30 06:01:26 -06:00
Idan Horowitz 0a2d520b15 Kernel: Handle CLINT interrupts separately from normal interrupts
Since CLINT interrupts are wired directly into the hart, instead of
going through an interrupt controller (the PLIC), trying to handle them
through the normal numbered-interrupt mechanism will just complicate it
for no reason.
Instead we now handle them directly in the trap handler.
2024-04-30 06:01:26 -06:00
Idan Horowitz 002bba4a97 Kernel: Configure PCI interrupt routing based on the FDT 2024-04-30 06:01:26 -06:00
Idan Horowitz 7102d90b2b Kernel: Verify we are running on hart 0
This is already an implicit assumption when we initialize our CPU id.
2024-04-30 06:01:26 -06:00
Idan Horowitz d3e285c253 Kernel: Deduplicate HardwareTimerBase::frequency()/ticks_per_second() 2024-04-30 06:01:26 -06:00
Liav A. b9df8deba2 Kernel/USB: Don't include UHCIController.h in USBPipe.h
The USB::Pipe is abstracted from the actual USB host controller
implementation, so don't include the UHCIController.h file.
Also, we missed an include to UserOrKernelBuffer.h, so this is added to
ensure the code can still compile.
2024-04-28 22:30:48 +02:00
Liav A. 2bba9411ca Kernel: Use the AK SetOnce container class in various cases
We have many places in the kernel code that we have boolean flags that
are only set once, and never reset again but are checked multiple times
before and after the time they're being set, which matches the purpose
of the SetOnce class.
2024-04-26 23:46:23 -06:00
Sönke Holz 01f1d2daaa Kernel/riscv64: Don't clobber the boot info argument in enable_paging
"register asm" variables don't preserve the register value, so the call
to calculate_physical_to_link_time_address_offset in the asm input
operands is allowed to clobber a0.
2024-04-26 15:01:31 -06:00
Timothy Flynn ab602cfc2c Kernel: Colorize log message for capabilities that have not been pledged
The log message can be hard to spot in a sea of debug messages. Colorize
it to make the message more immediately pop out.
2024-04-26 09:29:02 -04:00
Idan Horowitz 7339409575 Kernel: Properly initialize NVMe admin queue depth
We were reading the value instead of setting it (as required by the
specification). This worked only when we booted with a bootloader which
initialized NVMe before us.
2024-04-26 09:52:56 +02:00
Idan Horowitz a2b2209ea5 Kernel: Fix definition of CAP_TO_MASK
The default type for integer literals is signed int, so we were
accidentally smearing those bits to the upper 32 bit of the result.
This resulted in extremely unreasonable timeouts.
2024-04-26 09:52:56 +02:00
Idan Horowitz 543fc4d0fc Kernel: Support automatic configuration of PCI bridges based on the FDT
This let's us actually boot with RISC-V.
2024-04-26 09:52:56 +02:00
Idan Horowitz 08d4b231e1 Kernel: Take EnumerableDeviceIdentifier by const ref instead of by value
It's 48 bytes.
2024-04-26 09:52:56 +02:00
Idan Horowitz f6ae9f8a6d Kernel: Reset enumerated buses bitmap before enumerating PCI devices
This allows this method to be used more than once.
2024-04-26 09:52:56 +02:00
Idan Horowitz 95aff1cf13 Kernel: Remove unused IterationDecision in enumerate_attached_devices 2024-04-26 09:52:56 +02:00
Idan Horowitz e350d3b2c6 Kernel: Use PCI:Class:ID::Bridge instead of magic value 2024-04-26 09:52:56 +02:00
Idan Horowitz 519be6e626 Kernel: Use correctly-sized read when checking PCI host bridge function
We were accidentally doing a 16-bit read instead of an 8-bit read,
meaning we would also read the 'CACHE_LINE_SIZE' field immediately
following it, and never actually continue.
2024-04-26 09:52:56 +02:00
Timothy Flynn fecd08ce64 Everywhere: Remove 'clang-format off' comments that are no longer needed 2024-04-24 16:50:01 -04:00
Timothy Flynn ec492a1a08 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There are a couple of weird cases where clang-format now thinks that a
pointer access in an initializer list, e.g. `m_member(ptr->foo)`, is a
lambda return statement, and it puts spaces around the `->`.
2024-04-24 16:50:01 -04:00
Sönke Holz 511e411def Kernel/riscv64: Implement Processor::read_cpu_counter
This simply reads the current cycle count from the cycle CSR.
x86-64 uses the similar rdtsc instruction here, which also may or may
not tick at a constant rate.
2024-04-21 13:37:32 -06:00
Sönke Holz c57e39d52b Kernel/riscv64: Don't flush the entire TLB in Processor::flush_tlb_local 2024-04-21 13:37:06 -06:00
implicitfield c15b473c1a Kernel/FATFS: Only read the requested blocks in read_bytes_locked()
This dramatically improves performance when working with large files,
since we no longer re-read the entire file for each read.
2024-04-21 15:34:33 +02:00
implicitfield 5bc87ad1a5 Kernel/FATFS: Free an inode's clusters upon removal 2024-04-21 15:34:33 +02:00
implicitfield 32692f032c Kernel/FATFS: Keep the FSInfo sector's free cluster count in sync 2024-04-21 15:34:33 +02:00
implicitfield bd76dd2dc2 Kernel/FATFS: Initialize special directory entries 2024-04-21 15:34:33 +02:00
implicitfield 66e1f8812f Kernel/FATFS: Don't ignore special entries when traversing directories 2024-04-21 15:34:33 +02:00
Undefine 31174c43bf Kernel/FATFS: Implement a hacky replace_child
This is not a proper implementation, but it's good enough to get
the write support fully working.
2024-04-21 15:34:33 +02:00
Undefine 511b298a1d Kernel/FATFS: Implement remove_child 2024-04-21 15:34:33 +02:00
Undefine 3b39a2f71b Kernel/FATFS: Implement add_child 2024-04-21 15:34:33 +02:00
Undefine 2952401c58 Kernel/FATFS: Implement create_child
This is a large commit because it implements a lot of stuff to make
add_child simpler to get working. This allows us to create new files
on a FAT partition.
2024-04-21 15:34:33 +02:00
Undefine 098518cc57 Kernel/FATFS: Implement file modification
This is the first part of write support, it allows for full file
modification, but no creating or removing files yet.

Co-Authored-By: implicitfield <114500360+implicitfield@users.noreply.github.com>
2024-04-21 15:34:33 +02:00
Undefine fde7bd9190 Kernel/FATFS: Make the debug logs nicer
They now look the same way as the ones in Ext2FS inodes which are
quite nice for debugging.
2024-04-21 15:34:33 +02:00
Undefine 33f00a7efb Kernel/FATFS: Cache the cluster list and don't cache the InodeMetadata
Caching the cluster list allows us to fill the two fields in the
InodeMetadata. While at it, don't cache the metadata as when we
have write support having to keep both InodeMetadata and FATEntry
correct is going to get very annoying.
2024-04-21 15:34:33 +02:00
Undefine d4badfac72 Kernel/FATFS: Store cluster list instead of block list
Once we have write support, managing clusters is going to be
way easier than managing blocks.
2024-04-21 15:34:33 +02:00
Undefine 92d58a91a6 Kernel/FATFS: Read the FAT32 FSInfo structure
This structure contains information about free clusters which
is going to be useful when allocating clusters.
2024-04-21 15:34:33 +02:00
Undefine 7e251c3b4f Kernel/FATFS: Return ENOTSUP on chown and chmod 2024-04-21 15:34:33 +02:00
Undefine eb2721d650 Kernel/FATFS: Pass the FATEntry location to FATInode constructor
This is going to be necessary to flush the metadata later on.
2024-04-21 15:34:33 +02:00
Undefine de574b9ed9 Kernel/FATFS: Improve error propagation in FATInode 2024-04-21 15:34:33 +02:00
implicitfield 0f828768bb Kernel/FATFS: Implement fat_write 2024-04-21 15:34:33 +02:00
implicitfield a6a1508601 Kernel/FATFS: Fix reading from large 12-bit FATs
12-bit FATs aren't necessarily block-aligned, so in the worst case
we'll have to reach into the next block to perform the read properly.
2024-04-21 15:34:33 +02:00
Undefine 1350c555f6 Kernel/FATFS: Factor out the FAT reading to a function
Move the FAT reading code to a fat_read function in FATFS and move the
required functions to FATFS too.
2024-04-21 15:34:33 +02:00
implicitfield b9d7e2db93 Kernel/FATFS: Prefer read_block() over raw_read()
`raw_read()` has proven to be a source of subtle bugs that occur as a
result of the cache and disk contents being out of sync.
2024-04-21 15:34:33 +02:00
implicitfield b1af97810e Kernel/FATFS: Avoid creating reference bindings to packed struct members
dbgln() will always take its arguments by reference when possible, which
causes UB when dealing with packed structs. To avoid this, we now
explicitly copy all members whose alignment requirements aren't met.
2024-04-21 15:34:33 +02:00
Sönke Holz 243d7003a2 Kernel+LibC+LibELF: Move TLS handling to userspace
This removes the allocate_tls syscall and adds an archctl option to set
the fs_base for the current thread on x86-64, since you can't set that
register from userspace. enter_thread_context loads the fs_base for the
next thread on each context switch.
This also moves tpidr_el0 (the thread pointer register on AArch64) to
the register state, so it gets properly saved/restored on context
switches.

The userspace TLS allocation code is kept pretty similar to the original
kernel TLS code, aside from a couple of style changes.

We also have to add a new argument "tls_pointer" to
SC_create_thread_params, as we otherwise can't prevent race conditions
between setting the thread pointer register and signal handling code
that might be triggered before the thread pointer was set, which could
use TLS.
2024-04-19 16:46:47 -06:00
Sönke Holz 216089c7a1 Kernel: Add a Thread member for arch-specific data
This will be used to store the fs_base value on x86-64, which is needed
for thread-local storage.
2024-04-19 16:46:47 -06:00
Sönke Holz 57f4f8caf8 Kernel+LibC: Introduce new archctl syscall
This syscall will be used for architecture-specific operations.
2024-04-19 16:46:47 -06:00
Andrew Kaster a65c385057 Kernel: Don't try to copy empty Vector in sys$recvmsg
If there's no fds to copy in a message with proper space for an
SCM_RIGHTS set of cmsg headers, then don't try to copy them.

This avoids a Kernel panic when recvmsg-ing, as copy_to_user(p, 0, 0)
hits a VERIFY.
2024-04-19 16:38:55 -04:00
Dan Klishch 5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Sönke Holz bee7070da0 Kernel: Do not use -mcmodel=large for x86_64 kernel
Small position independent code model (which we end up using after this
change) is suitable for us since the kernel is not expected to grow more
than 2Gb in size. This might be a bit risky since this model is not
mentioned anywhere except for System V ABI document but experiments show
that the kernel compiled with this change works just fine.
2024-04-18 13:14:33 -06:00