Real Mode Interrupts

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
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Real Mode Interrupts

Post by Jeko »

What can I do with int 31 in Protected Mode? I see this code in a program working in PM:

Code: Select all

/* register data for calling real mode interrupts (DPMI format) */
typedef union 
{
   struct {
      unsigned long edi;
      unsigned long esi;
      unsigned long ebp;
      unsigned long res;
      unsigned long ebx;
      unsigned long edx;
      unsigned long ecx;
      unsigned long eax;
   } d;
   struct {
      unsigned short di, di_hi;
      unsigned short si, si_hi;
      unsigned short bp, bp_hi;
      unsigned short res, res_hi;
      unsigned short bx, bx_hi;
      unsigned short dx, dx_hi;
      unsigned short cx, cx_hi;
      unsigned short ax, ax_hi;
      unsigned short flags;
      unsigned short es;
      unsigned short ds;
      unsigned short fs;
      unsigned short gs;
      unsigned short ip;
      unsigned short cs;
      unsigned short sp;
      unsigned short ss;
   } x;
   struct {
      unsigned char edi[4];
      unsigned char esi[4];
      unsigned char ebp[4];
      unsigned char res[4];
      unsigned char bl, bh, ebx_b2, ebx_b3;
      unsigned char dl, dh, edx_b2, edx_b3;
      unsigned char cl, ch, ecx_b2, ecx_b3;
      unsigned char al, ah, eax_b2, eax_b3;
   } h;
} RM_REGS;

void rm_int(int num, RM_REGS *regs)
{
   regs->x.flags = 0;
   regs->x.sp = 0;
   regs->x.ss = 0;

   asm (
      " int $0x31 "
   :

   : "a" (0x300),
     "b" (num),
     "c" (0),
     "D" (regs)

   : "%eax", 
     "%ebx", 
     "%ecx", 
     "%edx", 
     "%esi", 
     "%edi"
   );
}
The rm_int function doesn't compile.
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

You may want to try to split your structures up a bit.
try:

Code: Select all

struct {
      unsigned long edi;
      unsigned long esi;
      unsigned long ebp;
      unsigned long res;
      unsigned long ebx;
      unsigned long edx;
      unsigned long ecx;
      unsigned long eax;
   } D;

   struct {
      unsigned short di, di_hi;
      unsigned short si, si_hi;
      unsigned short bp, bp_hi;
      unsigned short res, res_hi;
      unsigned short bx, bx_hi;
      unsigned short dx, dx_hi;
      unsigned short cx, cx_hi;
      unsigned short ax, ax_hi;
      unsigned short flags;
      unsigned short es;
      unsigned short ds;
      unsigned short fs;
      unsigned short gs;
      unsigned short ip;
      unsigned short cs;
      unsigned short sp;
      unsigned short ss;
   } X;

   struct {
      unsigned char edi[4];
      unsigned char esi[4];
      unsigned char ebp[4];
      unsigned char res[4];
      unsigned char bl, bh, ebx_b2, ebx_b3;
      unsigned char dl, dh, edx_b2, edx_b3;
      unsigned char cl, ch, ecx_b2, ecx_b3;
      unsigned char al, ah, eax_b2, eax_b3;
   } H;

typedef union
{
   struct D d;
   struct X x;
   struct H h;
} RM_REGS; 
and make sure you have

Code: Select all

#define asm __asm__ __volatile__
But quickly reading over the code and without knowing what error the compiler is giving you, I don't know your problem for sure.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

the error is on this line:

Code: Select all

   asm ( 
      " int $0x31 " 
   : 

   : "a" (0x300), 
     "b" (num), 
     "c" (0), 
     "D" (regs) 

   : "%eax", 
     "%ebx", 
     "%ecx", 
     "%edx", 
     "%esi", 
     "%edi" 
   ); 
Now I can't give you the error that the compiler give me
ntfs
Posts: 19
Joined: Tue Dec 12, 2006 9:55 am
Location: Czech Republic Prague

DMPI....

Post by ntfs »

INT 31 is used to acces DPMI(Dos protected mode interface). It is used under DOS and Win9x by apps to get to protected mode and then to make operations like changing memory selectors etc and also calling RM interrupts. But it's a Dossish thing, so hands away.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: DMPI....

Post by Jeko »

ntfs wrote:INT 31 is used to acces DPMI(Dos protected mode interface). It is used under DOS and Win9x by apps to get to protected mode and then to make operations like changing memory selectors etc and also calling RM interrupts. But it's a Dossish thing, so hands away.
ok thank you!
Post Reply