- added instructions how to update the online documentation
[bochs-mirror.git] / iodev / unmapped.cc
blob5074cfe6b78cdfab3ed53ff2f1fec42ca81e0080
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: unmapped.cc,v 1.27 2008/02/15 22:05:43 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 /////////////////////////////////////////////////////////////////////////
29 // Define BX_PLUGGABLE in files that can be compiled into plugins. For
30 // platforms that require a special tag on exported symbols, BX_PLUGGABLE
31 // is used to know when we are exporting symbols and when we are importing.
32 #define BX_PLUGGABLE
33 #include "iodev.h"
35 #define LOG_THIS theUnmappedDevice->
37 bx_unmapped_c *theUnmappedDevice = NULL;
39 int libunmapped_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
41 theUnmappedDevice = new bx_unmapped_c();
42 bx_devices.pluginUnmapped = theUnmappedDevice;
43 BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theUnmappedDevice, BX_PLUGIN_UNMAPPED);
44 return(0); // Success
47 void libunmapped_LTX_plugin_fini(void)
49 delete theUnmappedDevice;
52 bx_unmapped_c::bx_unmapped_c(void)
54 put("UNMP");
55 settype(UNMAPLOG);
58 bx_unmapped_c::~bx_unmapped_c(void)
60 BX_DEBUG(("Exit"));
63 void bx_unmapped_c::init(void)
65 DEV_register_default_ioread_handler(this, read_handler, "Unmapped", 7);
66 DEV_register_default_iowrite_handler(this, write_handler, "Unmapped", 7);
68 s.port80 = 0x00;
69 s.port8e = 0x00;
70 s.shutdown = 0;
73 // static IO port read callback handler
74 // redirects to non-static class handler to avoid virtual functions
75 Bit32u bx_unmapped_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
77 #if !BX_USE_UM_SMF
78 bx_unmapped_c *class_ptr = (bx_unmapped_c *) this_ptr;
79 return class_ptr->read(address, io_len);
82 Bit32u bx_unmapped_c::read(Bit32u address, unsigned io_len)
84 #else
85 UNUSED(this_ptr);
86 #endif // !BX_USE_UM_SMF
87 UNUSED(io_len);
89 Bit32u retval;
91 // This function gets called for access to any IO ports which
92 // are not mapped to any device handler. Reads return 0
94 if (address >= 0x02e0 && address <= 0x02ef) {
95 retval = 0;
96 goto return_from_read;
99 switch (address) {
100 case 0x80:
101 retval = BX_UM_THIS s.port80;
102 break;
103 case 0x8e:
104 retval = BX_UM_THIS s.port8e;
105 break;
106 #if BX_PORT_E9_HACK
107 // Unused port on ISA - this can be used by the emulated code
108 // to detect it is running inside Bochs and that the debugging
109 // features are available (write 0xFF or something on unused
110 // port 0x80, then read from 0xe9, if value is 0xe9, debug
111 // output is available) (see write() for that) -- Andreas and Emmanuel
112 case 0xe9:
113 retval = 0xe9;
114 break;
115 #endif
116 case 0x03df:
117 retval = 0xffffffff;
118 BX_DEBUG(("unsupported IO read from port %04x (CGA)", address));
119 break;
120 case 0x023a:
121 case 0x02f8: /* UART */
122 case 0x02f9: /* UART */
123 case 0x02fb: /* UART */
124 case 0x02fc: /* UART */
125 case 0x02fd: /* UART */
126 case 0x02ea:
127 case 0x02eb:
128 case 0x03e8:
129 case 0x03e9:
130 case 0x03ea:
131 case 0x03eb:
132 case 0x03ec:
133 case 0x03ed:
134 case 0x03f8: /* UART */
135 case 0x03f9: /* UART */
136 case 0x03fb: /* UART */
137 case 0x03fc: /* UART */
138 case 0x03fd: /* UART */
139 case 0x17c6:
140 retval = 0xffffffff;
141 BX_DEBUG(("unsupported IO read from port %04x", address));
142 break;
143 default:
144 retval = 0xffffffff;
147 return_from_read:
149 if (bx_dbg.unsupported_io) {
150 switch (io_len) {
151 case 1:
152 retval = (Bit8u)retval;
153 BX_DEBUG(("unmapped: 8-bit read from %04x = %02x", address, retval));
154 break;
155 case 2:
156 retval = (Bit16u)retval;
157 BX_DEBUG(("unmapped: 16-bit read from %04x = %04x", address, retval));
158 break;
159 case 4:
160 BX_DEBUG(("unmapped: 32-bit read from %04x = %08x", address, retval));
161 break;
162 default:
163 BX_DEBUG(("unmapped: %d-bit read from %04x = %x", io_len * 8, address, retval));
167 return retval;
170 // static IO port write callback handler
171 // redirects to non-static class handler to avoid virtual functions
173 void bx_unmapped_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
175 #if !BX_USE_UM_SMF
176 bx_unmapped_c *class_ptr = (bx_unmapped_c *) this_ptr;
177 class_ptr->write(address, value, io_len);
180 void bx_unmapped_c::write(Bit32u address, Bit32u value, unsigned io_len)
182 #else
183 UNUSED(this_ptr);
184 #endif // !BX_USE_UM_SMF
185 UNUSED(io_len);
187 // This function gets called for access to any IO ports which
188 // are not mapped to any device handler. Writes to an unmapped
189 // IO port are ignored.
191 if (address >= 0x02e0 && address <= 0x02ef)
192 goto return_from_write;
194 switch (address) {
195 case 0x80: // diagnostic test port to display progress of POST
196 //BX_DEBUG(("Diagnostic port 80h: write = %02xh", (unsigned) value));
197 BX_UM_THIS s.port80 = value;
198 break;
200 case 0x8e: // ???
201 BX_UM_THIS s.port8e = value;
202 break;
204 #if BX_PORT_E9_HACK
205 // This port doesn't exist on normal ISA architecture. However,
206 // we define a convention here, to display on the console of the
207 // system running Bochs, anything that is written to it. The
208 // idea is to provide debug output very early when writing
209 // BIOS or OS code for example, without having to bother with
210 // properly setting up a serial port or anything.
212 // Idea by Andreas Beck (andreas.beck@ggi-project.org)
214 case 0xe9:
215 putchar(value);
216 fflush(stdout);
217 break;
218 #endif
220 case 0xed: // Dummy port used as I/O delay
221 break;
222 case 0xee: // ???
223 break;
225 case 0x2f2:
226 case 0x2f3:
227 case 0x2f4:
228 case 0x2f5:
229 case 0x2f6:
230 case 0x2f7:
231 case 0x3e8:
232 case 0x3e9:
233 case 0x3eb:
234 case 0x3ec:
235 case 0x3ed:
236 // BX_DEBUG(("unsupported IO write to port %04x of %02x", address, value));
237 break;
239 case 0x8900: // Shutdown port, could be moved in a PM device
240 // or a host <-> guest communication device
241 switch (value) {
242 case 'S': if (BX_UM_THIS s.shutdown == 0) BX_UM_THIS s.shutdown = 1; break;
243 case 'h': if (BX_UM_THIS s.shutdown == 1) BX_UM_THIS s.shutdown = 2; break;
244 case 'u': if (BX_UM_THIS s.shutdown == 2) BX_UM_THIS s.shutdown = 3; break;
245 case 't': if (BX_UM_THIS s.shutdown == 3) BX_UM_THIS s.shutdown = 4; break;
246 case 'd': if (BX_UM_THIS s.shutdown == 4) BX_UM_THIS s.shutdown = 5; break;
247 case 'o': if (BX_UM_THIS s.shutdown == 5) BX_UM_THIS s.shutdown = 6; break;
248 case 'w': if (BX_UM_THIS s.shutdown == 6) BX_UM_THIS s.shutdown = 7; break;
249 case 'n': if (BX_UM_THIS s.shutdown == 7) BX_UM_THIS s.shutdown = 8; break;
250 #if BX_DEBUGGER
251 // Very handy for debugging:
252 // output 'D' to port 8900, and bochs quits to debugger
253 case 'D': bx_debug_break(); break;
254 #endif
255 default : BX_UM_THIS s.shutdown = 0; break;
257 if (BX_UM_THIS s.shutdown == 8) {
258 bx_user_quit = 1;
259 LOG_THIS setonoff(LOGLEV_PANIC, ACT_FATAL);
260 BX_PANIC(("Shutdown port: shutdown requested"));
262 break;
264 case 0xfedc:
265 bx_dbg.debugger = (value > 0);
266 BX_DEBUG(("DEBUGGER = %u", (unsigned) bx_dbg.debugger));
267 break;
269 default:
270 break;
273 return_from_write:
275 if (bx_dbg.unsupported_io) {
276 switch (io_len) {
277 case 1:
278 BX_INFO(("unmapped: 8-bit write to %04x = %02x", address, value));
279 break;
280 case 2:
281 BX_INFO(("unmapped: 16-bit write to %04x = %04x", address, value));
282 break;
283 case 4:
284 BX_INFO(("unmapped: 32-bit write to %04x = %08x", address, value));
285 break;
286 default:
287 BX_INFO(("unmapped: %d-bit write to %04x = %x", io_len * 8, address, value));
288 break;