Getting GPF in VMM Initialization

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ApplePieCodes
Posts: 6
Joined: Mon Apr 14, 2025 11:58 am

Getting GPF in VMM Initialization

Post by ApplePieCodes »

I am getting a general protection fault in my VMM Code. it may also be related to my pmm allocators
https://github.com/ApplePieCodes/kobold-new2
vortexian
Posts: 13
Joined: Fri Apr 04, 2025 10:25 pm

Re: Getting GPF in VMM Initialization

Post by vortexian »

Where is the fault happening? We need some more information to help you. If you're using QEMU, you can specify

Code: Select all

-d int,cpu_reset
and specify an output log to see what's happening in the system when you get a GPF. It will get logged as an exception and specify the PC, stack, etc.
ApplePieCodes
Posts: 6
Joined: Mon Apr 14, 2025 11:58 am

Re: Getting GPF in VMM Initialization

Post by ApplePieCodes »

vortexian wrote: Wed Apr 16, 2025 9:35 am Where is the fault happening? We need some more information to help you. If you're using QEMU, you can specify

Code: Select all

-d int,cpu_reset
and specify an output log to see what's happening in the system when you get a GPF. It will get logged as an exception and specify the PC, stack, etc.

Code: Select all

Servicing hardware INT=0x20
     0: v=20 e=0000 i=0 cpl=0 IP=0008:ffffffff8000a14e pc=ffffffff8000a14e SP=0010:ffff800007f87ec8 env->regs[R_EAX]=0000000000200000
RAX=0000000000200000 RBX=0000000000000000 RCX=00000000000000ff RDX=0000000000361178
RSI=0000000000000080 RDI=ffffffff800e5288 RBP=ffff800007f87ef0 RSP=ffff800007f87ec8
R8 =ffffffff800050b1 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000320
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff8000a14e RFL=00000287 [--S--PC] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
CS =0008 0000000000000000 ffffffff 00af9b00 DPL=0 CS64 [-RA]
SS =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
DS =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
FS =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
GS =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
LDT=0000 0000000000000000 00000000 00008200 DPL=0 LDT    
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     ffffffff800e5260 00000027
IDT=     ffffffff800e62c0 00001000
CR0=80010011 CR2=0000000000000000 CR3=0000000007f77000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000085 CCD=ffffffffffe6c230 CCO=EFLAGS     
EFER=0000000000000d00
check_exception old: 0xffffffff new 0xe
     1: v=0e e=0000 i=0 cpl=0 IP=0008:ffffffff8000a14e pc=ffffffff8000a14e SP=0010:ffff800007f87ec8 CR2=0000000000000318
RAX=0000000000000000 RBX=0000000000000000 RCX=0000000000000000 RDX=0000000000000000
RSI=0000000000000000 RDI=0000000000000000 RBP=0000000000000320 RSP=ffff800007f87ec8
R8 =ffffffff800050b1 R9 =0000000000000080 R10=ffffffff800e5288 R11=ffff800007f87ef0
R12=0000000000361178 R13=00000000000000ff R14=0000000000000000 R15=0000000000200000
RIP=ffffffff8000a14e RFL=00000287 [--S--PC] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
CS =0008 0000000000000000 ffffffff 00af9b00 DPL=0 CS64 [-RA]
SS =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
DS =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
FS =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
GS =0010 0000000000000000 ffffffff 00cf9700 DPL=0 DS   [EWA]
LDT=0000 0000000000000000 00000000 00008200 DPL=0 LDT    
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     ffffffff800e5260 00000027
IDT=     ffffffff800e62c0 00001000
CR0=80010011 CR2=0000000000000318 CR3=0000000007f77000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000085 CCD=ffff800007f87de0 CCO=EFLAGS     
EFER=0000000000000d00
ApplePieCodes
Posts: 6
Joined: Mon Apr 14, 2025 11:58 am

Re: Getting GPF in VMM Initialization

Post by ApplePieCodes »

Update: I ran it and it worked, but i ran it again and i'm back to different errors. this time it's a PF(i got it by changing kmalloc(sizeof(...)) in getorcreate page to kmalloc(1)
vortexian
Posts: 13
Joined: Fri Apr 04, 2025 10:25 pm

Re: Getting GPF in VMM Initialization

Post by vortexian »

Well, your posted log isn't a protection or a page fault exception, it's an interrupt (v=0x20). If you debug in GDB, you can set a breakpoint at the IP specified in your debug log with

Code: Select all

b *0x<paste PC address here>
. Make sure to compile your code with -g.

I can see you have code that remaps the PIC, but I don't remember the specifics on when certain interrupts fire. Using Limine you need to make sure you don't overwrite the Limine page tables while setting up your own.
ApplePieCodes
Posts: 6
Joined: Mon Apr 14, 2025 11:58 am

Re: Getting GPF in VMM Initialization

Post by ApplePieCodes »

I have updated the code to do this, and it mapps limine data, data, rodata, text, etc fine, but fails at the rest of the memory map
Octocontrabass
Member
Member
Posts: 5768
Joined: Mon Mar 25, 2013 7:01 pm

Re: Getting GPF in VMM Initialization

Post by Octocontrabass »

ApplePieCodes wrote: Wed Apr 16, 2025 9:56 am

Code: Select all

check_exception old: 0xffffffff new 0xe
     1: v=0e e=0000 i=0 cpl=0 IP=0008:ffffffff8000a14e pc=ffffffff8000a14e SP=0010:ffff800007f87ec8 CR2=0000000000000318
Limine doesn't identity-map the first 4kB of RAM to help catch null pointers.
Post Reply