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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestJump.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#include <gtest/gtest.h>
19
 
20
#include "EmulateFixture.h"
21
#include "Flags.h"
22
 
23
TEST_F(EmulateFixture, JmpDirectIntra)
24
{
25
    write_reg(CS, 0x2000);
26
    write_reg(IP, 0x0030);
27
    set_instruction({0xe9, 0x10, 0x20});
28
 
29
    emulate();
30
 
31
    ASSERT_EQ(0x2000, read_reg(CS));
32
    ASSERT_EQ(0x2043, read_reg(IP));
33
}
34
 
35
TEST_F(EmulateFixture, JmpDirectIntraShort)
36
{
37
    write_reg(CS, 0x2000);
38
    write_reg(IP, 0x0100);
39
    set_instruction({0xeb, 0x80});
40
 
41
    emulate();
42
 
43
    ASSERT_EQ(0x2000, read_reg(CS));
44
    ASSERT_EQ(0x0082, read_reg(IP));
45
}
46
 
47
TEST_F(EmulateFixture, JmpIndirectIntraReg)
48
{
49
    write_reg(CS, 0x2000);
50
    write_reg(IP, 0x0030);
51
    write_reg(AX, 0x0100);
52
    // jmp ax
53
    set_instruction({0xff, 0xe0});
54
 
55
    emulate();
56
 
57
    ASSERT_EQ(0x2000, read_reg(CS));
58
    ASSERT_EQ(0x0100, read_reg(IP));
59
}
60
 
61
TEST_F(EmulateFixture, JmpIndirectIntraMem)
62
{
63
    write_reg(CS, 0x2000);
64
    write_reg(IP, 0x0030);
65
 
66
    write_reg(BX, 0x0800);
67
    write_mem16(0x0800, 0x0100);
68
    // jmp [bx]
69
    set_instruction({0xff, 0x27});
70
 
71
    emulate();
72
 
73
    ASSERT_EQ(0x2000, read_reg(CS));
74
    ASSERT_EQ(0x0100, read_reg(IP));
75
}
76
 
77
TEST_F(EmulateFixture, DirectInter)
78
{
79
    write_reg(CS, 0x2000);
80
    write_reg(IP, 0x0030);
81
 
82
    // jmp 0x8000:0x1234
83
    set_instruction({0xea, 0x34, 0x12, 0x00, 0x80});
84
 
85
    emulate();
86
 
87
    ASSERT_EQ(0x8000, read_reg(CS));
88
    ASSERT_EQ(0x1234, read_reg(IP));
89
}
90
 
91
TEST_F(EmulateFixture, JmpIndirectInterReg)
92
{
93
    write_reg(CS, 0x2000);
94
    write_reg(IP, 0x0030);
95
    // jmp far ax (invalid encoding)
96
    set_instruction({0xff, 0xe8});
97
 
98
    emulate();
99
 
100
    ASSERT_EQ(0x2000, read_reg(CS));
101
    ASSERT_EQ(0x0032, read_reg(IP));
102
 
103
    ASSERT_FALSE(instruction_had_side_effects());
104
}
105
 
106
TEST_F(EmulateFixture, JmpIndirectInterMem)
107
{
108
    write_reg(CS, 0x2000);
109
    write_reg(IP, 0x0030);
110
 
111
    write_reg(BX, 0x0800);
112
    write_mem16(0x0800, 0x5678);
113
    write_mem16(0x0802, 0x4000);
114
    // jmp far [bx]
115
    set_instruction({0xff, 0x2f});
116
 
117
    emulate();
118
 
119
    ASSERT_EQ(0x4000, read_reg(CS));
120
    ASSERT_EQ(0x5678, read_reg(IP));
121
}
122
 
123
struct JmpTest {
124
    const char *name;
125
    uint8_t opcode;
126
    uint16_t flags;
127
    bool taken;
128
};
129
 
130
class JmpFixture : public EmulateFixture,
131
                   public ::testing::WithParamInterface<JmpTest>
132
{
133
};
134
 
135
TEST_P(JmpFixture, TakenNotTaken)
136
{
137
    auto old_ip = read_reg(IP);
138
 
139
    SCOPED_TRACE(GetParam().name + std::string(" [") +
140
                 flags_to_string(GetParam().flags) + std::string("]") +
141
                 (GetParam().taken ? " (taken)" : " (not taken)"));
142
 
143
    write_flags(GetParam().flags);
144
    set_instruction({GetParam().opcode, 0x0e});
145
 
146
    emulate();
147
 
148
    if (GetParam().taken)
149
        ASSERT_EQ(read_reg(IP), old_ip + 0x10);
150
    else
151
        ASSERT_EQ(read_reg(IP), old_ip + 0x02);
152
}
153
INSTANTIATE_TEST_CASE_P(
154
    JmpConditional,
155
    JmpFixture,
156
    ::testing::Values(JmpTest{"je/jz", 0x74, ZF, true},
157
                      JmpTest{"je/jz", 0x74, 0, false},
158
 
159
                      JmpTest{"jl/jnge", 0x7c, SF, true},
160
                      JmpTest{"jl/jnge", 0x7c, OF, true},
161
                      JmpTest{"jl/jnge", 0x7c, OF | SF, false},
162
                      JmpTest{"jl/jnge", 0x7c, 0, false},
163
 
164
                      JmpTest{"jle/jng", 0x7e, SF, true},
165
                      JmpTest{"jle/jng", 0x7e, OF, true},
166
                      JmpTest{"jle/jng", 0x7e, OF | SF, false},
167
                      JmpTest{"jle/jng", 0x7e, ZF | OF | SF, true},
168
                      JmpTest{"jle/jng", 0x7e, ZF, true},
169
                      JmpTest{"jle/jng", 0x7e, 0, false},
170
 
171
                      JmpTest{"jb/jnae", 0x72, 0, false},
172
                      JmpTest{"jb/jnae", 0x72, CF, true},
173
 
174
                      JmpTest{"jbe/jna", 0x76, 0, false},
175
                      JmpTest{"jbe/jna", 0x76, CF, true},
176
                      JmpTest{"jbe/jna", 0x76, ZF, true},
177
                      JmpTest{"jbe/jna", 0x76, CF | ZF, true},
178
 
179
                      JmpTest{"jp/jpe", 0x7a, 0, false},
180
                      JmpTest{"jp/jpe", 0x7a, PF, true},
181
 
182
                      JmpTest{"jo", 0x70, 0, false},
183
                      JmpTest{"jo", 0x70, OF, true},
184
 
185
                      JmpTest{"js", 0x78, 0, false},
186
                      JmpTest{"js", 0x78, SF, true},
187
 
188
                      JmpTest{"jne/jnz", 0x75, 0, true},
189
                      JmpTest{"jne/jnz", 0x75, ZF, false},
190
 
191
                      JmpTest{"jnl/jge", 0x7d, 0, true},
192
                      JmpTest{"jnl/jge", 0x7d, SF | OF, true},
193
                      JmpTest{"jnl/jge", 0x7d, OF, false},
194
                      JmpTest{"jnl/jge", 0x7d, SF, false},
195
 
196
                      JmpTest{"jnle/jg", 0x7f, ZF, false},
197
                      JmpTest{"jnle/jg", 0x7f, 0, true},
198
                      JmpTest{"jnle/jg", 0x7f, SF | OF, true},
199
                      JmpTest{"jnle/jg", 0x7f, SF, false},
200
                      JmpTest{"jnle/jg", 0x7f, OF, false},
201
 
202
                      JmpTest{"jnb/jae", 0x73, 0, true},
203
                      JmpTest{"jnb/jae", 0x73, CF, false},
204
 
205
                      JmpTest{"jnbe/ja", 0x77, 0, true},
206
                      JmpTest{"jnbe/ja", 0x77, CF, false},
207
                      JmpTest{"jnbe/ja", 0x77, ZF, false},
208
                      JmpTest{"jnbe/ja", 0x77, CF | ZF, false},
209
 
210
                      JmpTest{"jnp/jpo", 0x7b, 0, true},
211
                      JmpTest{"jnp/jpo", 0x7b, PF, false},
212
 
213
                      JmpTest{"jno", 0x71, 0, true},
214
                      JmpTest{"jno", 0x71, OF, false},
215
 
216
                      JmpTest{"jns", 0x79, SF, false},
217
                      JmpTest{"jns", 0x79, 0, true}));
218
 
219
TEST_F(EmulateFixture, JcxzNotTaken)
220
{
221
    write_reg(CX, 1);
222
    write_reg(IP, 0x0030);
223
    set_instruction({0xe3, 0x80});
224
 
225
    emulate();
226
 
227
    ASSERT_EQ(read_reg(IP), 0x0032);
228
}
229
 
230
TEST_F(EmulateFixture, JcxzTaken)
231
{
232
    write_reg(CX, 0);
233
    write_reg(IP, 0x0030);
234
    set_instruction({0xe3, 0x10});
235
 
236
    emulate();
237
 
238
    ASSERT_EQ(read_reg(IP), 0x0042);
239
}

powered by: WebSVN 2.1.0

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