1 /////////////////////////////////////////////////////////////////////////
2 // $Id: unmapped.cc,v 1.27 2008/02/15 22:05:43 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2001 MandrakeSoft S.A.
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.
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
);
47 void libunmapped_LTX_plugin_fini(void)
49 delete theUnmappedDevice
;
52 bx_unmapped_c::bx_unmapped_c(void)
58 bx_unmapped_c::~bx_unmapped_c(void)
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);
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
)
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
)
86 #endif // !BX_USE_UM_SMF
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) {
96 goto return_from_read
;
101 retval
= BX_UM_THIS s
.port80
;
104 retval
= BX_UM_THIS s
.port8e
;
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
118 BX_DEBUG(("unsupported IO read from port %04x (CGA)", address
));
121 case 0x02f8: /* UART */
122 case 0x02f9: /* UART */
123 case 0x02fb: /* UART */
124 case 0x02fc: /* UART */
125 case 0x02fd: /* UART */
134 case 0x03f8: /* UART */
135 case 0x03f9: /* UART */
136 case 0x03fb: /* UART */
137 case 0x03fc: /* UART */
138 case 0x03fd: /* UART */
141 BX_DEBUG(("unsupported IO read from port %04x", address
));
149 if (bx_dbg
.unsupported_io
) {
152 retval
= (Bit8u
)retval
;
153 BX_DEBUG(("unmapped: 8-bit read from %04x = %02x", address
, retval
));
156 retval
= (Bit16u
)retval
;
157 BX_DEBUG(("unmapped: 16-bit read from %04x = %04x", address
, retval
));
160 BX_DEBUG(("unmapped: 32-bit read from %04x = %08x", address
, retval
));
163 BX_DEBUG(("unmapped: %d-bit read from %04x = %x", io_len
* 8, address
, 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
)
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
)
184 #endif // !BX_USE_UM_SMF
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
;
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
;
201 BX_UM_THIS s
.port8e
= value
;
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)
220 case 0xed: // Dummy port used as I/O delay
236 // BX_DEBUG(("unsupported IO write to port %04x of %02x", address, value));
239 case 0x8900: // Shutdown port, could be moved in a PM device
240 // or a host <-> guest communication device
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;
251 // Very handy for debugging:
252 // output 'D' to port 8900, and bochs quits to debugger
253 case 'D': bx_debug_break(); break;
255 default : BX_UM_THIS s
.shutdown
= 0; break;
257 if (BX_UM_THIS s
.shutdown
== 8) {
259 LOG_THIS
setonoff(LOGLEV_PANIC
, ACT_FATAL
);
260 BX_PANIC(("Shutdown port: shutdown requested"));
265 bx_dbg
.debugger
= (value
> 0);
266 BX_DEBUG(("DEBUGGER = %u", (unsigned) bx_dbg
.debugger
));
275 if (bx_dbg
.unsupported_io
) {
278 BX_INFO(("unmapped: 8-bit write to %04x = %02x", address
, value
));
281 BX_INFO(("unmapped: 16-bit write to %04x = %04x", address
, value
));
284 BX_INFO(("unmapped: 32-bit write to %04x = %08x", address
, value
));
287 BX_INFO(("unmapped: %d-bit write to %04x = %x", io_len
* 8, address
, value
));