views:

78

answers:

1

As the Intel Manual illustrated, both Interrupt Gate and Trap Gate can be used to access a handler routine. And some exceptions even share vector numbers with interrupts. I am wondering when such a shared vector is detected by the CPU, how could CPU know whether it stands for an exception or an interrupt?

I am kind of confused about the logic among the following things:

(1) the decision of the gate types in the IDT

(2) the judgement of whether the vector stands for an exception or an interrupt

(1) and (2), which decides which?

I hope I made myself clear...

Update 1

Thanks for nos' reply. Do you mean I have to tell CPU which vector stands for an Interrupt or Trap? I know that CPU treat EFLAGS[IF] differently with regards to Interrupt and Trap, how does CPU know how to make this decision? Does CPU make decision based on the type fields of the IDT entry corresponding to the vector? Or rather it depends on how the system is wired up and we must set the type of the IDT entry according to that? i.e. Is the type fileds totally an illustration for us or imperative to the CPU?

and a related question: http://stackoverflow.com/questions/3425085/the-difference-between-call-gate-interrupt-gate-trap-gate

+1  A: 

You have to program the CPU as to what is an interrupt gate and what is a trap gate for a given ISR.

This is set by bit 40-43 in an IDT entry. Info here: http://wiki.osdev.org/Interrupt_Descriptor_Table

nos
Thanks for your reply. Do you mean I have to tell CPU which vector stands for an Interrupt or Trap? I know that CPU treat EFLAGS[IF] differently with regards to Interrupt and Trap, how does CPU know how to make this decision? Does CPU make decision based on the type fields of the IDT entry corresponding to the vector? Or rather it depends on how the system is wired up and we must set the type of the IDT entry according to that? i.e. Is the type fileds totally an illustration for us or imperative to the CPU?
smwikipedia
Yes, you have to tell the system if it's a trap or an interrupt. I believe the only real difference is that an interrupt will automatically disable interrupts for you while it's running and a trap will not, meaning you usually want to use an interrupt gate to handle hardware interrupts. The entry in the IDT is what's used, so you could set it to a trap gate and have it handle a hardware interrupt though.
nos