arm32check.c revision 1.1.1.2
1/* ARM32 calling conventions checking.
2
3Copyright 2000, 2001, 2004, 2007 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library test suite.
6
7The GNU MP Library test suite is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 3 of the License,
10or (at your option) any later version.
11
12The GNU MP Library test suite is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15Public License for more details.
16
17You should have received a copy of the GNU General Public License along with
18the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
19
20#include <stdio.h>
21#include "gmp.h"
22#include "gmp-impl.h"
23#include "tests.h"
24
25
26/* Vector if constants and register values.  */
27mp_limb_t calling_conventions_values[29] =
28{
29  0x12345678,	/*  0 want_r4 */
30  0x87654321,	/*  1 want_r5 */
31  0x89ABCDEF,	/*  2 want_r6 */
32  0xFEDCBA98,	/*  3 want_r7 */
33  0xDEADBEEF,	/*  4 want_r8 */
34  0xBADECAFE,	/*  5 want_r9 */
35  0xFFEEDDCC,	/*  6 want_r10 */
36  0xBBAA9988,	/*  7 want_r11 */
37
38  0x00000000,	/*  8 save_r4 */
39  0x00000000,	/*  9 save_r5 */
40  0x00000000,	/* 10 save_r6 */
41  0x00000000,	/* 11 save_r7 */
42  0x00000000,	/* 12 save_r8 */
43  0x00000000,	/* 13 save_r9 */
44  0x00000000,	/* 14 save_r10 */
45  0x00000000,	/* 15 save_r11 */
46  0x00000000,	/* 16 save_r14 */
47
48  0x00000000,	/* 17 got_r4 */
49  0x00000000,	/* 18 got_r5 */
50  0x00000000,	/* 19 got_r6 */
51  0x00000000,	/* 20 got_r7 */
52  0x00000000,	/* 21 got_r8 */
53  0x00000000,	/* 22 got_r9 */
54  0x00000000,	/* 23 got_r10 */
55  0x00000000,	/* 24 got_r11 */
56
57  0x00112233,	/* 25 junk_r0 */
58  0x44556677,	/* 26 junk_r1 */
59  0x12344321,	/* 27 junk_r2 */
60  0x56788765,	/* 28 junk_r3 */
61};
62
63/* Index starts for various regions in above vector.  */
64#define WANT_CALLEE_SAVES	0
65#define SAVE_CALLEE_SAVES	8
66#define RETADDR			16
67#define GOT_CALLEE_SAVES	17
68#define JUNK_PARAMS		25
69
70/* Return 1 if ok, 0 if not */
71
72int
73calling_conventions_check (void)
74{
75  const char  *header = "Violated calling conventions:\n";
76  int  ret = 1;
77  int i;
78
79#define CHECK(callreg, regnum, value)					\
80  if (callreg != value)							\
81    {									\
82      printf ("%s   r%d	got 0x%08lX want 0x%08lX\n",			\
83	      header, regnum, callreg, value);				\
84      header = "";							\
85      ret = 0;								\
86    }
87
88  for (i = 0; i < 8; i++)
89    {
90      CHECK (calling_conventions_values[GOT_CALLEE_SAVES + i],
91	     i + 4,
92	     calling_conventions_values[WANT_CALLEE_SAVES + i]);
93    }
94
95  return ret;
96}
97