Commit Graph

85 Commits

Author SHA1 Message Date
Tom
8c764319ad Kernel: Various APIC timer fixes 2020-10-26 08:57:25 +01:00
Tom
fe615e601a Kernel: Set up and calibrate APIC timer, and enable timer on all CPUs
This enables the APIC timer on all CPUs, which means Scheduler::timer_tick
is now called on all CPUs independently. We still don't do anything on
the APs as it instantly crashes due to a number of other problems.
2020-10-25 21:18:35 +01:00
Andreas Kling
af20b9424f Kernel: Unbreak /proc/interrupts when running with APIC
We can't assert here since these are exposed through /proc JSON.
2020-10-18 14:40:16 +02:00
Andreas Kling
c7a13b7a74 Kernel: Tweak strange PAGE_ROUND_UP(1) in APIC code 2020-10-18 14:18:38 +02:00
Ben Wiederhake
64cc3f51d0 Meta+Kernel: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Liav A
82b0171812 Kernel: Fix assertion statement in GenericInterruptHandler
We need to assert if interrupts are not disabled when changing the
interrupt number of an interrupt handler.
Before this fix, any change like this would lead to a crash,
because we are using InterruptDisabler in IRQHandler::change_irq_number.
2020-09-19 16:44:40 +02:00
Luke
68b361bd21 Kernel: Return ENOMEM in more places
There are plenty of places in the kernel that aren't
checking if they actually got their allocation.

This fixes some of them, but definitely not all.

Fixes #3390
Fixes #3391

Also, let's make find_one_free_page() return nullptr
if it doesn't get a free index. This stops the kernel
crashing when out of memory and allows memory purging
to take place again.

Fixes #3487
2020-09-16 20:38:19 +02:00
asynts
ec1080b18a Refactor: Replace usages of FixedArray with Vector. 2020-09-08 14:01:21 +02:00
asynts
9c83d6ff46 Refactor: Replace usages of FixedArray with Array. 2020-09-08 14:01:21 +02:00
Ben Wiederhake
eac3bbdcee Kernel: Unbreak building with extra debug macros, part 1 2020-08-30 09:43:49 +02:00
Liav A
ab87d42200 Kernel: Remove the enabled concept of IRQ handlers
An IRQ handler should always be ready to respond to any IRQ.
We must remember that hardware can generate IRQs without any interaction
from our code at all. Ignoring IRQs in such cases is obviously not the
right thing to do.
2020-08-28 09:16:18 +02:00
Liav A
a431108ab6 Kernel: Add and remove explicit keyword where needed 2020-08-28 09:16:18 +02:00
Tom
d89582880e Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because
MemoryManager::initialize is called before the global constructors
are run. That caused the Singleton to be re-initialized, causing
it to create another MemoryManager instance.

Fixes #3226
2020-08-25 09:48:48 +02:00
Andreas Kling
2fd9e72264 Revert "Kernel: Switch singletons to use new Singleton class"
This reverts commit f48feae0b2.
2020-08-22 18:01:59 +02:00
Andreas Kling
8925ad3fa0 Revert "Kernel: Move Singleton class to AK"
This reverts commit f0906250a1.
2020-08-22 16:34:49 +02:00
Andreas Kling
68580d5a8d Revert "AK: Get rid of make_singleton function"
This reverts commit 5a98e329d1.
2020-08-22 16:34:14 +02:00
Tom
5a98e329d1 AK: Get rid of make_singleton function
Just default the InitFunction template argument.
2020-08-22 10:46:24 +02:00
Tom
f0906250a1 Kernel: Move Singleton class to AK 2020-08-22 10:46:24 +02:00
Tom
f48feae0b2 Kernel: Switch singletons to use new Singleton class
Fixes #3226
2020-08-21 11:47:35 +02:00
Muhammad Zahalqa
8c7b5fb97b
Kernel: Remove unneeded header (#3196)
AK/HashTable.h is not needed from SpuriousInterruptHandler
2020-08-17 22:58:09 +02:00
Brian Gianforcaro
2eae70b097 Kernel: Mark MSIHandler as final 2020-08-10 09:57:50 +02:00
Tom
b02d33bd63 Kernel: Fix some flaws that caused crashes or hangs during boot
We need to halt the BSP briefly until all APs are ready for the
first context switch, but we can't hold the same spinlock by all
of them while doing so. So, while the APs are waiting on each other
they need to release the scheduler lock, and then once signaled
re-acquire it. Should solve some timing dependent hangs or crashes,
most easily observed using qemu with kvm disabled.
2020-07-09 23:24:55 +02:00
Tom
bc107d0b33 Kernel: Add SMP IPI support
We can now properly initialize all processors without
crashing by sending SMP IPI messages to synchronize memory
between processors.

We now initialize the APs once we have the scheduler running.
This is so that we can process IPI messages from the other
cores.

Also rework interrupt handling a bit so that it's more of a
1:1 mapping. We need to allocate non-sharable interrupts for
IPIs.

This also fixes the occasional hang/crash because all
CPUs now synchronize memory with each other.
2020-07-06 17:07:44 +02:00
Andreas Kling
11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
Tom
fb41d89384 Kernel: Implement software context switching and Processor structure
Moving certain globals into a new Processor structure for
each CPU allows us to eventually run an instance of the
scheduler on each CPU.
2020-07-01 12:07:01 +02:00
Tom
0bc92c259d Kernel: Detect APs and boot them into protected mode
This isn't fully working, the APs pretend like they're
fully initialized and are just halted permanently for now.
2020-06-04 18:15:23 +02:00
Andreas Kling
d83d46fd7a Kernel: Remove outdated FIXME in InterruptManagement::locate_apic_data 2020-05-28 10:55:51 +02:00
Andreas Kling
a75c290e51 Kernel: Use TypedMapping for accessing IOAPIC registers 2020-05-23 15:57:48 +02:00
Andreas Kling
59a56a78c0 Kernel: Oops, we need to use map_typed_writable() for write access :^) 2020-05-23 15:50:50 +02:00
Andreas Kling
a04c8d7101 Kernel: Use TypedMappings when looking for APIC information 2020-05-23 15:46:56 +02:00
Andreas Kling
2fe6b3725a Kernel: Use TypedMappings in the very unfinished APIC code 2020-05-23 15:25:43 +02:00
Andreas Kling
8ec8304d74 Kernel: Tweak some suspicious casts in InterruptManagement
This code needs a closer looking-into at some point. It doesn't seem
entirely safe to be casting u32's to pointers like it does.
2020-05-23 15:25:43 +02:00
Andreas Kling
4b847810bf Kernel: Simplify scanning BIOS/EBDA and MP parser initialization
Add a MappedROM::find_chunk_starting_with() helper since that's a very
common usage pattern in clients of this code.

Also convert MultiProcessorParser from a persistent singleton object
to a temporary object constructed via a failable factory function.
2020-05-22 13:36:57 +02:00
Andreas Kling
21d5f4ada1 Kernel: Absorb LibBareMetal back into the kernel
This was supposed to be the foundation for some kind of pre-kernel
environment, but nobody is working on it right now, so let's move
everything back into the kernel and remove all the confusion.
2020-05-16 12:00:04 +02:00
Andreas Kling
03eb0e5638 Kernel: Let's say that IO::delay(N) delays for N microseconds
Supposedly that's how much delay you get when doing I/O on port 0x80.
2020-05-16 10:55:54 +02:00
Shannon Booth
113a95e9e1 Kernel: Annotate UnhandledInterruptHandler::eoi with [[noreturn]] 2020-05-16 09:51:31 +02:00
Andreas Kling
d92f62db43 Kernel: Remove ref-counting from interrupt override metadata
I don't see a reason for these to be reference-counted, and removing it
simplifies a bunch of surrounding data structures.
2020-05-08 21:12:16 +02:00
Liav A
0fa50b6405 Interrupts: Simplify initialization a bit more 2020-04-09 20:45:44 +02:00
Liav A
6b38befd91 Interrupts: Remove irrelevant FIXME comment 2020-04-09 20:45:44 +02:00
Liav A
fec8763c21 Interrupts: Make the MultiProcessorParser functional again 2020-04-09 19:59:53 +02:00
Liav A
8139688ef1 Kernel: Simplify the Interrupt management initialization 2020-04-09 19:59:53 +02:00
Andreas Kling
a3ca745b5a Kernel: Use StringView for ACPI table signatures 2020-04-09 18:03:57 +02:00
Andreas Kling
f614f0e2cb Kernel: Add typed_map<T>(PhysicalAddress) and use it in ACPI parsing
There was a frequently occurring pattern of "map this physical address
into kernel VM, then read from it, then unmap it again".

This new typed_map() encapsulates that logic by giving you back a
typed pointer to the kind of structure you're interested in accessing.

It returns a TypedMapping<T> that can be used mostly like a pointer.
When destroyed, the TypedMapping object will unmap the memory. :^)
2020-04-09 17:19:11 +02:00
Liav A
5f579904c1 Interrupts: Handle spurious IRQs from eoi() method 2020-03-24 16:15:33 +01:00
Liav A
8d9b6c57b5 Interrupts: Use Optional container in IOAPIC
We return the Optional container in find_redirection_entry_by_vector()
method instead of a raw integer. This makes the code more readable and
correct.
2020-03-24 16:15:33 +01:00
Liav A
0b7fc525e1 Interrupts: Simplify IRQ disabling & enabling in IRQController(s)
Instead of blindly setting masks, if we want to disable an IRQ and it's
already masked, we just return. The same happens if we want to enable an
IRQ and it's unmasked.
2020-03-24 16:15:33 +01:00
Liav A
3f98a67d75 Interrupts: Remove unused methods 2020-03-24 16:15:33 +01:00
Liav A
8b38be3072 Kernel: Simplify disable_irq() and enable_irq() methods in IRQHandler
Setting the m_enabled variable to true or false can help
with monitoring the IRQHandler object(s) later, and there's no good
reason to have an if-else statement in those methods anyway.
2020-03-24 16:15:33 +01:00
Liav A
cb676f1211 Interrupts: Do a specific EOI when using the PIC
Before this change, we did a non-specific EOI, which could lead to
problems with other IRQs that are handled in the PIC. Since the original
8259A datasheet permits such functionality and we are not losing any
functionality, this change is acceptable even though we don't experience
problems with the EOI currently.
2020-03-24 16:15:33 +01:00
Liav A
dbc536e917 Interrupts: Assert if trying to install an handler on syscall vector
Installing an interrupt handler on the syscall IDT vector can lead to
fatal results, so we must assert if that happens.
2020-03-24 16:15:33 +01:00