1/* Copyright (C) 2014-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#include <errno.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <unistd.h>
23#include <setjmp.h>
24#include <sys/prctl.h>
25
26#if __mips_fpr != 0 || _MIPS_SPFPSET != 16
27# error This test requires -mfpxx -mno-odd-spreg
28#endif
29
30/* This test verifies that mode changes between a setjmp and longjmp do
31 not corrupt the state of callee-saved registers. */
32
33static int mode[6] =
34 {
35 0,
36 PR_FP_MODE_FR,
37 PR_FP_MODE_FR | PR_FP_MODE_FRE,
38 PR_FP_MODE_FR,
39 0,
40 PR_FP_MODE_FR | PR_FP_MODE_FRE
41 };
42static jmp_buf env;
43float check1 = 2.0;
44double check2 = 3.0;
45
46static int
47do_test (void)
48{
49 int i;
50 int result = 0;
51
52 for (i = 0 ; i < 7 ; i++)
53 {
54 int retval;
55 register float test1 __asm ("$f20");
56 register double test2 __asm ("$f22");
57
58 /* Hide what we are doing to $f20 and $f22 from the compiler. */
59 __asm __volatile ("l.s %0,%2\n"
60 "l.d %1,%3\n"
61 : "=f" (test1), "=f" (test2)
62 : "m" (check1), "m" (check2));
63
64 retval = setjmp (env);
65
66 /* Make sure the compiler knows we want to access the variables
67 via the named registers again. */
68 __asm __volatile ("" : : "f" (test1), "f" (test2));
69
70 if (test1 != check1 || test2 != check2)
71 {
72 printf (format: "Corrupt register detected: $20 %f = %f, $22 %f = %f\n",
73 test1, check1, test2, check2);
74 result = 1;
75 }
76
77 if (retval == 0)
78 {
79 if (prctl (PR_SET_FP_MODE, mode[i % 6]) != 0
80 && errno != ENOTSUP)
81 {
82 printf (format: "prctl PR_SET_FP_MODE failed: %m");
83 exit (1);
84 }
85 longjmp (env: env, val: 0);
86 }
87 }
88
89 return result;
90}
91
92#define TEST_FUNCTION do_test ()
93#include "../../test-skeleton.c"
94

source code of glibc/sysdeps/mips/tst-mode-switch-3.c