Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/45306 )
Change subject: arch-x86: When generating a fault, return it immediately.
......................................................................
arch-x86: When generating a fault, return it immediately.
When the register microops generate a fault, they were storing it in a
variable and then later returning it. They were also gating behavior
based on whether or not the fault happened.
Once a fault has occurred, the instruction shouldn't do anything else
other than return the fault, and the fault should definitley be
returned. Also, the compiler might not be able to figure out that a
fault means no registers are going to be written back leading to
spurious warnings.
Change-Id: Ib6fc6ea4fcadd66c15fe68ce9fe62857b564ce83
---
M src/arch/x86/isa/microops/regop.isa
1 file changed, 37 insertions(+), 41 deletions(-)
diff --git a/src/arch/x86/isa/microops/regop.isa
b/src/arch/x86/isa/microops/regop.isa
index 6f2febd..3e22089 100644
--- a/src/arch/x86/isa/microops/regop.isa
+++ b/src/arch/x86/isa/microops/regop.isa
@@ -44,8 +44,6 @@
%(class_name)s::execute(ExecContext *xc,
Trace::InstRecord *traceData) const
{
- Fault fault = NoFault;
-
DPRINTF(X86, "The data size is %d\n", dataSize);
%(op_decl)s;
%(op_rd)s;
@@ -60,10 +58,8 @@
}
//Write the resulting state to the execution context
- if (fault == NoFault) {
- %(op_wb)s;
- }
- return fault;
+ %(op_wb)s;
+ return NoFault;
}
}};
@@ -617,7 +613,7 @@
uint64_t dividend = remainder;
//Do the division.
if (divisor == 0) {
- fault = std::make_shared<DivideError>();
+ return std::make_shared<DivideError>();
} else {
divideStep(dividend, divisor, quotient, remainder);
//Record the final results.
@@ -640,7 +636,7 @@
//If we overshot, do nothing. This lets us unrool division
loops a
//little.
if (divisor == 0) {
- fault = std::make_shared<DivideError>();
+ return std::make_shared<DivideError>();
} else if (remaining) {
if (divisor & (1ULL << 63)) {
while (remaining && !(dividend & (1ULL << 63))) {
@@ -1301,9 +1297,9 @@
CR4 cr4 = CR4Op;
DR7 dr7 = DR7Op;
if ((cr4.de == 1 && (src1 == 4 || src1 == 5)) || src1 >= 8) {
- fault = std::make_shared<InvalidOpcode>();
+ return std::make_shared<InvalidOpcode>();
} else if (dr7.gd) {
- fault = std::make_shared<DebugException>();
+ return std::make_shared<DebugException>();
} else {
%s
}
@@ -1320,12 +1316,12 @@
CR4 cr4 = CR4Op;
DR7 dr7 = DR7Op;
if ((cr4.de == 1 && (dest == 4 || dest == 5)) || dest >= 8) {
- fault = std::make_shared<InvalidOpcode>();
+ return std::make_shared<InvalidOpcode>();
} else if ((dest == 6 || dest == 7) && bits(PSrcReg1, 63, 32)
&&
machInst.mode.mode == LongMode) {
- fault = std::make_shared<GeneralProtection>(0);
+ return std::make_shared<GeneralProtection>(0);
} else if (dr7.gd) {
- fault = std::make_shared<DebugException>();
+ return std::make_shared<DebugException>();
} else {
DebugDest = PSrcReg1;
}
@@ -1338,7 +1334,7 @@
dataSize=dataSize)
rdcrCode = '''
if (src1 == 1 || (src1 > 4 && src1 < 8) || (src1 > 8)) {
- fault = std::make_shared<InvalidOpcode>();
+ return std::make_shared<InvalidOpcode>();
} else {
%s
}
@@ -1354,7 +1350,7 @@
dataSize=dataSize)
code = '''
if (dest == 1 || (dest > 4 && dest < 8) || (dest > 8)) {
- fault = std::make_shared<InvalidOpcode>();
+ return std::make_shared<InvalidOpcode>();
} else {
RegVal newVal = PSrcReg1;
@@ -1369,7 +1365,7 @@
(!cr0.pe && cr0.pg) ||
(!cr0.cd && cr0.nw) ||
(cr0.pg && efer.lme && !oldCr4.pae))
- fault = std::make_shared<GeneralProtection>(0);
+ return std::make_shared<GeneralProtection>(0);
}
break;
case 2:
@@ -1382,17 +1378,17 @@
// PAE can't be disabled in long mode.
if (bits(newVal, 63, 11) ||
(machInst.mode.mode == LongMode
&& !cr4.pae))
- fault = std::make_shared<GeneralProtection>(0);
+ return std::make_shared<GeneralProtection>(0);
}
break;
case 8:
{
if (bits(newVal, 63, 4))
- fault = std::make_shared<GeneralProtection>(0);
+ return std::make_shared<GeneralProtection>(0);
}
break;
default:
- fault = std::make_shared<GenericISA::M5PanicFault>(
+ return std::make_shared<GenericISA::M5PanicFault>(
"Unrecognized control register %d.\\n", dest);
}
ControlDest = newVal;
@@ -1488,20 +1484,20 @@
case SegCSCheck:
// Make sure it's the right type
if (desc.s == 0 || desc.type.codeOrData != 1) {
- fault = std::make_shared<GeneralProtection>(0);
+ return std::make_shared<GeneralProtection>(0);
} else if (m5reg.cpl != desc.dpl) {
- fault = std::make_shared<GeneralProtection>(0);
+ return std::make_shared<GeneralProtection>(0);
}
break;
case SegCallGateCheck:
- fault = std::make_shared<GenericISA::M5PanicFault>(
+ return std::make_shared<GenericISA::M5PanicFault>(
"CS checks for far "
"calls/jumps through call gates not
implemented.\\n");
break;
case SegSoftIntGateCheck:
// Check permissions.
if (desc.dpl < m5reg.cpl) {
- fault = std::make_shared<GeneralProtection>(selector);
+ return std::make_shared<GeneralProtection>(selector);
break;
}
M5_FALLTHROUGH;
@@ -1509,22 +1505,22 @@
// Make sure the gate's the right type.
if ((m5reg.mode == LongMode && (desc.type & 0xe) != 0xe) ||
((desc.type & 0x6) != 0x6)) {
- fault = std::make_shared<GeneralProtection>(0);
+ return std::make_shared<GeneralProtection>(0);
}
break;
case SegSSCheck:
if (selector.si || selector.ti) {
if (!desc.p) {
- fault = std::make_shared<StackFault>(selector);
+ return std::make_shared<StackFault>(selector);
} else if (!(desc.s == 1 && desc.type.codeOrData == 0
&&
desc.type.w) ||
(desc.dpl != m5reg.cpl) ||
(selector.rpl != m5reg.cpl)) {
- fault =
std::make_shared<GeneralProtection>(selector);
+ return
std::make_shared<GeneralProtection>(selector);
}
} else if (m5reg.submode != SixtyFourBitMode ||
m5reg.cpl == 3) {
- fault = std::make_shared<GeneralProtection>(selector);
+ return std::make_shared<GeneralProtection>(selector);
}
break;
case SegIretCheck:
@@ -1534,51 +1530,51 @@
!(desc.s == 1 && desc.type.codeOrData == 1) ||
(!desc.type.c && desc.dpl != selector.rpl) ||
(desc.type.c && desc.dpl > selector.rpl)) {
- fault =
std::make_shared<GeneralProtection>(selector);
+ return
std::make_shared<GeneralProtection>(selector);
} else if (!desc.p) {
- fault =
std::make_shared<SegmentNotPresent>(selector);
+ return
std::make_shared<SegmentNotPresent>(selector);
}
break;
}
case SegIntCSCheck:
if (m5reg.mode == LongMode) {
if (desc.l != 1 || desc.d != 0) {
- fault =
std::make_shared<GeneralProtection>(selector);
+ return
std::make_shared<GeneralProtection>(selector);
}
} else {
- fault = std::make_shared<GenericISA::M5PanicFault>(
+ return std::make_shared<GenericISA::M5PanicFault>(
"Interrupt CS "
"checks not implemented in legacy mode.\\n");
}
break;
case SegTRCheck:
if (!selector.si || selector.ti) {
- fault = std::make_shared<GeneralProtection>(selector);
+ return std::make_shared<GeneralProtection>(selector);
}
break;
case SegTSSCheck:
if (!desc.p) {
- fault = std::make_shared<SegmentNotPresent>(selector);
+ return std::make_shared<SegmentNotPresent>(selector);
} else if (!(desc.type == 0x9 ||
(desc.type == 1 &&
m5reg.mode != LongMode))) {
- fault = std::make_shared<GeneralProtection>(selector);
+ return std::make_shared<GeneralProtection>(selector);
}
break;
case SegInGDTCheck:
if (selector.ti) {
- fault = std::make_shared<GeneralProtection>(selector);
+ return std::make_shared<GeneralProtection>(selector);
}
break;
case SegLDTCheck:
if (!desc.p) {
- fault = std::make_shared<SegmentNotPresent>(selector);
+ return std::make_shared<SegmentNotPresent>(selector);
} else if (desc.type != 0x2) {
- fault = std::make_shared<GeneralProtection>(selector);
+ return std::make_shared<GeneralProtection>(selector);
}
break;
default:
- fault = std::make_shared<GenericISA::M5PanicFault>(
+ return std::make_shared<GenericISA::M5PanicFault>(
"Undefined segment check type.\\n");
}
'''
@@ -1611,7 +1607,7 @@
replaceBits(target, 31, 16, bits(desc, 63, 48));
break;
default:
- fault = std::make_shared<GenericISA::M5PanicFault>(
+ return std::make_shared<GenericISA::M5PanicFault>(
"Wrdh used with wrong descriptor type!\\n");
}
DestReg = target;
@@ -1641,7 +1637,7 @@
while (true) {
if (selector.si || selector.ti) {
if (!desc.p) {
- fault = std::make_shared<GenericISA::M5PanicFault>(
+ return std::make_shared<GenericISA::M5PanicFault>(
"Segment not present.\\n");
break;
}
@@ -1658,7 +1654,7 @@
if (!desc.s) {
// The expand down bit happens to be set for gates.
if (desc.type.e) {
- fault =
std::make_shared<GenericISA::M5PanicFault>(
+ return
std::make_shared<GenericISA::M5PanicFault>(
"Gate descriptor encountered.\\n");
break;
}
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/45306
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib6fc6ea4fcadd66c15fe68ce9fe62857b564ce83
Gerrit-Change-Number: 45306
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s