-
Notifications
You must be signed in to change notification settings - Fork 1
Development #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Development #71
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#include "Pic.h" | ||
|
||
#include "Console.h" | ||
#include "Io.h" | ||
|
||
#define PIC1_COMMAND 0x20 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#ifndef PIC_H | ||
#define PIC_H | ||
#include "stdint.h" | ||
|
||
void PicInstall(); | ||
void PitInstall(); | ||
void PitSetFrequency(uint16_t hz); | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix parsing bugs and free allocated arg to avoid leaks
Optionally print the effective frequency if the driver clamps to achievable values.
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok ok that works, now, the final boss, APIC, ACPI, can you suggest me a way and a patch so we dont blow everything up, yeah it was hard but i think we can solve it1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
@assembler-0, Great question! APIC and ACPI are indeed the "final bosses" of x86 OS development. Based on my analysis of your codebase, you're currently using the legacy 8259 PIC. Here's a strategic approach to implement APIC/ACPI without breaking everything:
Phase 1: ACPI Tables Detection (Safe Foundation)
First, let's add ACPI table detection without touching interrupts:
Phase 2: APIC Implementation with PIC Fallback
Phase 3: Safe Integration Strategy
Safety Measures
-machine q35
for modern APICTesting Commands
This approach ensures you won't "blow everything up" - the system will gracefully fall back to PIC if APIC fails at any point. Start with Phase 1 (just detection), verify it works, then gradually add more functionality.
🏁 Script executed:
Length of output: 2214
🏁 Script executed:
Length of output: 3885
🏁 Script executed:
Length of output: 2392
🏁 Script executed:
Length of output: 323
🏁 Script executed:
Length of output: 2752
🏁 Script executed:
Length of output: 934
🏁 Script executed:
Length of output: 3684
🏁 Script executed:
Length of output: 331
@assembler-0, based on my thorough analysis of your VoidFrame kernel, here's a comprehensive and safe implementation strategy for APIC/ACPI. I've designed this to be gradual and non-destructive:
Complete Implementation Package
Step 1: Add MMIO Mapping to VMem (Required First)
Step 2: ACPI Implementation (Safe Read-Only)
Create
drivers/Acpi.h
:Create
drivers/Acpi.c
:Step 3: APIC with Safe Fallback
Create
drivers/Apic.h
:Create
drivers/Apic.c
:Step 4: Integration into Kernel
Update
kernel/core/Kernel.c
inKernelMainHigherHalf()
:Step 5: Add Shell Commands for Testing
In
kernel/etc/Shell.c
, add:Step 6: Update IDT Handler
In your interrupt handler (arch/x86_64/idt/Idt.c or similar):
Safe Testing Strategy
Phase 1: Compile with just ACPI detection
apic status
Phase 2: Test APIC initialization
Phase 3: Manual enable
apic enable
commandPhase 4: Stress test
This implementation ensures you never "blow everything up" - worst case, you stay on PIC!
🏁 Script executed:
Length of output: 11721
🏁 Script executed:
Length of output: 3402
🏁 Script executed:
Length of output: 5335
🏁 Script executed:
Length of output: 5211
@assembler-0, I've analyzed your codebase thoroughly. Here's the complete implementation package with all the necessary components for APIC/ACPI support:
Complete APIC/ACPI Implementation Patch
1. Add MMIO Mapping to VMem
File: kernel/memory/VMem.c - Add these functions:
File: kernel/memory/VMem.h - Add declarations:
2. Create ACPI Support
File: drivers/Acpi.h (new file):
File: drivers/Acpi.c (new file):
3. Create APIC Support
File: drivers/Apic.h (new file):
File: drivers/Apic.c (new file):
4. Update PIC Driver
File: drivers/Pic.h - Add:
File: drivers/Pic.c - Add:
5. Update Kernel Initialization
File: kernel/core/Kernel.c - Add includes and update
KernelMainHigherHalf
:6. Update Interrupt Handler
File: arch/x86_64/idt/Idt.c - Find
InterruptHandler
and update EOI sending:7. Add Shell Commands
File: kernel/etc/Shell.c - Add to
show_help()
:Add to
ExecuteCommand()
:8. Update Makefile
Add the new source files to your build system:
Testing Strategy
Phase 1 - Detection Only:
Should show if APIC is detected without enabling it.
Phase 2 - Safe Enable:
Test basic functionality after enabling.
Phase 3 - Stress Test:
Phase 4 - Fallback:
Should revert to PIC safely.
Safety Features
apic enable
This implementation ensures maximum safety while giving you full APIC/ACPI support. Start with just detection, then gradually test the enable/disable functionality!
🧬 Code Graph Analysis Results
File: drivers/Pic.c, Lines 25-41
File: kernel/process/Process.c, Lines 905-918
File: kernel/memory/VMem.c, Lines 525-539
File: kernel/memory/Memory.c, Lines 319-369
Summary: GetDetailedMemoryStats(MemoryStats* stats)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, excelent job and about step 6 (i think you meant Interrupts.c) heres the patch, is it correct
switch (regs->interrupt_number) {
case 32: // Timer interrupt
FastSchedule(regs);
if (regs->interrupt_number >= 0x20 && regs->interrupt_number < 0x30) {
ApicSendEoi(regs->interrupt_number - 0x20);
}
return;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@assembler-0 Good catch on the file name! Your patch is on the right track, but there are a few issues to fix:
Issues with the Current Patch
Redundant condition checks: In cases 32 and 33, you're checking if
interrupt_number >= 0x20
, but 32 IS 0x20, so this check will always be true and is redundant.Inconsistent EOI handling: You're using
ApicSendEoi
for timer/keyboard but direct PIC commands for IDE interrupts. The whole point ofApicSendEoi
is to abstract this - it handles both APIC and PIC internally.Incorrect IRQ calculation: When calling
ApicSendEoi
, you should pass the IRQ number (0-15), not the remapped interrupt number.Corrected Patch
Here's the fixed version:
Why This Works Better
ApicSendEoi
handles the logic of whether to send to APIC or PIC internallyApicSendEoi
, not the remapped vectorRemember,
ApicSendEoi
in Apic.c already does this:This way, your interrupt handler doesn't need to know whether APIC or PIC is active - it just works!
🧠 Learnings used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice nice also wait, i think this uint64_t* VMemGetPageTable(uint64_t* pml4, uint64_t vaddr, int level, int create); isnt implemented, can you help me we this, so we can get this all finished!, im hyped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 7170
🏁 Script executed:
Length of output: 6394
@assembler-0 Great catch! I can see
VMemGetPageTable
is declared but not implemented. Here's the missing implementation along with the required defines:Add Missing Definitions to VMem.h
First, add these missing defines to
kernel/memory/VMem.h
:Implement VMemGetPageTable in VMem.c
Add this implementation to
kernel/memory/VMem.c
:Update VMemMapMmio to Use the Simpler Approach
Now that we have
VMemGetPageTable
, here's a cleanerVMemMapMmio
implementation:Alternative: Simpler VMemGetPageTable
If you prefer a more straightforward implementation that directly uses the existing
VMemGetPageTablePhys
:With this implementation, you now have everything needed for the APIC/ACPI support! The MMIO mapping will work correctly, and you can map the LAPIC and IOAPIC registers. Let's get this final boss defeated! 🚀
🧬 Code Graph Analysis Results
File: kernel/memory/VMem.c
Line range: 525-539
Code snippet:
File: kernel/memory/VMem.c
Summary (docstring-style): VMemGetPageTable(uint64_t* pml4, uint64_t vaddr, int level, int create)
🧠 Learnings used