delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/21/12:30:55

From: Erik Berglund <erik2 DOT berglund AT telia DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: GPF with system() and clock int.
Lines: 99
Message-ID: <FG_d5.95$tab.135467008@newsb.telia.net>
Date: Fri, 21 Jul 2000 16:15:33 GMT
NNTP-Posting-Host: 194.237.158.30
X-Complaints-To: abuse AT telia DOT com
X-Trace: newsb.telia.net 964196133 194.237.158.30 (Fri, 21 Jul 2000 18:15:33 CEST)
NNTP-Posting-Date: Fri, 21 Jul 2000 18:15:33 CEST
Organization: Telia Internet
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi, today I tried the program tu20.c, included below.
It is part of my own IDE tool, much like Borland's Turbo Pascal.
The problem is that the program almost works, but sometimes
I get a GPF (see below).

I have not the slightest idea why this is happening.
Am I missing something in the coding? When the clock tick
frequency is set to 16x, the error shows up more frequently
(after 4-5 runs).

Without the clock interrupt everything works fine,
but I would like to use the clock interrupt for updating
a counter on the screen, as something similar to
"Line Number" in Turbo Pascal.

Without the "system()" call everything runs OK,
so it seems that it is the combination of "system()"
and clock interrupts that doesn't work.

As a work around solution, I have tried a 16-bit Turbo
Pascal TSR program which updates the screen in background,
and it seems to work.

gcc version is 2.7.2.1, DJGPP is 2.01, OS is plain DOS 6.22,
CSWDPMI version is r4, CPU is Pentium Pro 200 MHz, 128 Mb RAM.

Thank you for any ideas,

--

Erik Berglund
erik2 DOT berglund AT telia DOT com

-- Start of tu20.c --
#include <crt0.h>
#include <sys/farptr.h>
#include <go32.h>
#include <dpmi.h>
#include <pc.h>
#include <stdlib.h>

#define  textseg 0xb800
#define  numch 7
int      _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;
static   int int08flag;
/*
*  int08 - Clock interrupt service routine.
*          If int08flag=1, update counter on screen.
*/
void int08() {
static int cnt,i,j;
static char st[numch];

   if (!int08flag) cnt = 0;      /* Idle */
   else {                        /* Counting */
      cnt = cnt + 1;
      i   = cnt*56;
      for (j=0; j<numch; j++) {  /* Convert counter to string */
         st[numch-j-1] = (i % 10) + '0';
         if ((i == 0) && (j > 0)) st[numch-j-1] = ' ';
         i = i / 10;
      }
      for (j=0; j<numch; j++)    /* Write string to screen */
         _farpokeb(_dos_ds,textseg*16+(53+j+12*80)*2,st[j]);
   }
}
/*
*  Main program - Compile itself, and at the same time
*                 update counter on screen.
*/
int main(int argc,unsigned char *argv[]) {
static _go32_dpmi_seginfo oldint08,newint08;

   _go32_dpmi_get_protected_mode_interrupt_vector(0x08,&oldint08);
   newint08.pm_selector = _my_cs();
   newint08.pm_offset   = (unsigned)&int08;
   _go32_dpmi_chain_protected_mode_interrupt_vector(0x08,&newint08);
   outportb(0x40,0x00);  /* Setting 16x clock tick frequency */
   outportb(0x40,0x10);  /* ...will trigger the error easily */
   int08flag = 1;
   system("gcc -o tu20.exe tu20.c -s");  /* Compile itself */
   int08flag = 0;
   outportb(0x40,0x00);  /* Reset clock tick frequency */
   outportb(0x40,0x00);
   _go32_dpmi_set_protected_mode_interrupt_vector(0x08,&oldint08);
   return(0);
}
-- End of tu20.c --

-- Error message -- 
Page Fault cr2=82828408 in RMCB at eip=fff8; flags=3006
eax=00010080 ebx=00001a45 ecx=000010b6 edx=0033003b esi=00000009 edi=000010d9
ebp=0000208c esp=0000203c cs=e7 ds=3b es=33 fs=33 gs=ff ss=33 error=0004
General Protection Fault in RMCB at eip=405a; flags=3046
eax=01a94c00 ebx=000100a7 ecx=00000015 edx=00016500 esi=000010b6 edi=10000000
ebp=00000000 esp=00001120 cs=2b ds=33 es=8f fs=0 gs=0 ss=33 error=0000
-- End of error message --


- Raw text -


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