Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / osf1 / osf1_misc.c
blob60f7f21d2ef4082f6b360ee4d2d8bba553b98a64
1 /* $NetBSD: osf1_misc.c,v 1.83 2009/11/04 21:23:03 rmind Exp $ */
3 /*
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
8 * are met:
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"
65 #endif
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/namei.h>
70 #include <sys/proc.h>
71 #include <sys/file.h>
72 #include <sys/stat.h>
73 #include <sys/filedesc.h>
74 #include <sys/kernel.h>
75 #include <sys/malloc.h>
76 #include <sys/mman.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>
82 #include <sys/exec.h>
83 #include <sys/vnode.h>
84 #include <sys/socketvar.h>
85 #include <sys/resource.h>
86 #include <sys/resourcevar.h>
87 #include <sys/wait.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>
99 #ifdef SYSCALL_DEBUG
100 extern int scdebug;
101 #endif
104 osf1_sys_classcntl(struct lwp *l, const struct osf1_sys_classcntl_args *uap, register_t *retval)
107 /* XXX */
108 return (ENOSYS);
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;
117 /* translate opt */
118 SCARG(&a, opt) = emul_flags_translate(osf1_reboot_opt_xtab,
119 SCARG(uap, opt), &leftovers);
120 if (leftovers != 0)
121 return (EINVAL);
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)
138 return (ENOMEM);
139 if (tsize > MAXTSIZ)
140 return (ENOMEM);
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;
148 return (0);
152 osf1_sys_getsysinfo(struct lwp *l, const struct osf1_sys_getsysinfo_args *uap, register_t *retval)
154 extern int ncpus;
155 int error;
156 int unit;
157 long percpu;
158 long proctype;
159 u_int64_t fpflags;
160 struct osf1_cpu_info cpuinfo;
161 const void *data;
162 size_t datalen;
164 error = 0;
166 switch(SCARG(uap, op))
168 case OSF_GET_MAX_UPROCS:
169 data = &maxproc;
170 datalen = sizeof(maxproc);
171 break;
172 case OSF_GET_PHYSMEM:
173 data = &physmem;
174 datalen = sizeof(physmem);
175 break;
176 case OSF_GET_MAX_CPU:
177 case OSF_GET_CPUS_IN_BOX:
178 data = &ncpus;
179 datalen = sizeof(ncpus);
180 break;
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;
186 data = &fpflags;
187 datalen = sizeof(fpflags);
188 break;
189 case OSF_GET_CPU_INFO:
190 memset(&cpuinfo, 0, sizeof(cpuinfo));
191 #ifdef __alpha__
192 unit = alpha_pal_whami();
193 #else
194 unit = 0; /* XXX */
195 #endif
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;
205 data = &cpuinfo;
206 datalen = sizeof(cpuinfo);
207 break;
208 case OSF_GET_PROC_TYPE:
209 #ifdef __alpha__
210 unit = alpha_pal_whami();
211 proctype = LOCATE_PCS(hwrpb, unit)->pcs_proc_type;
212 #else
213 proctype = 0; /* XXX */
214 #endif
215 data = &proctype;
216 datalen = sizeof(percpu);
217 break;
218 case OSF_GET_HWRPB: /* note -- osf/1 doesn't have rpb_tbhint[8] */
219 data = hwrpb;
220 datalen = hwrpb->rpb_size;
221 break;
222 case OSF_GET_PLATFORM_NAME:
223 data = platform.model;
224 datalen = strlen(platform.model) + 1;
225 break;
226 default:
227 printf("osf1_getsysinfo called with unknown op=%ld\n",
228 SCARG(uap, op));
229 /* return EINVAL; */
230 return 0;
233 if (SCARG(uap, nbytes) < datalen)
234 return (EINVAL);
235 error = copyout(data, SCARG(uap, buffer), datalen);
236 if (!error)
237 retval[0] = 1;
238 return (error);
242 osf1_sys_setsysinfo(struct lwp *l, const struct osf1_sys_setsysinfo_args *uap, register_t *retval)
244 u_int64_t temp;
245 int error;
247 error = 0;
249 switch(SCARG(uap, op)) {
250 case OSF_SET_IEEE_FP_CONTROL:
252 if ((error = copyin(SCARG(uap, buffer), &temp, sizeof(temp))))
253 break;
254 if (temp >> 63 != 0)
255 temp |= IEEE_INHERIT;
256 alpha_write_fp_c(l, temp);
257 break;
258 default:
259 uprintf("osf1_setsysinfo called with op=%ld\n", SCARG(uap, op));
260 //error = EINVAL;
262 retval[0] = 0;
263 return (error);
267 osf1_sys_sysinfo(struct lwp *l, const struct osf1_sys_sysinfo_args *uap, register_t *retval)
269 const char *string;
270 size_t slen;
271 int error;
273 error = 0;
274 switch (SCARG(uap, cmd)) {
275 case OSF1_SI_SYSNAME:
276 string = ostype;
277 break;
279 case OSF1_SI_HOSTNAME:
280 string = hostname;
281 break;
283 case OSF1_SI_RELEASE:
284 string = osrelease;
285 break;
287 case OSF1_SI_VERSION:
288 goto should_handle;
290 case OSF1_SI_MACHINE:
291 string = MACHINE;
292 break;
294 case OSF1_SI_ARCHITECTURE:
295 string = MACHINE_ARCH;
296 break;
298 case OSF1_SI_HW_SERIAL:
299 string = "666"; /* OSF/1 emulation? YES! */
300 break;
302 case OSF1_SI_HW_PROVIDER:
303 string = "unknown";
304 break;
306 case OSF1_SI_SRPC_DOMAIN:
307 goto dont_care;
309 case OSF1_SI_SET_HOSTNAME:
310 goto should_handle;
312 case OSF1_SI_SET_SYSNAME:
313 goto should_handle;
315 case OSF1_SI_SET_SRPC_DOMAIN:
316 goto dont_care;
318 default:
319 should_handle:
320 printf("osf1_sys_sysinfo(%d, %p, 0x%lx)\n", SCARG(uap, cmd),
321 SCARG(uap, buf), SCARG(uap,len));
322 dont_care:
323 return (EINVAL);
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);
333 if (!error)
334 retval[0] = slen;
336 return (error);
340 osf1_sys_uname(struct lwp *l, const struct osf1_sys_uname_args *uap, register_t *retval)
342 struct osf1_utsname u;
343 const char *cp;
344 char *dp, *ep;
346 strncpy(u.sysname, ostype, sizeof(u.sysname));
347 strncpy(u.nodename, hostname, sizeof(u.nodename));
348 strncpy(u.release, osrelease, sizeof(u.release));
349 dp = u.version;
350 ep = &u.version[sizeof(u.version) - 1];
351 for (cp = version; *cp && *cp != '('; cp++)
353 for (cp++; *cp && *cp != ')' && dp < ep; cp++)
354 *dp++ = *cp;
355 for (; *cp && *cp != '#'; cp++)
357 for (; *cp && *cp != ':' && dp < ep; cp++)
358 *dp++ = *cp;
359 *dp = '\0';
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;
369 u_long ticks;
370 int error;
372 if ((error = copyin(SCARG(uap, sleep), &otv, sizeof otv)))
373 return (error);
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);
378 if (ticks == 0)
379 ticks = 1;
381 getmicrotime(&tv);
383 tsleep(l, PUSER|PCATCH, "uslpthrd", ticks); /* XXX */
385 if (SCARG(uap, slept) != NULL) {
386 getmicrotime(&ntv);
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);
395 return (error);
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;
404 int error, status;
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);
411 if (leftovers != 0)
412 return (EINVAL);
414 error = do_sys_wait(&pid, &status, options | WOPTSCHECKED,
415 SCARG(uap, rusage) != NULL ? &netbsd_rusage : NULL);
417 retval[0] = pid;
418 if (pid == 0)
419 return error;
421 if (SCARG(uap, rusage)) {
422 osf1_cvt_rusage_from_native(&netbsd_rusage, &osf1_rusage);
423 error = copyout(&osf1_rusage, SCARG(uap, rusage),
424 sizeof osf1_rusage);
427 if (error == 0 && SCARG(uap, status))
428 error = copyout(&status, SCARG(uap, status), sizeof(status));
430 return error;