fixed massive code duplication

This commit is contained in:
Stanislav Shwartsman 2014-07-03 06:40:42 +00:00
parent c7ae0310ac
commit 816f5cc2d7
8 changed files with 113 additions and 469 deletions

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2005-2010 The Bochs Project
// Copyright (C) 2005-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -288,7 +288,7 @@ BX_CPU_C::system_read_byte(bx_address laddr)
}
#endif
access_read_linear(laddr, 1, 0, BX_READ, (void *) &data);
access_read_linear(laddr, 1, 0, BX_READ, 0x0, (void *) &data);
return data;
}
@ -313,14 +313,7 @@ BX_CPU_C::system_read_word(bx_address laddr)
}
}
#if BX_SUPPORT_X86_64
if (! IsCanonical(laddr)) {
BX_ERROR(("system_read_word(): canonical failure"));
exception(BX_GP_EXCEPTION, 0);
}
#endif
if (access_read_linear(laddr, 2, 0, BX_READ, (void *) &data) < 0)
if (access_read_linear(laddr, 2, 0, BX_READ, 0x0, (void *) &data) < 0)
exception(BX_GP_EXCEPTION, 0);
return data;
@ -347,14 +340,7 @@ BX_CPU_C::system_read_dword(bx_address laddr)
}
}
#if BX_SUPPORT_X86_64
if (! IsCanonical(laddr)) {
BX_ERROR(("system_read_dword(): canonical failure"));
exception(BX_GP_EXCEPTION, 0);
}
#endif
if (access_read_linear(laddr, 4, 0, BX_READ, (void *) &data) < 0)
if (access_read_linear(laddr, 4, 0, BX_READ, 0x0, (void *) &data) < 0)
exception(BX_GP_EXCEPTION, 0);
return data;
@ -381,14 +367,7 @@ BX_CPU_C::system_read_qword(bx_address laddr)
}
}
#if BX_SUPPORT_X86_64
if (! IsCanonical(laddr)) {
BX_ERROR(("system_read_qword(): canonical failure"));
exception(BX_GP_EXCEPTION, 0);
}
#endif
if (access_read_linear(laddr, 8, 0, BX_READ, (void *) &data) < 0)
if (access_read_linear(laddr, 8, 0, BX_READ, 0x0, (void *) &data) < 0)
exception(BX_GP_EXCEPTION, 0);
return data;
@ -415,14 +394,7 @@ BX_CPU_C::system_write_byte(bx_address laddr, Bit8u data)
}
}
#if BX_SUPPORT_X86_64
if (! IsCanonical(laddr)) {
BX_ERROR(("system_write_byte(): canonical failure"));
exception(BX_GP_EXCEPTION, 0);
}
#endif
access_write_linear(laddr, 1, 0, (void *) &data);
access_write_linear(laddr, 1, 0, 0x0, (void *) &data);
}
void BX_CPP_AttrRegparmN(2)
@ -446,14 +418,7 @@ BX_CPU_C::system_write_word(bx_address laddr, Bit16u data)
}
}
#if BX_SUPPORT_X86_64
if (! IsCanonical(laddr)) {
BX_ERROR(("system_write_word(): canonical failure"));
exception(BX_GP_EXCEPTION, 0);
}
#endif
if (access_write_linear(laddr, 2, 0, (void *) &data) < 0)
if (access_write_linear(laddr, 2, 0, 0x0, (void *) &data) < 0)
exception(BX_GP_EXCEPTION, 0);
}
@ -478,14 +443,7 @@ BX_CPU_C::system_write_dword(bx_address laddr, Bit32u data)
}
}
#if BX_SUPPORT_X86_64
if (! IsCanonical(laddr)) {
BX_ERROR(("system_write_dword(): canonical failure"));
exception(BX_GP_EXCEPTION, 0);
}
#endif
if (access_write_linear(laddr, 4, 0, (void *) &data) < 0)
if (access_write_linear(laddr, 4, 0, 0x0, (void *) &data) < 0)
exception(BX_GP_EXCEPTION, 0);
}

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008-2013 Stanislav Shwartsman
// Copyright (c) 2008-2014 Stanislav Shwartsman
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
//
// This library is free software; you can redistribute it and/or
@ -55,7 +55,7 @@ accessOK:
return;
}
}
access_write_linear(laddr, 1, CPL, (void *) &data);
access_write_linear(laddr, 1, CPL, 0x0, (void *) &data);
return;
}
else {
@ -103,16 +103,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 1) {
BX_ERROR(("write_virtual_word_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_write_linear(laddr, 2, CPL, (void *) &data);
access_write_linear(laddr, 2, CPL, 0x1, (void *) &data);
return;
}
else {
@ -160,16 +151,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 3) {
BX_ERROR(("write_virtual_dword_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_write_linear(laddr, 4, CPL, (void *) &data);
access_write_linear(laddr, 4, CPL, 0x3, (void *) &data);
return;
}
else {
@ -217,16 +199,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 7) {
BX_ERROR(("write_virtual_qword_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_write_linear(laddr, 8, CPL, (void *) &data);
access_write_linear(laddr, 8, CPL, 0x7, (void *) &data);
return;
}
else {
@ -273,7 +246,7 @@ accessOK:
}
}
access_write_linear(laddr, 16, CPL, (void *) data);
access_write_linear(laddr, 16, CPL, 0x0, (void *) data);
return;
}
else {
@ -323,7 +296,7 @@ accessOK:
return;
}
}
access_write_linear(laddr, 16, CPL, (void *) data);
access_write_linear(laddr, 16, CPL, 0x0, (void *) data);
return;
}
else {
@ -370,7 +343,7 @@ accessOK:
}
}
access_write_linear(laddr, 32, CPL, (void *) data);
access_write_linear(laddr, 32, CPL, 0x0, (void *) data);
return;
}
else {
@ -420,7 +393,7 @@ accessOK:
return;
}
}
access_write_linear(laddr, 32, CPL, (void *) data);
access_write_linear(laddr, 32, CPL, 0x0, (void *) data);
return;
}
else {
@ -469,7 +442,7 @@ accessOK:
}
}
access_write_linear(laddr, 64, CPL, (void *) data);
access_write_linear(laddr, 64, CPL, 0x0, (void *) data);
return;
}
else {
@ -519,7 +492,7 @@ accessOK:
return;
}
}
access_write_linear(laddr, 64, CPL, (void *) data);
access_write_linear(laddr, 64, CPL, 0x0, (void *) data);
return;
}
else {
@ -566,7 +539,7 @@ accessOK:
return data;
}
}
access_read_linear(laddr, 1, CPL, BX_READ, (void *) &data);
access_read_linear(laddr, 1, CPL, BX_READ, 0, (void *) &data);
return data;
}
else {
@ -613,16 +586,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 1) {
BX_ERROR(("read_virtual_word_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_read_linear(laddr, 2, CPL, BX_READ, (void *) &data);
access_read_linear(laddr, 2, CPL, BX_READ, 0x1, (void *) &data);
return data;
}
else {
@ -669,16 +633,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 3) {
BX_ERROR(("read_virtual_dword_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_read_linear(laddr, 4, CPL, BX_READ, (void *) &data);
access_read_linear(laddr, 4, CPL, BX_READ, 0x3, (void *) &data);
return data;
}
else {
@ -725,16 +680,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 7) {
BX_ERROR(("read_virtual_qword_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_read_linear(laddr, 8, CPL, BX_READ, (void *) &data);
access_read_linear(laddr, 8, CPL, BX_READ, 0x7, (void *) &data);
return data;
}
else {
@ -778,7 +724,7 @@ accessOK:
return;
}
}
access_read_linear(laddr, 16, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 16, CPL, BX_READ, 0x0, (void *) data);
return;
}
else {
@ -826,7 +772,7 @@ accessOK:
return;
}
}
access_read_linear(laddr, 16, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 16, CPL, BX_READ, 0x0, (void *) data);
return;
}
else {
@ -870,7 +816,7 @@ accessOK:
return;
}
}
access_read_linear(laddr, 32, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 32, CPL, BX_READ, 0x0, (void *) data);
return;
}
else {
@ -918,7 +864,7 @@ accessOK:
return;
}
}
access_read_linear(laddr, 32, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 32, CPL, BX_READ, 0x0, (void *) data);
return;
}
else {
@ -964,7 +910,7 @@ accessOK:
return;
}
}
access_read_linear(laddr, 64, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 64, CPL, BX_READ, 0x0, (void *) data);
return;
}
else {
@ -1012,7 +958,7 @@ accessOK:
return;
}
}
access_read_linear(laddr, 64, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 64, CPL, BX_READ, 0x0, (void *) data);
return;
}
else {
@ -1067,7 +1013,7 @@ accessOK:
return data;
}
}
access_read_linear(laddr, 1, CPL, BX_RW, (void *) &data);
access_read_linear(laddr, 1, CPL, BX_RW, 0x0, (void *) &data);
return data;
}
else {
@ -1118,16 +1064,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 1) {
BX_ERROR(("read_RMW_virtual_word_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_read_linear(laddr, 2, CPL, BX_RW, (void *) &data);
access_read_linear(laddr, 2, CPL, BX_RW, 0x1, (void *) &data);
return data;
}
else {
@ -1178,16 +1115,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 3) {
BX_ERROR(("read_RMW_virtual_dword_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_read_linear(laddr, 4, CPL, BX_RW, (void *) &data);
access_read_linear(laddr, 4, CPL, BX_RW, 0x3, (void *) &data);
return data;
}
else {
@ -1238,16 +1166,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 7) {
BX_ERROR(("read_RMW_virtual_qword_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_read_linear(laddr, 8, CPL, BX_RW, (void *) &data);
access_read_linear(laddr, 8, CPL, BX_RW, 0x7, (void *) &data);
return data;
}
else {
@ -1441,16 +1360,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check() && user) {
if (laddr & 1) {
BX_ERROR(("write_new_stack_word_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_write_linear(laddr, 2, curr_pl, (void *) &data);
access_write_linear(laddr, 2, curr_pl, 0x1, (void *) &data);
return;
}
else {
@ -1499,16 +1409,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check() && user) {
if (laddr & 3) {
BX_ERROR(("write_new_stack_dword_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_write_linear(laddr, 4, curr_pl, (void *) &data);
access_write_linear(laddr, 4, curr_pl, 0x3, (void *) &data);
return;
}
else {
@ -1557,16 +1458,7 @@ accessOK:
}
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check() && user) {
if (laddr & 7) {
BX_ERROR(("write_new_stack_qword_32(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
access_write_linear(laddr, 8, curr_pl, (void *) &data);
access_write_linear(laddr, 8, curr_pl, 0x7, (void *) &data);
return;
}
else {

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008-2013 Stanislav Shwartsman
// Copyright (c) 2008-2014 Stanislav Shwartsman
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
//
// This library is free software; you can redistribute it and/or
@ -52,12 +52,7 @@ BX_CPU_C::write_virtual_byte_64(unsigned s, Bit64u offset, Bit8u data)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_virtual_byte_64(): canonical failure"));
exception(int_number(s), 0);
}
access_write_linear(laddr, 1, CPL, (void *) &data);
access_write_linear(laddr, 1, CPL, 0x0, (void *) &data);
}
void BX_CPP_AttrRegparmN(3)
@ -88,21 +83,7 @@ BX_CPU_C::write_virtual_word_64(unsigned s, Bit64u offset, Bit16u data)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_virtual_word_64(): canonical failure"));
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 1) {
BX_ERROR(("write_virtual_word_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_write_linear(laddr, 2, CPL, (void *) &data) < 0)
if (access_write_linear(laddr, 2, CPL, 0x1, (void *) &data) < 0)
exception(int_number(s), 0);
}
@ -139,16 +120,7 @@ BX_CPU_C::write_virtual_dword_64(unsigned s, Bit64u offset, Bit32u data)
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 3) {
BX_ERROR(("write_virtual_dword_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_write_linear(laddr, 4, CPL, (void *) &data) < 0)
if (access_write_linear(laddr, 4, CPL, 0x3, (void *) &data) < 0)
exception(int_number(s), 0);
}
@ -185,16 +157,7 @@ BX_CPU_C::write_virtual_qword_64(unsigned s, Bit64u offset, Bit64u data)
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 7) {
BX_ERROR(("write_virtual_qword_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_write_linear(laddr, 8, CPL, (void *) &data) < 0)
if (access_write_linear(laddr, 8, CPL, 0x7, (void *) &data) < 0)
exception(int_number(s), 0);
}
@ -223,12 +186,7 @@ BX_CPU_C::write_virtual_xmmword_64(unsigned s, Bit64u offset, const BxPackedXmmR
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_virtual_xmmword_64(): canonical failure"));
exception(int_number(s), 0);
}
if (access_write_linear(laddr, 16, CPL, (void *) data) < 0)
if (access_write_linear(laddr, 16, CPL, 0x0, (void *) data) < 0)
exception(int_number(s), 0);
}
@ -262,12 +220,7 @@ BX_CPU_C::write_virtual_xmmword_aligned_64(unsigned s, Bit64u offset, const BxPa
exception(BX_GP_EXCEPTION, 0);
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_virtual_xmmword_aligned_64(): canonical failure"));
exception(int_number(s), 0);
}
access_write_linear(laddr, 16, CPL, (void *) data);
access_write_linear(laddr, 16, CPL, 0x0, (void *) data);
}
#if BX_SUPPORT_AVX
@ -297,12 +250,7 @@ void BX_CPU_C::write_virtual_ymmword_64(unsigned s, Bit64u offset, const BxPacke
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_virtual_ymmword_64(): canonical failure"));
exception(int_number(s), 0);
}
if (access_write_linear(laddr, 32, CPL, (void *) data) < 0)
if (access_write_linear(laddr, 32, CPL, 0x0, (void *) data) < 0)
exception(int_number(s), 0);
}
@ -336,12 +284,7 @@ void BX_CPU_C::write_virtual_ymmword_aligned_64(unsigned s, Bit64u offset, const
exception(BX_GP_EXCEPTION, 0);
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_virtual_ymmword_aligned_64(): canonical failure"));
exception(int_number(s), 0);
}
access_write_linear(laddr, 32, CPL, (void *) data);
access_write_linear(laddr, 32, CPL, 0x0, (void *) data);
}
#endif
@ -373,12 +316,7 @@ void BX_CPU_C::write_virtual_zmmword_64(unsigned s, Bit64u offset, const BxPacke
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_virtual_zmmword_64(): canonical failure"));
exception(int_number(s), 0);
}
if (access_write_linear(laddr, 64, CPL, (void *) data) < 0)
if (access_write_linear(laddr, 64, CPL, 0x0, (void *) data) < 0)
exception(int_number(s), 0);
}
@ -412,12 +350,7 @@ void BX_CPU_C::write_virtual_zmmword_aligned_64(unsigned s, Bit64u offset, const
exception(BX_GP_EXCEPTION, 0);
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_virtual_zmmword_aligned_64(): canonical failure"));
exception(int_number(s), 0);
}
access_write_linear(laddr, 64, CPL, (void *) data);
access_write_linear(laddr, 64, CPL, 0x0, (void *) data);
}
#endif
@ -445,12 +378,7 @@ BX_CPU_C::read_virtual_byte_64(unsigned s, Bit64u offset)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_byte_64(): canonical failure"));
exception(int_number(s), 0);
}
access_read_linear(laddr, 1, CPL, BX_READ, (void *) &data);
access_read_linear(laddr, 1, CPL, BX_READ, 0x0, (void *) &data);
return data;
}
@ -481,21 +409,7 @@ BX_CPU_C::read_virtual_word_64(unsigned s, Bit64u offset)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_word_64(): canonical failure"));
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 1) {
BX_ERROR(("read_virtual_word_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_read_linear(laddr, 2, CPL, BX_READ, (void *) &data) < 0)
if (access_read_linear(laddr, 2, CPL, BX_READ, 0x1, (void *) &data) < 0)
exception(int_number(s), 0);
return data;
@ -528,21 +442,7 @@ BX_CPU_C::read_virtual_dword_64(unsigned s, Bit64u offset)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_dword_64(): canonical failure"));
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 3) {
BX_ERROR(("read_virtual_dword_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_read_linear(laddr, 4, CPL, BX_READ, (void *) &data) < 0)
if (access_read_linear(laddr, 4, CPL, BX_READ, 0x3, (void *) &data) < 0)
exception(int_number(s), 0);
return data;
@ -575,21 +475,7 @@ BX_CPU_C::read_virtual_qword_64(unsigned s, Bit64u offset)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_qword_64(): canonical failure"));
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 7) {
BX_ERROR(("read_virtual_qword_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_read_linear(laddr, 8, CPL, BX_READ, (void *) &data) < 0)
if (access_read_linear(laddr, 8, CPL, BX_READ, 0x7, (void *) &data) < 0)
exception(int_number(s), 0);
return data;
@ -618,12 +504,7 @@ BX_CPU_C::read_virtual_xmmword_64(unsigned s, Bit64u offset, BxPackedXmmRegister
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_xmmword_64(): canonical failure"));
exception(int_number(s), 0);
}
if (access_read_linear(laddr, 16, CPL, BX_READ, (void *) data) < 0)
if (access_read_linear(laddr, 16, CPL, BX_READ, 0x0, (void *) data) < 0)
exception(int_number(s), 0);
}
@ -655,12 +536,7 @@ BX_CPU_C::read_virtual_xmmword_aligned_64(unsigned s, Bit64u offset, BxPackedXmm
exception(BX_GP_EXCEPTION, 0);
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_xmmword_aligned_64(): canonical failure"));
exception(int_number(s), 0);
}
access_read_linear(laddr, 16, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 16, CPL, BX_READ, 0x0, (void *) data);
}
#if BX_SUPPORT_AVX
@ -688,12 +564,7 @@ void BX_CPU_C::read_virtual_ymmword_64(unsigned s, Bit64u offset, BxPackedYmmReg
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_ymmword_64(): canonical failure"));
exception(int_number(s), 0);
}
if (access_read_linear(laddr, 32, CPL, BX_READ, (void *) data) < 0)
if (access_read_linear(laddr, 32, CPL, BX_READ, 0x0, (void *) data) < 0)
exception(int_number(s), 0);
}
@ -725,12 +596,7 @@ void BX_CPU_C::read_virtual_ymmword_aligned_64(unsigned s, Bit64u offset, BxPack
exception(BX_GP_EXCEPTION, 0);
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_ymmword_aligned_64(): canonical failure"));
exception(int_number(s), 0);
}
access_read_linear(laddr, 32, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 32, CPL, BX_READ, 0x0, (void *) data);
}
#endif
@ -760,12 +626,7 @@ void BX_CPU_C::read_virtual_zmmword_64(unsigned s, Bit64u offset, BxPackedZmmReg
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_ymmword_64(): canonical failure"));
exception(int_number(s), 0);
}
if (access_read_linear(laddr, 64, CPL, BX_READ, (void *) data) < 0)
if (access_read_linear(laddr, 64, CPL, BX_READ, 0x0, (void *) data) < 0)
exception(int_number(s), 0);
}
@ -797,12 +658,7 @@ void BX_CPU_C::read_virtual_zmmword_aligned_64(unsigned s, Bit64u offset, BxPack
exception(BX_GP_EXCEPTION, 0);
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_virtual_zmmword_aligned_64(): canonical failure"));
exception(int_number(s), 0);
}
access_read_linear(laddr, 64, CPL, BX_READ, (void *) data);
access_read_linear(laddr, 64, CPL, BX_READ, 0x0, (void *) data);
}
#endif
@ -839,12 +695,7 @@ BX_CPU_C::read_RMW_virtual_byte_64(unsigned s, Bit64u offset)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_RMW_virtual_byte_64(): canonical failure"));
exception(int_number(s), 0);
}
access_read_linear(laddr, 1, CPL, BX_RW, (void *) &data);
access_read_linear(laddr, 1, CPL, BX_RW, 0x0, (void *) &data);
return data;
}
@ -879,21 +730,7 @@ BX_CPU_C::read_RMW_virtual_word_64(unsigned s, Bit64u offset)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_RMW_virtual_word_64(): canonical failure"));
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 1) {
BX_ERROR(("read_RMW_virtual_word_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_read_linear(laddr, 2, CPL, BX_RW, (void *) &data) < 0)
if (access_read_linear(laddr, 2, CPL, BX_RW, 0x1, (void *) &data) < 0)
exception(int_number(s), 0);
return data;
@ -930,21 +767,7 @@ BX_CPU_C::read_RMW_virtual_dword_64(unsigned s, Bit64u offset)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_RMW_virtual_dword_64(): canonical failure"));
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 3) {
BX_ERROR(("read_RMW_virtual_dword_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_read_linear(laddr, 4, CPL, BX_RW, (void *) &data) < 0)
if (access_read_linear(laddr, 4, CPL, BX_RW, 0x3, (void *) &data) < 0)
exception(int_number(s), 0);
return data;
@ -981,21 +804,7 @@ BX_CPU_C::read_RMW_virtual_qword_64(unsigned s, Bit64u offset)
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_RMW_virtual_qword_64(): canonical failure"));
exception(int_number(s), 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check()) {
if (laddr & 7) {
BX_ERROR(("read_RMW_virtual_qword_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_read_linear(laddr, 8, CPL, BX_RW, (void *) &data) < 0)
if (access_read_linear(laddr, 8, CPL, BX_RW, 0x7, (void *) &data) < 0)
exception(int_number(s), 0);
return data;
@ -1033,13 +842,8 @@ void BX_CPU_C::read_RMW_virtual_dqword_aligned_64(unsigned s, Bit64u offset, Bit
exception(BX_GP_EXCEPTION, 0);
}
if (! IsCanonical(laddr)) {
BX_ERROR(("read_RMW_virtual_dqword_aligned_64(): canonical failure"));
exception(int_number(s), 0);
}
access_read_linear(laddr, 8, CPL, BX_RW, (void *) lo);
access_read_linear(laddr + 8, 8, CPL, BX_RW, (void *) hi);
access_read_linear(laddr, 8, CPL, BX_RW, 0x0, (void *) lo);
access_read_linear(laddr + 8, 8, CPL, BX_RW, 0x0, (void *) hi);
}
void BX_CPU_C::write_RMW_virtual_dqword(Bit64u hi, Bit64u lo)
@ -1083,21 +887,7 @@ void BX_CPU_C::write_new_stack_word_64(Bit64u laddr, unsigned curr_pl, Bit16u da
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_new_stack_word_64(): canonical failure"));
exception(BX_SS_EXCEPTION, 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check() && user) {
if (laddr & 1) {
BX_ERROR(("write_new_stack_word_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_write_linear(laddr, 2, curr_pl, (void *) &data) < 0)
if (access_write_linear(laddr, 2, curr_pl, 0x1, (void *) &data) < 0)
exception(BX_SS_EXCEPTION, 0);
}
@ -1126,21 +916,7 @@ void BX_CPU_C::write_new_stack_dword_64(Bit64u laddr, unsigned curr_pl, Bit32u d
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_new_stack_dword_64(): canonical failure"));
exception(BX_SS_EXCEPTION, 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check() && user) {
if (laddr & 3) {
BX_ERROR(("write_new_stack_dword_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_write_linear(laddr, 4, curr_pl, (void *) &data) < 0)
if (access_write_linear(laddr, 4, curr_pl, 0x3, (void *) &data) < 0)
exception(BX_SS_EXCEPTION, 0);
}
@ -1169,21 +945,7 @@ void BX_CPU_C::write_new_stack_qword_64(Bit64u laddr, unsigned curr_pl, Bit64u d
}
}
if (! IsCanonical(laddr)) {
BX_ERROR(("write_new_stack_qword_64(): canonical failure"));
exception(BX_SS_EXCEPTION, 0);
}
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check() && user) {
if (laddr & 7) {
BX_ERROR(("write_new_stack_qword_64(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
if (access_write_linear(laddr, 8, curr_pl, (void *) &data) < 0)
if (access_write_linear(laddr, 8, curr_pl, 0x7, (void *) &data) < 0)
exception(BX_SS_EXCEPTION, 0);
}

View File

@ -4554,9 +4554,9 @@ public: // for now...
// linear address for access_linear expected to be canonical !
BX_SMF int access_read_linear(bx_address laddr, unsigned len, unsigned curr_pl,
unsigned rw, void *data);
unsigned rw, Bit32u ac_mask, void *data);
BX_SMF int access_write_linear(bx_address laddr, unsigned len, unsigned curr_pl,
void *data);
Bit32u ac_mask, void *data);
BX_SMF void page_fault(unsigned fault, bx_address laddr, unsigned user, unsigned rw);
BX_SMF void access_read_physical(bx_phy_address paddr, unsigned len, void *data);

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2013 The Bochs Project
// Copyright (C) 2001-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -1901,12 +1901,28 @@ page_fault:
}
#endif
int BX_CPU_C::access_write_linear(bx_address laddr, unsigned len, unsigned curr_pl, void *data)
int BX_CPU_C::access_write_linear(bx_address laddr, unsigned len, unsigned curr_pl, Bit32u ac_mask, void *data)
{
Bit32u pageOffset = PAGE_OFFSET(laddr);
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr);
#if BX_SUPPORT_X86_64
if (! IsCanonical(laddr)) {
BX_ERROR(("access_write_linear(): canonical failure"));
return -1;
}
#endif
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check() && (curr_pl == 3)) {
if (pageOffset & ac_mask) {
BX_ERROR(("access_write_linear(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
/* check for reference across multiple pages */
if ((pageOffset + len) <= 4096) {
// Access within single page.
@ -1976,12 +1992,28 @@ int BX_CPU_C::access_write_linear(bx_address laddr, unsigned len, unsigned curr_
return 0;
}
int BX_CPU_C::access_read_linear(bx_address laddr, unsigned len, unsigned curr_pl, unsigned xlate_rw, void *data)
int BX_CPU_C::access_read_linear(bx_address laddr, unsigned len, unsigned curr_pl, unsigned xlate_rw, Bit32u ac_mask, void *data)
{
BX_ASSERT(xlate_rw == BX_READ || xlate_rw == BX_RW);
Bit32u pageOffset = PAGE_OFFSET(laddr);
#if BX_SUPPORT_X86_64
if (! IsCanonical(laddr)) {
BX_ERROR(("access_read_linear(): canonical failure"));
return -1;
}
#endif
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
if (BX_CPU_THIS_PTR alignment_check() && (curr_pl == 3)) {
if (pageOffset & ac_mask) {
BX_ERROR(("access_read_linear(): #AC misaligned access"));
exception(BX_AC_EXCEPTION, 0);
}
}
#endif
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr);
/* check for reference across multiple pages */

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2012 The Bochs Project
// Copyright (C) 2001-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -570,7 +570,7 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::LTR_Ew(bxInstruction_c *i)
/* mark as busy */
if (!(dword2 & 0x0200)) {
dword2 |= 0x0200; /* set busy bit */
access_write_linear(BX_CPU_THIS_PTR gdtr.base + selector.index*8 + 4, 4, 0, &dword2);
access_write_linear(BX_CPU_THIS_PTR gdtr.base + selector.index*8 + 4, 4, 0, 0x0, &dword2);
}
BX_NEXT_INSTR(i);

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2012 The Bochs Project
// Copyright (C) 2001-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -512,10 +512,10 @@ BX_CPU_C::touch_segment(bx_selector_t *selector, bx_descriptor_t *descriptor)
descriptor->type |= 1;
if (selector->ti == 0) { /* GDT */
access_write_linear(BX_CPU_THIS_PTR gdtr.base + selector->index*8 + 5, 1, 0, &AR_byte);
access_write_linear(BX_CPU_THIS_PTR gdtr.base + selector->index*8 + 5, 1, 0, 0x0, &AR_byte);
}
else { /* LDT */
access_write_linear(BX_CPU_THIS_PTR ldtr.cache.u.segment.base + selector->index*8 + 5, 1, 0, &AR_byte);
access_write_linear(BX_CPU_THIS_PTR ldtr.cache.u.segment.base + selector->index*8 + 5, 1, 0, 0x0, &AR_byte);
}
}
}

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2012 The Bochs Project
// Copyright (C) 2001-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -222,9 +222,9 @@ void BX_CPU_C::task_switch(bxInstruction_c *i, bx_selector_t *tss_selector,
if (source == BX_TASK_FROM_JUMP || source == BX_TASK_FROM_IRET) {
// Bit is cleared
Bit32u laddr = (Bit32u) BX_CPU_THIS_PTR gdtr.base + (BX_CPU_THIS_PTR tr.selector.index<<3) + 4;
access_read_linear(laddr, 4, 0, BX_RW, &temp32);
access_read_linear(laddr, 4, 0, BX_RW, 0x0, &temp32);
temp32 &= ~0x200;
access_write_linear(laddr, 4, 0, &temp32);
access_write_linear(laddr, 4, 0, 0x0, &temp32);
}
// STEP 4: If the task switch was initiated with an IRET instruction,
@ -391,9 +391,9 @@ void BX_CPU_C::task_switch(bxInstruction_c *i, bx_selector_t *tss_selector,
{
// set the new task's busy bit
Bit32u laddr = (Bit32u)(BX_CPU_THIS_PTR gdtr.base) + (tss_selector->index<<3) + 4;
access_read_linear(laddr, 4, 0, BX_RW, &dword2);
access_read_linear(laddr, 4, 0, BX_RW, 0x0, &dword2);
dword2 |= 0x200;
access_write_linear(laddr, 4, 0, &dword2);
access_write_linear(laddr, 4, 0, 0x0, &dword2);
}
//