OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [cpu/] [mult8.cc] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: mult8.cc 11313 2012-08-05 13:52:40Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2001-2012  The Bochs Project
6
//
7
//  This library is free software; you can redistribute it and/or
8
//  modify it under the terms of the GNU Lesser General Public
9
//  License as published by the Free Software Foundation; either
10
//  version 2 of the License, or (at your option) any later version.
11
//
12
//  This library is distributed in the hope that it will be useful,
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
//  Lesser General Public License for more details.
16
//
17
//  You should have received a copy of the GNU Lesser General Public
18
//  License along with this library; if not, write to the Free Software
19
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
20
/////////////////////////////////////////////////////////////////////////
21
 
22
#define NEED_CPU_REG_SHORTCUTS 1
23
#include "bochs.h"
24
#include "cpu.h"
25
#define LOG_THIS BX_CPU_THIS_PTR
26
 
27
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MUL_ALEbR(bxInstruction_c *i)
28
{
29
  Bit8u op1 = AL;
30
  Bit8u op2 = BX_READ_8BIT_REGx(i->src(), i->extend8bitL());
31
 
32
  Bit32u product_16 = ((Bit16u) op1) * ((Bit16u) op2);
33
 
34
  Bit8u product_8l = (product_16 & 0xFF);
35
  Bit8u product_8h =  product_16 >> 8;
36
 
37
  /* now write product back to destination */
38
  AX = product_16;
39
 
40
  /* set EFLAGS */
41
  SET_FLAGS_OSZAPC_LOGIC_8(product_8l);
42
  if(product_8h != 0)
43
  {
44
    ASSERT_FLAGS_OxxxxC();
45
  }
46
 
47
  BX_NEXT_INSTR(i);
48
}
49
 
50
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::IMUL_ALEbR(bxInstruction_c *i)
51
{
52
  Bit8s op1 = AL;
53
  Bit8s op2 = BX_READ_8BIT_REGx(i->src(), i->extend8bitL());
54
 
55
  Bit16s product_16 = op1 * op2;
56
  Bit8u  product_8 = (product_16 & 0xFF);
57
 
58
  /* now write product back to destination */
59
  AX = product_16;
60
 
61
  /* set EFLAGS:
62
   * IMUL r/m8: condition for clearing CF & OF:
63
   *   AX = sign-extend of AL to 16 bits
64
   */
65
 
66
  SET_FLAGS_OSZAPC_LOGIC_8(product_8);
67
  if(product_16 != (Bit8s) product_16)
68
  {
69
    ASSERT_FLAGS_OxxxxC();
70
  }
71
 
72
  BX_NEXT_INSTR(i);
73
}
74
 
75
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::DIV_ALEbR(bxInstruction_c *i)
76
{
77
  Bit8u op2 = BX_READ_8BIT_REGx(i->src(), i->extend8bitL());
78
  if (op2 == 0) {
79
    exception(BX_DE_EXCEPTION, 0);
80
  }
81
 
82
  Bit16u op1 = AX;
83
 
84
  Bit16u quotient_16 = op1 / op2;
85
  Bit8u remainder_8 = op1 % op2;
86
  Bit8u quotient_8l = quotient_16 & 0xFF;
87
 
88
  if (quotient_16 != quotient_8l)
89
  {
90
    exception(BX_DE_EXCEPTION, 0);
91
  }
92
 
93
  /* now write quotient back to destination */
94
  AL = quotient_8l;
95
  AH = remainder_8;
96
 
97
  BX_NEXT_INSTR(i);
98
}
99
 
100
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::IDIV_ALEbR(bxInstruction_c *i)
101
{
102
  Bit16s op1 = AX;
103
 
104
  /* check MIN_INT case */
105
  if (op1 == ((Bit16s)0x8000))
106
    exception(BX_DE_EXCEPTION, 0);
107
 
108
  Bit8s op2 = BX_READ_8BIT_REGx(i->src(), i->extend8bitL());
109
 
110
  if (op2 == 0)
111
    exception(BX_DE_EXCEPTION, 0);
112
 
113
  Bit16s quotient_16 = op1 / op2;
114
  Bit8s remainder_8 = op1 % op2;
115
  Bit8s quotient_8l = quotient_16 & 0xFF;
116
 
117
  if (quotient_16 != quotient_8l)
118
    exception(BX_DE_EXCEPTION, 0);
119
 
120
  /* now write quotient back to destination */
121
  AL = quotient_8l;
122
  AH = remainder_8;
123
 
124
  BX_NEXT_INSTR(i);
125
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.