I've managed to setup a performance monitoring counter (PMC) and make it generate an APIC interrupt when it overflows.
In the Intel manuals is stated that when interrupted by a counter overflow, the (PMC) interrupt handler needs to perform the following actions:
- • Save the instruction pointer (EIP register), code-segment selector, TSS segment selector, counter values and other relevant information at the time of the interrupt.
• Reset the counter to its initial setting and return from the interrupt.
My PMC handler is actually executed when the counter overflows (I've verified this by a printf) but the processor generates a "General Protection Fault" when it returns from the PMC handler.
A second question is referred to the stub exception handler. In Intel manuals is stated that the steps required (by the OS) for being able to generate a local APIC interrupt when a performance-monitoring counter overflows are the following:
- 1) Provide an interrupt vector for handling the counter-overflow interrupt.
2) Initialize the APIC PERF local vector entry to enable handling of performance monitor counter overflow events.
3) Provide an entry in the IDT that points to a stub exception handler that returns without executing any instructions.
4) Provide an event monitor driver that provides the actual interrupt handler and modifies the reserved IDT entry to point to its interrupt routine.
Thank you all in advance.