Strange thing about IDT

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Strange thing about IDT

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

Code: Select all

printk("****!");
Immediately before 'asm("sti");'
and... It worked...
So now I wrote:

Code: Select all

printk("");
and it continues to work...
Why????????
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Pull every line of code out of printk() until it breaks again. Then you've found your problem.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post 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...
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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 ;).
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

MarkOS: Please re-read my answer. You have not understood it.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

JamesM wrote:MarkOS: Please re-read my answer. You have not understood it.
What must I pull out?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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!
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post 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!
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post 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...
Post Reply