operating system - Why do interrupts need to be disabled before switching to protected mode from real mode? -
i saw in many many oses (and bootloader), disable interrupt (cli
) before switch protected mode real mode. why need that?
bioses use pit interrupt (irq0) track time. enter protected mode, real mode interrupt handling no longer valid; cpu in protected mode requires protected mode idt (interrupt descriptor table). upon entering protected mode, idt limit in idtr (idt register) set 0 (any interrupt number makes cpu generate exception), pit (or else) generates interrupt, cpu generate exception, make exception generated, triggering #df (double fault) and, consequence, #tf (triple fault).
also, irq0 happening in protected mode trigger #de (divide exception) isr (interrupt service routine), interrupt vectors 0 31 reserved exceptions in protected mode.
so, (most probable, other interrupts pit might happen too) order of things happen (note: assumes pit interrupt triggered first, but, said before, can interrupt, each lead #df , triple fault):
- pe bit set in cr0.
- pit interrupt happens, pic (programmable interrupt controller) gets signal on it's pin #0.
- pic remapping isn't set, triggers irq0 on cpu.
- irq0 (= #de) attempts execute interrupt handler, idt's limit 0, (iirc) #gp (general protection fault) generated.
- idt's limit 0, #df generated.
- idt's limit 0, #tf generated.
- cpu either stops or reboots.
Comments
Post a Comment