sys_machdep.c revision 1.14
1/* $OpenBSD: sys_machdep.c,v 1.14 2013/06/02 16:38:05 guenther Exp $ */ 2/* $NetBSD: sys_machdep.c,v 1.1 2003/04/26 18:39:32 fvdl Exp $ */ 3 4/*- 5 * Copyright (c) 1998 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Charles M. Hannum. 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#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/ioctl.h> 36#include <sys/file.h> 37#include <sys/time.h> 38#include <sys/proc.h> 39#include <sys/user.h> 40#include <sys/uio.h> 41#include <sys/kernel.h> 42#include <sys/buf.h> 43#include <sys/signal.h> 44 45#include <sys/mount.h> 46#include <sys/syscallargs.h> 47 48#include <uvm/uvm_extern.h> 49 50#include <machine/cpu.h> 51#include <machine/cpufunc.h> 52#include <machine/psl.h> 53#include <machine/reg.h> 54#include <machine/sysarch.h> 55 56#if defined(PERFCTRS) && 0 57#include <machine/pmc.h> 58#endif 59 60extern struct vm_map *kernel_map; 61 62int amd64_iopl(struct proc *, void *, register_t *); 63 64#ifdef APERTURE 65extern int allowaperture; 66#endif 67 68int 69amd64_iopl(struct proc *p, void *args, register_t *retval) 70{ 71 int error; 72 struct trapframe *tf = p->p_md.md_regs; 73 struct amd64_iopl_args ua; 74 75 if ((error = suser(p, 0)) != 0) 76 return error; 77 78#ifdef APERTURE 79 if (!allowaperture && securelevel > 0) 80 return EPERM; 81#else 82 if (securelevel > 0) 83 return EPERM; 84#endif 85 86 if ((error = copyin(args, &ua, sizeof(ua))) != 0) 87 return error; 88 89 if (ua.iopl) 90 tf->tf_rflags |= PSL_IOPL; 91 else 92 tf->tf_rflags &= ~PSL_IOPL; 93 94 return 0; 95} 96 97int 98amd64_get_fsbase(struct proc *p, void *args) 99{ 100 return copyout(&p->p_addr->u_pcb.pcb_fsbase, args, 101 sizeof(p->p_addr->u_pcb.pcb_fsbase)); 102} 103 104int 105amd64_set_fsbase(struct proc *p, void *args) 106{ 107 int error; 108 uint64_t base; 109 110 if ((error = copyin(args, &base, sizeof(base))) != 0) 111 return (error); 112 113 if (base >= VM_MAXUSER_ADDRESS) 114 return (EINVAL); 115 116 p->p_addr->u_pcb.pcb_fsbase = base; 117 return 0; 118} 119 120int 121sys_sysarch(struct proc *p, void *v, register_t *retval) 122{ 123 struct sys_sysarch_args /* { 124 syscallarg(int) op; 125 syscallarg(void *) parms; 126 } */ *uap = v; 127 int error = 0; 128 129 switch(SCARG(uap, op)) { 130 case AMD64_IOPL: 131 error = amd64_iopl(p, SCARG(uap, parms), retval); 132 break; 133 134#if defined(PERFCTRS) && 0 135 case AMD64_PMC_INFO: 136 error = pmc_info(p, SCARG(uap, parms), retval); 137 break; 138 139 case AMD64_PMC_STARTSTOP: 140 error = pmc_startstop(p, SCARG(uap, parms), retval); 141 break; 142 143 case AMD64_PMC_READ: 144 error = pmc_read(p, SCARG(uap, parms), retval); 145 break; 146#endif 147 148 case AMD64_GET_FSBASE: 149 error = amd64_get_fsbase(p, SCARG(uap, parms)); 150 break; 151 152 case AMD64_SET_FSBASE: 153 error = amd64_set_fsbase(p, SCARG(uap, parms)); 154 break; 155 156 default: 157 error = EINVAL; 158 break; 159 } 160 return (error); 161} 162