IDT problems
Posted: Mon Feb 06, 2012 11:27 am
Please post any IDT problems you have here. WHen they're solved they will be placed on the the wiki here: IDT problems
I'm not sure we should have a wiki page for every struggle, specially when error message is so informative like this one:bellezzasolo wrote:Please post any IDT problems you have here. WHen they're solved they will be placed on the the wiki here: IDT problems
Code: Select all
interrupt(): not accessible or not code segment cs = 0x0008
interrupt(): gate descriptor not valid sys seg (vector = 0x0d)
Code: Select all
interrupt(): not accessible or not code segment cs = 0x0008
interrupt(): gate descriptor not valid sys seg (vector = 0x0d)
interrupt(): not accessible or not code segment cs = 0x0008
Machine is in protected mode (active)
CS.mode = 32 bit
SS.mode = 32 bit
Code: Select all
//definitions
#define PRESENT 0x80
#define USRPRIV 0x60
#define KRNLPRV 0x0
#define TASK32 0x5
#define INTR16 0x6
#define TRAP16 0x7
#define INTR32 0xE
#define TRAP32 0xF
void setvect(char vect, void(*function)(void), unsigned char priv = (PRESENT|KRNLPRV|INTR32));
void installIDT();
Code: Select all
#include "IDT.h"
#include "..\Asm\Asmlayer.h"
#include <cstddef.h>
#include <stdout.h>
#include "panic.h"
//structures
#pragma pack(push,1)
class IDT_entry {
public:
#ifdef WIN32
unsigned short baseLow;
unsigned short segment;
unsigned char reserved;
unsigned char flags;
unsigned short baseHigh;
#else
unsigned short baseLow;
unsigned short segment;
unsigned char reserved;
unsigned char flags;
unsigned short baseMed;
unsigned int baseHigh;
unsigned int reserved2;
#endif
};
#pragma pack(pop)
#pragma pack(push,1)
class IDT_reg {
public:
unsigned short limit;
IDT_entry* base;
};
#pragma pack(pop)
//data
static IDT_reg IDT_register;
static IDT_entry IDT [256] = {0};
//functions
void setvect(char vect, void(*function)(void), unsigned char priv)
{
#ifdef WIN32
IDT[vect].flags = priv;
IDT[vect].segment = (0x8); //Kernel mode
IDT[vect].reserved = 0;
IDT[vect].baseLow = (unsigned short)(unsigned int)function&0xFFFF;
IDT[vect].baseHigh = (unsigned short)(unsigned int)function>>16;
#else
IDT[vect].flags = priv;
IDT[vect].segment = (0x8); //Kernel mode
IDT[vect].reserved = 0;
IDT[vect].reserved2 = 0;
IDT[vect].baseLow = (unsigned short)(unsigned long long)function&0xFFFF;
IDT[vect].baseMed = (unsigned short)((unsigned long long)function>>16)&0xFFFF;
IDT[vect].baseHigh = (unsigned int)(unsigned long long)function>>16;
#endif
}
void installIDT()
{
if(sizeof(IDT_reg) != 6)
{
Puts("Bad IDT reg\n");
halt();
}
#ifdef WIN32
if(sizeof(IDT_entry) != 8)
{
Puts("Bad IDT struct\n");
halt();
}
#else
if(sizeof(IDT_entry) != 16)
{
Puts("Bad IDT struct\n");
halt();
}
#endif
IDT_register.base = &IDT[0];
#ifdef WIN32
IDT_register.limit = 256*8-1;
#else
IDT_register.limit = 256*16-1;
#endif
lidt(&IDT_register);
}
//ISR's
//These are called from assembly wrappers which handle the brunt
extern "C" {
void defaultHandler()
{
disable();
setColor(0x4,0xF);
Cls();
Puts(panicScreen);
halt();
}
}
Code: Select all
BITS 32 ;my 32 bit version
extern @defaultHandler@0
@handlerDefault@0:
pushad
call @defaultHandler@0
popad
iret
BITS 64 ;and my 64 bit version
extern defaultHandler
handlerDefault:
call pusha
call defaultHandler
call popa
iretq
Code: Select all
interrupt(): not accessible or not code segment cs = 0x0008
We speak in terms of a set of conventionally accepted tools on this forum: if you use a different toolchain/language, it's your job to ensure that you can translate information given here into your "nonstandard" working environment -- that's your issue, nobody here has to take your setup into consideration, or else we'd never get anything done.bellezzasolo wrote:Please note before you give me GCC specific adivce I have a slightly unusual setup
Bochs is telling you that there is a problem with the Code selector you loaded. You need to check it over, that's all. The bad selector is causing a fault.I don't know where I'm going wrong. I am using the ''linear'' address, as told to. If you need the code, here it is:Code: Select all
interrupt(): not accessible or not code segment cs = 0x0008 interrupt(): gate descriptor not valid sys seg (vector = 0x0d) interrupt(): not accessible or not code segment cs = 0x0008 Machine is in protected mode (active) CS.mode = 32 bit SS.mode = 32 bit
The preprocessing above is probably meant to ensure portabiilty across compilers, but you padded the structure for the non-MSVC case, so naturally the non-msvc case won't work; you might also want to look into using stdint.h for your integer types from now so you can save yourself trouble later on.IDT.cppCode: Select all
#pragma pack(push,1) class IDT_entry { public: #ifdef WIN32 unsigned short baseLow; unsigned short segment; unsigned char reserved; unsigned char flags; unsigned short baseHigh; #else unsigned short baseLow; unsigned short segment; unsigned char reserved; unsigned char flags; unsigned short baseMed; unsigned int baseHigh; unsigned int reserved2; #endif }; #pragma pack(pop)