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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestMov.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
 
22
TEST_F(EmulateFixture, MovRegReg8)
23
{
24
    // mov al, bl
25
    set_instruction({0x88, 0xd8});
26
 
27
    write_reg(AL, 0x1);
28
    write_reg(BL, 0x2);
29
 
30
    emulate();
31
 
32
    ASSERT_EQ(0x2, read_reg(AL));
33
    ASSERT_EQ(0x2, read_reg(BL));
34
}
35
 
36
TEST_F(EmulateFixture, MovMemReg8)
37
{
38
    // mov [bx], al
39
    set_instruction({0x88, 0x07});
40
 
41
    write_reg(AL, 0x12);
42
    write_reg(BX, 0x100);
43
    write_mem16(0x0100, 0);
44
 
45
    emulate();
46
 
47
    ASSERT_EQ(0x12, read_mem16(0x0100));
48
}
49
 
50
TEST_F(EmulateFixture, MovRegReg16)
51
{
52
    // mov ax, bx
53
    set_instruction({0x89, 0xd8});
54
 
55
    write_reg(AX, 0x1);
56
    write_reg(BX, 0x2);
57
 
58
    emulate();
59
 
60
    ASSERT_EQ(0x2, read_reg(AL));
61
    ASSERT_EQ(0x2, read_reg(BL));
62
}
63
 
64
TEST_F(EmulateFixture, MovMemReg16)
65
{
66
    // mov [bx], ax
67
    set_instruction({0x89, 0x07});
68
 
69
    write_reg(AL, 0x12);
70
    write_reg(BX, 0x100);
71
    write_mem16(0x0100, 0);
72
 
73
    emulate();
74
 
75
    ASSERT_EQ(0x12, read_mem16(0x0100));
76
}
77
 
78
TEST_F(EmulateFixture, MovRegReg8_8a)
79
{
80
    // mov bl, al
81
    set_instruction({0x8a, 0xd8});
82
 
83
    write_reg(AL, 0x1);
84
    write_reg(BL, 0x2);
85
 
86
    emulate();
87
 
88
    ASSERT_EQ(0x1, read_reg(AL));
89
    ASSERT_EQ(0x1, read_reg(BL));
90
}
91
 
92
TEST_F(EmulateFixture, MovRegMem8)
93
{
94
    // mov al, [bx]
95
    set_instruction({0x8a, 0x07});
96
 
97
    write_reg(AL, 0x12);
98
    write_reg(BX, 0x100);
99
    write_mem16(0x0100, 0x55);
100
 
101
    emulate();
102
 
103
    ASSERT_EQ(0x55, read_reg(AL));
104
}
105
 
106
TEST_F(EmulateFixture, MovRegReg16_8b)
107
{
108
    // mov bl, al
109
    set_instruction({0x8b, 0xd8});
110
 
111
    write_reg(AX, 0x1);
112
    write_reg(BX, 0x2);
113
 
114
    emulate();
115
 
116
    ASSERT_EQ(0x1, read_reg(AX));
117
    ASSERT_EQ(0x1, read_reg(BX));
118
}
119
 
120
TEST_F(EmulateFixture, MovRegMem16)
121
{
122
    // mov ax, [bx]
123
    set_instruction({0x8b, 0x07});
124
 
125
    write_reg(AL, 0x12);
126
    write_reg(BX, 0x100);
127
    write_mem16(0x0100, 0xaa55);
128
 
129
    emulate();
130
 
131
    ASSERT_EQ(0xaa55, read_reg(AX));
132
}
133
 
134
TEST_F(EmulateFixture, MovC6C7RegNot0IsNop)
135
{
136
    set_instruction({0xc6, 0xff});
137
    emulate();
138
    ASSERT_EQ(2LU, instr_len);
139
 
140
    reset();
141
 
142
    set_instruction({0xc7, 0xff});
143
    emulate();
144
    ASSERT_EQ(2LU, instr_len);
145
}
146
 
147
TEST_F(EmulateFixture, MovC6RegImmediate)
148
{
149
    // mov al, 0xaa
150
    set_instruction({0xc6, 0xc0, 0xaa});
151
    emulate();
152
 
153
    ASSERT_EQ(0xaa, read_reg(AL));
154
}
155
 
156
TEST_F(EmulateFixture, MovC6MemImmediate)
157
{
158
    // mov [bx], 0xaa
159
    set_instruction({0xc6, 0x07, 0xaa});
160
    write_reg(BX, 0x100);
161
    emulate();
162
 
163
    ASSERT_EQ(0xaa, read_mem8(0x100));
164
}
165
 
166
TEST_F(EmulateFixture, MovC7RegImmediate)
167
{
168
    // mov ax, 0xaa55
169
    set_instruction({0xc7, 0xc0, 0x55, 0xaa});
170
    emulate();
171
 
172
    ASSERT_EQ(0xaa55, read_reg(AX));
173
}
174
 
175
TEST_F(EmulateFixture, MovC7MemImmediate)
176
{
177
    // mov [bx], 0xaa55
178
    set_instruction({0xc7, 0x07, 0x55, 0xaa});
179
    write_reg(BX, 0x100);
180
    emulate();
181
 
182
    ASSERT_EQ(0xaa55, read_mem16(0x100));
183
}
184
 
185
TEST_F(EmulateFixture, MovRegImmediate8)
186
{
187
    // mov al, 0xaa
188
    for (uint8_t i = 0; i < 8; ++i) {
189
        reset();
190
 
191
        auto reg = static_cast<GPR>(static_cast<int>(AL) + i);
192
        write_reg(reg, 0);
193
 
194
        set_instruction({static_cast<uint8_t>(0xb0 + i), 0xaa});
195
        emulate();
196
 
197
        ASSERT_EQ(0xaa, read_reg(reg));
198
    }
199
}
200
 
201
TEST_F(EmulateFixture, MovRegImmediate16)
202
{
203
    // mov al, 0xaa55
204
    for (uint8_t i = 0; i < 8; ++i) {
205
        reset();
206
 
207
        auto reg = static_cast<GPR>(static_cast<int>(AX) + i);
208
        write_reg(reg, 0);
209
 
210
        set_instruction({static_cast<uint8_t>(0xb8 + i), 0x55, 0xaa});
211
        emulate();
212
 
213
        ASSERT_EQ(0xaa55, read_reg(reg));
214
    }
215
}
216
 
217
TEST_F(EmulateFixture, MovAccumulatorMemory8)
218
{
219
    // mov al, [1234]
220
    set_instruction({0xa0, 0x34, 0x12});
221
    write_mem16(0x1234, 0xaa55);
222
    emulate();
223
 
224
    ASSERT_EQ(0x55, read_reg(AL));
225
}
226
 
227
TEST_F(EmulateFixture, MovAccumulatorMemory16)
228
{
229
    // mov ax, [1234]
230
    set_instruction({0xa1, 0x34, 0x12});
231
    write_mem16(0x1234, 0xaa55);
232
    emulate();
233
 
234
    ASSERT_EQ(0xaa55, read_reg(AX));
235
}
236
 
237
TEST_F(EmulateFixture, MovMemoryAccumulator8)
238
{
239
    // mov [1234], al
240
    set_instruction({0xa2, 0x34, 0x12});
241
    write_reg(AL, 0x55);
242
    emulate();
243
 
244
    ASSERT_EQ(0x55, read_mem8(0x1234));
245
}
246
 
247
TEST_F(EmulateFixture, MovMemoryAccumulator16)
248
{
249
    // mov [1234], ax
250
    set_instruction({0xa3, 0x34, 0x12});
251
    write_reg(AX, 0xaa55);
252
    emulate();
253
 
254
    ASSERT_EQ(0xaa55, read_mem16(0x1234));
255
}
256
 
257
class MovSRFixture
258
    : public EmulateFixture,
259
      public ::testing::WithParamInterface<std::pair<uint8_t, GPR>>
260
{
261
};
262
TEST_P(MovSRFixture, MovSRReg)
263
{
264
    // mov ?s, ax
265
    set_instruction({0x8e, GetParam().first});
266
    write_reg(AX, 0x8000);
267
    emulate();
268
 
269
    ASSERT_EQ(read_reg(GetParam().second), 0x8000);
270
}
271
INSTANTIATE_TEST_CASE_P(
272
    MovSRReg,
273
    MovSRFixture,
274
    ::testing::Values(std::make_pair<uint8_t, GPR>(0xc0 | (0 << 3), ES),
275
                      std::make_pair<uint8_t, GPR>(0xc0 | (1 << 3), CS),
276
                      std::make_pair<uint8_t, GPR>(0xc0 | (2 << 3), SS),
277
                      std::make_pair<uint8_t, GPR>(0xc0 | (3 << 3), DS),
278
                      std::make_pair<uint8_t, GPR>(0xc0 | (4 << 3), ES),
279
                      std::make_pair<uint8_t, GPR>(0xc0 | (5 << 3), CS),
280
                      std::make_pair<uint8_t, GPR>(0xc0 | (6 << 3), SS),
281
                      std::make_pair<uint8_t, GPR>(0xc0 | (7 << 3), DS)));
282
 
283
TEST_F(EmulateFixture, MovSRMem)
284
{
285
    // mov es, [bx]
286
    set_instruction({0x8e, 0x07});
287
    write_mem16(0x0100, 0x8000);
288
    write_reg(BX, 0x0100);
289
    emulate();
290
 
291
    ASSERT_EQ(0x8000, read_reg(ES));
292
}
293
 
294
TEST_F(EmulateFixture, MovRegSR)
295
{
296
    // mov ax, cs
297
    write_reg(CS, 0x8000);
298
    set_instruction({0x8c, 0xc8});
299
    emulate();
300
 
301
    ASSERT_EQ(0x8000, read_reg(AX));
302
}
303
 
304
TEST_F(EmulateFixture, MovMemSR)
305
{
306
    // mov [bx], cs
307
    write_reg(BX, 0x0100);
308
    write_reg(CS, 0x8000);
309
    set_instruction({0x8c, 0x0f});
310
    emulate();
311
 
312
    ASSERT_EQ(0x8000, read_mem16(0x0100));
313
}
314
 
315
class MovRegSRFixture
316
    : public EmulateFixture,
317
      public ::testing::WithParamInterface<std::pair<uint8_t, GPR>>
318
{
319
};
320
TEST_P(MovRegSRFixture, MovSRReg)
321
{
322
    // mov ax, ?s
323
    write_reg(GetParam().second, 0x8000);
324
    set_instruction({0x8c, GetParam().first});
325
    emulate();
326
 
327
    ASSERT_EQ(0x8000, read_reg(AX));
328
}
329
INSTANTIATE_TEST_CASE_P(
330
    MovRegSR,
331
    MovRegSRFixture,
332
    ::testing::Values(std::make_pair<uint8_t, GPR>(0xc0 | (0 << 3), ES),
333
                      std::make_pair<uint8_t, GPR>(0xc0 | (1 << 3), CS),
334
                      std::make_pair<uint8_t, GPR>(0xc0 | (2 << 3), SS),
335
                      std::make_pair<uint8_t, GPR>(0xc0 | (3 << 3), DS),
336
                      std::make_pair<uint8_t, GPR>(0xc0 | (4 << 3), ES),
337
                      std::make_pair<uint8_t, GPR>(0xc0 | (5 << 3), CS),
338
                      std::make_pair<uint8_t, GPR>(0xc0 | (6 << 3), SS),
339
                      std::make_pair<uint8_t, GPR>(0xc0 | (7 << 3), DS)));

powered by: WebSVN 2.1.0

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