Demo 15 Problem

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:
Re: Demo 15 Problem

Post by Andyhhp » Fri Oct 09, 2009 1:27 pm

Did you make any changes to the code at all?

The optimiser can take the smallest change in source code into a huge change in terms of machine code

~Andrew
Image

Insightsoft
Posts:63
Joined:Wed Jul 22, 2009 6:44 am

Re: Demo 15 Problem

Post by Insightsoft » Fri Oct 09, 2009 5:48 pm

No. Only this 3 line of NOP... just to find a way to freeze at this precisely location...
(And, this simple change was a reaction to the problem)
_____________
Think it, build it, bit by bit...

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: Demo 15 Problem

Post by Mike » Fri Oct 09, 2009 9:33 pm

Hm, there is a couple of interesting things:

-You are using the floppy programming chapter. For simplicity purposes, please test with the keyboard chapters demo.
-Both of the above were built within Visual C++ 2008, so no upgrades of the project should be needed. What version of Visual C++ are you using?
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

Insightsoft
Posts:63
Joined:Wed Jul 22, 2009 6:44 am

Re: Demo 15 Problem

Post by Insightsoft » Wed Apr 14, 2010 4:06 pm

Oops, is asking me for the upgrade...
...and on the first compilation (just after the upgrade) it works fine
...then, on second compilation, and without any change, it crash!!!

I'm using the Visual Studio 2008 with Visual C++ 2008 Professional Edition...
_____________
Think it, build it, bit by bit...

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: Demo 15 Problem

Post by Mike » Fri Apr 16, 2010 12:06 am

Hello,

Please see my above post. Do you have the same problem with the keyboard programming chapters' demo? What happens when you Clean+Rebuild the project? Also, please post your compiler and linker command line switches please.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

User avatar
XV8
Posts:9
Joined:Tue Apr 06, 2010 10:47 am
Contact:

Re: Demo 15 Problem

Post by XV8 » Sat Apr 24, 2010 7:54 pm

I use bochs. When keyboard interrupt occured bochs crash.
I set for all interrupts one default IR. It do nothing.
When i use in asm :

Code: Select all

asm("int $0")
bochs crash too.
Where mistake? May be that IDT Register have wrong value?
How i check it?

Code: Select all

#define MAX_INTERRUPTS		256
#define IDT_DESC_TYPE_INT_GATE 	 	 0x0E    //00001110
#define IDT_DESC_TYPE_TASK_GATE		 0x05    //00000101
#define IDT_DESC_TYPE_TRAP_GATE		 0x0F    //00001111
#define IDT_DESC_RING_0			 0x00    //00000000
#define IDT_DESC_RING_1			 0x20	 //00100000
#define IDT_DESC_RING_2		 	 0x40	 //01000000
#define IDT_DESC_RING_3		 	 0x60	 //01100000
#define IDT_DESC_PRESENT		 	 0x80	 //10000000




typedef void (*IRQ_HANDLER)(void);


struct IDTDescriptor
{
	
	unsigned short		Offset1;
	unsigned short		Selector;
	unsigned char		Reserved;
	unsigned char		Flags;
	unsigned short		Offset2;
};

struct IDTRegister
{
	unsigned short	Limit;
           unsigned int	Base;
};

static IDTDescriptor IDT[MAX_INTERRUPTS];
static IDTRegister   IDTR;

class iIDTManager
{
  public :
   int InstallIR(unsigned int, unsigned short, unsigned short, void (*func) ());
   int Init(unsigned short);
   IDTDescriptor* GetIR(unsigned int);
   void Install();
   iMemory MM;
 };

Code: Select all

#include "IDTManager.hpp"

void iIDTManager :: Install ()
{
asm("lidt (,%0,)"::"a" (&IDTR) );
}

void DefaultIR ()
{
	for(;;);
}

IDTDescriptor* iIDTManager ::  GetIR (unsigned int IRNum)
{
	if (IRNum>MAX_INTERRUPTS)
		return 0;
	return &IDT[IRNum];
}

int iIDTManager :: InstallIR (unsigned int IRNum, unsigned short Flags, unsigned short Selector, IRQ_HANDLER IRQ)
{

	if (IRNum>MAX_INTERRUPTS)
		return 0;

	if (!IRQ)
		return 0;

	unsigned long long		Base = (unsigned long long)&(*IRQ);
	IDT[IRNum].Offset1		=	(unsigned short)(Base & 0xffff);
	IDT[IRNum].Offset2		=	(unsigned short)((Base >> 16) & 0xffff);

	IDT[IRNum].Reserved		=	0;
	IDT[IRNum].Flags		=	(unsigned char) Flags;
	IDT[IRNum].Selector			=	Selector;

	return	0;
}

int iIDTManager :: Init (unsigned short CodeSelector)
{
	IDTR.Limit = sizeof (struct IDTDescriptor) * MAX_INTERRUPTS -1;
	IDTR.Base  = (unsigned int)&IDT[0];

	MM.SetBytes ((void*)&IDT[0], 0, sizeof (IDTDescriptor) * MAX_INTERRUPTS-1);
	for (int i=0; i<MAX_INTERRUPTS; i++)
		InstallIR (i, IDT_DESC_TYPE_INT_GATE | IDT_DESC_RING_0 | IDT_DESC_PRESENT,
			CodeSelector, (IRQ_HANDLER) DefaultIR);
	Install ();
	return 0;
}

User avatar
XV8
Posts:9
Joined:Tue Apr 06, 2010 10:47 am
Contact:

Re: Demo 15 Problem

Post by XV8 » Sun Apr 25, 2010 7:48 pm

i check the GDT register by sgdt instructions. But i got a wrong result.
Value which i got from GDT register is not valid. it different from value which i Load into them.
Limit of GDT is correct, But address of GDT in GDT register is wrong. I check it and i have found that it is 16 low bit of original value.

For Load to GDTR i use

Code: Select all

asm("lgdt (,%0,)"::"a" (&GDTRegStruct1))
for get GDTR value i use

Code: Select all

asm("sgdt (,%0,)"::"a" (&GDTRegStruct2))
where GDTRegStruct1 (2)

Code: Select all

struct GDTR
{
  unsigned short Limit;
  unsigned int Base;
} 

GDTR GDTRegStruct2,GDTRegStruct1;
also IDT register Load and Read has this problem.
i think that bochs crash because of this problem.


whats problem?
I do not know that to do.

User avatar
XV8
Posts:9
Joined:Tue Apr 06, 2010 10:47 am
Contact:

Re: Demo 15 Problem

Post by XV8 » Mon Apr 26, 2010 7:55 pm

Problem is resolved.
GCC align structure by size of the biggest field.

this is example

Code: Select all

struct test_t
{
  int  a;
  char b;
  int  c;
} ;

struct test_t test = { 10, 20, 30};
GCC compilier it to

Code: Select all

test:
	.long	10
	.byte	20
	.zero	3
	.long	30
GCC use .zero 3 for alignment.

If use directive __attribute__ ((packed)) GCC ignores alignment
for example

Code: Select all

struct test_t
{
  int  a;
  char b;
  int  c;
} __attribute__ ((packed));

struct test_t test = { 10, 20, 30};
And the object file

Code: Select all

test:
	.long	10
	.byte	20
	.long	30

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Demo 15 Problem

Post by Andyhhp » Mon Apr 26, 2010 8:33 pm

ahh. I forgot about alignment problems

a better method is to use "__attribute__((packet))" which will ensure that no padding happens

~Andrew
Image

Fanael
Posts:8
Joined:Sat Feb 20, 2010 12:55 am
Location:Poland

Re: Demo 15 Problem

Post by Fanael » Sun May 02, 2010 1:20 pm

Andyhhp wrote:ahh. I forgot about alignment problems

a better method is to use "__attribute__((packet))" which will ensure that no padding happens

~Andrew
Isn't it "__attribute__((packed))"?

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Demo 15 Problem

Post by Andyhhp » Sun May 02, 2010 1:23 pm

Yes it is - i cant spell :P
Image

Post Reply