Double fault after initialize local apic

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
michael
Posts: 12
Joined: Fri Nov 12, 2021 1:09 am

Double fault after initialize local apic

Post 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?
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Double fault after initialize local apic

Post 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.
Carpe diem!
michael
Posts: 12
Joined: Fri Nov 12, 2021 1:09 am

Re: Double fault after initialize local apic

Post 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.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Double fault after initialize local apic

Post 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.
Post Reply