Author: aandrejevic
Date: Tue Dec 3 00:56:47 2013
New Revision: 61204
URL:
http://svn.reactos.org/svn/reactos?rev=61204&view=rev
Log:
[FAST486]
Check for division by zero, and generate the appropriate exception.
Modified:
branches/ntvdm/lib/fast486/opgroups.c
Modified: branches/ntvdm/lib/fast486/opgroups.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/fast486/opgroups.c?re…
==============================================================================
--- branches/ntvdm/lib/fast486/opgroups.c [iso-8859-1] (original)
+++ branches/ntvdm/lib/fast486/opgroups.c [iso-8859-1] Tue Dec 3 00:56:47 2013
@@ -1012,8 +1012,17 @@
/* DIV */
case 6:
{
- UCHAR Quotient = State->GeneralRegs[FAST486_REG_EAX].LowWord / Value;
- UCHAR Remainder = State->GeneralRegs[FAST486_REG_EAX].LowWord % Value;
+ UCHAR Quotient, Remainder;
+
+ if (Value == 0)
+ {
+ /* Divide error */
+ Fast486Exception(State, FAST486_EXCEPTION_DE);
+ return FALSE;
+ }
+
+ Quotient = State->GeneralRegs[FAST486_REG_EAX].LowWord / Value;
+ Remainder = State->GeneralRegs[FAST486_REG_EAX].LowWord % Value;
/* Write back the results */
State->GeneralRegs[FAST486_REG_EAX].LowByte = Quotient;
@@ -1025,8 +1034,17 @@
/* IDIV */
case 7:
{
- CHAR Quotient = (SHORT)State->GeneralRegs[FAST486_REG_EAX].LowWord /
(CHAR)Value;
- CHAR Remainder = (SHORT)State->GeneralRegs[FAST486_REG_EAX].LowWord %
(CHAR)Value;
+ CHAR Quotient, Remainder;
+
+ if (Value == 0)
+ {
+ /* Divide error */
+ Fast486Exception(State, FAST486_EXCEPTION_DE);
+ return FALSE;
+ }
+
+ Quotient = (SHORT)State->GeneralRegs[FAST486_REG_EAX].LowWord /
(CHAR)Value;
+ Remainder = (SHORT)State->GeneralRegs[FAST486_REG_EAX].LowWord %
(CHAR)Value;
/* Write back the results */
State->GeneralRegs[FAST486_REG_EAX].LowByte = (UCHAR)Quotient;
@@ -1225,6 +1243,13 @@
/* DIV */
case 6:
{
+ if (Value == 0)
+ {
+ /* Divide error */
+ Fast486Exception(State, FAST486_EXCEPTION_DE);
+ return FALSE;
+ }
+
if (OperandSize)
{
ULONGLONG Dividend =
(ULONGLONG)State->GeneralRegs[FAST486_REG_EAX].Long
@@ -1254,6 +1279,13 @@
/* IDIV */
case 7:
{
+ if (Value == 0)
+ {
+ /* Divide error */
+ Fast486Exception(State, FAST486_EXCEPTION_DE);
+ return FALSE;
+ }
+
if (OperandSize)
{
LONGLONG Dividend =
(LONGLONG)State->GeneralRegs[FAST486_REG_EAX].Long