blob: 0a9f86da48b9ff03363dedf8ac73cd828ddd449c [file] [log] [blame]
Austin Schuhdace2a62020-08-18 10:56:48 -07001/* 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-impl.h"
22#include "tests.h"
23
24
25/* Vector if constants and register values. */
26mp_limb_t calling_conventions_values[29] =
27{
28 0x12345678, /* 0 want_r4 */
29 0x87654321, /* 1 want_r5 */
30 0x89ABCDEF, /* 2 want_r6 */
31 0xFEDCBA98, /* 3 want_r7 */
32 0xDEADBEEF, /* 4 want_r8 */
33 0xBADECAFE, /* 5 want_r9 */
34 0xFFEEDDCC, /* 6 want_r10 */
35 0xBBAA9988, /* 7 want_r11 */
36
37 0x00000000, /* 8 save_r4 */
38 0x00000000, /* 9 save_r5 */
39 0x00000000, /* 10 save_r6 */
40 0x00000000, /* 11 save_r7 */
41 0x00000000, /* 12 save_r8 */
42 0x00000000, /* 13 save_r9 */
43 0x00000000, /* 14 save_r10 */
44 0x00000000, /* 15 save_r11 */
45 0x00000000, /* 16 save_r14 */
46
47 0x00000000, /* 17 got_r4 */
48 0x00000000, /* 18 got_r5 */
49 0x00000000, /* 19 got_r6 */
50 0x00000000, /* 20 got_r7 */
51 0x00000000, /* 21 got_r8 */
52 0x00000000, /* 22 got_r9 */
53 0x00000000, /* 23 got_r10 */
54 0x00000000, /* 24 got_r11 */
55
56 0x00112233, /* 25 junk_r0 */
57 0x44556677, /* 26 junk_r1 */
58 0x12344321, /* 27 junk_r2 */
59 0x56788765, /* 28 junk_r3 */
60};
61
62/* Index starts for various regions in above vector. */
63#define WANT_CALLEE_SAVES 0
64#define SAVE_CALLEE_SAVES 8
65#define RETADDR 16
66#define GOT_CALLEE_SAVES 17
67#define JUNK_PARAMS 25
68
69/* Return 1 if ok, 0 if not */
70
71int
72calling_conventions_check (void)
73{
74 const char *header = "Violated calling conventions:\n";
75 int ret = 1;
76 int i;
77
78#define CHECK(callreg, regnum, value) \
79 if (callreg != value) \
80 { \
81 printf ("%s r%d got 0x%08lX want 0x%08lX\n", \
82 header, regnum, callreg, value); \
83 header = ""; \
84 ret = 0; \
85 }
86
87 for (i = 0; i < 8; i++)
88 {
89 CHECK (calling_conventions_values[GOT_CALLEE_SAVES + i],
90 i + 4,
91 calling_conventions_values[WANT_CALLEE_SAVES + i]);
92 }
93
94 return ret;
95}