2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-04-07 20:12:19 +04:00
|
|
|
// $Id: io.cc,v 1.78 2009-04-07 16:12:19 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// 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
|
2009-01-16 21:18:59 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
2008-01-29 20:13:10 +03:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-05-24 22:46:34 +04:00
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "bochs.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu.h"
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "iodev/iodev.h"
|
|
|
|
|
2002-09-15 06:55:34 +04:00
|
|
|
#if BX_SUPPORT_X86_64==0
|
|
|
|
// Make life easier for merging cpu64 and cpu32 code.
|
|
|
|
#define RDI EDI
|
|
|
|
#define RSI ESI
|
|
|
|
#define RAX EAX
|
2007-09-27 20:11:32 +04:00
|
|
|
#define RCX ECX
|
2002-09-15 06:55:34 +04:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-01-05 16:40:47 +03:00
|
|
|
//
|
|
|
|
// Repeat Speedups methods
|
|
|
|
//
|
|
|
|
|
2006-05-08 00:45:42 +04:00
|
|
|
#if BX_SupportRepeatSpeedups
|
|
|
|
Bit32u BX_CPU_C::FastRepINSW(bxInstruction_c *i, bx_address dstOff, Bit16u port, Bit32u wordCount)
|
|
|
|
{
|
2007-10-29 18:39:18 +03:00
|
|
|
Bit32u wordsFitDst;
|
2006-05-08 00:45:42 +04:00
|
|
|
signed int pointerDelta;
|
2007-10-29 18:39:18 +03:00
|
|
|
Bit8u *hostAddrDst;
|
2008-03-21 23:35:46 +03:00
|
|
|
unsigned count;
|
2006-05-08 00:45:42 +04:00
|
|
|
|
2008-09-09 00:47:33 +04:00
|
|
|
BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
|
|
|
|
|
2006-05-08 00:45:42 +04:00
|
|
|
bx_segment_reg_t *dstSegPtr = &BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES];
|
2008-09-09 00:47:33 +04:00
|
|
|
if (!(dstSegPtr->cache.valid & SegAccessWOK))
|
|
|
|
return 0;
|
|
|
|
if ((dstOff | 0xfff) > dstSegPtr->cache.u.segment.limit_scaled)
|
2008-03-21 23:35:46 +03:00
|
|
|
return 0;
|
2006-05-08 00:45:42 +04:00
|
|
|
|
2008-04-07 22:39:17 +04:00
|
|
|
bx_address laddrDst = BX_CPU_THIS_PTR get_laddr(BX_SEG_REG_ES, dstOff);
|
2007-10-29 18:39:18 +03:00
|
|
|
// check that the address is word aligned
|
|
|
|
if (laddrDst & 1) return 0;
|
|
|
|
|
2008-08-03 23:53:09 +04:00
|
|
|
hostAddrDst = v2h_write_byte(laddrDst, BX_CPU_THIS_PTR user_pl);
|
2008-10-21 23:50:05 +04:00
|
|
|
// Check that native host access was not vetoed for that page
|
|
|
|
if (!hostAddrDst) return 0;
|
2006-05-08 00:45:42 +04:00
|
|
|
|
|
|
|
// See how many words can fit in the rest of this page.
|
|
|
|
if (BX_CPU_THIS_PTR get_DF()) {
|
|
|
|
// Counting downward
|
2008-01-10 22:37:56 +03:00
|
|
|
// 1st word must cannot cross page boundary because it is word aligned
|
2007-12-27 02:07:44 +03:00
|
|
|
wordsFitDst = (2 + (PAGE_OFFSET(laddrDst))) >> 1;
|
2006-05-08 00:45:42 +04:00
|
|
|
pointerDelta = -2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Counting upward
|
2007-12-27 02:07:44 +03:00
|
|
|
wordsFitDst = (0x1000 - PAGE_OFFSET(laddrDst)) >> 1;
|
2006-05-08 00:45:42 +04:00
|
|
|
pointerDelta = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restrict word count to the number that will fit in this page.
|
|
|
|
if (wordCount > wordsFitDst)
|
|
|
|
wordCount = wordsFitDst;
|
|
|
|
|
|
|
|
// If after all the restrictions, there is anything left to do...
|
|
|
|
if (wordCount) {
|
|
|
|
for (count=0; count<wordCount; ) {
|
|
|
|
bx_devices.bulkIOQuantumsTransferred = 0;
|
|
|
|
if (BX_CPU_THIS_PTR get_DF()==0) { // Only do accel for DF=0
|
|
|
|
bx_devices.bulkIOHostAddr = hostAddrDst;
|
|
|
|
bx_devices.bulkIOQuantumsRequested = (wordCount - count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bx_devices.bulkIOQuantumsRequested = 0;
|
|
|
|
Bit16u temp16 = BX_INP(port, 2);
|
|
|
|
if (bx_devices.bulkIOQuantumsTransferred) {
|
2008-03-21 23:35:46 +03:00
|
|
|
hostAddrDst = bx_devices.bulkIOHostAddr;
|
2006-05-08 00:45:42 +04:00
|
|
|
count += bx_devices.bulkIOQuantumsTransferred;
|
|
|
|
}
|
|
|
|
else {
|
2008-02-07 23:43:13 +03:00
|
|
|
WriteHostWordToLittleEndian(hostAddrDst, temp16);
|
2006-05-08 00:45:42 +04:00
|
|
|
hostAddrDst += pointerDelta;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
// Terminate early if there was an event.
|
|
|
|
if (BX_CPU_THIS_PTR async_event) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset for next non-bulk IO
|
|
|
|
bx_devices.bulkIOQuantumsRequested = 0;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u BX_CPU_C::FastRepOUTSW(bxInstruction_c *i, unsigned srcSeg, bx_address srcOff, Bit16u port, Bit32u wordCount)
|
|
|
|
{
|
2007-10-29 18:39:18 +03:00
|
|
|
Bit32u wordsFitSrc;
|
2006-05-08 00:45:42 +04:00
|
|
|
signed int pointerDelta;
|
2007-10-29 18:39:18 +03:00
|
|
|
Bit8u *hostAddrSrc;
|
2008-03-21 23:35:46 +03:00
|
|
|
unsigned count;
|
2006-05-08 00:45:42 +04:00
|
|
|
|
2008-09-09 00:47:33 +04:00
|
|
|
BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
|
|
|
|
|
2006-05-08 00:45:42 +04:00
|
|
|
bx_segment_reg_t *srcSegPtr = &BX_CPU_THIS_PTR sregs[srcSeg];
|
2008-09-09 00:47:33 +04:00
|
|
|
if (!(srcSegPtr->cache.valid & SegAccessROK))
|
|
|
|
return 0;
|
|
|
|
if ((srcOff | 0xfff) > srcSegPtr->cache.u.segment.limit_scaled)
|
2008-03-21 23:35:46 +03:00
|
|
|
return 0;
|
2006-05-08 00:45:42 +04:00
|
|
|
|
2008-04-07 22:39:17 +04:00
|
|
|
bx_address laddrSrc = BX_CPU_THIS_PTR get_laddr(srcSeg, srcOff);
|
2007-10-29 18:39:18 +03:00
|
|
|
// check that the address is word aligned
|
|
|
|
if (laddrSrc & 1) return 0;
|
|
|
|
|
2008-08-03 23:53:09 +04:00
|
|
|
hostAddrSrc = v2h_read_byte(laddrSrc, BX_CPU_THIS_PTR user_pl);
|
2006-05-08 00:45:42 +04:00
|
|
|
|
2007-10-29 18:39:18 +03:00
|
|
|
// Check that native host access was not vetoed for that page
|
|
|
|
if (!hostAddrSrc) return 0;
|
2006-05-08 00:45:42 +04:00
|
|
|
|
2007-10-29 18:39:18 +03:00
|
|
|
// See how many words can fit in the rest of this page.
|
|
|
|
if (BX_CPU_THIS_PTR get_DF()) {
|
|
|
|
// Counting downward
|
2008-01-10 22:37:56 +03:00
|
|
|
// 1st word must cannot cross page boundary because it is word aligned
|
2007-12-27 02:07:44 +03:00
|
|
|
wordsFitSrc = (2 + (PAGE_OFFSET(laddrSrc))) >> 1;
|
2007-10-29 18:39:18 +03:00
|
|
|
pointerDelta = (unsigned) -2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Counting upward
|
2007-12-27 02:07:44 +03:00
|
|
|
wordsFitSrc = (0x1000 - PAGE_OFFSET(laddrSrc)) >> 1;
|
2007-10-29 18:39:18 +03:00
|
|
|
pointerDelta = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restrict word count to the number that will fit in this page.
|
|
|
|
if (wordCount > wordsFitSrc)
|
|
|
|
wordCount = wordsFitSrc;
|
|
|
|
|
|
|
|
// If after all the restrictions, there is anything left to do...
|
|
|
|
if (wordCount) {
|
|
|
|
for (count=0; count<wordCount; ) {
|
|
|
|
bx_devices.bulkIOQuantumsTransferred = 0;
|
|
|
|
if (BX_CPU_THIS_PTR get_DF()==0) { // Only do accel for DF=0
|
|
|
|
bx_devices.bulkIOHostAddr = hostAddrSrc;
|
|
|
|
bx_devices.bulkIOQuantumsRequested = (wordCount - count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bx_devices.bulkIOQuantumsRequested = 0;
|
2008-02-07 23:43:13 +03:00
|
|
|
Bit16u temp16;
|
|
|
|
ReadHostWordFromLittleEndian(hostAddrSrc, temp16);
|
2007-10-29 18:39:18 +03:00
|
|
|
BX_OUTP(port, temp16, 2);
|
|
|
|
if (bx_devices.bulkIOQuantumsTransferred) {
|
2008-03-21 23:35:46 +03:00
|
|
|
hostAddrSrc = bx_devices.bulkIOHostAddr;
|
2007-10-29 18:39:18 +03:00
|
|
|
count += bx_devices.bulkIOQuantumsTransferred;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hostAddrSrc += pointerDelta;
|
|
|
|
count++;
|
2006-05-08 00:45:42 +04:00
|
|
|
}
|
2007-10-29 18:39:18 +03:00
|
|
|
// Terminate early if there was an event.
|
|
|
|
if (BX_CPU_THIS_PTR async_event) break;
|
|
|
|
}
|
2006-05-08 00:45:42 +04:00
|
|
|
|
2007-10-29 18:39:18 +03:00
|
|
|
// Reset for next non-bulk IO
|
|
|
|
bx_devices.bulkIOQuantumsRequested = 0;
|
2006-05-08 00:45:42 +04:00
|
|
|
|
2007-10-29 18:39:18 +03:00
|
|
|
return count;
|
2006-05-08 00:45:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2002-09-09 20:56:56 +04:00
|
|
|
|
2007-01-05 16:40:47 +03:00
|
|
|
//
|
|
|
|
// REP INS methods
|
|
|
|
//
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::REP_INSB_YbDX(bxInstruction_c *i)
|
2007-01-05 16:40:47 +03:00
|
|
|
{
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, DX, 1)) {
|
2008-12-29 20:35:35 +03:00
|
|
|
BX_DEBUG(("INSB_YbDX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-04-16 20:44:06 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-06-13 00:12:25 +04:00
|
|
|
if (i->as64L()) {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSB64_YbDX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2008-04-16 20:44:06 +04:00
|
|
|
if (i->as32L()) {
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSB32_YbDX);
|
2008-04-16 20:44:06 +04:00
|
|
|
BX_CLEAR_64BIT_HIGH(BX_64BIT_REG_RDI); // always clear upper part of RDI
|
|
|
|
}
|
2008-06-13 00:12:25 +04:00
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSB16_YbDX);
|
|
|
|
}
|
2007-01-05 16:40:47 +03:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 16-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSB16_YbDX(bxInstruction_c *i)
|
2007-01-05 16:40:47 +03:00
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
|
|
|
Bit8u value8 = read_RMW_virtual_byte_32(BX_SEG_REG_ES, DI);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
value8 = BX_INP(DX, 1);
|
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_byte(value8);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
|
|
|
DI--;
|
|
|
|
else
|
|
|
|
DI++;
|
2007-01-05 16:40:47 +03:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 32-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSB32_YbDX(bxInstruction_c *i)
|
2007-01-05 16:40:47 +03:00
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
|
|
|
Bit8u value8 = read_RMW_virtual_byte_32(BX_SEG_REG_ES, EDI);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
value8 = BX_INP(DX, 1);
|
|
|
|
|
|
|
|
/* no seg override possible */
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_byte(value8);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF()) {
|
|
|
|
RDI = EDI - 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RDI = EDI + 1;
|
2008-04-16 20:44:06 +04:00
|
|
|
}
|
2007-01-05 16:40:47 +03:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2007-01-05 16:40:47 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 64-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSB64_YbDX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
|
|
|
Bit8u value8 = read_RMW_virtual_byte_64(BX_SEG_REG_ES, RDI);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
value8 = BX_INP(DX, 1);
|
2002-09-15 06:55:34 +04:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_byte(value8);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
|
|
|
RDI--;
|
|
|
|
else
|
|
|
|
RDI++;
|
|
|
|
}
|
2002-09-15 06:55:34 +04:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#endif
|
2002-09-15 06:55:34 +04:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::REP_INSW_YwDX(bxInstruction_c *i)
|
|
|
|
{
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, DX, 2)) {
|
2008-12-29 20:35:35 +03:00
|
|
|
BX_DEBUG(("INSW_YwDX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (i->as64L()) {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSW64_YwDX);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2004-03-02 23:48:48 +03:00
|
|
|
else
|
|
|
|
#endif
|
2008-06-13 00:12:25 +04:00
|
|
|
if (i->as32L()) {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSW32_YwDX);
|
|
|
|
BX_CLEAR_64BIT_HIGH(BX_64BIT_REG_RDI); // always clear upper part of RDI
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSW16_YwDX);
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 16-bit operand size, 16-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSW16_YwDX(bxInstruction_c *i)
|
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit16u value16 = read_RMW_virtual_word_32(BX_SEG_REG_ES, DI);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-06-25 14:34:21 +04:00
|
|
|
value16 = BX_INP(DX, 2);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_word(value16);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-06-25 14:34:21 +04:00
|
|
|
DI -= 2;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-06-25 14:34:21 +04:00
|
|
|
DI += 2;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 16-bit operand size, 32-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSW32_YwDX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-12-18 00:13:55 +03:00
|
|
|
Bit16u value16=0;
|
2008-06-13 00:12:25 +04:00
|
|
|
Bit32u edi = EDI;
|
|
|
|
unsigned incr = 2;
|
2006-05-07 22:27:36 +04:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if (BX_SupportRepeatSpeedups) && (BX_DEBUGGER == 0)
|
|
|
|
/* If conditions are right, we can transfer IO to physical memory
|
|
|
|
* in a batch, rather than one instruction at a time.
|
|
|
|
*/
|
|
|
|
if (i->repUsedL() && !BX_CPU_THIS_PTR async_event)
|
|
|
|
{
|
|
|
|
Bit32u wordCount = ECX;
|
|
|
|
BX_ASSERT(wordCount > 0);
|
|
|
|
wordCount = FastRepINSW(i, edi, DX, wordCount);
|
|
|
|
if (wordCount) {
|
|
|
|
// Decrement the ticks count by the number of iterations, minus
|
|
|
|
// one, since the main cpu loop will decrement one. Also,
|
|
|
|
// the count is predecremented before examined, so defintely
|
|
|
|
// don't roll it under zero.
|
|
|
|
BX_TICKN(wordCount-1);
|
|
|
|
RCX = ECX - (wordCount-1);
|
|
|
|
incr = wordCount << 1; // count * 2.
|
|
|
|
}
|
|
|
|
else {
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
|
|
|
value16 = read_RMW_virtual_word_32(BX_SEG_REG_ES, edi);
|
2007-12-18 00:13:55 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
value16 = BX_INP(DX, 2);
|
2007-12-18 00:13:55 +03:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_word(value16);
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
2007-12-18 00:13:55 +03:00
|
|
|
}
|
|
|
|
else
|
2002-09-24 08:43:59 +04:00
|
|
|
#endif
|
2007-12-18 00:13:55 +03:00
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
|
|
|
value16 = read_RMW_virtual_word_32(BX_SEG_REG_ES, edi);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-12-18 00:13:55 +03:00
|
|
|
value16 = BX_INP(DX, 2);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_word(value16);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
|
|
|
RDI = EDI - incr;
|
|
|
|
else
|
|
|
|
RDI = EDI + incr;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
|
|
|
|
// 16-bit operand size, 64-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSW64_YwDX(bxInstruction_c *i)
|
2006-05-07 22:27:36 +04:00
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit16u value16 = read_RMW_virtual_word_64(BX_SEG_REG_ES, RDI);
|
2006-05-07 22:27:36 +04:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
value16 = BX_INP(DX, 2);
|
2006-05-07 22:27:36 +04:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_word(value16);
|
2006-05-07 22:27:36 +04:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
RDI -= 2;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
RDI += 2;
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
2006-05-07 22:27:36 +04:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#endif
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::REP_INSD_YdDX(bxInstruction_c *i)
|
|
|
|
{
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, DX, 4)) {
|
2008-12-29 20:35:35 +03:00
|
|
|
BX_DEBUG(("INSD_YdDX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (i->as64L()) {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSD64_YdDX);
|
2006-05-07 22:27:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (i->as32L()) {
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSD32_YdDX);
|
|
|
|
BX_CLEAR_64BIT_HIGH(BX_64BIT_REG_RDI); // always clear upper part of RDI
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::INSD16_YdDX);
|
|
|
|
}
|
|
|
|
}
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 32-bit operand size, 16-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSD16_YdDX(bxInstruction_c *i)
|
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit32u value32 = read_RMW_virtual_dword_32(BX_SEG_REG_ES, DI);
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
value32 = BX_INP(DX, 4);
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_dword(value32);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
DI -= 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
DI += 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 32-bit operand size, 32-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSD32_YdDX(bxInstruction_c *i)
|
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit32u value32 = read_RMW_virtual_dword_32(BX_SEG_REG_ES, EDI);
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
value32 = BX_INP(DX, 4);
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_dword(value32);
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
RDI = EDI - 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
RDI = EDI + 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
|
|
|
|
// 32-bit operand size, 64-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSD64_YdDX(bxInstruction_c *i)
|
|
|
|
{
|
2008-07-13 17:24:36 +04:00
|
|
|
// trigger any segment or page faults before reading from IO port
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit32u value32 = read_RMW_virtual_dword_64(BX_SEG_REG_ES, RDI);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
value32 = BX_INP(DX, 4);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
2008-07-13 17:24:36 +04:00
|
|
|
write_RMW_virtual_dword(value32);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
RDI -= 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
RDI += 4;
|
2006-05-07 22:27:36 +04:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#endif
|
|
|
|
|
2007-01-05 16:40:47 +03:00
|
|
|
//
|
|
|
|
// REP OUTS methods
|
|
|
|
//
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::REP_OUTSB_DXXb(bxInstruction_c *i)
|
2007-01-05 16:40:47 +03:00
|
|
|
{
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, DX, 1)) {
|
2008-12-29 20:35:35 +03:00
|
|
|
BX_DEBUG(("OUTSB_DXXb: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-04-16 20:44:06 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-06-13 00:12:25 +04:00
|
|
|
if (i->as64L()) {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSB64_DXXb);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2008-04-16 20:44:06 +04:00
|
|
|
if (i->as32L()) {
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSB32_DXXb);
|
2008-04-16 20:44:06 +04:00
|
|
|
BX_CLEAR_64BIT_HIGH(BX_64BIT_REG_RSI); // always clear upper part of RSI
|
|
|
|
}
|
2008-06-13 00:12:25 +04:00
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSB16_DXXb);
|
|
|
|
}
|
2007-01-05 16:40:47 +03:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 16-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSB16_DXXb(bxInstruction_c *i)
|
2007-01-05 16:40:47 +03:00
|
|
|
{
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit8u value8 = read_virtual_byte_32(i->seg(), SI);
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_OUTP(DX, value8, 1);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
SI--;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
SI++;
|
2007-01-05 16:40:47 +03:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 32-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSB32_DXXb(bxInstruction_c *i)
|
2007-01-05 16:40:47 +03:00
|
|
|
{
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit8u value8 = read_virtual_byte(i->seg(), ESI);
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_OUTP(DX, value8, 1);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI = ESI - 1;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI = ESI + 1;
|
2007-01-05 16:40:47 +03:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2007-01-05 16:40:47 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 64-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSB64_DXXb(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit8u value8 = read_virtual_byte_64(i->seg(), RSI);
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_OUTP(DX, value8, 1);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI--;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI++;
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#endif
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::REP_OUTSW_DXXw(bxInstruction_c *i)
|
|
|
|
{
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, DX, 2)) {
|
2008-12-29 20:35:35 +03:00
|
|
|
BX_DEBUG(("OUTSW_DXXw: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (i->as64L()) {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSW64_DXXw);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2004-03-02 23:48:48 +03:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (i->as32L()) {
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSW32_DXXw);
|
|
|
|
BX_CLEAR_64BIT_HIGH(BX_64BIT_REG_RSI); // always clear upper part of RSI
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2008-06-13 00:12:25 +04:00
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSW16_DXXw);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 16-bit operand size, 16-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSW16_DXXw(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-06-25 14:34:21 +04:00
|
|
|
Bit16u value16 = read_virtual_word_32(i->seg(), SI);
|
|
|
|
BX_OUTP(DX, value16, 2);
|
2008-06-13 00:12:25 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-06-25 14:34:21 +04:00
|
|
|
SI -= 2;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-06-25 14:34:21 +04:00
|
|
|
SI += 2;
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 16-bit operand size, 32-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSW32_DXXw(bxInstruction_c *i)
|
|
|
|
{
|
|
|
|
Bit16u value16;
|
|
|
|
Bit32u esi = ESI;
|
|
|
|
unsigned incr = 2;
|
2006-05-07 22:27:36 +04:00
|
|
|
|
2007-12-23 20:46:44 +03:00
|
|
|
#if (BX_SupportRepeatSpeedups) && (BX_DEBUGGER == 0)
|
2008-06-13 00:12:25 +04:00
|
|
|
/* If conditions are right, we can transfer IO to physical memory
|
|
|
|
* in a batch, rather than one instruction at a time.
|
|
|
|
*/
|
|
|
|
if (i->repUsedL() && !BX_CPU_THIS_PTR async_event) {
|
|
|
|
Bit32u wordCount = ECX;
|
|
|
|
wordCount = FastRepOUTSW(i, i->seg(), esi, DX, wordCount);
|
|
|
|
if (wordCount) {
|
|
|
|
// Decrement eCX. Note, the main loop will decrement 1 also, so
|
|
|
|
// decrement by one less than expected, like the case above.
|
|
|
|
BX_TICKN(wordCount-1); // Main cpu loop also decrements one more.
|
|
|
|
RCX = ECX - (wordCount-1);
|
|
|
|
incr = wordCount << 1; // count * 2.
|
2007-10-29 18:39:18 +03:00
|
|
|
}
|
2008-06-13 00:12:25 +04:00
|
|
|
else {
|
2007-12-23 21:09:34 +03:00
|
|
|
value16 = read_virtual_word(i->seg(), esi);
|
2007-10-29 18:39:18 +03:00
|
|
|
BX_OUTP(DX, value16, 2);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
|
|
|
}
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
value16 = read_virtual_word(i->seg(), esi);
|
|
|
|
BX_OUTP(DX, value16, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
|
|
|
RSI = ESI - incr;
|
|
|
|
else
|
|
|
|
RSI = ESI + incr;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
|
|
|
|
// 16-bit operand size, 64-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSW64_DXXw(bxInstruction_c *i)
|
2006-05-07 22:27:36 +04:00
|
|
|
{
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit16u value16 = read_virtual_word_64(i->seg(), RSI);
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_OUTP(DX, value16, 2);
|
2006-05-07 22:27:36 +04:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI -= 2;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI += 2;
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::REP_OUTSD_DXXd(bxInstruction_c *i)
|
|
|
|
{
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, DX, 4)) {
|
2008-12-29 20:35:35 +03:00
|
|
|
BX_DEBUG(("OUTSD_DXXd: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (i->as64L()) {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSD64_DXXd);
|
2006-05-07 22:27:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (i->as32L()) {
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSD32_DXXd);
|
|
|
|
BX_CLEAR_64BIT_HIGH(BX_64BIT_REG_RSI); // always clear upper part of RSI
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR repeat(i, &BX_CPU_C::OUTSD16_DXXd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 32-bit operand size, 16-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSD16_DXXd(bxInstruction_c *i)
|
|
|
|
{
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit32u value32 = read_virtual_dword_32(i->seg(), SI);
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_OUTP(DX, value32, 4);
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
SI -= 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
SI += 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
// 32-bit operand size, 32-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSD32_DXXd(bxInstruction_c *i)
|
|
|
|
{
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit32u value32 = read_virtual_dword(i->seg(), ESI);
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_OUTP(DX, value32, 4);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI = ESI - 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI = ESI + 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
}
|
2007-12-23 21:09:34 +03:00
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
|
|
|
|
// 32-bit operand size, 64-bit address size
|
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSD64_DXXd(bxInstruction_c *i)
|
|
|
|
{
|
2008-07-13 17:32:15 +04:00
|
|
|
Bit32u value32 = read_virtual_dword_64(i->seg(), RSI);
|
2008-06-13 00:12:25 +04:00
|
|
|
BX_OUTP(DX, value32, 4);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_DF())
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI -= 4;
|
2008-06-13 00:12:25 +04:00
|
|
|
else
|
2008-07-13 17:32:15 +04:00
|
|
|
RSI += 4;
|
2006-05-07 22:27:36 +04:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:12:25 +04:00
|
|
|
#endif
|
|
|
|
|
2007-01-05 16:40:47 +03:00
|
|
|
//
|
|
|
|
// non repeatable IN/OUT methods
|
|
|
|
//
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::IN_ALIb(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = i->Ib();
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 1)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("IN_ALIb: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
AL = BX_INP(port, 1);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::IN_AXIb(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = i->Ib();
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 2)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("IN_AXIb: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
AX = BX_INP(port, 2);
|
2006-05-07 22:27:36 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::IN_EAXIb(bxInstruction_c *i)
|
2006-05-07 22:27:36 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = i->Ib();
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 4)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("IN_EAXIb: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
RAX = BX_INP(port, 4);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUT_IbAL(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = i->Ib();
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 1)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("OUT_IbAL: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_OUTP(port, AL, 1);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUT_IbAX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = i->Ib();
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 2)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("OUT_IbAX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_OUTP(port, AX, 2);
|
2006-05-07 22:27:36 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUT_IbEAX(bxInstruction_c *i)
|
2006-05-07 22:27:36 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = i->Ib();
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 4)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("OUT_IbEAX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_OUTP(port, EAX, 4);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::IN_ALDX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = DX;
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 1)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("IN_ALDX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
AL = BX_INP(port, 1);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::IN_AXDX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = DX;
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 2)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("IN_AXDX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
AX = BX_INP(port, 2);
|
2006-05-07 22:27:36 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::IN_EAXDX(bxInstruction_c *i)
|
2006-05-07 22:27:36 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = DX;
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 4)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("IN_EAXDX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
RAX = BX_INP(port, 4);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUT_DXAL(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = DX;
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 1)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("OUT_DXAL: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_OUTP(port, AL, 1);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUT_DXAX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = DX;
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 2)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("OUT_DXAX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_OUTP(port, AX, 2);
|
2006-05-07 22:27:36 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUT_DXEAX(bxInstruction_c *i)
|
2006-05-07 22:27:36 +04:00
|
|
|
{
|
2009-01-15 19:53:08 +03:00
|
|
|
unsigned port = DX;
|
|
|
|
|
2009-01-23 12:26:24 +03:00
|
|
|
if (! allow_io(i, port, 4)) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("OUT_DXEAX: I/O access not allowed !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_OUTP(port, EAX, 4);
|
|
|
|
}
|
|
|
|
|
2009-01-23 12:33:11 +03:00
|
|
|
bx_bool BX_CPP_AttrRegparmN(3) BX_CPU_C::allow_io(bxInstruction_c *i, Bit16u port, unsigned len)
|
2009-01-15 19:53:08 +03:00
|
|
|
{
|
|
|
|
/* If CPL <= IOPL, then all IO portesses are accessible.
|
|
|
|
* Otherwise, must check the IO permission map on >286.
|
|
|
|
* On the 286, there is no IO permissions map */
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR cr0.get_PE() && (BX_CPU_THIS_PTR get_VM() || (CPL>BX_CPU_THIS_PTR get_IOPL())))
|
|
|
|
{
|
|
|
|
if (BX_CPU_THIS_PTR tr.cache.valid==0 ||
|
|
|
|
(BX_CPU_THIS_PTR tr.cache.type != BX_SYS_SEGMENT_AVAIL_386_TSS &&
|
|
|
|
BX_CPU_THIS_PTR tr.cache.type != BX_SYS_SEGMENT_BUSY_386_TSS))
|
|
|
|
{
|
|
|
|
BX_ERROR(("allow_io(): TR doesn't point to a valid 32bit TSS, TR.TYPE=%u", BX_CPU_THIS_PTR tr.cache.type));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2009-04-05 23:09:44 +04:00
|
|
|
if (BX_CPU_THIS_PTR tr.cache.u.segment.limit_scaled < 103) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_ERROR(("allow_io(): TR.limit < 103"));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2009-04-07 20:12:19 +04:00
|
|
|
Bit32u io_base = system_read_word(BX_CPU_THIS_PTR tr.cache.u.segment.base + 102);
|
2009-01-15 19:53:08 +03:00
|
|
|
|
2009-04-05 23:09:44 +04:00
|
|
|
if ((io_base + port/8) >= BX_CPU_THIS_PTR tr.cache.u.segment.limit_scaled) {
|
2009-01-15 19:53:08 +03:00
|
|
|
BX_DEBUG(("allow_io(): IO port %x (len %d) outside TSS IO permission map (base=%x, limit=%x) #GP(0)",
|
2009-04-05 23:09:44 +04:00
|
|
|
port, len, io_base, BX_CPU_THIS_PTR tr.cache.u.segment.limit_scaled));
|
2009-01-15 19:53:08 +03:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2009-04-05 23:09:44 +04:00
|
|
|
Bit16u permission16 = system_read_word(BX_CPU_THIS_PTR tr.cache.u.segment.base + io_base + port/8);
|
2009-01-15 19:53:08 +03:00
|
|
|
|
|
|
|
unsigned bit_index = port & 0x7;
|
|
|
|
unsigned mask = (1 << len) - 1;
|
|
|
|
if ((permission16 >> bit_index) & mask)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2009-01-31 13:43:24 +03:00
|
|
|
#if BX_SUPPORT_VMX
|
|
|
|
VMexit_IO(i, port, len);
|
|
|
|
#endif
|
|
|
|
|
2009-01-15 19:53:08 +03:00
|
|
|
#if BX_X86_DEBUGGER
|
|
|
|
iobreakpoint_match(port, len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return(1);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|