Demo 15 Problem
Moderator:Moderators
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
The optimiser can take the smallest change in source code into a huge change in terms of machine code
~Andrew

-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Demo 15 Problem
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)
(And, this simple change was a reaction to the problem)
_____________
Think it, build it, bit by bit...
Think it, build it, bit by bit...
Re: Demo 15 Problem
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?
-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
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Demo 15 Problem
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...
...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...
Think it, build it, bit by bit...
Re: Demo 15 Problem
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.
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
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
Re: Demo 15 Problem
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 :
bochs crash too.
Where mistake? May be that IDT Register have wrong value?
How i check it?
I set for all interrupts one default IR. It do nothing.
When i use in asm :
Code: Select all
asm("int $0")
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;
}
Re: Demo 15 Problem
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
for get GDTR value i use
where GDTRegStruct1 (2)
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.
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))
Code: Select all
asm("sgdt (,%0,)"::"a" (&GDTRegStruct2))
Code: Select all
struct GDTR
{
unsigned short Limit;
unsigned int Base;
}
GDTR GDTRegStruct2,GDTRegStruct1;
i think that bochs crash because of this problem.
whats problem?
I do not know that to do.
Re: Demo 15 Problem
Problem is resolved.
GCC align structure by size of the biggest field.
this is example
GCC compilier it to
GCC use .zero 3 for alignment.
If use directive __attribute__ ((packed)) GCC ignores alignment
for example
And the object file
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};
Code: Select all
test:
.long 10
.byte 20
.zero 3
.long 30
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};
Code: Select all
test:
.long 10
.byte 20
.long 30
Re: Demo 15 Problem
ahh. I forgot about alignment problems
a better method is to use "__attribute__((packet))" which will ensure that no padding happens
~Andrew
a better method is to use "__attribute__((packet))" which will ensure that no padding happens
~Andrew

Re: Demo 15 Problem
Isn't it "__attribute__((packed))"?Andyhhp wrote:ahh. I forgot about alignment problems
a better method is to use "__attribute__((packet))" which will ensure that no padding happens
~Andrew