OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 5:29 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: IDT problems
PostPosted: Mon Feb 06, 2012 11:27 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
Please post any IDT problems you have here. WHen they're solved they will be placed on the the wiki here: IDT problems

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Mon Feb 06, 2012 11:54 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 08, 2011 1:58 pm
Posts: 496
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

I'm not sure we should have a wiki page for every struggle, specially when error message is so informative like this one:
Code:
interrupt(): not accessible or not code segment cs = 0x0008
interrupt(): gate descriptor not valid sys seg (vector = 0x0d)

It's more than obvious.

I think this kind of topic belongs to forum, not wiki documentation, it cloud mislead people searching for "IDT" by irrelevant results.


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Mon Feb 06, 2012 12:59 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
It's funny to see #ifdef WIN32 in your OS code...

And for your IDT problem article, you are solving alignment / padding issue...


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Wed Feb 08, 2012 7:13 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
I am demoting the code to the forum.
Solved problems will be paced on the wiki

so here it is:
Please note before you give me GCC specific adivce I have a slightly unusual setup. My setup is MS VC++ 2010 Express SP1 with the [Updated] Windows SDK, enabling 64 bit development. I use a separate assembly layer. I am currently writing my bootloader, but as I will use a custom file system I am currently testing the 32 bit version with the [http://www.brokenthorn.com/Resources/OSDevIndex.html bootloader] available at BrokenThorn, which is a tutorial on a PE kernel. My kernel is higher half at 0xC0000000, and has no memory magager (it relies on the bootloader's). I intend to change this in the near future. It does however, manage it's GDT. My kernel works perfectly without interrupts, and even presents a command line. This is one of the reasons I want IRQ's however, I can only get 1 character. '''This might be changed ''very soon!'''''. When I enable interrupts, the machine reboots. And again.... ad infanatum.

Now you understand the environment, this is the bochs output
Code:
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

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:

IDT.h
Code:
//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();


IDT.cpp
Code:
#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();
}

}


Finally, my assembly routine

Code:
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


Where Halt is "hlt" so that you can actually see the message being put. Interrupts should be disabled before lidt, so if I don't see the message problem could be that.
I agree it's funny to see #ifdef WIN32, but thats VC++ for you. :lol:

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Wed Feb 08, 2012 7:14 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
By upolling the PIC I can now get a command line. But I still want interrupts! Please help! [-o<

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Wed Feb 08, 2012 12:24 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hello,

May I ask why you still arent packing the structure to 1 byte? That would greatly simplify your code. Also, dont ever use WIN32 in your system software. If you must utilize MSVC specific code, use _MSC_VER.

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Wed Feb 08, 2012 1:36 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
Sorry for the lack of clarification.
I am compiling for 64 bit as well. That is why I use the #ifdef WIN32 ... #else
also, I define myself, and as it is simplest to do it this way I do it.

P.S I am a great fan of your series

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Wed Feb 08, 2012 3:00 pm 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Hi,

I don't understand the logic behind an "IDT Problem" article. Surely the IDT is one of the most documented, well defined features of the x86/x86_64 processor? If there's a problem with the IDT, you're not doing it right and the information will be in the Intel manuals.

@OP: Is this just a round-about way of you asking for help setting up your IDT?

Cheers,
Adam


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Thu Feb 09, 2012 1:48 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
I feel people can benefit from this article as the documentation will tell you a large amount of information about the structure, but not implementation in an compiled environment. We all can find out the basic structures from the IDT page, but the implementation could be a lot more difficult.
Please help me, as I can't see what's wrong with it! :?

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Thu Feb 09, 2012 5:52 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
In fact the implementation is not that difficult once you understand the manual. It's just few lines of code.
I discourage skipping the manual simply because you feel it contain too much information and try to avoid it.

EDIT: If you need an implementation, there are plenty of barebone tutorials.


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Thu Feb 09, 2012 6:13 am 
Offline
Member
Member

Joined: Thu Mar 25, 2010 11:26 pm
Posts: 1801
Location: Melbourne, Australia
According to
Code:
interrupt(): not accessible or not code segment cs = 0x0008
your GDT may be wrong. Have you tested your GDT by doing a far jmp ?

_________________
If a trainstation is where trains stop, what is a workstation ?


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Thu Feb 09, 2012 7:06 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
actually no. I will try it.

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Thu Feb 09, 2012 7:14 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
yeah, and don't point out the >>16 error on the 64 bit version, I will correct that. I tried &(*function) but still wouldn't work. Thankyou for the GDT lead. I should know if this is the problem within a few hours.

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Thu Feb 09, 2012 8:14 am 
Offline
Member
Member
User avatar

Joined: Tue Jun 02, 2009 4:35 pm
Posts: 737
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.
bellezzasolo wrote:
Please note before you give me GCC specific adivce I have a slightly unusual setup

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.

Some things I noticed in passing that aren't very palatable:

Quote:
Code:
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

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:


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.

Quote:
IDT.cpp
Code:
#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)


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.

--Peace out
gravaera

_________________
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.


Top
 Profile  
 
 Post subject: Re: IDT problems
PostPosted: Thu Feb 09, 2012 11:12 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
Thankyou. IRQ's now work (although a panic screen)
Here is normal operation:
Attachment:
File comment: Normal operation (no IRQ)
TeraOS screenshot.png
TeraOS screenshot.png [ 122.93 KiB | Viewed 12156 times ]

Here is panic:
Attachment:
File comment: Panic
Panic.png
Panic.png [ 84.47 KiB | Viewed 12156 times ]

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 85 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group