linux_machdep.c revision 1.9.2.2 1 1.9.2.2 thorpej /* $NetBSD: linux_machdep.c,v 1.9.2.2 2002/01/10 19:51:33 thorpej Exp $ */
2 1.9.2.2 thorpej
3 1.9.2.2 thorpej /*-
4 1.9.2.2 thorpej * Copyright (c) 1995, 2000, 2001 The NetBSD Foundation, Inc.
5 1.9.2.2 thorpej * All rights reserved.
6 1.9.2.2 thorpej *
7 1.9.2.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.9.2.2 thorpej * by Frank van der Linden and Emmanuel Dreyfus.
9 1.9.2.2 thorpej *
10 1.9.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.9.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.9.2.2 thorpej * are met:
13 1.9.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.9.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.9.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.9.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.9.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.9.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.9.2.2 thorpej * must display the following acknowledgement:
20 1.9.2.2 thorpej * This product includes software developed by the NetBSD
21 1.9.2.2 thorpej * Foundation, Inc. and its contributors.
22 1.9.2.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.9.2.2 thorpej * contributors may be used to endorse or promote products derived
24 1.9.2.2 thorpej * from this software without specific prior written permission.
25 1.9.2.2 thorpej *
26 1.9.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.9.2.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.9.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.9.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.9.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.9.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.9.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.9.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.9.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.9.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.9.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.9.2.2 thorpej */
38 1.9.2.2 thorpej
39 1.9.2.2 thorpej #include <sys/cdefs.h>
40 1.9.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.9.2.2 2002/01/10 19:51:33 thorpej Exp $");
41 1.9.2.2 thorpej
42 1.9.2.2 thorpej #include <sys/param.h>
43 1.9.2.2 thorpej #include <sys/systm.h>
44 1.9.2.2 thorpej #include <sys/signalvar.h>
45 1.9.2.2 thorpej #include <sys/kernel.h>
46 1.9.2.2 thorpej #include <sys/map.h>
47 1.9.2.2 thorpej #include <sys/proc.h>
48 1.9.2.2 thorpej #include <sys/user.h>
49 1.9.2.2 thorpej #include <sys/buf.h>
50 1.9.2.2 thorpej #include <sys/reboot.h>
51 1.9.2.2 thorpej #include <sys/conf.h>
52 1.9.2.2 thorpej #include <sys/exec.h>
53 1.9.2.2 thorpej #include <sys/file.h>
54 1.9.2.2 thorpej #include <sys/callout.h>
55 1.9.2.2 thorpej #include <sys/malloc.h>
56 1.9.2.2 thorpej #include <sys/mbuf.h>
57 1.9.2.2 thorpej #include <sys/msgbuf.h>
58 1.9.2.2 thorpej #include <sys/mount.h>
59 1.9.2.2 thorpej #include <sys/vnode.h>
60 1.9.2.2 thorpej #include <sys/device.h>
61 1.9.2.2 thorpej #include <sys/syscallargs.h>
62 1.9.2.2 thorpej #include <sys/filedesc.h>
63 1.9.2.2 thorpej #include <sys/exec_elf.h>
64 1.9.2.2 thorpej #include <sys/disklabel.h>
65 1.9.2.2 thorpej #include <sys/ioctl.h>
66 1.9.2.2 thorpej #include <sys/sysctl.h>
67 1.9.2.2 thorpej #include <miscfs/specfs/specdev.h>
68 1.9.2.2 thorpej
69 1.9.2.2 thorpej #include <compat/linux/common/linux_types.h>
70 1.9.2.2 thorpej #include <compat/linux/common/linux_signal.h>
71 1.9.2.2 thorpej #include <compat/linux/common/linux_util.h>
72 1.9.2.2 thorpej #include <compat/linux/common/linux_ioctl.h>
73 1.9.2.2 thorpej #include <compat/linux/common/linux_hdio.h>
74 1.9.2.2 thorpej #include <compat/linux/common/linux_exec.h>
75 1.9.2.2 thorpej #include <compat/linux/common/linux_machdep.h>
76 1.9.2.2 thorpej
77 1.9.2.2 thorpej #include <compat/linux/linux_syscallargs.h>
78 1.9.2.2 thorpej
79 1.9.2.2 thorpej #include <machine/cpu.h>
80 1.9.2.2 thorpej #include <machine/psl.h>
81 1.9.2.2 thorpej #include <machine/reg.h>
82 1.9.2.2 thorpej #include <machine/regnum.h>
83 1.9.2.2 thorpej #include <machine/vmparam.h>
84 1.9.2.2 thorpej #include <machine/locore.h>
85 1.9.2.2 thorpej
86 1.9.2.2 thorpej #include <mips/cache.h>
87 1.9.2.2 thorpej
88 1.9.2.2 thorpej /*
89 1.9.2.2 thorpej * To see whether wscons is configured (for virtual console ioctl calls).
90 1.9.2.2 thorpej */
91 1.9.2.2 thorpej #if defined(_KERNEL_OPT)
92 1.9.2.2 thorpej #include "wsdisplay.h"
93 1.9.2.2 thorpej #endif
94 1.9.2.2 thorpej #if (NWSDISPLAY > 0)
95 1.9.2.2 thorpej #include <dev/wscons/wsconsio.h>
96 1.9.2.2 thorpej #include <dev/wscons/wsdisplay_usl_io.h>
97 1.9.2.2 thorpej #endif
98 1.9.2.2 thorpej
99 1.9.2.2 thorpej /*
100 1.9.2.2 thorpej * Set set up registers on exec.
101 1.9.2.2 thorpej * XXX not used at the moment since in sys/kern/exec_conf, LINUX_COMPAT
102 1.9.2.2 thorpej * entry uses NetBSD's native setregs instead of linux_setregs
103 1.9.2.2 thorpej */
104 1.9.2.2 thorpej void
105 1.9.2.2 thorpej linux_setregs(p, pack, stack)
106 1.9.2.2 thorpej struct proc *p;
107 1.9.2.2 thorpej struct exec_package *pack;
108 1.9.2.2 thorpej u_long stack;
109 1.9.2.2 thorpej {
110 1.9.2.2 thorpej setregs(p, pack, stack);
111 1.9.2.2 thorpej return;
112 1.9.2.2 thorpej }
113 1.9.2.2 thorpej
114 1.9.2.2 thorpej /*
115 1.9.2.2 thorpej * Send an interrupt to process.
116 1.9.2.2 thorpej *
117 1.9.2.2 thorpej * Adapted from sys/arch/mips/mips/mips_machdep.c
118 1.9.2.2 thorpej *
119 1.9.2.2 thorpej * XXX Does not work well yet with RT signals
120 1.9.2.2 thorpej *
121 1.9.2.2 thorpej */
122 1.9.2.2 thorpej
123 1.9.2.2 thorpej void
124 1.9.2.2 thorpej linux_sendsig(catcher, sig, mask, code) /* XXX Check me */
125 1.9.2.2 thorpej sig_t catcher;
126 1.9.2.2 thorpej int sig;
127 1.9.2.2 thorpej sigset_t *mask;
128 1.9.2.2 thorpej u_long code;
129 1.9.2.2 thorpej {
130 1.9.2.2 thorpej struct proc *p = curproc;
131 1.9.2.2 thorpej struct linux_sigframe *fp;
132 1.9.2.2 thorpej struct frame *f;
133 1.9.2.2 thorpej int i,onstack;
134 1.9.2.2 thorpej struct linux_sigframe sf;
135 1.9.2.2 thorpej
136 1.9.2.2 thorpej #ifdef DEBUG_LINUX
137 1.9.2.2 thorpej printf("linux_sendsig()\n");
138 1.9.2.2 thorpej #endif /* DEBUG_LINUX */
139 1.9.2.2 thorpej f = (struct frame *)p->p_md.md_regs;
140 1.9.2.2 thorpej
141 1.9.2.2 thorpej /*
142 1.9.2.2 thorpej * Do we need to jump onto the signal stack?
143 1.9.2.2 thorpej */
144 1.9.2.2 thorpej onstack =
145 1.9.2.2 thorpej (p->p_sigctx.ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
146 1.9.2.2 thorpej (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
147 1.9.2.2 thorpej
148 1.9.2.2 thorpej /*
149 1.9.2.2 thorpej * Signal stack is broken (see at the end of linux_sigreturn), so we do
150 1.9.2.2 thorpej * not use it yet. XXX fix this.
151 1.9.2.2 thorpej */
152 1.9.2.2 thorpej onstack=0;
153 1.9.2.2 thorpej
154 1.9.2.2 thorpej /*
155 1.9.2.2 thorpej * Allocate space for the signal handler context.
156 1.9.2.2 thorpej */
157 1.9.2.2 thorpej if (onstack)
158 1.9.2.2 thorpej fp = (struct linux_sigframe *)
159 1.9.2.2 thorpej ((caddr_t)p->p_sigctx.ps_sigstk.ss_sp
160 1.9.2.2 thorpej + p->p_sigctx.ps_sigstk.ss_size);
161 1.9.2.2 thorpej else
162 1.9.2.2 thorpej /* cast for _MIPS_BSD_API == _MIPS_BSD_API_LP32_64CLEAN case */
163 1.9.2.2 thorpej fp = (struct linux_sigframe *)(u_int32_t)f->f_regs[SP];
164 1.9.2.2 thorpej
165 1.9.2.2 thorpej /*
166 1.9.2.2 thorpej * Build stack frame for signal trampoline.
167 1.9.2.2 thorpej */
168 1.9.2.2 thorpej memset(&sf, 0, sizeof sf);
169 1.9.2.2 thorpej
170 1.9.2.2 thorpej /*
171 1.9.2.2 thorpej * This is the signal trampoline used by Linux, we don't use it,
172 1.9.2.2 thorpej * but we set it up in case an application expects it to be there
173 1.9.2.2 thorpej */
174 1.9.2.2 thorpej sf.lsf_code[0] = 0x24020000; /* li v0, __NR_sigreturn */
175 1.9.2.2 thorpej sf.lsf_code[1] = 0x0000000c; /* syscall */
176 1.9.2.2 thorpej
177 1.9.2.2 thorpej native_to_linux_sigset(mask, &sf.lsf_mask);
178 1.9.2.2 thorpej for (i=0; i<32; i++) {
179 1.9.2.2 thorpej sf.lsf_sc.lsc_regs[i] = f->f_regs[i];
180 1.9.2.2 thorpej }
181 1.9.2.2 thorpej sf.lsf_sc.lsc_mdhi = f->f_regs[MULHI];
182 1.9.2.2 thorpej sf.lsf_sc.lsc_mdlo = f->f_regs[MULLO];
183 1.9.2.2 thorpej sf.lsf_sc.lsc_pc = f->f_regs[PC];
184 1.9.2.2 thorpej sf.lsf_sc.lsc_status = f->f_regs[SR]; /* XXX */
185 1.9.2.2 thorpej sf.lsf_sc.lsc_cause = f->f_regs[CAUSE];
186 1.9.2.2 thorpej sf.lsf_sc.lsc_badvaddr = f->f_regs[BADVADDR]; /* XXX */
187 1.9.2.2 thorpej
188 1.9.2.2 thorpej /*
189 1.9.2.2 thorpej * Save signal stack. XXX broken
190 1.9.2.2 thorpej */
191 1.9.2.2 thorpej /* kregs.sc_onstack = p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK; */
192 1.9.2.2 thorpej
193 1.9.2.2 thorpej /*
194 1.9.2.2 thorpej * Install the sigframe onto the stack
195 1.9.2.2 thorpej */
196 1.9.2.2 thorpej fp -= sizeof(struct linux_sigframe);
197 1.9.2.2 thorpej if (copyout(&sf, fp, sizeof(sf)) != 0) {
198 1.9.2.2 thorpej /*
199 1.9.2.2 thorpej * Process has trashed its stack; give it an illegal
200 1.9.2.2 thorpej * instruction to halt it in its tracks.
201 1.9.2.2 thorpej */
202 1.9.2.2 thorpej #ifdef DEBUG_LINUX
203 1.9.2.2 thorpej printf("linux_sendsig: stack trashed\n");
204 1.9.2.2 thorpej #endif /* DEBUG_LINUX */
205 1.9.2.2 thorpej sigexit(p, SIGILL);
206 1.9.2.2 thorpej /* NOTREACHED */
207 1.9.2.2 thorpej }
208 1.9.2.2 thorpej
209 1.9.2.2 thorpej /* Set up the registers to return to sigcode. */
210 1.9.2.2 thorpej f->f_regs[A0] = native_to_linux_sig[sig];
211 1.9.2.2 thorpej f->f_regs[A1] = 0;
212 1.9.2.2 thorpej f->f_regs[A2] = (unsigned long)&fp->lsf_sc;
213 1.9.2.2 thorpej
214 1.9.2.2 thorpej #ifdef DEBUG_LINUX
215 1.9.2.2 thorpej printf("sigcontext is at %p\n", &fp->lsf_sc);
216 1.9.2.2 thorpej #endif /* DEBUG_LINUX */
217 1.9.2.2 thorpej
218 1.9.2.2 thorpej f->f_regs[SP] = (unsigned long)fp;
219 1.9.2.2 thorpej /* Signal trampoline code is at base of user stack. */
220 1.9.2.2 thorpej f->f_regs[RA] = (unsigned long)p->p_sigctx.ps_sigcode;
221 1.9.2.2 thorpej f->f_regs[T9] = (unsigned long)catcher;
222 1.9.2.2 thorpej f->f_regs[PC] = (unsigned long)catcher;
223 1.9.2.2 thorpej
224 1.9.2.2 thorpej /* Remember that we're now on the signal stack. */
225 1.9.2.2 thorpej if (onstack)
226 1.9.2.2 thorpej p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
227 1.9.2.2 thorpej
228 1.9.2.2 thorpej return;
229 1.9.2.2 thorpej }
230 1.9.2.2 thorpej
231 1.9.2.2 thorpej /*
232 1.9.2.2 thorpej * System call to cleanup state after a signal
233 1.9.2.2 thorpej * has been taken. Reset signal mask and
234 1.9.2.2 thorpej * stack state from context left by sendsig (above).
235 1.9.2.2 thorpej */
236 1.9.2.2 thorpej int
237 1.9.2.2 thorpej linux_sys_sigreturn(p, v, retval)
238 1.9.2.2 thorpej struct proc *p;
239 1.9.2.2 thorpej void *v;
240 1.9.2.2 thorpej register_t *retval;
241 1.9.2.2 thorpej {
242 1.9.2.2 thorpej struct linux_sys_sigreturn_args /* {
243 1.9.2.2 thorpej syscallarg(struct linux_sigframe *) sf;
244 1.9.2.2 thorpej } */ *uap = v;
245 1.9.2.2 thorpej struct linux_sigframe *sf, ksf;
246 1.9.2.2 thorpej struct frame *f;
247 1.9.2.2 thorpej sigset_t mask;
248 1.9.2.2 thorpej int i, error;
249 1.9.2.2 thorpej
250 1.9.2.2 thorpej #ifdef DEBUG_LINUX
251 1.9.2.2 thorpej printf("linux_sys_sigreturn()\n");
252 1.9.2.2 thorpej #endif /* DEBUG_LINUX */
253 1.9.2.2 thorpej
254 1.9.2.2 thorpej /*
255 1.9.2.2 thorpej * The trampoline code hands us the context.
256 1.9.2.2 thorpej * It is unsafe to keep track of it ourselves, in the event that a
257 1.9.2.2 thorpej * program jumps out of a signal handler.
258 1.9.2.2 thorpej */
259 1.9.2.2 thorpej sf = SCARG(uap, sf);
260 1.9.2.2 thorpej
261 1.9.2.2 thorpej if ((error = copyin(sf, &ksf, sizeof(ksf))) != 0)
262 1.9.2.2 thorpej return (error);
263 1.9.2.2 thorpej
264 1.9.2.2 thorpej /* Restore the register context. */
265 1.9.2.2 thorpej f = (struct frame *)p->p_md.md_regs;
266 1.9.2.2 thorpej for (i=0; i<32; i++)
267 1.9.2.2 thorpej f->f_regs[i] = ksf.lsf_sc.lsc_regs[i];
268 1.9.2.2 thorpej f->f_regs[MULLO] = ksf.lsf_sc.lsc_mdlo;
269 1.9.2.2 thorpej f->f_regs[MULHI] = ksf.lsf_sc.lsc_mdhi;
270 1.9.2.2 thorpej f->f_regs[PC] = ksf.lsf_sc.lsc_pc;
271 1.9.2.2 thorpej f->f_regs[BADVADDR] = ksf.lsf_sc.lsc_badvaddr;
272 1.9.2.2 thorpej f->f_regs[CAUSE] = ksf.lsf_sc.lsc_cause;
273 1.9.2.2 thorpej f->f_regs[SR] = ksf.lsf_sc.lsc_status;
274 1.9.2.2 thorpej
275 1.9.2.2 thorpej /* Restore signal stack. */
276 1.9.2.2 thorpej p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
277 1.9.2.2 thorpej
278 1.9.2.2 thorpej /* Restore signal mask. */
279 1.9.2.2 thorpej linux_to_native_sigset((linux_sigset_t *)&ksf.lsf_mask, &mask);
280 1.9.2.2 thorpej (void)sigprocmask1(p, SIG_SETMASK, &mask, 0);
281 1.9.2.2 thorpej
282 1.9.2.2 thorpej return (EJUSTRETURN);
283 1.9.2.2 thorpej }
284 1.9.2.2 thorpej
285 1.9.2.2 thorpej
286 1.9.2.2 thorpej int
287 1.9.2.2 thorpej linux_sys_rt_sigreturn(p, v, retval)
288 1.9.2.2 thorpej struct proc *p;
289 1.9.2.2 thorpej void *v;
290 1.9.2.2 thorpej register_t *retval;
291 1.9.2.2 thorpej {
292 1.9.2.2 thorpej return 0;
293 1.9.2.2 thorpej }
294 1.9.2.2 thorpej
295 1.9.2.2 thorpej
296 1.9.2.2 thorpej #if 0
297 1.9.2.2 thorpej int
298 1.9.2.2 thorpej linux_sys_modify_ldt(p, v, retval)
299 1.9.2.2 thorpej struct proc *p;
300 1.9.2.2 thorpej void *v;
301 1.9.2.2 thorpej register_t *retval;
302 1.9.2.2 thorpej {
303 1.9.2.2 thorpej /*
304 1.9.2.2 thorpej * This syscall is not implemented in Linux/Mips: we should not
305 1.9.2.2 thorpej * be here
306 1.9.2.2 thorpej */
307 1.9.2.2 thorpej #ifdef DEBUG_LINUX
308 1.9.2.2 thorpej printf("linux_sys_modify_ldt: should not be here.\n");
309 1.9.2.2 thorpej #endif /* DEBUG_LINUX */
310 1.9.2.2 thorpej return 0;
311 1.9.2.2 thorpej }
312 1.9.2.2 thorpej #endif
313 1.9.2.2 thorpej
314 1.9.2.2 thorpej /*
315 1.9.2.2 thorpej * major device numbers remapping
316 1.9.2.2 thorpej */
317 1.9.2.2 thorpej dev_t
318 1.9.2.2 thorpej linux_fakedev(dev)
319 1.9.2.2 thorpej dev_t dev;
320 1.9.2.2 thorpej {
321 1.9.2.2 thorpej /* XXX write me */
322 1.9.2.2 thorpej return dev;
323 1.9.2.2 thorpej }
324 1.9.2.2 thorpej
325 1.9.2.2 thorpej /*
326 1.9.2.2 thorpej * We come here in a last attempt to satisfy a Linux ioctl() call
327 1.9.2.2 thorpej */
328 1.9.2.2 thorpej int
329 1.9.2.2 thorpej linux_machdepioctl(p, v, retval)
330 1.9.2.2 thorpej struct proc *p;
331 1.9.2.2 thorpej void *v;
332 1.9.2.2 thorpej register_t *retval;
333 1.9.2.2 thorpej {
334 1.9.2.2 thorpej return 0;
335 1.9.2.2 thorpej }
336 1.9.2.2 thorpej
337 1.9.2.2 thorpej /*
338 1.9.2.2 thorpej * See above. If a root process tries to set access to an I/O port,
339 1.9.2.2 thorpej * just let it have the whole range.
340 1.9.2.2 thorpej */
341 1.9.2.2 thorpej int
342 1.9.2.2 thorpej linux_sys_ioperm(p, v, retval)
343 1.9.2.2 thorpej struct proc *p;
344 1.9.2.2 thorpej void *v;
345 1.9.2.2 thorpej register_t *retval;
346 1.9.2.2 thorpej {
347 1.9.2.2 thorpej /*
348 1.9.2.2 thorpej * This syscall is not implemented in Linux/Mips: we should not be here
349 1.9.2.2 thorpej */
350 1.9.2.2 thorpej #ifdef DEBUG_LINUX
351 1.9.2.2 thorpej printf("linux_sys_ioperm: should not be here.\n");
352 1.9.2.2 thorpej #endif /* DEBUG_LINUX */
353 1.9.2.2 thorpej return 0;
354 1.9.2.2 thorpej }
355 1.9.2.2 thorpej
356 1.9.2.2 thorpej /*
357 1.9.2.2 thorpej * wrapper linux_sys_new_uname() -> linux_sys_uname()
358 1.9.2.2 thorpej */
359 1.9.2.2 thorpej int
360 1.9.2.2 thorpej linux_sys_new_uname(p, v, retval)
361 1.9.2.2 thorpej struct proc *p;
362 1.9.2.2 thorpej void *v;
363 1.9.2.2 thorpej register_t *retval;
364 1.9.2.2 thorpej {
365 1.9.2.2 thorpej /*
366 1.9.2.2 thorpej * Use this if you want to try Linux emulation with a glibc-2.2
367 1.9.2.2 thorpej * or higher. Note that signals will not work
368 1.9.2.2 thorpej */
369 1.9.2.2 thorpej #if 0
370 1.9.2.2 thorpej struct linux_sys_uname_args /* {
371 1.9.2.2 thorpej syscallarg(struct linux_utsname *) up;
372 1.9.2.2 thorpej } */ *uap = v;
373 1.9.2.2 thorpej struct linux_utsname luts;
374 1.9.2.2 thorpej
375 1.9.2.2 thorpej strncpy(luts.l_sysname, linux_sysname, sizeof(luts.l_sysname));
376 1.9.2.2 thorpej strncpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
377 1.9.2.2 thorpej strncpy(luts.l_release, "2.4.0", sizeof(luts.l_release));
378 1.9.2.2 thorpej strncpy(luts.l_version, linux_version, sizeof(luts.l_version));
379 1.9.2.2 thorpej strncpy(luts.l_machine, machine, sizeof(luts.l_machine));
380 1.9.2.2 thorpej strncpy(luts.l_domainname, domainname, sizeof(luts.l_domainname));
381 1.9.2.2 thorpej
382 1.9.2.2 thorpej return copyout(&luts, SCARG(uap, up), sizeof(luts));
383 1.9.2.2 thorpej #else
384 1.9.2.2 thorpej return linux_sys_uname(p, v, retval);
385 1.9.2.2 thorpej #endif
386 1.9.2.2 thorpej }
387 1.9.2.2 thorpej
388 1.9.2.2 thorpej /*
389 1.9.2.2 thorpej * In Linux, cacheflush is icurrently implemented
390 1.9.2.2 thorpej * as a whole cache flush (arguments are ignored)
391 1.9.2.2 thorpej * we emulate this broken beahior.
392 1.9.2.2 thorpej */
393 1.9.2.2 thorpej int
394 1.9.2.2 thorpej linux_sys_cacheflush(p, v, retval)
395 1.9.2.2 thorpej struct proc *p;
396 1.9.2.2 thorpej void *v;
397 1.9.2.2 thorpej register_t *retval;
398 1.9.2.2 thorpej {
399 1.9.2.2 thorpej mips_icache_sync_all();
400 1.9.2.2 thorpej mips_dcache_wbinv_all();
401 1.9.2.2 thorpej return 0;
402 1.9.2.2 thorpej }
403 1.9.2.2 thorpej
404 1.9.2.2 thorpej /*
405 1.9.2.2 thorpej * This system call is depecated in Linux, but
406 1.9.2.2 thorpej * some binaries and some libraries use it.
407 1.9.2.2 thorpej */
408 1.9.2.2 thorpej int
409 1.9.2.2 thorpej linux_sys_sysmips(p, v, retval)
410 1.9.2.2 thorpej struct proc *p;
411 1.9.2.2 thorpej void *v;
412 1.9.2.2 thorpej register_t *retval;
413 1.9.2.2 thorpej {
414 1.9.2.2 thorpej struct linux_sys_sysmips_args {
415 1.9.2.2 thorpej syscallarg(int) cmd;
416 1.9.2.2 thorpej syscallarg(int) arg1;
417 1.9.2.2 thorpej syscallarg(int) arg2;
418 1.9.2.2 thorpej syscallarg(int) arg3;
419 1.9.2.2 thorpej } *uap = v;
420 1.9.2.2 thorpej int error;
421 1.9.2.2 thorpej
422 1.9.2.2 thorpej switch (SCARG(uap, cmd)) {
423 1.9.2.2 thorpej case LINUX_SETNAME: {
424 1.9.2.2 thorpej char nodename [LINUX___NEW_UTS_LEN + 1];
425 1.9.2.2 thorpej int name;
426 1.9.2.2 thorpej size_t len;
427 1.9.2.2 thorpej
428 1.9.2.2 thorpej if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
429 1.9.2.2 thorpej return error;
430 1.9.2.2 thorpej if ((error = copyinstr((char *)SCARG(uap, arg1), nodename,
431 1.9.2.2 thorpej LINUX___NEW_UTS_LEN, &len)) != 0)
432 1.9.2.2 thorpej return error;
433 1.9.2.2 thorpej
434 1.9.2.2 thorpej name = KERN_HOSTNAME;
435 1.9.2.2 thorpej return (kern_sysctl(&name, 1, 0, 0, nodename, len, p));
436 1.9.2.2 thorpej
437 1.9.2.2 thorpej break;
438 1.9.2.2 thorpej }
439 1.9.2.2 thorpej case LINUX_MIPS_ATOMIC_SET: {
440 1.9.2.2 thorpej void *addr;
441 1.9.2.2 thorpej int s;
442 1.9.2.2 thorpej
443 1.9.2.2 thorpej addr = (void *)SCARG(uap, arg1);
444 1.9.2.2 thorpej
445 1.9.2.2 thorpej if ((uvm_useracc((caddr_t)addr, sizeof(int),
446 1.9.2.2 thorpej B_READ | B_WRITE)) != 1)
447 1.9.2.2 thorpej return EFAULT;
448 1.9.2.2 thorpej
449 1.9.2.2 thorpej s = splhigh();
450 1.9.2.2 thorpej /*
451 1.9.2.2 thorpej * No error testing here. This is bad, but Linux does
452 1.9.2.2 thorpej * it like this. The source aknowledge "This is broken"
453 1.9.2.2 thorpej * in a comment...
454 1.9.2.2 thorpej */
455 1.9.2.2 thorpej *retval = (register_t)fubyte(addr);
456 1.9.2.2 thorpej error = subyte(addr, SCARG(uap, arg2));
457 1.9.2.2 thorpej splx(s);
458 1.9.2.2 thorpej
459 1.9.2.2 thorpej return 0;
460 1.9.2.2 thorpej break;
461 1.9.2.2 thorpej }
462 1.9.2.2 thorpej case LINUX_MIPS_FIXADE: /* XXX not implemented */
463 1.9.2.2 thorpej break;
464 1.9.2.2 thorpej case LINUX_FLUSH_CACHE:
465 1.9.2.2 thorpej mips_icache_sync_all();
466 1.9.2.2 thorpej mips_dcache_wbinv_all();
467 1.9.2.2 thorpej break;
468 1.9.2.2 thorpej case LINUX_MIPS_RDNVRAM:
469 1.9.2.2 thorpej return EIO;
470 1.9.2.2 thorpej break;
471 1.9.2.2 thorpej default:
472 1.9.2.2 thorpej return EINVAL;
473 1.9.2.2 thorpej break;
474 1.9.2.2 thorpej }
475 1.9.2.2 thorpej #ifdef DEBUG_LINUX
476 1.9.2.2 thorpej printf("linux_sys_sysmips(): unimplemented command %d\n",
477 1.9.2.2 thorpej SCARG(uap,cmd));
478 1.9.2.2 thorpej #endif /* DEBUG_LINUX */
479 1.9.2.2 thorpej return 0;
480 1.9.2.2 thorpej }
481