[syslinux] com32: custom int3 handler

H. Peter Anvin hpa at zytor.com
Fri Nov 19 21:07:50 PST 2004


H. Peter Anvin wrote:
> Jeff Kalikstein wrote:
> 
>>
>>         __asm__("sidt (%0)" :: "r"(&idtr));
>>
>>         unsigned long *idt = (void*)idtr.base;
>>         idt[3] = int3_handler;
>>
> 
> Check the format of an IDT descriptor; this isn't it.
> 

Here is a function which should make a valid IDT entry.  Note that it's 
64 bits long, not 32.  "disable_int" controls if you want it to disable
interrupts when the trap is taken or not.

#include <stdint.h>

static inline uint64_t
make_idt_entry(uintptr_t handler, int disable_int)
{
	uint64_t v;
	uint16_t cs;

	asm("movw %%cs,%0" : "=rm" (cs));

	v  = handler & 0xffff;
	v |= (uint64_t)cs << 16;
	v |= (uint64_t)(disable_int ? 0x8E00 : 0x8F00) << 32;
	v |= (uint64_t)(handler & 0xffff0000) << 32;

	return v;
}




More information about the Syslinux mailing list