/*
 * Set the Cirrus Logic MaverickCrunch's ISAT bit in the DSPSC register
 * so that 64-bit add/sub/mul do not saturete.
 *
 * Usage:
 * gcc -mcpu=ep9312 -mfpu=maverick -mfloat-abi=softfp \
 *     -fPIC -shared -o isat.so isat.c
 * LD_PRELOAD=isat.o program
 */
__attribute__((constructor))
void maverick_dspsc_set_isat()
{
        volatile register long long mvdx0 asm("mvdx0");
        volatile register int tmp;

        asm("cfmv32sc   mvdx0, dspsc");         /* Get DSPSC contents */
        asm("cfmvrdl    %0, mvd0" : "=r"(tmp)); /* Put lower 32 in ARM reg */
        asm("orr        %0, %0, #0x00800000" : "=r"(tmp) : "r"(tmp)); /* Set bit 23 (ISAT) */
        asm("cfmvdlr    mvd0, %0" : : "r"(tmp));/* Copy back to 64-bit reg */
        asm("cfmvsc32   dspsc, mvdx0");         /* Write to DSPSC */
}

