fpu_denormal.c 878 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright IBM Corp. 2020
  4. *
  5. * This test attempts to cause a FP denormal exception on POWER8 CPUs. Unfortunately
  6. * if the denormal handler is not configured or working properly, this can cause a bad
  7. * crash in kernel mode when the kernel tries to save FP registers when the process
  8. * exits.
  9. */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "utils.h"
  13. static int test_denormal_fpu(void)
  14. {
  15. unsigned int m32;
  16. unsigned long m64;
  17. volatile float f;
  18. volatile double d;
  19. /* try to induce lfs <denormal> ; stfd */
  20. m32 = 0x00715fcf; /* random denormal */
  21. memcpy((float *)&f, &m32, sizeof(f));
  22. d = f;
  23. memcpy(&m64, (double *)&d, sizeof(d));
  24. FAIL_IF((long)(m64 != 0x380c57f3c0000000)); /* renormalised value */
  25. return 0;
  26. }
  27. int main(int argc, char *argv[])
  28. {
  29. return test_harness(test_denormal_fpu, "fpu_denormal");
  30. }