Here's the main happenings of the problem.
QEMU crashes when calling "KeHalt" at first line of KeInitGDT code, QEMU says:
Code: Select all
Could not open '\\.\kqemu' - QEMU acceleration layer not activated
qemu: fatal: Trying to execute code outside RAM or ROM at 0xb0000092
EAX=00000001 EBX=00009000 ECX=00000001 EDX=00000002
ESI=ffff7cd1 EDI=0004ffde EBP=630001bf ESP=0001bfbd
EIP=b0000092 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300
CS =0008 00000000 ffffffff 00cf9a00
SS =0010 00000000 ffffffff 00cf9300
DS =0010 00000000 ffffffff 00cf9300
FS =0010 00000000 ffffffff 00cf9300
GS =0010 00000000 ffffffff 00cf9300
LDT=0000 00000000 0000ffff 00008000
TR =0000 00000000 0000ffff 00008000
GDT= 00007cb6 00007ccd
IDT= 00000000 000003ff
CR0=60000011 CR2=00000000 CR3=00000000 CR4=00000000
CCS=00000000 CCD=0001bfa5 CCO=INCL
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Code: Select all
// Initialize the GDT function set
NOEXPORT void KRNLAPI KeInitGDT(void)
{
// Setup the GDT pointer and limit
KeHalt(); // Halt the kernel to try and trap a bug
g_pGdt.limit = (sizeof(GDT_ENTRY) * 3) - 1;
g_pGdt.base = (u32)&g_gdt;
// Setup the null descriptor
GdtSetGate(0, 0, 0, 0, 0);
// Setup the code segment (Base = 0, Limit = 4GB, Granularity = 4KB, 32-bits)
GdtSetGate(1, 0, 0xffffffff, 0x9a, 0xcf);
// Setup the data segment (Base = 0, Limit = 4GB, Granularity = 4KB, 32-bits)
GdtSetGate(2, 0, 0xffffffff, 0x92, 0xcf);
// Setup the GDT
GdtFlush();
}
I've got no idea why this is happening: I've tried the __cdecl and __stdcall calling conventions and both yield the same result, it would appear that it's trying to jump to an area of memory that doesn't exist, yet I can't see *why* it would... I think the above is sufficient enough information to query an answer, but in case it's not I'll upload my entire build environment (portions subject to the GPL). Credit goes out to all the various tutorials on osdever.net and osdev.org
Btw: This is a port of my old C kernel, the boot loader is the same, some ASM differences in the code.
Cheers,
-naota
Download the Development Environment + Source Code Here

