1 /* $NetBSD: osf1_misc.c,v 1.83 2009/11/04 21:23:03 rmind Exp $ */
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
35 * All rights reserved.
37 * Author: Chris G. Demetriou
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.
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.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: osf1_misc.c,v 1.83 2009/11/04 21:23:03 rmind Exp $");
63 #if defined(_KERNEL_OPT)
64 #include "opt_syscall_debug.h"
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/namei.h>
73 #include <sys/filedesc.h>
74 #include <sys/kernel.h>
75 #include <sys/malloc.h>
77 #include <sys/mount.h>
78 #include <sys/signal.h>
79 #include <sys/signalvar.h>
80 #include <sys/reboot.h>
81 #include <sys/syscallargs.h>
83 #include <sys/vnode.h>
84 #include <sys/socketvar.h>
85 #include <sys/resource.h>
86 #include <sys/resourcevar.h>
89 #include <machine/alpha.h>
90 #include <machine/cpuconf.h>
91 #include <machine/rpb.h>
92 #include <machine/fpu.h>
94 #include <compat/osf1/osf1.h>
95 #include <compat/osf1/osf1_syscallargs.h>
96 #include <compat/common/compat_util.h>
97 #include <compat/osf1/osf1_cvt.h>
104 osf1_sys_classcntl(struct lwp
*l
, const struct osf1_sys_classcntl_args
*uap
, register_t
*retval
)
112 osf1_sys_reboot(struct lwp
*l
, const struct osf1_sys_reboot_args
*uap
, register_t
*retval
)
114 struct sys_reboot_args a
;
115 unsigned long leftovers
;
118 SCARG(&a
, opt
) = emul_flags_translate(osf1_reboot_opt_xtab
,
119 SCARG(uap
, opt
), &leftovers
);
123 SCARG(&a
, bootstr
) = NULL
;
125 return sys_reboot(l
, &a
, retval
);
129 osf1_sys_set_program_attributes(struct lwp
*l
, const struct osf1_sys_set_program_attributes_args
*uap
, register_t
*retval
)
131 struct proc
*p
= l
->l_proc
;
132 segsz_t tsize
, dsize
;
134 tsize
= btoc(SCARG(uap
, tsize
));
135 dsize
= btoc(SCARG(uap
, dsize
));
137 if (dsize
> p
->p_rlimit
[RLIMIT_DATA
].rlim_cur
)
142 /* XXXSMP unlocked */
143 p
->p_vmspace
->vm_taddr
= SCARG(uap
, taddr
);
144 p
->p_vmspace
->vm_tsize
= tsize
;
145 p
->p_vmspace
->vm_daddr
= SCARG(uap
, daddr
);
146 p
->p_vmspace
->vm_dsize
= dsize
;
152 osf1_sys_getsysinfo(struct lwp
*l
, const struct osf1_sys_getsysinfo_args
*uap
, register_t
*retval
)
160 struct osf1_cpu_info cpuinfo
;
166 switch(SCARG(uap
, op
))
168 case OSF_GET_MAX_UPROCS
:
170 datalen
= sizeof(maxproc
);
172 case OSF_GET_PHYSMEM
:
174 datalen
= sizeof(physmem
);
176 case OSF_GET_MAX_CPU
:
177 case OSF_GET_CPUS_IN_BOX
:
179 datalen
= sizeof(ncpus
);
181 case OSF_GET_IEEE_FP_CONTROL
:
182 if (((fpflags
= alpha_read_fp_c(l
)) & IEEE_INHERIT
) != 0) {
183 fpflags
|= 1ULL << 63;
184 fpflags
&= ~IEEE_INHERIT
;
187 datalen
= sizeof(fpflags
);
189 case OSF_GET_CPU_INFO
:
190 memset(&cpuinfo
, 0, sizeof(cpuinfo
));
192 unit
= alpha_pal_whami();
196 cpuinfo
.current_cpu
= unit
;
197 cpuinfo
.cpus_in_box
= ncpus
;
198 cpuinfo
.cpu_type
= LOCATE_PCS(hwrpb
, unit
)->pcs_proc_type
;
199 cpuinfo
.ncpus
= ncpus
;
200 cpuinfo
.cpus_present
= ncpus
;
201 cpuinfo
.cpus_running
= ncpus
;
202 cpuinfo
.cpu_binding
= 1;
203 cpuinfo
.cpu_ex_binding
= 0;
204 cpuinfo
.mhz
= hwrpb
->rpb_cc_freq
/ 1000000;
206 datalen
= sizeof(cpuinfo
);
208 case OSF_GET_PROC_TYPE
:
210 unit
= alpha_pal_whami();
211 proctype
= LOCATE_PCS(hwrpb
, unit
)->pcs_proc_type
;
213 proctype
= 0; /* XXX */
216 datalen
= sizeof(percpu
);
218 case OSF_GET_HWRPB
: /* note -- osf/1 doesn't have rpb_tbhint[8] */
220 datalen
= hwrpb
->rpb_size
;
222 case OSF_GET_PLATFORM_NAME
:
223 data
= platform
.model
;
224 datalen
= strlen(platform
.model
) + 1;
227 printf("osf1_getsysinfo called with unknown op=%ld\n",
233 if (SCARG(uap
, nbytes
) < datalen
)
235 error
= copyout(data
, SCARG(uap
, buffer
), datalen
);
242 osf1_sys_setsysinfo(struct lwp
*l
, const struct osf1_sys_setsysinfo_args
*uap
, register_t
*retval
)
249 switch(SCARG(uap
, op
)) {
250 case OSF_SET_IEEE_FP_CONTROL
:
252 if ((error
= copyin(SCARG(uap
, buffer
), &temp
, sizeof(temp
))))
255 temp
|= IEEE_INHERIT
;
256 alpha_write_fp_c(l
, temp
);
259 uprintf("osf1_setsysinfo called with op=%ld\n", SCARG(uap
, op
));
267 osf1_sys_sysinfo(struct lwp
*l
, const struct osf1_sys_sysinfo_args
*uap
, register_t
*retval
)
274 switch (SCARG(uap
, cmd
)) {
275 case OSF1_SI_SYSNAME
:
279 case OSF1_SI_HOSTNAME
:
283 case OSF1_SI_RELEASE
:
287 case OSF1_SI_VERSION
:
290 case OSF1_SI_MACHINE
:
294 case OSF1_SI_ARCHITECTURE
:
295 string
= MACHINE_ARCH
;
298 case OSF1_SI_HW_SERIAL
:
299 string
= "666"; /* OSF/1 emulation? YES! */
302 case OSF1_SI_HW_PROVIDER
:
306 case OSF1_SI_SRPC_DOMAIN
:
309 case OSF1_SI_SET_HOSTNAME
:
312 case OSF1_SI_SET_SYSNAME
:
315 case OSF1_SI_SET_SRPC_DOMAIN
:
320 printf("osf1_sys_sysinfo(%d, %p, 0x%lx)\n", SCARG(uap
, cmd
),
321 SCARG(uap
, buf
), SCARG(uap
,len
));
326 slen
= strlen(string
) + 1;
327 if (SCARG(uap
, buf
)) {
328 error
= copyout(string
, SCARG(uap
, buf
),
329 min(slen
, SCARG(uap
, len
)));
330 if (!error
&& (SCARG(uap
, len
) > 0) && (SCARG(uap
, len
) < slen
))
331 subyte(SCARG(uap
, buf
) + SCARG(uap
, len
) - 1, 0);
340 osf1_sys_uname(struct lwp
*l
, const struct osf1_sys_uname_args
*uap
, register_t
*retval
)
342 struct osf1_utsname u
;
346 strncpy(u
.sysname
, ostype
, sizeof(u
.sysname
));
347 strncpy(u
.nodename
, hostname
, sizeof(u
.nodename
));
348 strncpy(u
.release
, osrelease
, sizeof(u
.release
));
350 ep
= &u
.version
[sizeof(u
.version
) - 1];
351 for (cp
= version
; *cp
&& *cp
!= '('; cp
++)
353 for (cp
++; *cp
&& *cp
!= ')' && dp
< ep
; cp
++)
355 for (; *cp
&& *cp
!= '#'; cp
++)
357 for (; *cp
&& *cp
!= ':' && dp
< ep
; cp
++)
360 strncpy(u
.machine
, MACHINE
, sizeof(u
.machine
));
361 return (copyout((void *)&u
, (void *)SCARG(uap
, name
), sizeof u
));
365 osf1_sys_usleep_thread(struct lwp
*l
, const struct osf1_sys_usleep_thread_args
*uap
, register_t
*retval
)
367 struct osf1_timeval otv
, endotv
;
368 struct timeval tv
, ntv
, endtv
;
372 if ((error
= copyin(SCARG(uap
, sleep
), &otv
, sizeof otv
)))
374 tv
.tv_sec
= otv
.tv_sec
;
375 tv
.tv_usec
= otv
.tv_usec
;
377 ticks
= howmany((u_long
)tv
.tv_sec
* 1000000 + tv
.tv_usec
, tick
);
383 tsleep(l
, PUSER
|PCATCH
, "uslpthrd", ticks
); /* XXX */
385 if (SCARG(uap
, slept
) != NULL
) {
387 timersub(&ntv
, &tv
, &endtv
);
388 if (endtv
.tv_sec
< 0 || endtv
.tv_usec
< 0)
389 endtv
.tv_sec
= endtv
.tv_usec
= 0;
391 endotv
.tv_sec
= endtv
.tv_sec
;
392 endotv
.tv_usec
= endtv
.tv_usec
;
393 error
= copyout(&endotv
, SCARG(uap
, slept
), sizeof endotv
);
399 osf1_sys_wait4(struct lwp
*l
, const struct osf1_sys_wait4_args
*uap
, register_t
*retval
)
401 struct osf1_rusage osf1_rusage
;
402 struct rusage netbsd_rusage
;
403 unsigned long leftovers
;
405 int options
= SCARG(uap
, options
);
406 int pid
= SCARG(uap
, pid
);
408 /* translate options */
409 options
= emul_flags_translate(osf1_wait_options_xtab
,
410 options
, &leftovers
);
414 error
= do_sys_wait(&pid
, &status
, options
| WOPTSCHECKED
,
415 SCARG(uap
, rusage
) != NULL
? &netbsd_rusage
: NULL
);
421 if (SCARG(uap
, rusage
)) {
422 osf1_cvt_rusage_from_native(&netbsd_rusage
, &osf1_rusage
);
423 error
= copyout(&osf1_rusage
, SCARG(uap
, rusage
),
427 if (error
== 0 && SCARG(uap
, status
))
428 error
= copyout(&status
, SCARG(uap
, status
), sizeof(status
));