1 /* $OpenBSD: sys_machdep.c,v 1.8 2022/10/31 03:20:41 guenther Exp $ */
2 /* $NetBSD: sys_machdep.c,v 1.14 2002/01/14 00:53:16 thorpej Exp $ */
3
4 /*-
5 * Copyright (c) 2000 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
35 * All rights reserved.
36 *
37 * Author: Chris G. Demetriou
38 *
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
44 *
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 *
49 * Carnegie Mellon requests users of this software to return to
50 *
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
55 *
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
58 */
59
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #ifndef NO_IEEE
63 #include <sys/device.h>
64 #include <sys/proc.h>
65 #endif
66
67 #include <sys/mount.h>
68 #include <sys/syscallargs.h>
69
70 #ifndef NO_IEEE
71 #include <machine/fpu.h>
72 #include <machine/sysarch.h>
73
74 #include <dev/pci/pcivar.h>
75
76 int
sys_sysarch(struct proc * p,void * v,register_t * retval)77 sys_sysarch(struct proc *p, void *v, register_t *retval)
78 {
79 struct sys_sysarch_args /* {
80 syscallarg(int) op;
81 syscallarg(void *) parms;
82 } */ *uap = v;
83 int error = 0;
84
85 switch(SCARG(uap, op)) {
86 case ALPHA_FPGETMASK:
87 *retval = FP_C_TO_OPENBSD_MASK(p->p_md.md_flags);
88 break;
89 case ALPHA_FPGETSTICKY:
90 *retval = FP_C_TO_OPENBSD_FLAG(p->p_md.md_flags);
91 break;
92 case ALPHA_FPSETMASK:
93 case ALPHA_FPSETSTICKY:
94 {
95 fp_except m;
96 u_int64_t md_flags;
97 struct alpha_fp_except_args args;
98
99 error = copyin(SCARG(uap, parms), &args, sizeof args);
100 if (error)
101 return error;
102 m = args.mask;
103 md_flags = p->p_md.md_flags;
104 switch (SCARG(uap, op)) {
105 case ALPHA_FPSETMASK:
106 *retval = FP_C_TO_OPENBSD_MASK(md_flags);
107 md_flags = SET_FP_C_MASK(md_flags, m);
108 break;
109 case ALPHA_FPSETSTICKY:
110 *retval = FP_C_TO_OPENBSD_FLAG(md_flags);
111 md_flags = SET_FP_C_FLAG(md_flags, m);
112 break;
113 }
114 alpha_write_fp_c(p, md_flags);
115 break;
116 }
117 case ALPHA_GET_FP_C:
118 {
119 struct alpha_fp_c_args args;
120
121 args.fp_c = alpha_read_fp_c(p);
122 error = copyout(&args, SCARG(uap, parms), sizeof args);
123 break;
124 }
125 case ALPHA_SET_FP_C:
126 {
127 struct alpha_fp_c_args args;
128
129 error = copyin(SCARG(uap, parms), &args, sizeof args);
130 if (error)
131 return (error);
132 if ((args.fp_c >> 63) != 0)
133 args.fp_c |= IEEE_INHERIT;
134 alpha_write_fp_c(p, args.fp_c);
135 break;
136 }
137
138 default:
139 error = EINVAL;
140 break;
141 }
142
143 return (error);
144 }
145 #else
146 int
sys_sysarch(struct proc * p,void * v,register_t * retval)147 sys_sysarch(struct proc *p, void *v, register_t *retval)
148 {
149 return (ENOSYS);
150 }
151 #endif
152