IDT problem [SOLVED]
Posted: Fri Apr 27, 2007 10:17 am
hi all,
i am currently working on my osloader in c.
but when i call a HLT or JMP insturction after
setting up the idt and enabling interrupts it throws
a general protection fault (13). and bochs restarts.
it says the system segments are not valid.
but why?
the jumps from c-code to asm-code and back
are correct.
and all typdefs are defined with #pragma pack( 1 )
thanks
Uni_Sol
---
now the code:
error:
tydefs:
functions:
asm:
i am currently working on my osloader in c.
but when i call a HLT or JMP insturction after
setting up the idt and enabling interrupts it throws
a general protection fault (13). and bochs restarts.
it says the system segments are not valid.
but why?
the jumps from c-code to asm-code and back
are correct.
and all typdefs are defined with #pragma pack( 1 )
thanks
Uni_Sol
---
now the code:
Code: Select all
void osloader() {
/* ************************************************************************* */
TableRegister gdt, idt;
char* con = (char*)0xB8000;
int n=0, i=0;
char* version = VER_STRING;
/* ************************************************************************* */
pDescriptor GDT_BASE_POINTER = (pDescriptor) 0x00100000;
pGate IDT_BASE_POINTER = (pGate) 0x00110000;
gdt.size = (unsigned short) 0xFFFF;
gdt.base = (unsigned long ) GDT_BASE_POINTER;
idt.size = (unsigned short) 0xFFFF;
idt.base = (unsigned long ) IDT_BASE_POINTER;
/* ************************************************************************* */
FlushGDT();
GDTCreateDesc( 0, 0x00, 0x00, 0, 0, 0, 0, 0 );
GDTCreateDesc( 1, 0x00, 0xFFFFFFFF, TYPE_CODE_EXEC_AND_READ, LEVEL_RING_0, SYSTEM_SEGMENT, PRESENT, SIZE_4KBYTE );
GDTCreateDesc( 2, 0x00, 0xFFFFFFFF, TYPE_DATA_READ_AND_WRITE, LEVEL_RING_0, SYSTEM_SEGMENT, PRESENT, SIZE_4KBYTE );
/* ************************************************************************* */
FlushIDT();
isr_install();
irq_install();
/* ************************************************************************* */
LoadIDT( idt );
LoadGDT( gdt );
/* ************************************************************************* */
enable();
halt();
}
Code: Select all
00015000306-e-@00000708-[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00015000306-e-@00000708-[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00015000306-e-@00000708-[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00015000306-i-@00000708-[CPU0 ] protected mode
00015000306-i-@00000708-[CPU0 ] CS.d_b = 32 bit
00015000306-i-@00000708-[CPU0 ] SS.d_b = 32 bit
00015000306-i-@00000708-[CPU0 ] | EAX=00000010 EBX=00008003 ECX=00000021 EDX=0000008e
00015000306-i-@00000708-[CPU0 ] | ESP=0001050b EBP=00000000 ESI=0000803c EDI=00000010
00015000306-i-@00000708-[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df IF tf sf zf af pf cf
00015000306-i-@00000708-[CPU0 ] | SEG selector base limit G D
00015000306-i-@00000708-[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00015000306-i-@00000708-[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00015000306-i-@00000708-[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00015000306-i-@00000708-[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00015000306-i-@00000708-[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00015000306-i-@00000708-[CPU0 ] | FS:0000( 0000| 0| 0) 000ffff0 0000ffff 0 0
00015000306-i-@00000708-[CPU0 ] | GS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00015000306-i-@00000708-[CPU0 ] | EIP=00000708 (00000708)
00015000306-i-@00000708-[CPU0 ] | CR0=0x00000011 CR1=0 CR2=0x00000000
00015000306-i-@00000708-[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00015000306-i-@00000708-[CPU0 ] >> ret : C3
00015000306-e-@00000708-[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Code: Select all
typedef struct _Gate { /* Gate in der IDT */
unsigned int offset_low :16; /* 1. Word der Funk.-Adresse */
unsigned int selector :16; /* Selektor aus der GDT */
unsigned int reserved :8; /* Reserviert */
unsigned int type :8; /* Zugriffs- und Statusbyte */
unsigned int offset_high :16; /* 2. Word der Funk.-Adresse */
} Gate, *pGate;
Code: Select all
void GDTCreateDesc( unsigned int num,
unsigned long base,
unsigned long size,
unsigned int type, // 3
unsigned int level, // 2
unsigned int system, // 1
unsigned int present, // 1
unsigned int seg_size ) { // 1
/* Setup the descriptor base address */
GDT_BASE_POINTER[num].base_low = (base & 0xFFFF);
GDT_BASE_POINTER[num].base_mid = (base >> 16) & 0xFF;
GDT_BASE_POINTER[num].base_high = (base >> 24) & 0xFF;
/* Setup the descriptor size */
GDT_BASE_POINTER[num].size_low = (size & 0xFFFF);
GDT_BASE_POINTER[num].size_high = ((size >> 16) & 0xF);
GDT_BASE_POINTER[num].type = type;
GDT_BASE_POINTER[num].level = level;
GDT_BASE_POINTER[num].system = system;
GDT_BASE_POINTER[num].present = present;
GDT_BASE_POINTER[num].seg_size = seg_size;
}
/* ***************************************************************************** */
void IDTCreateGate( unsigned int num,
unsigned long offset,
unsigned short selector,
unsigned char type ) {
/* Setup the gate base address */
IDT_BASE_POINTER[num].offset_low = (offset & 0xFFFF);
IDT_BASE_POINTER[num].offset_high = (offset >> 16);
/* Setup the gate selector */
IDT_BASE_POINTER[num].selector = selector;
/* Finally, set up the type and reserved */
IDT_BASE_POINTER[num].type = type;
IDT_BASE_POINTER[num].reserved = 0;
}
/* ***************************************************************************** */
void LoadGDT( TableRegister gdt ) {
asm( "lgdt %0" : "=m" (gdt) );
}
/* ***************************************************************************** */
void LoadIDT( TableRegister idt ) {
asm( "lidt %0" : "=m" (idt) );
}
/* ***************************************************************************** */
void FlushIDT() {
int i=0;
for( i; i <= 0xFFFF; i++ ) {
IDTCreateGate( 0, 0, 0, 0 );
}
}
/* ***************************************************************************** */
void FlushGDT() {
int i=0;
for( i; i <= 0xFFFF; i++ ) {
GDTCreateDesc( 0, 0, 0, 0, 0, 0, 0, 0 );
}
}
/* ***************************************************************************** */
Code: Select all
CODE_SECTION32:
call _osloader
; künstlicher fehler
;xor eax, eax
;mov ebx, eax
;div ebx
; ***********************************************
hang: jmp hang
; ***********************************************
; void halt()
_halt: hlt
ret
; ***********************************************
; void disable()
_disable:
cli
ret
; ***********************************************
; void enable()
_enable: sti
ret