How call a software interrupt?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pepito

How call a software interrupt?

Post by pepito »

How can I call a software interrupt from C (djgpp) working in protected mode?
It is available the funcition int86()?

Thank you
carbonBased

RE:How call a software interrupt?

Post by carbonBased »

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
pepito

RE:How call a software interrupt?

Post by pepito »

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".
Tim Robinson

RE:How call a software interrupt?

Post by Tim Robinson »

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) )
pepito

RE:How call a software interrupt?

Post by pepito »

Thank you very much for every body.
Post Reply