FreeBSD/Linux Kernel Cross Reference
sys/i386/io_emulate.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: io_emulate.c,v $
29 * Revision 2.6 92/01/03 20:06:54 dbg
30 * Move AT-bus IO port emulation to i386at/iopl.c.
31 * [92/01/02 dbg]
32 *
33 * Rewrite to map IO ports into 'faulting' thread.
34 * Move actual instruction decoding to trap.c.
35 * Emulate certain IO ports for AT bus machines.
36 * [91/11/09 dbg]
37 *
38 * Revision 2.5 91/05/14 16:09:24 mrt
39 * Correcting copyright
40 *
41 * Revision 2.4 91/02/05 17:12:27 mrt
42 * Changed to new Mach copyright
43 * [91/02/01 17:35:06 mrt]
44 *
45 * Revision 2.3 90/06/02 14:48:35 rpd
46 * Converted to new IPC.
47 * [90/06/01 rpd]
48 *
49 * Revision 2.2 90/05/21 13:26:32 dbg
50 * Created.
51 * [90/05/09 dbg]
52 *
53 */
54 #include <platforms.h>
55
56 #include <mach/boolean.h>
57 #include <mach/port.h>
58 #include <kern/thread.h>
59 #include <kern/task.h>
60
61 #include <ipc/ipc_port.h>
62 #include <ipc/ipc_space.h>
63 #include <ipc/ipc_right.h>
64 #include <ipc/ipc_object.h>
65 #include <ipc/ipc_entry.h>
66
67 #include <device/dev_hdr.h>
68
69 #include <i386/thread.h>
70 #include <i386/io_port.h>
71 #include <i386/io_emulate.h>
72
73 extern ipc_port_t iopl_device_port;
74 extern device_t iopl_device;
75
76 int
77 emulate_io(regs, opcode, io_port)
78 struct i386_saved_state *regs;
79 int opcode;
80 int io_port;
81 {
82 thread_t thread = current_thread();
83
84 #if AT386
85 if (iopl_emulate(regs, opcode, io_port))
86 return EM_IO_DONE;
87 #endif /* AT386 */
88
89 if (iopb_check_mapping(thread, iopl_device))
90 return EM_IO_ERROR;
91
92 /*
93 * Check for send rights to the IOPL device port.
94 */
95 if (iopl_device_port == IP_NULL)
96 return EM_IO_ERROR;
97 {
98 ipc_space_t space = current_space();
99 mach_port_t name;
100 ipc_entry_t entry;
101 boolean_t has_rights = FALSE;
102
103 is_write_lock(space);
104 assert(space->is_active);
105
106 if (ipc_right_reverse(space, (ipc_object_t) iopl_device_port,
107 &name, &entry)) {
108 /* iopl_device_port is locked and active */
109 if (entry->ie_bits & MACH_PORT_TYPE_SEND)
110 has_rights = TRUE;
111 ip_unlock(iopl_device_port);
112 }
113
114 is_write_unlock(space);
115 if (!has_rights) {
116 return EM_IO_ERROR;
117 }
118 }
119
120
121 /*
122 * Map the IOPL port set into the thread.
123 */
124
125 if (i386_io_port_add(thread, iopl_device)
126 != KERN_SUCCESS)
127 return EM_IO_ERROR;
128
129 /*
130 * Make the thread use its IO_TSS to get the IO permissions;
131 * it may not have had one before this.
132 */
133 switch_ktss(thread->pcb);
134
135 return EM_IO_RETRY;
136 }
Cache object: 935a3c69f2008d27cad0174795bf63c6
|