summaryrefslogtreecommitdiff
path: root/lib/libarch
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2004-02-27 23:44:57 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2004-02-27 23:44:57 +0000
commite5240435f2a680a24b7cfa751b8bcd6514d2a4ef (patch)
tree04a0a98c8b5d10595d7e502db7af69176be10b87 /lib/libarch
parent390eafafdf5f2dca98a1aebad012e2bf2a092601 (diff)
change to amd_*() functions
Diffstat (limited to 'lib/libarch')
-rw-r--r--lib/libarch/amd64/Makefile14
-rw-r--r--lib/libarch/amd64/amd64_get_ioperm.2116
-rw-r--r--lib/libarch/amd64/amd64_get_ioperm.c56
-rw-r--r--lib/libarch/amd64/amd64_get_ldt.2113
-rw-r--r--lib/libarch/amd64/amd64_get_ldt.c50
-rw-r--r--lib/libarch/amd64/amd64_iopl.285
-rw-r--r--lib/libarch/amd64/amd64_iopl.c56
-rw-r--r--lib/libarch/amd64/amd64_set_ioperm.c56
-rw-r--r--lib/libarch/amd64/amd64_set_ldt.c50
-rw-r--r--lib/libarch/amd64/amd64_vm86.2117
-rw-r--r--lib/libarch/amd64/amd64_vm86.c55
11 files changed, 761 insertions, 7 deletions
diff --git a/lib/libarch/amd64/Makefile b/lib/libarch/amd64/Makefile
index ec8831b5ccf..961c5792f14 100644
--- a/lib/libarch/amd64/Makefile
+++ b/lib/libarch/amd64/Makefile
@@ -1,17 +1,17 @@
-# $OpenBSD: Makefile,v 1.2 2004/02/27 17:36:14 deraadt Exp $
+# $OpenBSD: Makefile,v 1.3 2004/02/27 23:44:56 deraadt Exp $
# $NetBSD: Makefile,v 1.1 1996/02/21 02:45:47 jtk Exp $
-MAN+= x86_64_get_ldt.2 \
- x86_64_iopl.2 x86_64_get_ioperm.2
+MAN+= amd64_get_ldt.2 \
+ amd64_iopl.2 amd64_get_ioperm.2
MANSUBDIR=amd64
-MLINKS+=x86_64_get_ldt.2 x86_64_set_ldt.2 \
- x86_64_get_ioperm.2 x86_64_set_ioperm.2
+MLINKS+=amd64_get_ldt.2 amd64_set_ldt.2 \
+ amd64_get_ioperm.2 amd64_set_ioperm.2
.if ${MACHINE_ARCH} == "amd64"
.PATH: ${LIBC}/amd64
NOPIC=
-SRCS+= x86_64_get_ldt.c x86_64_set_ldt.c \
- x86_64_iopl.c x86_64_get_ioperm.c x86_64_set_ioperm.c
+SRCS+= amd64_get_ldt.c amd64_set_ldt.c \
+ amd64_iopl.c amd64_get_ioperm.c amd64_set_ioperm.c
.include <bsd.lib.mk>
.else
NOPROG=
diff --git a/lib/libarch/amd64/amd64_get_ioperm.2 b/lib/libarch/amd64/amd64_get_ioperm.2
new file mode 100644
index 00000000000..a03416f0936
--- /dev/null
+++ b/lib/libarch/amd64/amd64_get_ioperm.2
@@ -0,0 +1,116 @@
+.\" $OpenBSD: amd64_get_ioperm.2,v 1.1 2004/02/27 23:44:56 deraadt Exp $
+.\" $NetBSD: amd64_get_ioperm.2,v 1.3 1996/02/27 22:57:17 jtc Exp $
+.\"
+.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by John T. Kohl and Charles M. Hannum.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd October 14, 1995
+.Dt AMD64_GET_IOPERM 2
+.Os
+.Sh NAME
+.Nm amd64_get_ioperm ,
+.Nm amd64_set_ioperm
+.Nd manage amd64 per-process I/O permission bitmap
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <machine/sysarch.h>
+.Ft int
+.Fn amd64_get_ioperm "u_long *iomap"
+.Ft int
+.Fn amd64_set_ioperm "u_long *iomap"
+.Sh DESCRIPTION
+.Fn amd64_get_ioperm
+copies the current I/O permission bitmap into the memory referenced by
+.Fa iomap .
+.Pp
+.Fn amd64_set_ioperm
+sets the I/O permission bitmap from the data pointed to by
+.Fa iomap .
+This call is restricted to the superuser.
+.Pp
+The permission bitmap contains 1024 bits in 32 longwords.
+If bit
+.Va n
+is clear in the bitmap, then access is granted to I/O port
+.Va n .
+If bit
+.Va n
+is set in the bitmap, then an attempt to access I/O port
+.Va n
+results in delivery of a
+.Dv SIGBUS
+signal unless the process's I/O permission level would grant I/O access.
+.Pp
+.Sy Note:
+Code using the
+.Fn amd64_get_ioperm
+and
+.Fn amd64_set_ioperm
+functions must be compiled using
+.Cm -lamd64 .
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn amd64_get_ioperm
+and
+.Fn amd64_set_ioperm
+return 0.
+Otherwise, a value of \-1 is returned and the global variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn amd64_get_ioperm
+and
+.Fn amd64_set_ioperm
+will fail if:
+.Bl -tag -width [EINVAL]
+.It Bq Er EFAULT
+.Fa iomap
+points outside the process's allocated address space.
+.It Bq Er EPERM
+The caller was not the superuser.
+.El
+.Sh SEE ALSO
+.Xr amd64_iopl 2
+.Rs
+.%A Intel
+.%T AMD64 Microprocessor Programmer's Reference Manual
+.Re
+.Sh WARNING
+You can really hose your machine if you enable user-level I/O and
+write to hardware ports without care.
+.Sh BUGS
+The bitmap should really cover 65536 bits, but that's just too big for
+allocation in a kernel structure.
+If you need access to ports beyond 1024, use
+.Xr amd64_iopl 2 .
diff --git a/lib/libarch/amd64/amd64_get_ioperm.c b/lib/libarch/amd64/amd64_get_ioperm.c
new file mode 100644
index 00000000000..bf5a7d5a7a2
--- /dev/null
+++ b/lib/libarch/amd64/amd64_get_ioperm.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: amd64_get_ioperm.c,v 1.1 2004/02/27 23:44:56 deraadt Exp $ */
+/* $NetBSD: amd64_get_ioperm.c,v 1.2 1996/02/27 22:57:22 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by John T. Kohl and Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <machine/segments.h>
+#include <machine/sysarch.h>
+
+int
+amd64_get_ioperm(iomap)
+ u_long *iomap;
+{
+ struct amd64_get_ioperm_args p;
+
+ p.iomap = iomap;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(AMD64_GET_IOPERM, (char *)&p);
+}
diff --git a/lib/libarch/amd64/amd64_get_ldt.2 b/lib/libarch/amd64/amd64_get_ldt.2
new file mode 100644
index 00000000000..29531e21ef8
--- /dev/null
+++ b/lib/libarch/amd64/amd64_get_ldt.2
@@ -0,0 +1,113 @@
+.\" $OpenBSD: amd64_get_ldt.2,v 1.1 2004/02/27 23:44:56 deraadt Exp $
+.\"
+.\" Copyright (c) 1980, 1991 Regents of the University of California.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" from: @(#)fork.2 6.5 (Berkeley) 3/10/91
+.\" $NetBSD: amd64_get_ldt.2,v 1.3 1996/01/05 14:56:44 pk Exp $
+.\"
+.Dd September 20, 1993
+.Dt AMD64_GET_LDT 2
+.Os
+.Sh NAME
+.Nm amd64_get_ldt ,
+.Nm amd64_set_ldt
+.Nd manage amd64 per-process Local Descriptor Table entries
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <machine/segments.h>
+.Fd #include <machine/sysarch.h>
+.Ft int
+.Fn amd64_get_ldt "int start_sel" "union descriptor *descs" "int num_sels"
+.Ft int
+.Fn amd64_set_ldt "int start_sel" "union descriptor *descs" "int num_sels"
+.Sh DESCRIPTION
+.Fn amd64_get_ldt
+will return the list of amd64 descriptors that the process has in its
+LDT.
+.Fn amd64_set_ldt
+will set a list of amd64 descriptors for the current process in its
+LDT.
+Both routines accept a starting selector number
+.Fa start_sel ,
+an array of memory that
+will contain the descriptors to be set or returned
+.Fa descs ,
+and the number of entries to set or return
+.Fa num_sels .
+.Pp
+The argument
+.Fa descs
+can be either segment_descriptor or gate_descriptor, as defined in
+.Ao Pa amd64/segments.h Ac .
+These structures are defined by the architecture
+as disjoint bit-fields, so care must be taken in constructing them.
+.Pp
+Before this API can be used the functionality has to be enabled
+using the machdep.userldt
+.Xr sysctl 8
+variable.
+.Pp
+.Sy Note:
+Code using the
+.Fn amd64_get_ldt
+and
+.Fn amd64_set_ldt
+functions must be compiled using
+.Cm -lamd64 .
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn amd64_get_ldt
+returns the number of descriptors currently in the LDT.
+.Fn amd64_set_ldt
+returns the first selector set.
+Otherwise, a value of \-1 is returned and the global
+variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn amd64_get_ldt
+and
+.Fn amd64_set_ldt
+will fail if:
+.Bl -tag -width [EINVAL]
+.It Bq Er EINVAL
+An inappropriate parameter was used for
+.Fa start_sel
+or
+.Fa num_sels .
+.It Bq Er EACCES
+The caller attempted to use a descriptor that would
+circumvent protection or cause a failure.
+.El
+.Sh REFERENCES
+.Rs
+.%A Intel
+.%T AMD64 Microprocessor Programmer's Reference Manual
+.Re
+.Sh WARNING
+You can really hose your process using this.
diff --git a/lib/libarch/amd64/amd64_get_ldt.c b/lib/libarch/amd64/amd64_get_ldt.c
new file mode 100644
index 00000000000..4989f9787be
--- /dev/null
+++ b/lib/libarch/amd64/amd64_get_ldt.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 1993 John Brezak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <machine/segments.h>
+#include <machine/sysarch.h>
+
+int
+amd64_get_ldt(start, desc, num)
+ int start;
+ union descriptor *desc;
+ int num;
+{
+ struct amd64_get_ldt_args p;
+
+ p.start = start;
+ p.desc = desc;
+ p.num = num;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(AMD64_GET_LDT, (char *)&p);
+}
diff --git a/lib/libarch/amd64/amd64_iopl.2 b/lib/libarch/amd64/amd64_iopl.2
new file mode 100644
index 00000000000..d473cd8a709
--- /dev/null
+++ b/lib/libarch/amd64/amd64_iopl.2
@@ -0,0 +1,85 @@
+.\" $OpenBSD: amd64_iopl.2,v 1.1 2004/02/27 23:44:56 deraadt Exp $
+.\" $NetBSD: amd64_iopl.2,v 1.3 1996/02/27 22:57:25 jtc Exp $
+.\"
+.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by John T. Kohl and Charles M. Hannum.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd October 14, 1995
+.Dt AMD64_IOPL 2
+.Os
+.Sh NAME
+.Nm amd64_iopl
+.Nd change the amd64 I/O privilege level
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <machine/sysarch.h>
+.Ft int
+.Fn amd64_iopl "int iopl"
+.Sh DESCRIPTION
+.Fn amd64_iopl
+sets the amd64 I/O privilege level to the value specified by
+.Ar iopl .
+This call is restricted to the superuser.
+.Pp
+.Sy Note:
+Code using the
+.Fn amd64_iopl
+function must be compiled using
+.Cm -lamd64 .
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn amd64_iopl
+returns 0.
+Otherwise, a value of \-1 is returned and the global
+variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn amd64_iopl
+will fail if:
+.Bl -tag -width [EINVAL]
+.It Bq Er EPERM
+The caller was not the superuser.
+.El
+.Sh SEE ALSO
+.Xr amd64_get_ioperm 2 ,
+.Xr amd64_set_ioperm 2
+.Sh REFERENCES
+.Rs
+.%A Intel
+.%T AMD64 Microprocessor Programmer's Reference Manual
+.Re
+.Sh WARNING
+You can really hose your machine if you enable user-level I/O and
+write to hardware ports without care.
diff --git a/lib/libarch/amd64/amd64_iopl.c b/lib/libarch/amd64/amd64_iopl.c
new file mode 100644
index 00000000000..6570496737a
--- /dev/null
+++ b/lib/libarch/amd64/amd64_iopl.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: amd64_iopl.c,v 1.1 2004/02/27 23:44:56 deraadt Exp $ */
+/* $NetBSD: i386_iopl.c,v 1.2 1996/02/27 22:57:29 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by John T. Kohl and Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <machine/segments.h>
+#include <machine/sysarch.h>
+
+int
+amd64_iopl(iopl)
+ int iopl;
+{
+ struct amd64_iopl_args p;
+
+ p.iopl = iopl;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(AMD64_IOPL, (char *)&p);
+}
diff --git a/lib/libarch/amd64/amd64_set_ioperm.c b/lib/libarch/amd64/amd64_set_ioperm.c
new file mode 100644
index 00000000000..a02c1049ab2
--- /dev/null
+++ b/lib/libarch/amd64/amd64_set_ioperm.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: amd64_set_ioperm.c,v 1.1 2004/02/27 23:44:56 deraadt Exp $ */
+/* $NetBSD: amd64_set_ioperm.c,v 1.2 1996/02/27 22:57:31 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by John T. Kohl and Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <machine/segments.h>
+#include <machine/sysarch.h>
+
+int
+amd64_set_ioperm(iomap)
+ u_long *iomap;
+{
+ struct amd64_set_ioperm_args p;
+
+ p.iomap = iomap;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(AMD64_SET_IOPERM, (char *)&p);
+}
diff --git a/lib/libarch/amd64/amd64_set_ldt.c b/lib/libarch/amd64/amd64_set_ldt.c
new file mode 100644
index 00000000000..e64b1e8df80
--- /dev/null
+++ b/lib/libarch/amd64/amd64_set_ldt.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 1993 John Brezak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <machine/segments.h>
+#include <machine/sysarch.h>
+
+int
+amd64_set_ldt(start, desc, num)
+ int start;
+ union descriptor *desc;
+ int num;
+{
+ struct amd64_set_ldt_args p;
+
+ p.start = start;
+ p.desc = desc;
+ p.num = num;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(AMD64_SET_LDT, (char *)&p);
+}
diff --git a/lib/libarch/amd64/amd64_vm86.2 b/lib/libarch/amd64/amd64_vm86.2
new file mode 100644
index 00000000000..eb8b50a7795
--- /dev/null
+++ b/lib/libarch/amd64/amd64_vm86.2
@@ -0,0 +1,117 @@
+.\" $OpenBSD: amd64_vm86.2,v 1.1 2004/02/27 23:44:56 deraadt Exp $
+.\" $NetBSD: amd64_vm86.2,v 1.1 1996/02/21 00:21:52 jtk Exp $
+.\"
+.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by John Kohl.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" from: @(#)fork.2 6.5 (Berkeley) 3/10/91
+.\"
+.Dd February 20, 1996
+.Dt AMD64_VM86 2
+.Os
+.Sh NAME
+.Nm amd64_vm86
+.Nd set virtual 8086 processor registers and mode
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <signal.h>
+.Fd #include <machine/segments.h>
+.Fd #include <machine/sysarch.h>
+.Fd #include <machine/vm86.h>
+.Ft int
+.Fn amd64_vm86 "struct vm86_struct *vmcp"
+.Sh DESCRIPTION
+.Fn amd64_vm86
+will set the process into virtual 8086 mode using the registers and
+selectors specified by the context pointed to by
+.Ar vmcp .
+The processor registers are set from
+.Ar vmcp->substr.regs ,
+and the emulated processor type from
+.Ar vmcp->substr.ss_cpu_type .
+.Pp
+The kernel keeps a pointer to the context, and uses the tables stored at
+.Ar vmcp->int_byuser
+and
+.Ar vmcp->int21_byuser
+for fast virtual interrupt handling.
+If the
+.Ar n Ns Li th
+bit is clear in the first of
+these arrays, then the kernel may directly emulate the real-mode x86 INT
+.Ar n
+instruction handling.
+If the
+.Ar n Ns Li th
+bit is set, then the process is
+delivered a signal when an INT instruction is executed.
+.Pp
+Since MS-DOS puts many DOS functions onto interrupt 21, it is handled
+specially: the
+.Ar k Ns Li th
+bit in the
+.Ar vmcp->int21_byuser
+array is checked when INT
+.Ar 21
+is requested and the
+.Ar ah
+register is
+.Ar k .
+.Pp
+.Sy Note:
+Code using the
+.Fn amd64_vm86
+function must be compiled using
+.Cm -lamd64 .
+.Sh RETURN VALUES
+This routine does not normally return: 32-bit mode will be restored by
+the delivery of a signal to the process.
+In case of an error in setting
+the VM86 mode, a value of \-1 is returned and the global variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn amd64_vm86
+will fail if:
+.Bl -tag -width [EINVAL]
+.It Bq Er EFAULT
+The state at
+.Ar vmcp
+was not readable to the user process.
+.El
+.Sh REFERENCES
+.Rs
+.%A Intel
+.%T AMD64 Microprocessor Programmer's Reference Manual
+.Re
diff --git a/lib/libarch/amd64/amd64_vm86.c b/lib/libarch/amd64/amd64_vm86.c
new file mode 100644
index 00000000000..a307c76682a
--- /dev/null
+++ b/lib/libarch/amd64/amd64_vm86.c
@@ -0,0 +1,55 @@
+/* $OpenBSD: amd64_vm86.c,v 1.1 2004/02/27 23:44:56 deraadt Exp $ */
+/* $NetBSD: i386_vm86.c,v 1.1 1996/02/21 00:21:56 jtk Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by John Kohl.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <machine/signal.h>
+#include <machine/segments.h>
+#include <machine/sysarch.h>
+#include <machine/vm86.h>
+
+int
+i386_vm86(vmcp)
+ register struct vm86_struct *vmcp;
+{
+
+ /* LINTED pointer cast may be troublesome */
+ return sysarch(I386_VM86, (char *)vmcp);
+}
+