-
Notifications
You must be signed in to change notification settings - Fork 1
patches #95
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
patches #95
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,11 @@ | ||||||||||||||||||||||||||||||||||||
| #include "Interrupts.h" | ||||||||||||||||||||||||||||||||||||
| #include "Console.h" | ||||||||||||||||||||||||||||||||||||
| #include "Ide.h" | ||||||||||||||||||||||||||||||||||||
| #include "Io.h" | ||||||||||||||||||||||||||||||||||||
| #include "MemOps.h" | ||||||||||||||||||||||||||||||||||||
| #include "PS2.h" | ||||||||||||||||||||||||||||||||||||
| #include "Panic.h" | ||||||||||||||||||||||||||||||||||||
| #include "Pic.h" | ||||||||||||||||||||||||||||||||||||
| #include "Process.h" | ||||||||||||||||||||||||||||||||||||
| #include "MemOps.h" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // The C-level interrupt handler, called from the assembly stub | ||||||||||||||||||||||||||||||||||||
| void InterruptHandler(Registers* regs) { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -15,50 +15,43 @@ void InterruptHandler(Registers* regs) { | |||||||||||||||||||||||||||||||||||
| switch (regs->interrupt_number) { | ||||||||||||||||||||||||||||||||||||
| case 32: // Timer interrupt (IRQ 0) | ||||||||||||||||||||||||||||||||||||
| FastSchedule(regs); | ||||||||||||||||||||||||||||||||||||
| outb(0x20, 0x20); // EOI to master PIC | ||||||||||||||||||||||||||||||||||||
| PICSendEOI(regs->interrupt_number); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case 33: // Keyboard interrupt (IRQ 1) | ||||||||||||||||||||||||||||||||||||
| KeyboardHandler(); | ||||||||||||||||||||||||||||||||||||
| outb(0x20, 0x20); // EOI to master PIC | ||||||||||||||||||||||||||||||||||||
| PICSendEOI(regs->interrupt_number); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case 34: | ||||||||||||||||||||||||||||||||||||
| PICSendEOI(regs->interrupt_number); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case 44: // mouse (IRQ 12) | ||||||||||||||||||||||||||||||||||||
| MouseHandler(); | ||||||||||||||||||||||||||||||||||||
| outb(0xA0, 0x20); // EOI to slave PIC | ||||||||||||||||||||||||||||||||||||
| outb(0x20, 0x20); // EOI to master PIC | ||||||||||||||||||||||||||||||||||||
| PICSendEOI(regs->interrupt_number); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case 46: // IDE Primary (IRQ 14) | ||||||||||||||||||||||||||||||||||||
| IDEPrimaryIRQH(); | ||||||||||||||||||||||||||||||||||||
| outb(0xA0, 0x20); // EOI to slave PIC | ||||||||||||||||||||||||||||||||||||
| outb(0x20, 0x20); // EOI to master PIC | ||||||||||||||||||||||||||||||||||||
| PICSendEOI(regs->interrupt_number); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case 47: // IDE Secondary (IRQ 15) | ||||||||||||||||||||||||||||||||||||
| IDESecondaryIRQH(); | ||||||||||||||||||||||||||||||||||||
| outb(0xA0, 0x20); // EOI to slave PIC | ||||||||||||||||||||||||||||||||||||
| outb(0x20, 0x20); // EOI to master PIC | ||||||||||||||||||||||||||||||||||||
| PICSendEOI(regs->interrupt_number); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Handle other hardware interrupts (34-45) | ||||||||||||||||||||||||||||||||||||
| case 34 ... 43: case 45: // passthrough | ||||||||||||||||||||||||||||||||||||
| case 35 ... 43: case 45: // passthrough | ||||||||||||||||||||||||||||||||||||
| PrintKernelWarning("[IRQ] Unhandled hardware interrupt: "); | ||||||||||||||||||||||||||||||||||||
| PrintKernelInt(regs->interrupt_number - 32); | ||||||||||||||||||||||||||||||||||||
| PrintKernelWarning("\n"); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Send EOI to the appropriate PIC | ||||||||||||||||||||||||||||||||||||
| if (regs->interrupt_number >= 40) { | ||||||||||||||||||||||||||||||||||||
| outb(0xA0, 0x20); // EOI to slave PIC | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| outb(0x20, 0x20); // EOI to master PIC | ||||||||||||||||||||||||||||||||||||
| PICSendEOI(regs->interrupt_number); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Handle CPU exceptions (0-31) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Buffer for creating descriptive panic messages. | ||||||||||||||||||||||||||||||||||||
| // Made static to reside in .bss rather than on a potentially corrupt stack. | ||||||||||||||||||||||||||||||||||||
| static char panic_message[256]; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| switch (regs->interrupt_number) { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -72,6 +65,15 @@ void InterruptHandler(Registers* regs) { | |||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case 8: | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| char rip_str[20]; | ||||||||||||||||||||||||||||||||||||
| htoa(regs->rip, rip_str); | ||||||||||||||||||||||||||||||||||||
| strcpy(panic_message, "Double Fault at "); | ||||||||||||||||||||||||||||||||||||
| strcat(panic_message, rip_str); | ||||||||||||||||||||||||||||||||||||
| PanicFromInterrupt(panic_message, regs); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing break after Double Fault handler; avoid accidental fall-through If PanicFromInterrupt ever returns (e.g., in debug builds), execution will fall through to case 13. Add a break for consistency with other cases (6, 13, 14, default). case 8:
{
char rip_str[20];
htoa(regs->rip, rip_str);
strcpy(panic_message, "Double Fault at ");
strcat(panic_message, rip_str);
PanicFromInterrupt(panic_message, regs);
+ break;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| case 13: // General Protection Fault | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| char ec_str[20]; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ void InterruptControllerEnable(void); | |
| void InterruptControllerDisable(void); | ||
| void IC_enable_irq(uint8_t irq_line); | ||
| void IC_disable_irq(uint8_t irq_line); | ||
| void InterruptControllerSendEOI(void); | ||
| void InterruptControllerSendEOI(uint64_t interrupt_number); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAPI change to InterruptControllerSendEOI(vec) is fine; ensure callsites updated and centralize PIC EOI.
Run: 🏁 Script executed: #!/bin/bash
# 1) Ensure all callsites provide an argument now
rg -nP --type=c -C1 '\bInterruptControllerSendEOI\s*\('
# 2) Find lingering direct PIC EOI writes (should be replaced with PICSendEOI)
rg -nP --type=c -C2 'outb\s*\(\s*(0x20|0xA0)\s*,\s*0x20\s*\)'
# 3) Prefer using PICSendEOI in PIC path
rg -nP --type=c 'PICSendEOI\s*\('Length of output: 1782 Centralize EOI logic through the To fully leverage the new • In drivers/InterruptController.c • In arch/x86_64/interrupts/Interrupts.c (and any other arch-specific handlers) • Verify that there are no remaining callsites of Suggested diffs: --- drivers/InterruptController.c
+++ drivers/InterruptController.c
@@ -57,8 +57,7 @@ void InterruptControllerSendEOI(uint64_t interrupt_number) {
case INTC_PIC:
- if (interrupt_number >= 40) {
- outb(0xA0, 0x20); // EOI to slave PIC
- }
- outb(0x20, 0x20); // EOI to master PIC
+ PICSendEOI(interrupt_number);
break;--- arch/x86_64/interrupts/Interrupts.c
+++ arch/x86_64/interrupts/Interrupts.c
@@ -18,7 +18,7 @@ void handle_interrupt(struct regs *regs) {
- PICSendEOI(regs->interrupt_number);
+ InterruptControllerSendEOI(regs->interrupt_number);🤖 Prompt for AI Agents |
||
| void InterruptControllerSetTimer(uint32_t frequency_hz); | ||
|
|
||
| // Query functions | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| #include "Panic.h" | ||
|
|
||
| #include "Io.h" | ||
| // The ONLY necessary includes for display are now Console and Serial | ||
| #include "Console.h" | ||
| #include "KernelHeap.h" | ||
|
|
@@ -61,7 +61,7 @@ static void U32ToDecStr(uint32_t value, char* buffer) { | |
| // --- High-Level Panic Screen Composition --- | ||
|
|
||
| void __attribute__((noreturn)) KernelPanicHandler(const char* message, uint64_t error_code, PanicContext* ctx) { | ||
| asm volatile("cli"); | ||
| cli(); | ||
| ClearScreen(); | ||
| ConsoleSetColor(VGA_COLOR_WHITE); | ||
|
|
||
|
Comment on lines
65
to
67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: mixing VBE graphics path with Console text output causes framebuffer corruption during panic. In the VBE branch, after VBEShowPanic(), the code continues to use PrintKernel/PrintKernelAt and other console-based dumps. Per prior guidance in this codebase, the panic path must choose either pure VBE graphics or pure text console, not both. Apply this minimal, safe diff to avoid mixing:
@@
- cli();
- ClearScreen();
- ConsoleSetColor(VGA_COLOR_WHITE);
+ cli();
@@
- if (use_vbe_graphics) {
- // Pure VBE graphics path - show panic image ONLY
- VBEShowPanic();
-
- delay(600000000); // to give "real" look
- PrintKernel("[FATAL] - [KERNEL PANIC] - ");
- if (message) PrintKernel(message);
- else PrintKernel("No message provided.");
- PrintKernel("\n");
- if (ctx) {
- char hex[20];
- char dec_buffer[12];
- char temp_buffer[128];
- temp_buffer[0] = '\0';
- PrintKernel("[CPU CONTEXT]\n");
- PrintKernel("----------------------\n");
- U64ToHexStr(ctx->rip, hex);
- temp_buffer[0] = '\0'; strcat(temp_buffer, "RIP: "); strcat(temp_buffer, hex);
- PrintKernel(temp_buffer);
- PrintKernel("\n");
- U64ToHexStr(ctx->rsp, hex);
- temp_buffer[0] = '\0'; strcat(temp_buffer, "RSP: "); strcat(temp_buffer, hex);
- PrintKernel(temp_buffer);
- PrintKernel("\n");
- U64ToHexStr(ctx->rbp, hex);
- temp_buffer[0] = '\0'; strcat(temp_buffer, "RBP: "); strcat(temp_buffer, hex);
- PrintKernel(temp_buffer);
- PrintKernel("\n");
- U64ToHexStr(error_code, hex);
- temp_buffer[0] = '\0'; strcat(temp_buffer, "CODE: "); strcat(temp_buffer, hex);
- PrintKernel(temp_buffer);
- PrintKernel("\n");
- // --- Source Location ---
- PrintKernel("[SOURCE LOCATION]\n");
- PrintKernel("----------------------\n");
- if (ctx->file && ctx->file[0] != '\0') {
- temp_buffer[0] = '\0'; strcat(temp_buffer, "File: "); strcat(temp_buffer, ctx->file);
- PrintKernel(temp_buffer);
- PrintKernel("\n");
- temp_buffer[0] = '\0'; strcat(temp_buffer, "Func: "); strcat(temp_buffer, ctx->function);
- PrintKernel(temp_buffer);
- PrintKernel("\n");
- U32ToDecStr(ctx->line, dec_buffer);
- temp_buffer[0] = '\0'; strcat(temp_buffer, "Line: "); strcat(temp_buffer, dec_buffer);
- PrintKernel(temp_buffer);
- PrintKernel("\n");
- } else {
- PrintKernel("Unavailable\n");
- }
- PrintKernel("[SYSTEM INFORMATION]\n");
- PrintKernel("----------------------\n");
- DumpSchedulerState();
- DumpPerformanceStats();
- MemoryStats stats;
- GetDetailedMemoryStats(&stats);
- PrintKernel(" Physical: ");
- PrintKernelInt(stats.free_physical_bytes / (1024*1024));
- PrintKernel("MB free, ");
- PrintKernelInt(stats.fragmentation_score);
- PrintKernel("% fragmented\n");
- PrintVMemStats();
- PrintHeapStats();
- PrintKernelAt("SYSTEM HALTED.", 50, 45);
- ConsoleSetColor(VGA_COLOR_DEFAULT);
- }
- } else {
+ if (use_vbe_graphics) {
+ // Pure VBE graphics path - image only, no console text
+ VBEShowPanic();
+ // Log to serial so the info is still captured
+ SerialWrite("[FATAL] - [KERNEL PANIC] -- ");
+ if (message) SerialWrite(message);
+ SerialWrite("\n");
+ goto hang;
+ } else {
+ ClearScreen();
+ ConsoleSetColor(VGA_COLOR_WHITE);If you prefer, we can also strip the now-unreachable text block instead of relying on goto. Do you want me to follow up with a cleanup patch that removes the now-dead code in the VBE branch? Also applies to: 77-151 🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well theres a reason for that, i want it to overlap, so the stack trace can be viewed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @assembler-0, I understand now - you intentionally want the stack trace and debugging information to be displayed over the VBE panic image so that critical diagnostic information remains visible even in graphics mode. This is a reasonable design choice for a panic handler where debugging information takes priority over visual presentation. I'll note this for future reference so I don't flag this pattern again in your panic handling code. ✏️ Learnings added
🧠 Learnings used |
||
|
|
@@ -253,7 +253,7 @@ static inline uint64_t __get_rip(void) { | |
| } | ||
|
|
||
| void __attribute__((noreturn)) PanicFromInterrupt(const char* message, Registers* regs) { | ||
| asm volatile("cli"); | ||
| cli(); | ||
| PanicContext ctx = {0}; | ||
| ctx.rip = regs->rip; | ||
| ctx.rsp = regs->rsp; | ||
|
|
@@ -266,7 +266,7 @@ void __attribute__((noreturn)) PanicFromInterrupt(const char* message, Registers | |
| } | ||
|
|
||
| void __attribute__((noreturn)) Panic(const char* message) { | ||
| asm volatile("cli"); | ||
| cli(); | ||
| PanicContext ctx = {0}; | ||
| ctx.rip = __get_rip(); | ||
| asm volatile("movq %%rsp, %0" : "=r"(ctx.rsp)); | ||
|
|
@@ -275,7 +275,7 @@ void __attribute__((noreturn)) Panic(const char* message) { | |
| } | ||
|
|
||
| void __attribute__((noreturn)) PanicWithCode(const char* message, uint64_t error_code) { | ||
| asm volatile("cli"); | ||
| cli(); | ||
| PanicContext ctx = {0}; | ||
| ctx.rip = __get_rip(); | ||
| asm volatile("movq %%rsp, %0" : "=r"(ctx.rsp)); | ||
|
|
@@ -284,7 +284,7 @@ void __attribute__((noreturn)) PanicWithCode(const char* message, uint64_t error | |
| } | ||
|
|
||
| void __attribute__((noreturn)) PanicWithContext(const char* message, uint64_t error_code, const char* function, const char* file, int line) { | ||
| asm volatile("cli"); | ||
| cli(); | ||
| PanicContext ctx = {0}; | ||
| ctx.rip = __get_rip(); | ||
| asm volatile("movq %%rsp, %0" : "=r"(ctx.rsp)); | ||
|
|
||
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.
Critical: EOI path is hardwired to PIC; breaks APIC mode
All EOI calls here go to PICSendEOI(), bypassing the controller abstraction. In APIC mode, failing to write LAPIC EOI will wedge further interrupts. Route through InterruptControllerSendEOI(regs->interrupt_number) instead, and include InterruptController.h.
Apply this diff:
Optional: If you want to keep direct PIC usage for PIC-only builds, add a fast path chosen at compile- or run-time, but keep one public API for EOIs.
Also applies to: 18-18, 23-25, 26-28, 32-33, 37-38, 42-43, 46-47, 50-51
🤖 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.
well i acknowledge that but the thing is, the APIC, does NOT work, when STI, it just dies, no kernel panic, no crashing, no continue and just stops (not crashed btw, if it were to crash, qemu would said that its paused)
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, I understand the APIC hang issue - that's a classic symptom of APIC initialization problems. The "dies on STI" behavior typically indicates interrupt routing or LAPIC configuration issues.
However, we can solve both problems properly:
For the architecture issue: Instead of hardcoding PIC calls, let's use conditional compilation or runtime detection:
The
InterruptController.calready handles the APIC/PIC selection, so this maintains the abstraction while letting you force PIC mode through the interrupt controller's logic.For debugging the APIC hang: The STI hang suggests:
Want me to help investigate the specific APIC hang issue? The proper fix is getting APIC working, not bypassing the abstraction layer.
🏁 Script executed:
Length of output: 12325
I found the issue! The APIC initialization is setting all interrupt entries as MASKED initially, but then never enables/unmasks them when setting up the interrupts.
Looking at the code:
IoApicWrite(IOAPIC_REG_REDTBL_BASE + 0*2, 32 | APIC_DELMODE_FIXED | **APIC_INT_MASKED**);APIC_INT_MASKEDBut when you call
APIC_enable_irq(), it only unmasks if the IRQ is <ioapic_max_redirections, andioapic_max_redirectionsis never initialized!The fix is simple: Initialize
ioapic_max_redirectionsand actually unmask the interrupts during APIC setup.In your APIC installation, you need to:
This explains the STI hang - interrupts are routed to APIC but all masked, so no interrupts fire and the system appears hung.
Want me to show the specific fixes needed in the APIC code?
🏁 Script executed:
Length of output: 8212
Perfect! I found the exact issue. The APIC setup is almost correct, but there's a critical missing piece:
The kernel calls
PIC_enable_irq()directly instead of using the abstraction layer!Look at
kernel/core/Kernel.clines 505-510:When APIC is active, these
PIC_enable_irq()calls do nothing to the APIC - they only modify the PIC mask state, but the APIC interrupts remain masked!The Fix
Replace the direct PIC calls with the abstraction layer:
And fix the interrupt handler to use the abstraction:
This explains the STI hang perfectly:
PIC_enable_irq()The
ioapic_max_redirectionsis being initialized correctly (line 61), so the APIC code itself is fine - it's just never being called!Want me to create the full fix patch?
🧬 Code Graph Analysis Results
Summary (docstring-style):
🧠 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.
bruh just skip it, do i look like i forgot to change the IRQ handler?, anyways, room for improvements for the MLFQ sched and security features, since this is a syscall less kernel, and this uint32_t new_priority = 0;, if its not 0, it would just blew up, hmm no user process will be scheduled
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, got it - skipping the interrupt controller abstraction for now. Let me investigate that MLFQ priority issue you mentioned.
🏁 Script executed:
Length of output: 18711
I found the exact issue you're referring to! The problem is in the
SmartAging()function at line 645:The Issue: This hardcodes user processes to boost to priority 0 (RT level), but your MLFQ design has
RT_PRIORITY_THRESHOLD = 3. This means:When user processes get boosted to priority 0, they're jumping into the system-level RT queue, which breaks the isolation between system and user processes in your syscall-less kernel.
The Fix: Change the hardcoded
new_priority = 0to respect the RT threshold:This aligns with your other user process handling:
processes[i].priority = RT_PRIORITY_THRESHOLD; // User processes to user RTold_proc->priority = RT_PRIORITY_THRESHOLD;processes[slot].priority = (privilege == PROC_PRIV_SYSTEM) ? 0 : RT_PRIORITY_THRESHOLD;Security Implications: The current hardcoded 0 accidentally elevates user processes to system-level priority during anti-starvation boosts, potentially breaking your privilege separation in the syscall-less design.
Want me to create an issue for this MLFQ priority isolation fix?
🧬 Code Graph Analysis Results
Here are the snippets and summaries from other parts of the codebase that are relevant to understanding arch/x86_64/interrupts/Interrupts.c and its handling of IRQs, scheduling, and security checks.
File: drivers/Pic.c [lines 67-70]
Full snippet:
void PICSendEOI(uint64_t interrupt_number) {
if (interrupt_number >= 40) outb(PIC2_COMMAND, 0x20);
outb(PIC1_COMMAND, 0x20);
}
File: drivers/Ide.c [lines 257-261]
Full snippet:
void IDEPrimaryIRQH(void) {
// Primary IDE channel interrupt
// Read status to acknowledge
inb(IDE_PRIMARY_BASE + IDE_REG_STATUS);
}
File: drivers/Ide.c [lines 263-267]
Full snippet:
void IDESecondaryIRQH(void) {
// Secondary IDE channel interrupt
// Read status to acknowledge
inb(IDE_SECONDARY_BASE + IDE_REG_STATUS);
}
File: kernel/etc/Console.c [lines 190-195]
Full snippet:
void PrintKernelWarning(const char* str) {
ConsoleSetColor(VGA_COLOR_WARNING);
PrintKernelBadge("WARNING");
PrintKernel(str);
ConsoleSetColor(VGA_COLOR_DEFAULT);
}
File: kernel/etc/Console.c [lines 259-283]
Full snippet:
void PrintKernelInt(int64_t num) {
char buffer[21];
}
File: kernel/memory/MemOps.c [lines 44-67]
Full snippet:
void htoa(uint64_t n, char* buffer) {
static const char hex_chars[16] = "0123456789ABCDEF";
buffer[0] = '0';
buffer[1] = 'x';
}
File: kernel/memory/MemOps.c [lines 6-36]
Full snippet:
void strcpy(char* dest, const char* src) {
// Optimize for 64-bit aligned copies when possible
if (((uintptr_t)dest & 7) == 0 && ((uintptr_t)src & 7) == 0) {
uint64_t* d64 = (uint64_t*)dest;
const uint64_t* s64 = (const uint64_t*)src;
}
File: kernel/memory/MemOps.c [lines 38-42]
Full snippet:
void strcat(char* dest, const char* src) {
// Find end of dest string more efficiently
while (*dest) dest++;
strcpy(dest, src); // Reuse optimized strcpy
}
File: kernel/memory/MemOps.c [lines 69-89]
Full snippet:
void itoa(uint64_t n, char* buffer) {
if (n == 0) {
buffer[0] = '0';
buffer[1] = '\0';
return;
}
}
File: drivers/PS2.c [lines 118-168]
Summary:
KeyboardHandler(void) reads the PS/2 keyboard status, filters out mouse input, decodes scancodes, tracks modifier keys (Shift, Ctrl, Alt), translates to ASCII with or without shift, applies Ctrl-key combinations, and buffers input into input_buffer with wraparound. It updates internal state such as shift_pressed, ctrl_pressed, alt_pressed, and buffer_tail/buffer_count.
File: drivers/PS2.c [lines 170-226]
Summary:
MouseHandler(void) reads PS/2 mouse data when available, accumulates 3-byte packets, validates the packet, computes deltas with overflow handling, inverts Y axis, updates mouse state (x, y, delta_x, delta_y, buttons), and clamps coordinates to a defined range. It then resets the packet index.
File: kernel/process/Process.c [lines 705-882]
Summary:
FastSchedule(struct Registers* regs) implements a multi-level feedback queue (MLFQ) scheduler with various illness/fairness adjustments:
Note: The Interrupts.c file calls:
Also relevant for understanding: Token validation and AstraPreflightCheck usage indicate security checks during scheduling and interrupt handling.
✏️ Learnings added
🧠 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.
how is that useful when i literally says uint32_t new_priority = RT_PRIORITY_THRESHOLD; literally blew up the entire scheduler?, it just only doesnt starve, it simply refuses to switch, and the problem is uint32_t new_priority = RT_PRIORITY_THRESHOLD; is the problem, that i found interesting
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 That's a fascinating observation! You're right - there's clearly something deeper going on with the scheduler's queue management at
RT_PRIORITY_THRESHOLD. Let me investigate why boosting to priority 3 breaks process switching entirely.The issue might be in how the scheduler differentiates between RT and regular queues at the boundary. When you boost to exactly
RT_PRIORITY_THRESHOLD(priority 3), it could be:rt_bitmapandactive_bitmap- boosting to priority 3 might not set the right bitmap bitsWhat specific behavior do you see when it "refuses to switch"? Does it:
This will help pinpoint whether it's a queue selection issue or bitmap management problem.
🏁 Script executed:
Length of output: 6774
@assembler-0 Found the root cause! The issue is a critical bitmap management bug in
AddToScheduler().The Bug: When adding processes to the scheduler,
rt_bitmapis never set, only cleared:Why Priority 0 "Works":
FindBestQueue()checksrt_active = active_bitmap & rt_bitmap(line 569)rt_bitmapis always 0,rt_activeis always 0Why RT_PRIORITY_THRESHOLD "Breaks":
rt_bitmapis emptyThe Fix: Add rt_bitmap initialization in
AddToScheduler():This explains why your entire RT scheduling has been accidentally broken but seemed to work - everything was falling through to regular queue selection! Want me to check if there are other bitmap inconsistencies?
🧬 Code Graph Analysis Results
File: kernel/process/Process.c, lines 705-882
Summary (docstring-style):
File: drivers/Pic.c, lines 67-70
Complete snippet:
void PICSendEOI(uint64_t interrupt_number) {
if (interrupt_number >= 40) outb(PIC2_COMMAND, 0x20);
outb(PIC1_COMMAND, 0x20);
}
File: drivers/Ide.c, lines 257-261
Complete snippet:
void IDEPrimaryIRQH(void) {
// Primary IDE channel interrupt
// Read status to acknowledge
inb(IDE_PRIMARY_BASE + IDE_REG_STATUS);
}
File: drivers/Ide.c, lines 263-267
Complete snippet:
void IDESecondaryIRQH(void) {
// Secondary IDE channel interrupt
// Read status to acknowledge
inb(IDE_SECONDARY_BASE + IDE_REG_STATUS);
}
🧠 Learnings used