[syslinux] com32: custom int3 handler
Jeff Kalikstein
jeff at kalikstein.com
Mon Nov 22 08:10:46 PST 2004
--- "H. Peter Anvin" <hpa at zytor.com> wrote:
> At the simplest, this could
> look like:
>
> .globl int3_entry
> .type int3_entry, @function
> int3_entry:
> pushal
> call int3
> popal
> iret
> .size int3_entry, .-int3_entry
>
Call me stubborn, but I just really like keeping my
code inside of C files. I took your suggestion above
and hacked it into the following (which works!):
void init_handlers()
{
__asm__(
"jmp int3_entrydone \n"
// the symbol below will not be visible to the C
code,
// so we will calculate it from the start of
init_handlers.
// The symbol is placed here, so it can be seen from
the
// disassembly of the .elf file
"int3_entry: \n"
"pusha \n"
"call int3_handler \n"
"popa \n"
"iret \n"
"int3_entrydone: \n");
struct {
unsigned long limit : 16;
unsigned long base : 32;
} __attribute__((packed)) idtr;
struct {
unsigned long off_low : 16;
unsigned long cs : 16;
unsigned long reserved : 8;
unsigned long type : 4;
unsigned long zero : 1;
unsigned long dpl : 2;
unsigned long present : 1;
unsigned long off_high : 16;
} __attribute__((packed)) *idt;
__asm__("sidt (%0)" :: "r"(&idtr));
idt = (void*)idtr.base;
unsigned short cs;
__asm__("movw %%cs,%0" : "=rm" (cs));
// int3_entry calculation based on disassembly of
inline entry
// code, above
unsigned long int3_entry = (unsigned
long)init_handlers + 5;
idt[3].off_low = (unsigned long)int3_entry;
idt[3].off_high = (unsigned long)int3_entry >> 16;
idt[3].cs = cs;
idt[3].type = 0xe; // 32-bit trap gate
idt[3].dpl = 0x3;
idt[3].present = 1;
idt[3].reserved = 0;
idt[3].zero = 0;
put_str("trying int3");
__asm__("int3");
put_str("DONE!");
}
I couldn't figure out how to let the gcc inline
assembler export it's labels to the rest of the C
code, so you see the ugly little hack I did there. Is
there a better way? I'm pretty new to this low level
gcc stuff, and I really appreciate your insight.
> I don't want to turn all of this into API functions,
> because a) I think
> it's a rare need, b) it can be done without code in
> syslinux, and c) I
> think it's asking for people who don't understand
> the limitations to try
> to use it.
I understand and respect your syslinux design and
implementation decisions. I think syslinux is one of
the slickest open-source projects around. Thanks!
More information about the Syslinux
mailing list