cannot fire timer interrupt

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
goku
Member
Member
Posts: 29
Joined: Sat Oct 25, 2008 11:32 am
Location: until we meet again!!

cannot fire timer interrupt

Post by goku »

Hi
i am new to the world of osdev. read some tutorials and now following JamesM tutorial to get started with the initial learning phase. problem is that i cannot fire the timer interrupt.when i compile timer.c i am getting the following warning

timer.c: In function ‘init_timer’:
timer.c:16: warning: passing argument 2 of ‘register_interrupt_handler’ from incompatible pointer type

i ran the linked file using bochs and the output i am getting is :

unhandled interrupt: 0x6

i have cross checked the code with the source provided along with the tutorial but cannot find out what i am doing wrong.have attached my source files and also i am using gcc 4.2.4 and nasm to compile.

Any help guys.
Thanks

Mayank
Attachments
source.rar
(11.41 KiB) Downloaded 52 times
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: cannot fire timer interrupt

Post by jal »

mayankgrover wrote:unhandled interrupt: 0x6
Interrupt 6 is the invalid opcode exception. Most likely, you are hitting some random address, which'll contain invalid code. Try debugging your code in Bochs.


JAL
User avatar
goku
Member
Member
Posts: 29
Joined: Sat Oct 25, 2008 11:32 am
Location: until we meet again!!

Re: cannot fire timer interrupt

Post by goku »

Ok. i am not aware of how to use bochs debugger or gdb. have googled it and started reading some tutorial related to bochs debugging. meanwhile if anyone knows some nice tutorials or links from where i can learn about them do post.

Thanks
Mayank
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: cannot fire timer interrupt

Post by AJ »

Hi,

If you are using the timer interrupt (based on the original post, you are), it looks to me like your stack is getting corrupted somewhere in your IRQ handler. Check the assembly stub - do you have the same number of PUSHes and POPs (or do you add anything to ESP)?

The compilation warning looks very much like a simple type-casting issue. Check that you are passing the function the correct data type, and then apply the appropriate cast. Also check that you are at the right reference level (no extraneous '*' or '&' operator).

Cheers,
Adam
User avatar
goku
Member
Member
Posts: 29
Joined: Sat Oct 25, 2008 11:32 am
Location: until we meet again!!

Re: cannot fire timer interrupt

Post by goku »

AJ wrote:Check the assembly stub - do you have the same number of PUSHes and POPs (or do you add anything to ESP)?
i have checked the number of push and pops and seems there is no prob there. But i am not sure about the way IRQ's have been implemented in JamesMolloy tutorial. I think there are a few type errors because of which the program is going nuts. i would like if someone can conform whether there is some error specially with this:

Code: Select all

//isr.h
typedef void (*isr_t)(registers_t);
void register_interrupt_handler(u8int n, isr_t handler);
or if i am making a mistake.
AJ wrote:Check that you are passing the function the correct data type, and then apply the appropriate cast.
i am not sure of the data type becuase of the mentioned piece of code.not able to figure out what the typedef statement means. Any help.

Thanks
Mayank
User avatar
goku
Member
Member
Posts: 29
Joined: Sat Oct 25, 2008 11:32 am
Location: until we meet again!!

Re: cannot fire timer interrupt

Post by goku »

Hi
Problem solved. I was not sure about the way IRQ were being set up in James Molloy tutorial.So i refered to Bran's tutorial and used the method used for setting up the IRQ's. The only difference being in the way address of the timer handler function is passed to the interrupt_handler_register function. And it worked. Now i am convinced there is some type errors as i mentioned before.Changed my function defination to this

Code: Select all

void register_interrupt_handler(u8int n, void (*handler)(registers_t r));
and it worked.. =D>

Thanks
Mayank
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: cannot fire timer interrupt

Post by AJ »

Hi,

Glad you got it sorted out but I am a little concerned about the following:
mayankgrover wrote:i am not sure of the data type becuase of the mentioned piece of code.not able to figure out what the typedef statement means.
As you continue with OS dev, you will use lots of this kind of thing (function pointers, unusual use of casts and so on...). I would really suggest that you find a good language guide (either online or a book) so that you can familiarise yourself with those parts of the language you may not have used too much in the past. For this specific example:

Code: Select all

typedef void (*isr_t)(registers_t);
Defines a type of function pointer - the the function that has the prototype:

Code: Select all

void functionName(registers_t)
I would assume (without looking at your code or the tutorial) that registers_t is a type of pointer to a structure containing your general purpose and segment registers.

Cheers,
Adam
User avatar
goku
Member
Member
Posts: 29
Joined: Sat Oct 25, 2008 11:32 am
Location: until we meet again!!

Re: cannot fire timer interrupt

Post by goku »

Hi

Thanks alot AJ for the explanation and advice. I am sure i must have studied it in some textbook but these things do not click until you practice. I will certainly look it up on the net and rest assured i can add one more thing that i learned today.

Thanks once again....... :)

Mayank
Post Reply