Page 1 of 1

Double fault after initialize local apic

Posted: Fri Nov 19, 2021 1:57 pm
by michael
I've met a double fault after I initialized local apic and execute sti() instruction. What I did to initialize local apic is:

1. enable xapic and x2apic
2. enable local apic
3. mask all LVT registers (since my CPU platform is Pentium 4, it only has 6 LVT registers)

here is my code to mask all LVT register:

Code: Select all

__asm__ __volatile__(
		"movq $0x832,%%rcx	\n\t"//mask LVT Timer register 
		"wrmsr				\n\t"
		"movq $0x833,%%rcx	\n\t"//mask LVT Thermal Sensor register
		"wrmsr				\n\t"
		"movq $0x834,%%rcx	\n\t"//mask LVT Performance Monitoring register
		"wrmsr				\n\t"
		"movq $0x835,%%rcx	\n\t"//mask LVT LINT0 register
		"wrmsr				\n\t"
		"movq $0x836,%%rcx	\n\t"//mask LVT LINT1 register
		"wrmsr				\n\t"
		"movq $0x837,%%rcx	\n\t"//mask LVT Error register
		"wrmsr				\n\t"
		:
		:"a"(0x10000),"d"(0x00)
		:
		);
(I know it looks a little bit silly to use a lot of embedded assembly, but I just want to take a test over local apic)

After that, I execute sti() to set IF eflags to 1 and got a double fault. I suppose all the interrupt received by local apic was masked through LVT, but where did the first interrupt of double fault come from?

Re: Double fault after initialize local apic

Posted: Fri Nov 19, 2021 2:22 pm
by nullplan
Have you initialized (and disabled) the 8259 PIC pair? In the BIOS compatible configuration, the timer interrupt happens to be on INT 8, which is the double fault exception.

Re: Double fault after initialize local apic

Posted: Fri Nov 19, 2021 4:14 pm
by michael
nullplan wrote:Have you initialized (and disabled) the 8259 PIC pair? In the BIOS compatible configuration, the timer interrupt happens to be on INT 8, which is the double fault exception.
Yes, I've already disabled 8259 pic before setup my apic. And also, I've set the idt entries with vector numbers 0-20 to default exception and 32-55 with the interrupt handler, but it still turns out a double fault.

Re: Double fault after initialize local apic

Posted: Fri Nov 19, 2021 6:39 pm
by Octocontrabass
michael wrote:here is my code to mask all LVT register:
Your inline assembly clobbers RCX. This can cause other code to misbehave for no apparent reason.

Add RCX to the clobber list or write a wrmsr() function.