How can I call a software interrupt from C (djgpp) working in protected mode?
It is available the funcition int86()?
Thank you
How call a software interrupt?
RE:How call a software interrupt?
You can use int86 to call _real mode_ interrupts, but this is going to require a DPMI interface, which your OS has, no doubt, not implemented (there's very little reason to).
Alternatively, you can use asm:
__asm__("int $0x20");
Which will call a protected mode interrupt (ie, int 32). You'll have to have a proper IDT entry for the handler, though, of course.
Jeff
Alternatively, you can use asm:
__asm__("int $0x20");
Which will call a protected mode interrupt (ie, int 32). You'll have to have a proper IDT entry for the handler, though, of course.
Jeff
RE:How call a software interrupt?
Thank you, I am doing it this way but I like to write a rutine that recieves an interrupt number as parameter, I have it:
struct regs_386 { unsigned long int eax;
unsigned long int ebx;
unsigned long int ecx;
unsigned long int edx; };
void interrupcion (char vector, struct regs_386 * r) {
asm("int %8\n\t" :
"=q" ((*r).eax),
"=q" ((*r).ebx),
"=q" ((*r).ecx),
"=q" ((*r).edx):
"a" ((*r).eax),
"b" ((*r).ebx),
"c" ((*r).ecx),
"d" ((*r).edx),
"I" (vector) ); }
But I have a problem with the constant value "I".
struct regs_386 { unsigned long int eax;
unsigned long int ebx;
unsigned long int ecx;
unsigned long int edx; };
void interrupcion (char vector, struct regs_386 * r) {
asm("int %8\n\t" :
"=q" ((*r).eax),
"=q" ((*r).ebx),
"=q" ((*r).ecx),
"=q" ((*r).edx):
"a" ((*r).eax),
"b" ((*r).ebx),
"c" ((*r).ecx),
"d" ((*r).edx),
"I" (vector) ); }
But I have a problem with the constant value "I".
RE:How call a software interrupt?
This won't work, because you can't pass a variable to the INT instruction. You will need to hard-code it, use self-modifying code to patch the interrupt number at run time, or implement 256 different interrupt functions.
If I were you I'd embed __asm__("int ...") statements in the code itself, or implement this as a macro:
#define interrupcion (vector, r) \
\
asm("int %8\n\t" :\
"=q" ((*r).eax),\
"=q" ((*r).ebx),\
"=q" ((*r).ecx),\
"=q" ((*r).edx):\
"a" ((*r).eax),\
"b" ((*r).ebx),\
"c" ((*r).ecx), \
"d" ((*r).edx),\
"I" (vector) )
If I were you I'd embed __asm__("int ...") statements in the code itself, or implement this as a macro:
#define interrupcion (vector, r) \
\
asm("int %8\n\t" :\
"=q" ((*r).eax),\
"=q" ((*r).ebx),\
"=q" ((*r).ecx),\
"=q" ((*r).edx):\
"a" ((*r).eax),\
"b" ((*r).ebx),\
"c" ((*r).ecx), \
"d" ((*r).edx),\
"I" (vector) )