Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright IBM Corp. 2020
0004  *
0005  * This test attempts to cause a FP denormal exception on POWER8 CPUs. Unfortunately
0006  * if the denormal handler is not configured or working properly, this can cause a bad
0007  * crash in kernel mode when the kernel tries to save FP registers when the process
0008  * exits.
0009  */
0010 
0011 #include <stdio.h>
0012 #include <string.h>
0013 
0014 #include "utils.h"
0015 
0016 static int test_denormal_fpu(void)
0017 {
0018     unsigned int m32;
0019     unsigned long m64;
0020     volatile float f;
0021     volatile double d;
0022 
0023     /* try to induce lfs <denormal> ; stfd */
0024 
0025     m32 = 0x00715fcf; /* random denormal */
0026     memcpy((float *)&f, &m32, sizeof(f));
0027     d = f;
0028     memcpy(&m64, (double *)&d, sizeof(d));
0029 
0030     FAIL_IF((long)(m64 != 0x380c57f3c0000000)); /* renormalised value */
0031 
0032     return 0;
0033 }
0034 
0035 int main(int argc, char *argv[])
0036 {
0037     return test_harness(test_denormal_fpu, "fpu_denormal");
0038 }