admin管理员组

文章数量:1405543

When switching from real mode to i386 32-bit protected mode, what is the practical difference between not setting an IDT (i.e. not running an lidt instruction) or setting an empty IDT?

Which one is more useful, and which one should I do?

When switching from real mode to i386 32-bit protected mode, what is the practical difference between not setting an IDT (i.e. not running an lidt instruction) or setting an empty IDT?

Which one is more useful, and which one should I do?

Share Improve this question asked Mar 22 at 2:38 ptspts 87.7k23 gold badges115 silver badges198 bronze badges 1
  • 1 One of the most valuable things I did was to create reliable fault handlers that print useful information. It's so much easier to debug when you get a fault code and register dump instead of a hang or instant reboot. – prl Commented Mar 22 at 21:12
Add a comment  | 

1 Answer 1

Reset to default 5

There's no practical difference. If you don't enable interrupts or cause any exceptions, then it's moot because the CPU will never use the IDT. If you do, then both cases will result in failure.

Specifically, an interrupt or exception occurring when the IDT is empty (limit of 0) will cause a triple fault and reset the CPU. If you leave IDTR uninitialized, it is possible in principle that it's pointing to something that resembles a valid IDT enough that the CPU would actually jump somewhere if an interrupt or exception occurred, and you'd execute whatever garbage that happened to be. More likely, it doesn't, and an interrupt or exception would just cause a triple fault as before.

So in practice, you must leave interrupts disabled, and avoid causing any exceptions, until you have set up a real (non-empty) interrupt descriptor table. Until then, it's irrelevant what you do with the IDTR, so you might as well not bother to initialize it.

本文标签: x86Why set or not set the IDT when switching to protected modeStack Overflow