www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/05/16:23:31

Xref: news2.mv.net comp.os.msdos.djgpp:8318
From: Matthias Grimrath <y0001032 AT ws DOT rz DOT tu-bs DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: divide by zero under win95
Date: Thu, 05 Sep 1996 17:23:36 +0200
Organization: TU-Braunschweig, Rechenzentrum
Lines: 47
Distribution: world
Message-ID: <322EF078.4CBD@ws.rz.tu-bs.de>
References: <50f6p1$16gc AT news DOT missouri DOT edu>
NNTP-Posting-Host: rz0cosv2.rz.tu-bs.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

c533483 AT showme DOT missouri DOT edu wrote:
> 
> The following code to catch a divide by zero interrupt works perfectly under
> DOS, but fails under win95.  I would prefer to use win95 than have to go out
> to DOS everytime to run my program.  If anyone out there has experience and
> can offer me some help in trying to fix it, I would appreciate it.

Under DPMI there is a difference between exceptions and interrupts. (Though
this difference is artificial, since the CPU doesn't distinguish between them)

A divide by zero error is treated as an exception. If you want to catch it,
try __dpmi_set_exception_anything (can't remember). Your handler must far
return, if I remember right. For details take a look at the DPMI specs.

Another way would be to use signals, but I don't anything about them except
they exist.

Try this out, maybe it works:

void divide_overflow(void)
{
__asm__
(
"       popl    %ebp
        cmpl    $0, %ebx                
        jz      1f                      
        shll    $4, %ebx                
        lret                            
1:	movl    $0x00000001, %ebx       
        lret                            "
);
}

void set_divide_interrupt(void)
{
__dpmi_paddr    new_vector;
__dpmi_get_exception_handler(0x00, &old_interrupt_vector);

new_vector.selector = _go32_my_cs();
new_vector.offset32 = (long)divide_overflow;
__dpmi_set_exception_handler(0x00, &new_vector);
}

void restore_divide_interrupt(void)
{
__dpmi_set_exception_handler(0x00, &old_interrupt_vector);
}

- Raw text -


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