When to use Interrupt Gate or Trap Gate?
Asked Answered
P

1

2

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:

  • the decision of the gate types in the IDT

  • the judgement of whether the vector stands for an exception or an interrupt

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: The difference between Call Gate, Interrupt Gate, Trap Gate?

Pupiparous answered 9/8, 2010 at 16:42 Comment(1)
Possible duplicate of The difference between Call Gate, Interrupt Gate, Trap Gate?Benefit
P
1

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

Pulliam answered 9/8, 2010 at 17:2 Comment(2)
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?Pupiparous
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.Pulliam

© 2022 - 2024 — McMap. All rights reserved.