www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/28/19:49:24

Xref: news2.mv.net comp.os.msdos.djgpp:7981
From: "Mike Marcelais" <michmarc AT microsoft DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Random crashes under DJ with interrupt handlers
Date: 28 Aug 1996 20:05:47 GMT
Organization: Microsoft Corporation
Lines: 104
Message-ID: <01bb951c$f492b9a0$ba27379d@michmarc2>
NNTP-Posting-Host: 157.55.39.186
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Okay...I've read the DJGPP interrupt guides, I've done real mode interrupt
handlers before with no problem, and now I want to do a simple protected mode
interrupt thing.  But it doesn't work.

Symptom: The code works fine right up until I hook the clock interrupt.  Then
it immediately crashes with an error.  The error is not consistant; I've seen
`Bound Check', `General Protection Fault', `Stack Fault', `Page Fault', etc.

Symify won't help (I can't get it to put symbols there and I don't think it
helps much because there is no stack trace except for the crash address).  The
list of registers shows that CS is the programs CS, but all of the other
registers are the same, and are -not- my programs initial DS or SS.

The interrupt routines works correctly if called directly, so it's not the
code inside that hurts.

Environment: Win95, but also happens in exclusive mode (usually resulting in a
complete system lock).  The code also uses the FastGraph graphics library,
which (in the shareware version) makes interrupt requests to a TSR (real mode)
driver to do the work.  [This is actually good since FG doesn't have a DJGPP
compatable compile time library.]  I wrote the stub functions for this TSR
based on the information in Ralf's Interrupt list and they work correctly.

Code that breaks:  I seem to be doing things right...what am I missing?

/* I'm listing this stub function here because I call it during my interrupt
loop */
void fg_setrgb(int number, int red, int green, int blue)
{
   REGS r;

   r.x.ax = 0x00B3;
   r.x.bx = number;
   r.x.cx = red;
   r.x.dx = green;
   r.x.si = blue;

   int86(0x62,&r,&r);
};

unsigned char col = 60;
signed char dir = -4;

void cycleColors(void)
{
   /* This is the interrupt routine */
   col += dir;
   if ((col == 0) || (col == 60))
      dir = -dir;

   fg_setrgb(1,col,0,0);
   fg_setrgb(2,0,0,col);
};

int main(void)
{
   printf("Segments: CS: %04x  DS: %04x  SS: %04x\n",_go32_my_cs(),
          _go32_my_ds(), _go32_my_ss());

   fg_initpm();
   if (fg_svgainit(0)==0)
      {
      printf("No SVGA available.\n");
      return(0);
      };

   fg_setmode(25);

   /* Etc, draw some stuff on the screen this all works */

   getch();  /* NOTE: I do get to here */

   /* Lock my code */
   _go32_dpmi_lock_code(cycleColors, (void *)main-(void *)cycleColors);
   _go32_dpmi_lock_data(&col, sizeof(col));
   _go32_dpmi_lock_data(&dir, sizeof(dir));

   /* Install the interrupt handlers */
   _go32_dpmi_seginfo old_handler, new_handler;

   _go32_dpmi_get_protected_mode_interrupt_vector(0x08,&old_handler);
   new_handler.pm_offset = _go32_my_cs();
   new_handler.pm_selector = (int)cycleColors;
   _go32_dpmi_chain_protected_mode_interrupt_vector(0x08,&new_handler);

   /* Let you watch the demo */
   getch();

   /* Shutdown */
   _go32_dpmi_set_protected_mode_interrupt_vector(0x08, &old_handler);

   fg_setmode(3);
   return(0);
};


-- 
+------------------------+----------------------+
| Mike Marcelais         | Excel Developer and  |
| michmarc AT microsoft DOT com | Magic Rules Guru     |
+------------------------+----------------------+
| Opinions expressed in this post are mine, and |
| do not necessarily reflect those of Microsoft |
+--= Moonstone Dragon =---------------= UDIC =--+

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019