1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
/////////////////////////////////////////////////////////////////////////
// $Id: io.cc,v 1.5 2001/10/03 13:10:37 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
//
// MandrakeSoft S.A.
// 43, rue d'Aboukir
// 75002 Paris - France
// http://www.linux-mandrake.com/
// http://www.mandrakesoft.com/
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define NEED_CPU_REG_SHORTCUTS 1
#include "bochs.h"
#define LOG_THIS BX_CPU_THIS_PTR
void
BX_CPU_C::INSB_YbDX(BxInstruction_t *i)
{
Bit8u value8=0;
if (BX_CPU_THIS_PTR cr0.pe && (BX_CPU_THIS_PTR eflags.vm || (CPL>IOPL))) {
if ( !BX_CPU_THIS_PTR allow_io(DX, 1) ) {
exception(BX_GP_EXCEPTION, 0, 0);
}
}
if (i->as_32) {
// Write a zero to memory, to trigger any segment or page
// faults before reading from IO port.
write_virtual_byte(BX_SEG_REG_ES, EDI, &value8);
value8 = BX_INP(DX, 1);
/* no seg override possible */
write_virtual_byte(BX_SEG_REG_ES, EDI, &value8);
if (BX_CPU_THIS_PTR eflags.df) {
EDI = EDI - 1;
}
else {
EDI = EDI + 1;
}
}
else {
// Write a zero to memory, to trigger any segment or page
// faults before reading from IO port.
write_virtual_byte(BX_SEG_REG_ES, DI, &value8);
value8 = BX_INP(DX, 1);
/* no seg override possible */
write_virtual_byte(BX_SEG_REG_ES, DI, &value8);
if (BX_CPU_THIS_PTR eflags.df) {
DI = DI - 1;
}
else {
DI = DI + 1;
}
}
}
void
BX_CPU_C::INSW_YvDX(BxInstruction_t *i)
// input word/doubleword from port to string
{
Bit32u edi;
unsigned int incr;
if (i->as_32)
edi = EDI;
else
edi = DI;
if (i->os_32) {
Bit32u value32=0;
if (BX_CPU_THIS_PTR cr0.pe && (BX_CPU_THIS_PTR eflags.vm || (CPL>IOPL))) {
if ( !BX_CPU_THIS_PTR allow_io(DX, 4) ) {
exception(BX_GP_EXCEPTION, 0, 0);
}
}
// Write a zero to memory, to trigger any segment or page
// faults before reading from IO port.
write_virtual_dword(BX_SEG_REG_ES, edi, &value32);
value32 = BX_INP(DX, 4);
/* no seg override allowed */
write_virtual_dword(BX_SEG_REG_ES, edi, &value32);
incr = 4;
}
else {
Bit16u value16=0;
if (BX_CPU_THIS_PTR cr0.pe && (BX_CPU_THIS_PTR eflags.vm || (CPL>IOPL))) {
if ( !BX_CPU_THIS_PTR allow_io(DX, 2) ) {
exception(BX_GP_EXCEPTION, 0, 0);
}
}
// Write a zero to memory, to trigger any segment or page
// faults before reading from IO port.
write_virtual_word(BX_SEG_REG_ES, edi, &value16);
value16 = BX_INP(DX, 2);
/* no seg override allowed */
write_virtual_word(BX_SEG_REG_ES, edi, &value16);
incr = 2;
}
if (i->as_32) {
if (BX_CPU_THIS_PTR eflags.df)
EDI = EDI - incr;
else
EDI = EDI + incr;
}
else {
if (BX_CPU_THIS_PTR eflags.df)
DI = DI - incr;
else
DI = DI + incr;
}
}
void
BX_CPU_C::OUTSB_DXXb(BxInstruction_t *i)
{
unsigned seg;
Bit8u value8;
Bit32u esi;
if (BX_CPU_THIS_PTR cr0.pe && (BX_CPU_THIS_PTR eflags.vm || (CPL>IOPL))) {
if ( !BX_CPU_THIS_PTR allow_io(DX, 1) ) {
exception(BX_GP_EXCEPTION, 0, 0);
}
}
if (!BX_NULL_SEG_REG(i->seg)) {
seg = i->seg;
}
else {
seg = BX_SEG_REG_DS;
}
if (i->as_32)
esi = ESI;
else
esi = SI;
read_virtual_byte(seg, esi, &value8);
BX_OUTP(DX, value8, 1);
if (i->as_32) {
if (BX_CPU_THIS_PTR eflags.df)
ESI -= 1;
else
ESI += 1;
}
else {
if (BX_CPU_THIS_PTR eflags.df)
SI -= 1;
else
SI += 1;
}
}
void
BX_CPU_C::OUTSW_DXXv(BxInstruction_t *i)
// output word/doubleword string to port
{
unsigned seg;
Bit32u esi;
unsigned int incr;
if (!BX_NULL_SEG_REG(i->seg)) {
seg = i->seg;
}
else {
seg = BX_SEG_REG_DS;
}
if (i->as_32)
esi = ESI;
else
esi = SI;
if (i->os_32) {
Bit32u value32;
if (BX_CPU_THIS_PTR cr0.pe && (BX_CPU_THIS_PTR eflags.vm || (CPL>IOPL))) {
if ( !BX_CPU_THIS_PTR allow_io(DX, 4) ) {
exception(BX_GP_EXCEPTION, 0, 0);
}
}
read_virtual_dword(seg, esi, &value32);
BX_OUTP(DX, value32, 4);
incr = 4;
}
else {
Bit16u value16;
if (BX_CPU_THIS_PTR cr0.pe && (BX_CPU_THIS_PTR eflags.vm || (CPL>IOPL))) {
if ( !BX_CPU_THIS_PTR allow_io(DX, 2) ) {
exception(BX_GP_EXCEPTION, 0, 0);
}
}
read_virtual_word(seg, esi, &value16);
BX_OUTP(DX, value16, 2);
incr = 2;
}
if (i->as_32) {
if (BX_CPU_THIS_PTR eflags.df)
ESI = ESI - incr;
else
ESI = ESI + incr;
}
else {
if (BX_CPU_THIS_PTR eflags.df)
SI = SI - incr;
else
SI = SI + incr;
}
}
void
BX_CPU_C::IN_ALIb(BxInstruction_t *i)
{
Bit8u al, imm8;
imm8 = i->Ib;
al = BX_CPU_THIS_PTR inp8(imm8);
AL = al;
}
void
BX_CPU_C::IN_eAXIb(BxInstruction_t *i)
{
Bit8u imm8;
imm8 = i->Ib;
#if BX_CPU_LEVEL > 2
if (i->os_32) {
Bit32u eax;
eax = BX_CPU_THIS_PTR inp32(imm8);
EAX = eax;
}
else
#endif /* BX_CPU_LEVEL > 2 */
{
Bit16u ax;
ax = BX_CPU_THIS_PTR inp16(imm8);
AX = ax;
}
}
void
BX_CPU_C::OUT_IbAL(BxInstruction_t *i)
{
Bit8u al, imm8;
imm8 = i->Ib;
al = AL;
BX_CPU_THIS_PTR outp8(imm8, al);
}
void
BX_CPU_C::OUT_IbeAX(BxInstruction_t *i)
{
Bit8u imm8;
imm8 = i->Ib;
#if BX_CPU_LEVEL > 2
if (i->os_32) {
BX_CPU_THIS_PTR outp32(imm8, EAX);
}
else
#endif /* BX_CPU_LEVEL > 2 */
{
BX_CPU_THIS_PTR outp16(imm8, AX);
}
}
void
BX_CPU_C::IN_ALDX(BxInstruction_t *i)
{
Bit8u al;
al = BX_CPU_THIS_PTR inp8(DX);
AL = al;
}
void
BX_CPU_C::IN_eAXDX(BxInstruction_t *i)
{
#if BX_CPU_LEVEL > 2
if (i->os_32) {
Bit32u eax;
eax = BX_CPU_THIS_PTR inp32(DX);
EAX = eax;
}
else
#endif /* BX_CPU_LEVEL > 2 */
{
Bit16u ax;
ax = BX_CPU_THIS_PTR inp16(DX);
AX = ax;
}
}
void
BX_CPU_C::OUT_DXAL(BxInstruction_t *i)
{
Bit16u dx;
Bit8u al;
dx = DX;
al = AL;
BX_CPU_THIS_PTR outp8(dx, al);
}
void
BX_CPU_C::OUT_DXeAX(BxInstruction_t *i)
{
Bit16u dx;
dx = DX;
#if BX_CPU_LEVEL > 2
if (i->os_32) {
BX_CPU_THIS_PTR outp32(dx, EAX);
}
else
#endif /* BX_CPU_LEVEL > 2 */
{
BX_CPU_THIS_PTR outp16(dx, AX);
}
}
|