X86: Fault on divide by zero instead of panicing.
This commit is contained in:
parent
7378424b14
commit
373154a25a
|
@ -178,8 +178,7 @@ output decoder {{
|
||||||
uint64_t "ient, uint64_t &remainder)
|
uint64_t "ient, uint64_t &remainder)
|
||||||
{
|
{
|
||||||
//Check for divide by zero.
|
//Check for divide by zero.
|
||||||
if (divisor == 0)
|
assert(divisor != 0);
|
||||||
panic("Divide by zero!\\n");
|
|
||||||
//If the divisor is bigger than the dividend, don't do anything.
|
//If the divisor is bigger than the dividend, don't do anything.
|
||||||
if (divisor <= dividend) {
|
if (divisor <= dividend) {
|
||||||
//Shift the divisor so it's msb lines up with the dividend.
|
//Shift the divisor so it's msb lines up with the dividend.
|
||||||
|
@ -518,11 +517,15 @@ let {{
|
||||||
//This is a temporary just for consistency and clarity.
|
//This is a temporary just for consistency and clarity.
|
||||||
uint64_t dividend = remainder;
|
uint64_t dividend = remainder;
|
||||||
//Do the division.
|
//Do the division.
|
||||||
divide(dividend, divisor, quotient, remainder);
|
if (divisor == 0) {
|
||||||
//Record the final results.
|
fault = new DivideByZero;
|
||||||
Remainder = remainder;
|
} else {
|
||||||
Quotient = quotient;
|
divide(dividend, divisor, quotient, remainder);
|
||||||
Divisor = divisor;
|
//Record the final results.
|
||||||
|
Remainder = remainder;
|
||||||
|
Quotient = quotient;
|
||||||
|
Divisor = divisor;
|
||||||
|
}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# Step divide
|
# Step divide
|
||||||
|
@ -535,7 +538,9 @@ let {{
|
||||||
int remaining = op2;
|
int remaining = op2;
|
||||||
//If we overshot, do nothing. This lets us unrool division loops a
|
//If we overshot, do nothing. This lets us unrool division loops a
|
||||||
//little.
|
//little.
|
||||||
if (remaining) {
|
if (divisor == 0) {
|
||||||
|
fault = new DivideByZero;
|
||||||
|
} else if (remaining) {
|
||||||
if (divisor & (ULL(1) << 63)) {
|
if (divisor & (ULL(1) << 63)) {
|
||||||
while (remaining && !(dividend & (ULL(1) << 63))) {
|
while (remaining && !(dividend & (ULL(1) << 63))) {
|
||||||
dividend = (dividend << 1) |
|
dividend = (dividend << 1) |
|
||||||
|
|
Loading…
Reference in a new issue