Page 1 of 1
Strange thing about IDT
Posted: Sat Mar 01, 2008 3:55 am
by Jeko
I was programming the interrupt handling functions, more precisely the IDT, when a strange thing happened.
My code wasn't working:
Code: Select all
struct idt_t {
unsigned short offset0_15;
unsigned short segment;
unsigned short reserved : 5;
unsigned short options : 11;
unsigned short offset16_31;
};
struct idt_t idt[256];
asm("cli");
... //Here each entry in the IDT
... //is initialized
unsigned int idt_reg[2];
idt_reg[0] = (256*8) << 16;
idt_reg[1] = (unsigned int)idt;
__asm__ __volatile__ ("lidt (%0)": :"g" ((char*)idt_reg+2));
asm("sti");
Then I was very angry after a lot of tests and I wrote:
Immediately before 'asm("sti");'
and... It worked...
So now I wrote:
and it continues to work...
Why????????
Posted: Sat Mar 01, 2008 8:00 am
by JamesM
Pull every line of code out of printk() until it breaks again. Then you've found your problem.
Posted: Sat Mar 01, 2008 12:55 pm
by Jeko
JamesM wrote:Pull every line of code out of printk() until it breaks again. Then you've found your problem.
Maybe I hadn't explained very well...
If I insert a printk, also with an empty string, my code works and exceptions a re handled.
If I don't insert a printk, bochs (and also real computers) reboots...
This is the log of bochs when there isn't printk:
Code: Select all
00005787616i[CPU0 ] >> mov word ptr ds:0xe00b8000, 0x0009 : 66C70500800BE00900
00005787616e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
When there is the printk:
Code: Select all
//On the screen is written: "Page fault exception"
00005768624i[CPU0 ] WARNING: HLT instruction with IF=0!
So it works with the printk and not without the printk...
Posted: Sat Mar 01, 2008 4:52 pm
by pcmattman
What's *AFTER* the printk?
Looks to me like there might be dud code executing after the asm( "sti" ); which your printk stops thanks to a page fault
.
Posted: Sun Mar 02, 2008 3:03 am
by JamesM
No, you explained yourself well, and my answer still stands.
Some line(s) of code in printk are changing the result. So go through it and pull out everything until it breaks again. Then you know what it causing it.
Unfortunately too often in OSDev we use intrusive methods of debugging, and this is one of the consequences.
Posted: Sun Mar 02, 2008 4:21 am
by Jeko
JamesM wrote:No, you explained yourself well, and my answer still stands.
Some line(s) of code in printk are changing the result. So go through it and pull out everything until it breaks again. Then you know what it causing it.
Unfortunately too often in OSDev we use intrusive methods of debugging, and this is one of the consequences.
But with printk it doesn't break. With printk my exception handler works fine. Without printk my exception handler doesn't work.
Edit: my printk is based on your monitor_write
Posted: Sun Mar 02, 2008 7:48 am
by JamesM
MarkOS: Please re-read my answer. You have not understood it.
Posted: Sun Mar 02, 2008 11:01 am
by Jeko
JamesM wrote:MarkOS: Please re-read my answer. You have not understood it.
What must I pull out?
Posted: Sun Mar 02, 2008 11:26 am
by JamesM
I'll say it again. Remove every line from printk, until you find the line that causes your function to stop breaking. Then you will know how to fix it!
Posted: Sun Mar 02, 2008 11:36 am
by Jeko
JamesM wrote:I'll say it again. Remove every line from printk, until you find the line that causes your function to stop breaking. Then you will know how to fix it!
ah now I understand!
Sorry but I don't know english very well...sorry!
Posted: Sun Mar 02, 2008 11:41 am
by Jeko
ehm...
Now it's very very strange...
I commented all the function printk:
Code: Select all
void printk(char *format, ...)
{
/*unsigned int curchar, varnumber=0, curpos=0;
unsigned char *tmp;
va_list pt = pt; //Serve solo ad eliminare un warning (probabilmente)
while((curchar = format[curpos++]))
if(curchar == '%')
varnumber += 1;
if(varnumber)
va_start(pt, format);
while((curchar = *format++)) { //Loop attraverso la stringa
switch(curchar) {
case '%':
curchar = *format++;
switch(curchar) {
case 'd':
case 'l':
print_dec((int)va_arg(pt, int));
break;
case 'u':
print_unsigned((unsigned int)va_arg(pt, unsigned int));
break;
case 'f':
print_float((float)va_arg(pt, float));
break;
case 'b':
print_binary(va_arg(pt, unsigned int));
break;
case 'x':
print_hex(va_arg(pt, unsigned int));
break;
case 's':
tmp = va_arg(pt, unsigned char *);
print_string(tmp);
break;
case 'c':
putc(va_arg(pt, unsigned char));
break;
}
break;
default:
putc(curchar);
}
}
va_end(pt);*/
}
and...it continues to work. Without the all commented printk, it doesn't work...