]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/io_emulate.c
xnu-792.6.61.tar.gz
[apple/xnu.git] / osfmk / i386 / io_emulate.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
e5568f75 11 *
37839358
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * @OSF_COPYRIGHT@
24 */
25/*
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50/*
51 */
52
53#include <platforms.h>
1c79356b
A
54#include <mach/boolean.h>
55#include <mach/port.h>
56#include <kern/thread.h>
57#include <kern/task.h>
58
59#include <ipc/ipc_port.h>
60#include <ipc/ipc_space.h>
61#include <ipc/ipc_right.h>
62#include <ipc/ipc_object.h>
63#include <ipc/ipc_entry.h>
64
65#include <i386/thread.h>
66#include <i386/io_port.h>
67#include <i386/io_emulate.h>
68#include <i386/iopb_entries.h>
69
91447636 70#if 1
1c79356b
A
71int
72emulate_io(
91447636
A
73 __unused struct i386_saved_state *regs,
74 __unused int opcode,
75 __unused int io_port)
1c79356b 76{
1c79356b
A
77 /* At the moment, we are not allowing I/O emulation
78 *
79 * FIXME - this should probably change due to
80 * the Window Server's need to map I/O ports into its space.
81 */
82
83 return EM_IO_ERROR;
91447636 84}
1c79356b 85#else
91447636
A
86int
87emulate_io(
88 struct i386_saved_state *regs,
89 int opcode,
90 int io_port)
91{
1c79356b
A
92 thread_t thread = current_thread();
93 at386_io_lock_state();
94
95 if (iopl_emulate(regs, opcode, io_port))
96 return EM_IO_DONE;
97
98 if (iopb_check_mapping(thread, iopl_device))
99 return EM_IO_ERROR;
100
101 /*
102 * Check for send rights to the IOPL device port.
103 */
104 if (iopl_device_port == IP_NULL)
105 return EM_IO_ERROR;
106 {
107 ipc_space_t space = current_space();
108 mach_port_name_t name;
109 ipc_entry_t entry;
110 boolean_t has_rights = FALSE;
111 ipc_entry_bits_t *capability;
112
113 is_write_lock(space);
114 assert(space->is_active);
115
116 if (ipc_right_reverse(space, (ipc_object_t) iopl_device_port,
117 &name, &entry, &capability)) {
118 /* iopl_device_port is locked and active */
119 if (capability[space->server_id] & MACH_PORT_TYPE_SEND)
120 has_rights = TRUE;
121 ip_unlock(iopl_device_port);
122 }
123
124 is_write_unlock(space);
125 if (!has_rights) {
126 return EM_IO_ERROR;
127 }
128 }
129
130 /*
131 * Map the IOPL port set into the thread.
132 */
133
134 if (i386_io_port_add(thread, iopl_device)
135 != KERN_SUCCESS)
136 return EM_IO_ERROR;
137
138 /*
139 * Make the thread use its IO_TSS to get the IO permissions;
140 * it may not have had one before this.
141 */
91447636 142 act_machine_switch_pcb(thread);
1c79356b
A
143
144 return EM_IO_RETRY;
1c79356b 145}
91447636 146#endif