1

I'm trying to cross-compile a program (Yorick in case that's any use) to run on a LE ARM... I want to use feenableexcept() to catch SIGFPE... trouble is objdumping libraries for the target show no such symbol exists. Does anyone know if QNX libraries have an equivalent functionality? I've been googling around to find out about the QNX support for this with not much luck... all I can see is that in all the libraries for my target platform there is no feenableexcept symbol... Thanks!

UPDATE: I have found QNX has a library called fpemu, which looks interesting but only seems to exist for x86, mips and ppc... does anyone know if there is an ARM version?

Also probably of interest the chip im using is at91sam9263

UPDATE2: So having dub around it appears QNX has the following documentation on fenv.h. Based on this I have tried the following program...

#pragma STD FENV_ACCESS ON
#include <stdio.h>
#include <signal.h>
#include <fenv.h>

void signal_handler (int signo) {
    if(signo == SIGFPE) {
      printf("Caught FPE\n");
    }
}

int main(int argc, char *argv[])
{
    double d;
    fexcept_t enables;

    signal(SIGFPE,(*signal_handler));   

    enables = fegettrapenable();
    printf("The FP trap enable mask is 0x%X\n", enables);

    if( fesettrapenable(fegettrapenable() | FE_DIVBYZERO) )
    {
    printf("### ERROR could not set the FE enable mask\n");
        fexcept_t enables = fegettrapenable();
    printf("The FP trap enable mask is 0x%X\n", enables);
        return(-1);
    }

    printf("Floating point mask successfully set\n");
    enables = fegettrapenable();
    printf("The FP trap enable mask is 0x%X and FE_DIVBYZERO is 0x%X\n", enables, (int)FE_DIVBYZERO);

    d = 2.0 / 0.0;
    printf("For div by zero, got the result %e\n", d);
    printf("The exception test is %d\n", fetestexcept(FE_DIVBYZERO));


    printf("Testing feraiseexcpetion()\n");
    feraiseexcept(FE_DIVBYZERO);

    return 0 ;
}

Which gives me the following output....

The FP trap enable mask is 0x0
Floating point mask successfully set
The FP trap enable mask is 0x4 and FE_DIVBYZERO is 0x4
For div by zero, got the result inf **<<<< DAMN IT - no signal!!!!**
The exception test is 0
Testing feraiseexcpetion()
Caught FPE

Bugger!! It almost looked like it would work, except that the div by zero clearly does not raise SIGFPE... anyone know why?!

4

0 回答 0