]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
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> | |
54 | #include <cpus.h> | |
55 | #include <mach/boolean.h> | |
56 | #include <mach/port.h> | |
57 | #include <kern/thread.h> | |
58 | #include <kern/task.h> | |
59 | ||
60 | #include <ipc/ipc_port.h> | |
61 | #include <ipc/ipc_space.h> | |
62 | #include <ipc/ipc_right.h> | |
63 | #include <ipc/ipc_object.h> | |
64 | #include <ipc/ipc_entry.h> | |
65 | ||
66 | #include <i386/thread.h> | |
67 | #include <i386/io_port.h> | |
68 | #include <i386/io_emulate.h> | |
69 | #include <i386/iopb_entries.h> | |
70 | ||
71 | int | |
72 | emulate_io( | |
73 | struct i386_saved_state *regs, | |
74 | int opcode, | |
75 | int io_port) | |
76 | { | |
77 | #if 1 | |
78 | /* At the moment, we are not allowing I/O emulation | |
79 | * | |
80 | * FIXME - this should probably change due to | |
81 | * the Window Server's need to map I/O ports into its space. | |
82 | */ | |
83 | ||
84 | return EM_IO_ERROR; | |
85 | #else | |
86 | thread_t thread = current_thread(); | |
87 | at386_io_lock_state(); | |
88 | ||
89 | if (iopl_emulate(regs, opcode, io_port)) | |
90 | return EM_IO_DONE; | |
91 | ||
92 | if (iopb_check_mapping(thread, iopl_device)) | |
93 | return EM_IO_ERROR; | |
94 | ||
95 | /* | |
96 | * Check for send rights to the IOPL device port. | |
97 | */ | |
98 | if (iopl_device_port == IP_NULL) | |
99 | return EM_IO_ERROR; | |
100 | { | |
101 | ipc_space_t space = current_space(); | |
102 | mach_port_name_t name; | |
103 | ipc_entry_t entry; | |
104 | boolean_t has_rights = FALSE; | |
105 | ipc_entry_bits_t *capability; | |
106 | ||
107 | is_write_lock(space); | |
108 | assert(space->is_active); | |
109 | ||
110 | if (ipc_right_reverse(space, (ipc_object_t) iopl_device_port, | |
111 | &name, &entry, &capability)) { | |
112 | /* iopl_device_port is locked and active */ | |
113 | if (capability[space->server_id] & MACH_PORT_TYPE_SEND) | |
114 | has_rights = TRUE; | |
115 | ip_unlock(iopl_device_port); | |
116 | } | |
117 | ||
118 | is_write_unlock(space); | |
119 | if (!has_rights) { | |
120 | return EM_IO_ERROR; | |
121 | } | |
122 | } | |
123 | ||
124 | /* | |
125 | * Map the IOPL port set into the thread. | |
126 | */ | |
127 | ||
128 | if (i386_io_port_add(thread, iopl_device) | |
129 | != KERN_SUCCESS) | |
130 | return EM_IO_ERROR; | |
131 | ||
132 | /* | |
133 | * Make the thread use its IO_TSS to get the IO permissions; | |
134 | * it may not have had one before this. | |
135 | */ | |
136 | act_machine_switch_pcb(thread->top_act); | |
137 | ||
138 | return EM_IO_RETRY; | |
139 | #endif | |
140 | } |