1 /*	$OpenBSD: main.c,v 1.1 2003/07/12 04:08:33 jason Exp $	*/
2 
3 /*
4  * Copyright (c) 2003 Jason L. Wright (jason@thought.net)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 #include <sys/types.h>
29 #include <signal.h>
30 #include <stdio.h>
31 #include <err.h>
32 #include <string.h>
33 #include <unistd.h>
34 
35 struct fpquad {
36 	u_int64_t x1;
37 	u_int64_t x2;
38 	u_int64_t x3;
39 	u_int64_t x4;
40 };
41 
42 void test_ldq_f2_g0(struct fpquad *);
43 void test_ldq_f2_simm13(struct fpquad *);
44 void test_stq_f2_g0(struct fpquad *);
45 void test_stq_f2_simm13(struct fpquad *);
46 void test_ldq_f6_g0(struct fpquad *);
47 void test_ldq_f6_simm13(struct fpquad *);
48 void test_stq_f6_g0(struct fpquad *);
49 void test_stq_f6_simm13(struct fpquad *);
50 void test_ldq_f10_g0(struct fpquad *);
51 void test_ldq_f10_simm13(struct fpquad *);
52 void test_stq_f10_g0(struct fpquad *);
53 void test_stq_f10_simm13(struct fpquad *);
54 void test_ldq_f14_g0(struct fpquad *);
55 void test_ldq_f14_simm13(struct fpquad *);
56 void test_stq_f14_g0(struct fpquad *);
57 void test_stq_f14_simm13(struct fpquad *);
58 void test_ldq_f18_g0(struct fpquad *);
59 void test_ldq_f18_simm13(struct fpquad *);
60 void test_stq_f18_g0(struct fpquad *);
61 void test_stq_f18_simm13(struct fpquad *);
62 void test_ldq_f22_g0(struct fpquad *);
63 void test_ldq_f22_simm13(struct fpquad *);
64 void test_stq_f22_g0(struct fpquad *);
65 void test_stq_f22_simm13(struct fpquad *);
66 void test_ldq_f26_g0(struct fpquad *);
67 void test_ldq_f26_simm13(struct fpquad *);
68 void test_stq_f26_g0(struct fpquad *);
69 void test_stq_f26_simm13(struct fpquad *);
70 void test_ldq_f30_g0(struct fpquad *);
71 void test_ldq_f30_simm13(struct fpquad *);
72 void test_stq_f30_g0(struct fpquad *);
73 void test_stq_f30_simm13(struct fpquad *);
74 void test_ldq_f34_g0(struct fpquad *);
75 void test_ldq_f34_simm13(struct fpquad *);
76 void test_stq_f34_g0(struct fpquad *);
77 void test_stq_f34_simm13(struct fpquad *);
78 void test_ldq_f38_g0(struct fpquad *);
79 void test_ldq_f38_simm13(struct fpquad *);
80 void test_stq_f38_g0(struct fpquad *);
81 void test_stq_f38_simm13(struct fpquad *);
82 void test_ldq_f42_g0(struct fpquad *);
83 void test_ldq_f42_simm13(struct fpquad *);
84 void test_stq_f42_g0(struct fpquad *);
85 void test_stq_f42_simm13(struct fpquad *);
86 void test_ldq_f46_g0(struct fpquad *);
87 void test_ldq_f46_simm13(struct fpquad *);
88 void test_stq_f46_g0(struct fpquad *);
89 void test_stq_f46_simm13(struct fpquad *);
90 void test_ldq_f50_g0(struct fpquad *);
91 void test_ldq_f50_simm13(struct fpquad *);
92 void test_stq_f50_g0(struct fpquad *);
93 void test_stq_f50_simm13(struct fpquad *);
94 void test_ldq_f54_g0(struct fpquad *);
95 void test_ldq_f54_simm13(struct fpquad *);
96 void test_stq_f54_g0(struct fpquad *);
97 void test_stq_f54_simm13(struct fpquad *);
98 void test_ldq_f58_g0(struct fpquad *);
99 void test_ldq_f58_simm13(struct fpquad *);
100 void test_stq_f58_g0(struct fpquad *);
101 void test_stq_f58_simm13(struct fpquad *);
102 void test_ldq_f62_g0(struct fpquad *);
103 void test_ldq_f62_simm13(struct fpquad *);
104 void test_stq_f62_g0(struct fpquad *);
105 void test_stq_f62_simm13(struct fpquad *);
106 
107 struct fptest {
108 	char *reg;
109 	char *ldst;
110 	char *dir;
111 	void (*func)(struct fpquad *);
112 } thetests[] = {
113 	{"2", "st", "reg", test_stq_f2_g0},
114 	{"2", "ld", "reg", test_ldq_f2_g0},
115 	{"2", "st", "imm", test_stq_f2_simm13},
116 	{"2", "ld", "imm", test_ldq_f2_simm13},
117 	{"6", "st", "reg", test_stq_f6_g0},
118 	{"6", "ld", "reg", test_ldq_f6_g0},
119 	{"6", "st", "imm", test_stq_f6_simm13},
120 	{"6", "ld", "imm", test_ldq_f6_simm13},
121 	{"10", "st", "reg", test_stq_f10_g0},
122 	{"10", "ld", "reg", test_ldq_f10_g0},
123 	{"10", "st", "imm", test_stq_f10_simm13},
124 	{"10", "ld", "imm", test_ldq_f10_simm13},
125 	{"14", "st", "reg", test_stq_f14_g0},
126 	{"14", "ld", "reg", test_ldq_f14_g0},
127 	{"14", "st", "imm", test_stq_f14_simm13},
128 	{"14", "ld", "imm", test_ldq_f14_simm13},
129 	{"18", "st", "reg", test_stq_f18_g0},
130 	{"18", "ld", "reg", test_ldq_f18_g0},
131 	{"18", "st", "imm", test_stq_f18_simm13},
132 	{"18", "ld", "imm", test_ldq_f18_simm13},
133 	{"22", "st", "reg", test_stq_f22_g0},
134 	{"22", "ld", "reg", test_ldq_f22_g0},
135 	{"22", "st", "imm", test_stq_f22_simm13},
136 	{"22", "ld", "imm", test_ldq_f22_simm13},
137 	{"26", "st", "reg", test_stq_f26_g0},
138 	{"26", "ld", "reg", test_ldq_f26_g0},
139 	{"26", "st", "imm", test_stq_f26_simm13},
140 	{"26", "ld", "imm", test_ldq_f26_simm13},
141 	{"30", "st", "reg", test_stq_f30_g0},
142 	{"30", "ld", "reg", test_ldq_f30_g0},
143 	{"30", "st", "imm", test_stq_f30_simm13},
144 	{"30", "ld", "imm", test_ldq_f30_simm13},
145 	{"34", "st", "reg", test_stq_f34_g0},
146 	{"34", "ld", "reg", test_ldq_f34_g0},
147 	{"34", "st", "imm", test_stq_f34_simm13},
148 	{"34", "ld", "imm", test_ldq_f34_simm13},
149 	{"38", "st", "reg", test_stq_f38_g0},
150 	{"38", "ld", "reg", test_ldq_f38_g0},
151 	{"38", "st", "imm", test_stq_f38_simm13},
152 	{"38", "ld", "imm", test_ldq_f38_simm13},
153 	{"42", "st", "reg", test_stq_f42_g0},
154 	{"42", "ld", "reg", test_ldq_f42_g0},
155 	{"42", "st", "imm", test_stq_f42_simm13},
156 	{"42", "ld", "imm", test_ldq_f42_simm13},
157 	{"46", "st", "reg", test_stq_f46_g0},
158 	{"46", "ld", "reg", test_ldq_f46_g0},
159 	{"46", "st", "imm", test_stq_f46_simm13},
160 	{"46", "ld", "imm", test_ldq_f46_simm13},
161 	{"50", "st", "reg", test_stq_f50_g0},
162 	{"50", "ld", "reg", test_ldq_f50_g0},
163 	{"50", "st", "imm", test_stq_f50_simm13},
164 	{"50", "ld", "imm", test_ldq_f50_simm13},
165 	{"54", "st", "reg", test_stq_f54_g0},
166 	{"54", "ld", "reg", test_ldq_f54_g0},
167 	{"54", "st", "imm", test_stq_f54_simm13},
168 	{"54", "ld", "imm", test_ldq_f54_simm13},
169 	{"58", "st", "reg", test_stq_f58_g0},
170 	{"58", "ld", "reg", test_ldq_f58_g0},
171 	{"58", "st", "imm", test_stq_f58_simm13},
172 	{"58", "ld", "imm", test_ldq_f58_simm13},
173 	{"62", "st", "reg", test_stq_f62_g0},
174 	{"62", "ld", "reg", test_ldq_f62_g0},
175 	{"62", "st", "imm", test_stq_f62_simm13},
176 	{"62", "ld", "imm", test_ldq_f62_simm13},
177 };
178 #define	NTESTS	(sizeof(thetests)/sizeof(thetests[0]))
179 
180 void ill_catcher(int, siginfo_t *, void *);
181 
182 int
183 main(int argc, char *argv[])
184 {
185 	struct fptest *fpt;
186 	struct fpquad fpq;
187 	struct sigaction sa;
188 	int i;
189 
190 	if (argc != 4) {
191 		fprintf(stderr, "badreg regnum [ld|st] [reg|imm]\n");
192 		return (1);
193 	}
194 
195 	for (i = 0; i < NTESTS; i++) {
196 		fpt = thetests + i;
197 		if (strcmp(fpt->reg, argv[1]) == 0 &&
198 		    strcmp(fpt->ldst, argv[2]) == 0 &&
199 		    strcmp(fpt->dir, argv[3]) == 0)
200 			break;
201 	}
202 	if (i == NTESTS)
203 		errx(1, "unknown test: %s %s %s", argv[1], argv[2], argv[3]);
204 
205 	sa.sa_sigaction = ill_catcher;
206 	sigemptyset(&sa.sa_mask);
207 	sa.sa_flags = SA_SIGINFO;
208 
209 	if (sigaction(SIGILL, &sa, NULL) == -1)
210 		err(1, "sigaction");
211 
212 	(*fpt->func)(&fpq);
213 	err(1, "%s %s %s did not generate sigill", argv[1], argv[2], argv[3]);
214 	return (0);
215 }
216 
217 void
218 ill_catcher(int sig, siginfo_t *si, void *v)
219 {
220 	_exit(0);
221 }
222