Initial import from FreeBSD RELENG_4:
[games.git] / usr.bin / uac / uac.c
1 /*
2  * Copyright (c) 2000 Andrew Gallatin and David E. O'Brien
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer 
10  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software withough specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD: src/usr.bin/uac/uac.c,v 1.1 2000/01/19 09:47:19 obrien Exp $
29  */
30
31 #include <sys/types.h>
32 #include <machine/sysarch.h>
33 #include <machine/proc.h>
34
35 #include <stdio.h>
36 #include <unistd.h>
37 #include <err.h>
38
39 extern int sysarch(int, char *);
40 static void usage ();
41
42 struct parms {
43         u_int64_t uac;
44 };
45
46 int
47 alpha_setuac(u_int64_t uac)
48 {
49         struct parms p;
50
51         p.uac = uac;
52         return (sysarch(ALPHA_SET_UAC, (char *)&p));
53 }
54
55 int
56 alpha_getuac(u_int64_t *uac)
57 {
58         struct parms p;
59         int error;
60
61         error = sysarch(ALPHA_GET_UAC, (char *)&p);
62         *uac = p.uac;
63         return (error);
64 }
65
66 static void
67 print_uac(u_int64_t uac)
68 {
69
70         printf("parent printing is ");
71         if (uac & MDP_UAC_NOPRINT)
72                 printf("off\n");
73         else 
74                 printf("on\n");
75
76         printf("parent fixup is ");
77         if (uac & MDP_UAC_NOFIX)
78                 printf("off\n");
79         else 
80                 printf("on\n");
81
82         printf("parent sigbus is ");
83         if (uac & MDP_UAC_SIGBUS)
84                 printf("on \n");
85         else 
86                 printf("off\n");
87 }
88
89 int
90 main(argc, argv)
91         int argc;
92         char **argv;
93 {
94         int c;
95         u_int64_t uac;
96
97         if (alpha_getuac(&uac) != 0)
98                 err(1, NULL);
99
100         while ((c = getopt(argc, argv, "fpsr")) != -1) {
101                 switch (c) {
102                 case 'f':
103                         uac |= MDP_UAC_NOFIX;
104                         break;
105                 case 'p':
106                         uac |= MDP_UAC_NOPRINT;
107                         break;
108                 case 's':
109                         uac |= MDP_UAC_SIGBUS;
110                         break;
111                 case 'r':
112                         uac = 0;
113                         break;
114                 default:
115                         usage();
116                         /* NOTREACHED */   
117                 }
118         }
119
120         if (argc != 1) {        
121                 if (alpha_setuac(uac) != 0)
122                         err(1, NULL);
123         }
124
125         print_uac(uac);
126         return 0;
127 }
128
129 static void
130 usage ()
131 {
132
133         fprintf(stderr, "usage: uac [-fprs]\n");
134 }