Dual core APIC Timer issue
Posted: Wed Dec 26, 2007 8:07 pm
Hello OS Gurus,
I'm facing some problems with the local-APIC timer.
My config is tyan s2881/dual-core opteron. The second core is masked from Linux OS along
with a piece of memory.
As soon as this AP core is initialized, I'm launching a tiny OS to run on it. This OS has its
own gdt and idt. I've hooked an ISR to be called during local APIC timer interrupts.
The AP core gets the timer interrupt and its handler gets called. But the BSP core also gets
an interrupt and reboots.
I'd assume that the local-APIC's interrupt should not be broadcast.
Same story when I set the local-apic timer to "no interrupts and periodic mode". The BSP core
gets a reset.
However, when I make this as a standalone kernel like PyrOS and
boot with grub in a floppy, it gets executed in the BSP core and runs fine.
Any help will be highly appreciated.
serial out
Welcome to xxxx_OS
.......
apic_id= 1
Apic Ver= 16
maxLVT =4
currentCount = 0xFFFF8C57
### recvd SW interrupt: 80 (APIC int handler)
Here is the APIC code:
The IDT hook:
int handler:
isr entry:
I'm facing some problems with the local-APIC timer.
My config is tyan s2881/dual-core opteron. The second core is masked from Linux OS along
with a piece of memory.
As soon as this AP core is initialized, I'm launching a tiny OS to run on it. This OS has its
own gdt and idt. I've hooked an ISR to be called during local APIC timer interrupts.
The AP core gets the timer interrupt and its handler gets called. But the BSP core also gets
an interrupt and reboots.
I'd assume that the local-APIC's interrupt should not be broadcast.
Same story when I set the local-apic timer to "no interrupts and periodic mode". The BSP core
gets a reset.
However, when I make this as a standalone kernel like PyrOS and
boot with grub in a floppy, it gets executed in the BSP core and runs fine.
Any help will be highly appreciated.
serial out
Welcome to xxxx_OS
.......
apic_id= 1
Apic Ver= 16
maxLVT =4
currentCount = 0xFFFF8C57
### recvd SW interrupt: 80 (APIC int handler)
Here is the APIC code:
Code: Select all
/*Credits: taken from spoon microkernel and pyrOS*/
void load_apic( int cpu_id )
{
unsigned long decrease,currentCount=0;
unsigned int m;
// Software enable the local APIC
APIC_WRITE( APIC_spurious, ((1<<8 ) | (APIC_INTERRUPT + 15)) );
#if 1 // no intr
/* Set the divider to 1, no divider */
APIC_WRITE(APIC_TIMERdivider, APIC_TIMERdivideBy1);
/* Set the initial counter to 0xffffffff */
APIC_WRITE(APIC_TIMERinitialCount, 0xffffffff);
/* Set the apic timer to no interrupts and periodic mode */
APIC_WRITE(APIC_LVTtimer, (1 << 17)|(1<< 16)|(0 << 12)|(0 << 0)); //no interrupt
#else // intr mode
APIC_WRITE( APIC_LVTtimer, APIC_INTERRUPT );
APIC_WRITE( APIC_TIMERdivider, APIC_TIMERdivideBy128 );
// Starts it counting down..
APIC_WRITE( APIC_TIMERinitialCount, 0xFFFFFFFF );
for(m=0;m<699999;m++) // approx 50 ms
{
;
}
currentCount = APIC_READ( APIC_TIMERcurrentCount );
decrease = 0xFFFFFFFF - currentCount;
APIC_WRITE( APIC_TIMERdivider, APIC_TIMERdivideBy16 );
APIC_WRITE( APIC_TIMERinitialCount, (unsigned int)decrease );
/* Set the apic timer to interrupt and periodic mode */
APIC_WRITE( APIC_LVTtimer, (1 << 17)|(0<< 16)|(0 << 12)|APIC_INTERRUPT);
#endif // if 0
}
void microdelay(unsigned microsecs)
{
unsigned long start, value, ticks;
/* Calculate the number of ticks to run, our FSB runs a 200Mhz */
ticks = microsecs * 200;
start = APIC_READ(APIC_TIMERcurrentCount);
do {
value = APIC_READ(APIC_TIMERcurrentCount);
} while((start - value) < ticks);
}Code: Select all
....
idt_set_gate(80, (unsigned)apic_isr1, 0x08, 0x8E); // test apic isr hook 0x50
idt_set_gate(95, (unsigned)apic_isr15, 0x08, 0x8E); // test apic isr
...int handler:
Code: Select all
void apic_isr_handler(struct REGS *r)
{
serialOut("### recvd APIC interrupt: %d",r->int_no);
if(r->int_no >= 80)
{
APIC_SET( APIC_endOfInterrupt, 0 );
}
}Code: Select all
.type apic_isr1,@function
apic_isr1:
push $0
push $80
jmp sw_isr_common
.................