im making an os kernel in zig (grub to boot) and im trying to get interrupts to work specifically hardware interrupts and as soon as i enable them (i have a pic, gdt and idt setup) it gives me a double fault
but the crazy thing is when i mask the first hardware interrupt at 32 IRQ0 it gives me a stack segment fault
you can take a look at the code but i feel like i'm making no progress and yes im a beginner this is my second time trying but this time im using a language im more use to ZIG!
https://github.com/levi73159/LazyOS/tree/main
Unhandled exception 8 double_fault
eax=8 ebx=10000 ecx=0 edx=f000ff53 esi=0 edi=0
ebp=1ca008 esp=0 eip=8 eflags=1331ff
cs=206 ds=10
error=13340a interrupt=8
Unhandled exception 12 stack_segment_fault
eax=c ebx=10000 ecx=0 edx=f000ff53 esi=0 edi=0
ebp=1ca008 esp=0 eip=8 eflags=1331ff
cs=10206 ds=10
error=13340a interrupt=c
and i do not know why esp is zero since i am setting it up correctly here
const STACK_SIZE = 16 * 1024;
var stack_bytes: [STACK_SIZE]u8 align(16) linksection(".bss") = undefined;
export fn __kernel_start() callconv(.naked) noreturn {
asm volatile (
// make sure interrupts are disabled
// set up the stack
\\ cli
\\ movl %[stack_top], %%esp
\\ movl %%esp, %%ebp
\\ call %[_start:P]
:
: [stack_top] "r" (@as([*]align(16) u8, @ptrCast(&stack_bytes)) + @sizeOf(@TypeOf(stack_bytes))),
// We let the compiler handle the reference to kmain by passing it as an input operand as well.
[_start] "X" (&_start),
);
while (true) {}
}
idk what it is but whatever it is, it not wanting to go away. I don't think it a real double fault tho because a real one should have an error code of zero but this one don't
and the qemu log shows me that it a hardware interrupt that calling it for some reason:
SMM: after RSM
EAX=00000000 EBX=00000000 ECX=02000000 EDX=02000628
ESI=0000000b EDI=02000000 EBP=1efed210 ESP=00006d54
EIP=000f05ae EFL=00000046 [---Z-P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 000f7440 00000037
IDT= 000f747e 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000044 CCD=00000000 CCO=EFLAGS
EFER=0000000000000000
Servicing hardware INT=0x08
SMM: enter
EAX=000000b5 EBX=000f86be ECX=00001234 EDX=00006cff
ESI=00006cc8 EDI=1efff755 EBP=00006c88 ESP=00006c88
EIP=000086bb EFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =de80 000de800 ffffffff 008f9300
CS =f000 000f0000 ffffffff 008f9b00
SS =0000 00000000 ffffffff 008f9300
DS =0000 00000000 ffffffff 008f9300
FS =0000 00000000 ffffffff 008f9300
GS =0000 00000000 ffffffff 008f9300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT= 00000000 00000000
IDT= 00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000000 CCD=00006c88 CCO=ADDL
EFER=0000000000000000