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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [cpu/] [bcd.cc] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: bcd.cc 10451 2011-07-06 20:01:18Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2001-2011  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::AAA(bxInstruction_c *i)
28
{
29
  int tmpCF = 0, tmpAF = 0;
30
 
31
  /*
32
   *  Note: This instruction incorrectly documented in Intel's materials.
33
   *        The right description is:
34
   *
35
   *    IF (((AL and 0FH) > 9) or (AF==1)
36
   *    THEN
37
   *        IF CPU<286 THEN {  AL <- AL+6 }
38
   *                   ELSE {  AX <- AX+6 }
39
   *        AH <- AH+1
40
   *        CF <- 1
41
   *        AF <- 1
42
   *    ELSE
43
   *        CF <- 0
44
   *        AF <- 0
45
   *    ENDIF
46
   *    AL <- AL and 0Fh
47
   */
48
 
49
  /* Validated against Intel Pentium family hardware. */
50
 
51
  /* AAA affects the following flags: A,C */
52
 
53
  if (((AL & 0x0f) > 9) || get_AF())
54
  {
55
    AX = AX + 0x106;
56
    tmpAF = tmpCF = 1;
57
  }
58
 
59
  AL = AL & 0x0f;
60
 
61
  /* AAA affects also the following flags: Z,S,O,P */
62
  /* modification of the flags is undocumented */
63
 
64
  /* The following behaviour seems to match the P6 and
65
     its derived processors. */
66
  SET_FLAGS_OSZAPC_LOGIC_8(AL);
67
  set_CF(tmpCF);
68
  set_AF(tmpAF);
69
 
70
  BX_NEXT_INSTR(i);
71
}
72
 
73
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::AAS(bxInstruction_c *i)
74
{
75
  int tmpCF = 0, tmpAF = 0;
76
 
77
  /* AAS affects the following flags: A,C */
78
 
79
  if (((AL & 0x0F) > 0x09) || get_AF())
80
  {
81
    AX = AX - 0x106;
82
    tmpAF = tmpCF = 1;
83
  }
84
 
85
  AL = AL & 0x0f;
86
 
87
  /* AAS affects also the following flags: Z,S,O,P */
88
  /* modification of the flags is undocumented */
89
 
90
  /* The following behaviour seems to match the P6 and
91
     its derived processors. */
92
  SET_FLAGS_OSZAPC_LOGIC_8(AL);
93
  set_CF(tmpCF);
94
  set_AF(tmpAF);
95
 
96
  BX_NEXT_INSTR(i);
97
}
98
 
99
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::AAM(bxInstruction_c *i)
100
{
101
  Bit8u al, imm8 = i->Ib();
102
 
103
  if (imm8 == 0)
104
    exception(BX_DE_EXCEPTION, 0);
105
 
106
  al = AL;
107
  AH = al / imm8;
108
  AL = al % imm8;
109
 
110
  /* modification of flags A,C,O is undocumented */
111
  /* The following behaviour seems to match the P6 and
112
     its derived processors. */
113
  SET_FLAGS_OSZAPC_LOGIC_8(AL);
114
 
115
  BX_NEXT_INSTR(i);
116
}
117
 
118
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::AAD(bxInstruction_c *i)
119
{
120
  Bit16u tmp = AH;
121
  tmp *= i->Ib();
122
  tmp += AL;
123
 
124
  AX = (tmp & 0xff);
125
 
126
  /* modification of flags A,C,O is undocumented */
127
  /* The following behaviour seems to match the P6 and
128
     its derived processors. */
129
  SET_FLAGS_OSZAPC_LOGIC_8(AL);
130
 
131
  BX_NEXT_INSTR(i);
132
}
133
 
134
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::DAA(bxInstruction_c *i)
135
{
136
  Bit8u tmpAL = AL;
137
  int   tmpCF = 0, tmpAF = 0;
138
 
139
  /* Validated against Intel Pentium family hardware. */
140
 
141
  // DAA affects the following flags: S,Z,A,P,C
142
 
143
  if (((tmpAL & 0x0F) > 0x09) || get_AF())
144
  {
145
    tmpCF = ((AL > 0xF9) || get_CF());
146
    AL = AL + 0x06;
147
    tmpAF = 1;
148
  }
149
 
150
  if ((tmpAL > 0x99) || get_CF())
151
  {
152
    AL = AL + 0x60;
153
    tmpCF = 1;
154
  }
155
 
156
  SET_FLAGS_OSZAPC_LOGIC_8(AL);
157
  set_CF(tmpCF);
158
  set_AF(tmpAF);
159
 
160
  BX_NEXT_INSTR(i);
161
}
162
 
163
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::DAS(bxInstruction_c *i)
164
{
165
  /* The algorithm for DAS is fashioned after the pseudo code in the
166
   * Pentium Processor Family Developer's Manual, volume 3.  It seems
167
   * to have changed from earlier processor's manuals.  I'm not sure
168
   * if this is a correction in the algorithm printed, or Intel has
169
   * changed the handling of instruction. Validated against Intel
170
   * Pentium family hardware.
171
   */
172
 
173
  Bit8u tmpAL = AL;
174
  int tmpCF = 0, tmpAF = 0;
175
 
176
  /* DAS effect the following flags: A,C,S,Z,P */
177
 
178
  if (((tmpAL & 0x0F) > 0x09) || get_AF())
179
  {
180
    tmpCF = (AL < 0x06) || get_CF();
181
    AL = AL - 0x06;
182
    tmpAF = 1;
183
  }
184
 
185
  if ((tmpAL > 0x99) || get_CF())
186
  {
187
    AL = AL - 0x60;
188
    tmpCF = 1;
189
  }
190
 
191
  SET_FLAGS_OSZAPC_LOGIC_8(AL);
192
  set_CF(tmpCF);
193
  set_AF(tmpAF);
194
 
195
  BX_NEXT_INSTR(i);
196
}

powered by: WebSVN 2.1.0

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