xref: /openbsd-src/regress/sys/arch/hppa/probe/probe.c (revision 49a6e16f2c2c8e509184b1f777366d1a6f337e1c)
1 /*	$OpenBSD: probe.c,v 1.4 2021/12/13 16:56:49 deraadt Exp $	*/
2 
3 /*
4  * Written by Michael Shalayeff, 2004. Public Domain.
5  */
6 
7 #include <sys/types.h>
8 #include <signal.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <err.h>
14 
15 #ifdef __hppa__
16 
17 char moo[] = "moo";	/* writable */
18 const char blah[] = "blah";	/* not */
19 volatile char *label;
20 
21 #define	prober(r,a)	__asm volatile(	\
22     "prober	(%2),%1,%0" : "=r" (r) : "r" (3), "r" (a));
23 #define	proberi(r,a)	__asm volatile(	\
24     "proberi	(%2),%1,%0" : "=r" (r) : "i" (3), "r" (a));
25 #define	probew(r,a)	__asm volatile(	\
26     "probew	(%2),%1,%0" : "=r" (r) : "r" (3), "r" (a));
27 #define	probewi(r,a)	__asm volatile(	\
28     "probewi	(%2),%1,%0" : "=r" (r) : "i" (3), "r" (a));
29 
30 void
sigsegv(int sig,siginfo_t * sip,void * scp)31 sigsegv(int sig, siginfo_t *sip, void *scp)
32 {
33 	char buf[1024];
34 
35 	snprintf(buf, sizeof buf, "%s not decoded\n", label);
36 	write(STDOUT_FILENO, buf, strlen(buf));
37         _exit(1);
38 }
39 
40 int
main(int argc,char * argv[])41 main(int argc, char *argv[])
42 {
43 	struct sigaction sa;
44 	int rv;
45 
46 	sa.sa_sigaction = &sigsegv;
47 	sa.sa_flags = SA_SIGINFO;
48 	sigemptyset(&sa.sa_mask);
49 	sigaction(SIGSEGV, &sa, NULL);
50 
51 #define	test_probe(n,a,r)	\
52 	label = #n;		\
53 	n(rv, a);		\
54 	if (rv != (r))		\
55 		errx(1, "%s(%p) returned %d", label, (a), rv);
56 
57 	test_probe(prober, 1, 0);
58 	test_probe(prober, &blah, 1);
59 
60 	test_probe(proberi, 1, 0);
61 	test_probe(proberi, &blah, 1);
62 
63 	test_probe(probew, 1, 0);
64 	test_probe(probew, &blah, 0);
65 	test_probe(probew, &moo, 1);
66 
67 	test_probe(probewi, 1, 0);
68 	test_probe(probewi, &blah, 0);
69 	test_probe(probewi, &moo, 1);
70 
71 	exit(0);
72 }
73 
74 #else
75 
76 int
main(int argc,char * argv[])77 main(int argc, char *argv[])
78 {
79 	printf("SKIPPED\n");
80 	exit(0);
81 }
82 
83 #endif
84