GPF when running graphics mode
Posted: Sun Mar 10, 2024 4:13 pm
Hello, I have an issue when running graphics mode where I first get Page Fault and then I get GPF. Looking at qemu output and using addr2line I found that page fault happens in my kernel heap code and GPFs happen at iret call in my interrupt handler. In text mode I don't get anything and everything works as expected. This is qemu output:
addr2line -a -f -e kernel.bin 00101f25 --> kernel_heap.cpp:79
This is part of kernel heap code:
addr2line -a -f -e kernel.bin 001039e9 -> interrupts.s:94
This is interrupt stub code where iret is found:
Any ideas what could be the issue?
Code: Select all
check_exception old: 0xffffffff new 0xe
0: v=0e e=0002 i=0 cpl=0 IP=0010:00101f25 pc=00101f25 SP=0018:0010ba68 CR2=c0400008
EAX=c0400000 EBX=00010000 ECX=00107ad8 EDX=0110f000
ESI=07fdffff EDI=00000000 EBP=0010ba94 ESP=0010ba68
EIP=00101f25 EFL=00200016 [----AP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0018 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0010 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0018 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0018 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0018 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0018 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0028 00107038 00000068 0000e900 DPL=3 TSS32-avl
GDT= 00107006 0000002f
IDT= 0010716a 000007ff
CR0=80000011 CR2=c0400008 CR3=0010f000 CR4=00000200
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000024 CCD=0010ba60 CCO=ADDL
EFER=0000000000000000
check_exception old: 0xffffffff new 0xd
1: v=0d e=0010 i=0 cpl=0 IP=0008:001039e9 pc=001039e9 SP=0018:0010ba5c env->regs[R_EAX]=00000003
EAX=00000003 EBX=00000001 ECX=00107ad8 EDX=0110f000
ESI=07fdffff EDI=00000000 EBP=0010ba94 ESP=0010ba5c
EIP=001039e9 EFL=00200002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0018 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0018 00000000 ffffffff 00cffb00 DPL=3 CS32 [-RA]
FS =0018 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0018 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0028 00107038 00000068 0000e900 DPL=3 TSS32-avl
GDT= 00107006 0000002f
IDT= 0010716a 000007ff
CR0=80000011 CR2=c0400008 CR3=0010f000 CR4=00000200
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000001 CCD=00000001 CCO=ADDL
EFER=0000000000000000
This is part of kernel heap code:
Code: Select all
void KernelHeap::Initialize()
{
kheap_page_count = KERNEL_HEAP_SIZE / PAGE_SIZE;
physical_heap = g_PMM.Alloc(kheap_page_count);
if(!physical_heap)
{
CORAL_PANIC_MSG("Kernel Heap initialization failed! \n");
return;
}
Terminal::Print("Kernel virtual address: %p", KERNEL_HEAP_ADDRESS);
Terminal::Print("Kernel physical address: %p", physical_heap);
g_VMM.MapRange(KERNEL_HEAP_ADDRESS, physical_heap, KERNEL_HEAP_SIZE);
KernelHeapHeader* segment = (KernelHeapHeader*)KERNEL_HEAP_ADDRESS;
segment->length = KERNEL_HEAP_SIZE - sizeof(KernelHeapHeader);//this is line 79
segment->next = nullptr;
segment->prev = nullptr;
segment->free = true;
}
This is interrupt stub code where iret is found:
Code: Select all
.macro ISR_NO_ERR index
.global isr\index
isr\index:
pushl $0
pushl $\index
jmp isr_entry
.endm
.macro ISR_ERR index
.global isr\index
isr\index:
pushl $\index
jmp isr_entry
.endm
ISR_NO_ERR 0
ISR_NO_ERR 1
ISR_NO_ERR 2
ISR_NO_ERR 3
ISR_NO_ERR 4
ISR_NO_ERR 5
ISR_NO_ERR 6
ISR_NO_ERR 7
ISR_ERR 8
ISR_NO_ERR 9
ISR_ERR 10
ISR_ERR 11
ISR_ERR 12
ISR_ERR 13
ISR_ERR 14
ISR_NO_ERR 15
ISR_NO_ERR 16
ISR_ERR 17
ISR_NO_ERR 18
ISR_NO_ERR 19
ISR_NO_ERR 20
ISR_ERR 21
ISR_NO_ERR 22
ISR_NO_ERR 23
ISR_NO_ERR 24
ISR_NO_ERR 25
ISR_NO_ERR 26
ISR_NO_ERR 27
ISR_NO_ERR 28
ISR_NO_ERR 29
ISR_NO_ERR 30
ISR_NO_ERR 31
ISR_NO_ERR 32
ISR_NO_ERR 33
ISR_NO_ERR 34
ISR_NO_ERR 35
ISR_NO_ERR 36
ISR_NO_ERR 37
ISR_NO_ERR 38
ISR_NO_ERR 39
ISR_NO_ERR 40
ISR_NO_ERR 41
ISR_NO_ERR 42
ISR_NO_ERR 43
ISR_NO_ERR 44
ISR_NO_ERR 45
ISR_NO_ERR 46
ISR_NO_ERR 47
isr_entry:
pushal
pushl %ds
call ISRDelegate
popl %ds
popal
add $8, %esp
return:
iret # this is line 94