summaryrefslogtreecommitdiff
path: root/lib/libarch/amd64
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2004-02-26 00:10:55 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2004-02-26 00:10:55 +0000
commit6a246f06cfd44c878800cbf9248bf5efea260d54 (patch)
tree5dd51a13f8c455185def8d203780fee703d46d10 /lib/libarch/amd64
parentfd93564e9d44ac157099ab7c84d3c1eddeec7417 (diff)
x86_64 libarch
Diffstat (limited to 'lib/libarch/amd64')
-rw-r--r--lib/libarch/amd64/Makefile20
-rw-r--r--lib/libarch/amd64/x86_64_get_ioperm.2116
-rw-r--r--lib/libarch/amd64/x86_64_get_ioperm.c56
-rw-r--r--lib/libarch/amd64/x86_64_get_ldt.2113
-rw-r--r--lib/libarch/amd64/x86_64_get_ldt.c50
-rw-r--r--lib/libarch/amd64/x86_64_iopl.285
-rw-r--r--lib/libarch/amd64/x86_64_iopl.c56
-rw-r--r--lib/libarch/amd64/x86_64_set_ioperm.c56
-rw-r--r--lib/libarch/amd64/x86_64_set_ldt.c50
-rw-r--r--lib/libarch/amd64/x86_64_vm86.2117
-rw-r--r--lib/libarch/amd64/x86_64_vm86.c55
11 files changed, 774 insertions, 0 deletions
diff --git a/lib/libarch/amd64/Makefile b/lib/libarch/amd64/Makefile
new file mode 100644
index 00000000000..b32bd7996b8
--- /dev/null
+++ b/lib/libarch/amd64/Makefile
@@ -0,0 +1,20 @@
+# $OpenBSD: Makefile,v 1.1 2004/02/26 00:10:54 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
+MANSUBDIR=amd64
+MLINKS+=x86_64_get_ldt.2 x86_64_set_ldt.2 \
+ x86_64_get_ioperm.2 x86_64_set_ioperm.2
+
+.if ${MACHINE_ARCH} == "x86_64"
+.PATH: ${LIBC}/x86_64
+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
+.include <bsd.lib.mk>
+.else
+NOPROG=
+.include <bsd.prog.mk>
+.endif
+
diff --git a/lib/libarch/amd64/x86_64_get_ioperm.2 b/lib/libarch/amd64/x86_64_get_ioperm.2
new file mode 100644
index 00000000000..ac1da46c820
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_get_ioperm.2
@@ -0,0 +1,116 @@
+.\" $OpenBSD: x86_64_get_ioperm.2,v 1.1 2004/02/26 00:10:54 deraadt Exp $
+.\" $NetBSD: x86_64_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 X86_64_GET_IOPERM 2
+.Os
+.Sh NAME
+.Nm x86_64_get_ioperm ,
+.Nm x86_64_set_ioperm
+.Nd manage x86_64 per-process I/O permission bitmap
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <machine/sysarch.h>
+.Ft int
+.Fn x86_64_get_ioperm "u_long *iomap"
+.Ft int
+.Fn x86_64_set_ioperm "u_long *iomap"
+.Sh DESCRIPTION
+.Fn x86_64_get_ioperm
+copies the current I/O permission bitmap into the memory referenced by
+.Fa iomap .
+.Pp
+.Fn x86_64_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 x86_64_get_ioperm
+and
+.Fn x86_64_set_ioperm
+functions must be compiled using
+.Cm -lx86_64 .
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn x86_64_get_ioperm
+and
+.Fn x86_64_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 x86_64_get_ioperm
+and
+.Fn x86_64_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 x86_64_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 x86_64_iopl 2 .
diff --git a/lib/libarch/amd64/x86_64_get_ioperm.c b/lib/libarch/amd64/x86_64_get_ioperm.c
new file mode 100644
index 00000000000..053e661441e
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_get_ioperm.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: x86_64_get_ioperm.c,v 1.1 2004/02/26 00:10:54 deraadt Exp $ */
+/* $NetBSD: x86_64_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
+x86_64_get_ioperm(iomap)
+ u_long *iomap;
+{
+ struct x86_64_get_ioperm_args p;
+
+ p.iomap = iomap;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(X86_64_GET_IOPERM, (char *)&p);
+}
diff --git a/lib/libarch/amd64/x86_64_get_ldt.2 b/lib/libarch/amd64/x86_64_get_ldt.2
new file mode 100644
index 00000000000..fd2f6430c87
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_get_ldt.2
@@ -0,0 +1,113 @@
+.\" $OpenBSD: x86_64_get_ldt.2,v 1.1 2004/02/26 00:10:54 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: x86_64_get_ldt.2,v 1.3 1996/01/05 14:56:44 pk Exp $
+.\"
+.Dd September 20, 1993
+.Dt X86_64_GET_LDT 2
+.Os
+.Sh NAME
+.Nm x86_64_get_ldt ,
+.Nm x86_64_set_ldt
+.Nd manage x86_64 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 x86_64_get_ldt "int start_sel" "union descriptor *descs" "int num_sels"
+.Ft int
+.Fn x86_64_set_ldt "int start_sel" "union descriptor *descs" "int num_sels"
+.Sh DESCRIPTION
+.Fn x86_64_get_ldt
+will return the list of x86_64 descriptors that the process has in its
+LDT.
+.Fn x86_64_set_ldt
+will set a list of x86_64 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 x86_64/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 x86_64_get_ldt
+and
+.Fn x86_64_set_ldt
+functions must be compiled using
+.Cm -lx86_64 .
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn x86_64_get_ldt
+returns the number of descriptors currently in the LDT.
+.Fn x86_64_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 x86_64_get_ldt
+and
+.Fn x86_64_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/x86_64_get_ldt.c b/lib/libarch/amd64/x86_64_get_ldt.c
new file mode 100644
index 00000000000..a2fb9512a01
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_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
+x86_64_get_ldt(start, desc, num)
+ int start;
+ union descriptor *desc;
+ int num;
+{
+ struct x86_64_get_ldt_args p;
+
+ p.start = start;
+ p.desc = desc;
+ p.num = num;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(X86_64_GET_LDT, (char *)&p);
+}
diff --git a/lib/libarch/amd64/x86_64_iopl.2 b/lib/libarch/amd64/x86_64_iopl.2
new file mode 100644
index 00000000000..a1e612bc464
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_iopl.2
@@ -0,0 +1,85 @@
+.\" $OpenBSD: x86_64_iopl.2,v 1.1 2004/02/26 00:10:54 deraadt Exp $
+.\" $NetBSD: x86_64_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 X86_64_IOPL 2
+.Os
+.Sh NAME
+.Nm x86_64_iopl
+.Nd change the x86_64 I/O privilege level
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <machine/sysarch.h>
+.Ft int
+.Fn x86_64_iopl "int iopl"
+.Sh DESCRIPTION
+.Fn x86_64_iopl
+sets the x86_64 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 x86_64_iopl
+function must be compiled using
+.Cm -lx86_64 .
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn x86_64_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 x86_64_iopl
+will fail if:
+.Bl -tag -width [EINVAL]
+.It Bq Er EPERM
+The caller was not the superuser.
+.El
+.Sh SEE ALSO
+.Xr x86_64_get_ioperm 2 ,
+.Xr x86_64_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/x86_64_iopl.c b/lib/libarch/amd64/x86_64_iopl.c
new file mode 100644
index 00000000000..4a257db89f9
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_iopl.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: x86_64_iopl.c,v 1.1 2004/02/26 00:10:54 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
+x86_64_iopl(iopl)
+ int iopl;
+{
+ struct x86_64_iopl_args p;
+
+ p.iopl = iopl;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(X86_64_IOPL, (char *)&p);
+}
diff --git a/lib/libarch/amd64/x86_64_set_ioperm.c b/lib/libarch/amd64/x86_64_set_ioperm.c
new file mode 100644
index 00000000000..e51d1b89a5f
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_set_ioperm.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: x86_64_set_ioperm.c,v 1.1 2004/02/26 00:10:54 deraadt Exp $ */
+/* $NetBSD: x86_64_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
+x86_64_set_ioperm(iomap)
+ u_long *iomap;
+{
+ struct x86_64_set_ioperm_args p;
+
+ p.iomap = iomap;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(X86_64_SET_IOPERM, (char *)&p);
+}
diff --git a/lib/libarch/amd64/x86_64_set_ldt.c b/lib/libarch/amd64/x86_64_set_ldt.c
new file mode 100644
index 00000000000..4d8abd75386
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_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
+x86_64_set_ldt(start, desc, num)
+ int start;
+ union descriptor *desc;
+ int num;
+{
+ struct x86_64_set_ldt_args p;
+
+ p.start = start;
+ p.desc = desc;
+ p.num = num;
+
+ /* LINTED pointer casts may be troublesome */
+ return sysarch(X86_64_SET_LDT, (char *)&p);
+}
diff --git a/lib/libarch/amd64/x86_64_vm86.2 b/lib/libarch/amd64/x86_64_vm86.2
new file mode 100644
index 00000000000..d62f43ae15e
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_vm86.2
@@ -0,0 +1,117 @@
+.\" $OpenBSD: x86_64_vm86.2,v 1.1 2004/02/26 00:10:54 deraadt Exp $
+.\" $NetBSD: x86_64_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 X86_64_VM86 2
+.Os
+.Sh NAME
+.Nm x86_64_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 x86_64_vm86 "struct vm86_struct *vmcp"
+.Sh DESCRIPTION
+.Fn x86_64_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 x86_64_vm86
+function must be compiled using
+.Cm -lx86_64 .
+.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 x86_64_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/x86_64_vm86.c b/lib/libarch/amd64/x86_64_vm86.c
new file mode 100644
index 00000000000..0886873a063
--- /dev/null
+++ b/lib/libarch/amd64/x86_64_vm86.c
@@ -0,0 +1,55 @@
+/* $OpenBSD: x86_64_vm86.c,v 1.1 2004/02/26 00:10:54 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);
+}
+