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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [common/] [TestModRM.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
#include <gmock/gmock.h>
20
 
21
#include "TestModRM.h"
22
 
23
using ::testing::Return;
24
 
25
enum Reg {
26
    MODRM_REG_AL = 0,
27
    MODRM_REG_AX = 0,
28
    MODRM_REG_CL = 1,
29
    MODRM_REG_CX = 1,
30
    MODRM_REG_DL = 2,
31
    MODRM_REG_DX = 2,
32
    MODRM_REG_BL = 3,
33
    MODRM_REG_BX = 3,
34
    MODRM_REG_AH = 4,
35
    MODRM_REG_SP = 4,
36
    MODRM_REG_CH = 5,
37
    MODRM_REG_BP = 5,
38
    MODRM_REG_DH = 6,
39
    MODRM_REG_SI = 6,
40
    MODRM_REG_BH = 7,
41
    MODRM_REG_DI = 7
42
};
43
 
44
template <typename T>
45
class ModRMTestFixture : public ::testing::Test
46
{
47
public:
48
    void validate_effective_address(const T &decoder, uint16_t expected)
49
    {
50
        ASSERT_EQ(OP_MEM, decoder.get_rm_type());
51
        ASSERT_EQ(expected, decoder.get_effective_address());
52
        ASSERT_EQ(AX, decoder.get_register());
53
    }
54
};
55
TYPED_TEST_CASE_P(ModRMTestFixture);
56
 
57
TYPED_TEST_P(ModRMTestFixture, Regreg16)
58
{
59
    TypeParam decoder;
60
 
61
    uint8_t modrm = (0x3 << 6) | (MODRM_REG_AX << 3) | (MODRM_REG_CX << 0);
62
    decoder.set_instruction({modrm});
63
 
64
    decoder.decode();
65
    ASSERT_EQ(OP_REG, decoder.get_rm_type());
66
    ASSERT_EQ(AX, decoder.get_register());
67
    ASSERT_EQ(CX, decoder.get_rm_register());
68
}
69
 
70
TYPED_TEST_P(ModRMTestFixture, RegReg8)
71
{
72
    TypeParam decoder;
73
 
74
    uint8_t modrm = (0x3 << 6) | (MODRM_REG_AL << 3) | (MODRM_REG_CH << 0);
75
    decoder.set_instruction({modrm});
76
 
77
    decoder.set_width(OP_WIDTH_8);
78
    decoder.decode();
79
    ASSERT_EQ(OP_REG, decoder.get_rm_type());
80
    ASSERT_EQ(AL, decoder.get_register());
81
    ASSERT_EQ(CH, decoder.get_rm_register());
82
}
83
 
84
////////////////////////////////////////////////////////////////////////////////
85
// mod=00
86
////////////////////////////////////////////////////////////////////////////////
87
 
88
TYPED_TEST_P(ModRMTestFixture, Mod00RM000)
89
{
90
    TypeParam decoder;
91
 
92
    decoder.get_registers()->set(BX, 0x100);
93
    decoder.get_registers()->set(SI, 0x4);
94
 
95
    decoder.set_instruction({0});
96
    decoder.decode();
97
 
98
    TestFixture::validate_effective_address(decoder, 0x104);
99
}
100
 
101
TYPED_TEST_P(ModRMTestFixture, Mod00RM001)
102
{
103
    TypeParam decoder;
104
 
105
    decoder.get_registers()->set(BX, 0x100);
106
    decoder.get_registers()->set(DI, 0x4);
107
 
108
    decoder.set_instruction({0x01});
109
    decoder.decode();
110
 
111
    TestFixture::validate_effective_address(decoder, 0x104);
112
}
113
 
114
TYPED_TEST_P(ModRMTestFixture, Mod00RM010)
115
{
116
    TypeParam decoder;
117
 
118
    decoder.get_registers()->set(BP, 0x100);
119
    decoder.get_registers()->set(SI, 0x004);
120
 
121
    decoder.set_instruction({0x02});
122
    decoder.decode();
123
 
124
    TestFixture::validate_effective_address(decoder, 0x104);
125
}
126
 
127
TYPED_TEST_P(ModRMTestFixture, Mod00RM011)
128
{
129
    TypeParam decoder;
130
 
131
    decoder.get_registers()->set(BP, 0x100);
132
    decoder.get_registers()->set(DI, 0x4);
133
 
134
    decoder.set_instruction({0x03});
135
    decoder.decode();
136
 
137
    TestFixture::validate_effective_address(decoder, 0x104);
138
}
139
 
140
TYPED_TEST_P(ModRMTestFixture, Mod00RM100)
141
{
142
    TypeParam decoder;
143
 
144
    decoder.get_registers()->set(SI, 0x100);
145
 
146
    decoder.set_instruction({0x04});
147
    decoder.decode();
148
 
149
    TestFixture::validate_effective_address(decoder, 0x100);
150
}
151
 
152
TYPED_TEST_P(ModRMTestFixture, Mod00RM101)
153
{
154
    TypeParam decoder;
155
 
156
    decoder.get_registers()->set(DI, 0x100);
157
 
158
    decoder.set_instruction({0x05});
159
    decoder.decode();
160
 
161
    TestFixture::validate_effective_address(decoder, 0x100);
162
}
163
 
164
TYPED_TEST_P(ModRMTestFixture, Mod00RM110)
165
{
166
    TypeParam decoder;
167
 
168
    decoder.set_instruction({0x06, 0x34, 0x12});
169
 
170
    decoder.decode();
171
 
172
    TestFixture::validate_effective_address(decoder, 0x1234);
173
}
174
 
175
TYPED_TEST_P(ModRMTestFixture, Mod00RM111)
176
{
177
    TypeParam decoder;
178
 
179
    decoder.get_registers()->set(BX, 0x100);
180
 
181
    decoder.set_instruction({0x07});
182
    decoder.decode();
183
 
184
    TestFixture::validate_effective_address(decoder, 0x100);
185
}
186
 
187
////////////////////////////////////////////////////////////////////////////////
188
// mod=01
189
////////////////////////////////////////////////////////////////////////////////
190
 
191
TYPED_TEST_P(ModRMTestFixture, Mod01RM000)
192
{
193
    TypeParam decoder;
194
 
195
    decoder.get_registers()->set(BX, 0x100);
196
    decoder.get_registers()->set(SI, 0x4);
197
 
198
    decoder.set_instruction({0x40, 0xff});
199
    decoder.decode();
200
 
201
    TestFixture::validate_effective_address(decoder, 0x103);
202
}
203
 
204
TYPED_TEST_P(ModRMTestFixture, Mod01RM001)
205
{
206
    TypeParam decoder;
207
 
208
    decoder.get_registers()->set(BX, 0x100);
209
    decoder.get_registers()->set(DI, 0x4);
210
 
211
    decoder.set_instruction({0x41, 0xff});
212
    decoder.decode();
213
 
214
    TestFixture::validate_effective_address(decoder, 0x103);
215
}
216
 
217
TYPED_TEST_P(ModRMTestFixture, Mod01RM010)
218
{
219
    TypeParam decoder;
220
 
221
    decoder.get_registers()->set(BP, 0x100);
222
    decoder.get_registers()->set(SI, 0x4);
223
 
224
    decoder.set_instruction({0x42, 0xff});
225
    decoder.decode();
226
 
227
    TestFixture::validate_effective_address(decoder, 0x103);
228
}
229
 
230
TYPED_TEST_P(ModRMTestFixture, Mod01RM011)
231
{
232
    TypeParam decoder;
233
 
234
    decoder.get_registers()->set(BP, 0x100);
235
    decoder.get_registers()->set(DI, 0x4);
236
 
237
    decoder.set_instruction({0x43, 0xff});
238
    decoder.decode();
239
 
240
    TestFixture::validate_effective_address(decoder, 0x103);
241
}
242
 
243
TYPED_TEST_P(ModRMTestFixture, Mod01RM100)
244
{
245
    TypeParam decoder;
246
 
247
    decoder.get_registers()->set(SI, 0x100);
248
 
249
    decoder.set_instruction({0x44, 0xff});
250
    decoder.decode();
251
 
252
    TestFixture::validate_effective_address(decoder, 0xff);
253
}
254
 
255
TYPED_TEST_P(ModRMTestFixture, Mod01RM101)
256
{
257
    TypeParam decoder;
258
 
259
    decoder.get_registers()->set(DI, 0x100);
260
 
261
    decoder.set_instruction({0x45, 0xff});
262
    decoder.decode();
263
 
264
    TestFixture::validate_effective_address(decoder, 0xff);
265
}
266
 
267
TYPED_TEST_P(ModRMTestFixture, Mod01RM110)
268
{
269
    TypeParam decoder;
270
 
271
    decoder.get_registers()->set(BP, 0x100);
272
 
273
    decoder.set_instruction({0x46, 0xff});
274
 
275
    decoder.decode();
276
 
277
    TestFixture::validate_effective_address(decoder, 0xff);
278
}
279
 
280
TYPED_TEST_P(ModRMTestFixture, Mod01RM111)
281
{
282
    TypeParam decoder;
283
 
284
    decoder.get_registers()->set(BX, 0x100);
285
 
286
    decoder.set_instruction({0x47, 0xff});
287
    decoder.decode();
288
 
289
    TestFixture::validate_effective_address(decoder, 0xff);
290
}
291
 
292
////////////////////////////////////////////////////////////////////////////////
293
// mod=10
294
////////////////////////////////////////////////////////////////////////////////
295
 
296
TYPED_TEST_P(ModRMTestFixture, Mod10RM000)
297
{
298
    TypeParam decoder;
299
 
300
    decoder.get_registers()->set(BX, 0x100);
301
    decoder.get_registers()->set(SI, 0x4);
302
 
303
    decoder.set_instruction({0x80, 0xff, 0xff});
304
    decoder.decode();
305
 
306
    TestFixture::validate_effective_address(decoder, 0x103);
307
}
308
 
309
TYPED_TEST_P(ModRMTestFixture, Mod10RM001)
310
{
311
    TypeParam decoder;
312
 
313
    decoder.get_registers()->set(BX, 0x100);
314
    decoder.get_registers()->set(DI, 0x4);
315
 
316
    decoder.set_instruction({0x81, 0xff, 0xff});
317
    decoder.decode();
318
 
319
    TestFixture::validate_effective_address(decoder, 0x103);
320
}
321
 
322
TYPED_TEST_P(ModRMTestFixture, Mod10RM010)
323
{
324
    TypeParam decoder;
325
 
326
    decoder.get_registers()->set(BP, 0x100);
327
    decoder.get_registers()->set(SI, 0x4);
328
 
329
    decoder.set_instruction({0x82, 0xff, 0xff});
330
    decoder.decode();
331
 
332
    TestFixture::validate_effective_address(decoder, 0x103);
333
}
334
 
335
TYPED_TEST_P(ModRMTestFixture, Mod10RM011)
336
{
337
    TypeParam decoder;
338
 
339
    decoder.get_registers()->set(BP, 0x100);
340
    decoder.get_registers()->set(DI, 0x4);
341
 
342
    decoder.set_instruction({0x83, 0xff, 0xff});
343
    decoder.decode();
344
 
345
    TestFixture::validate_effective_address(decoder, 0x103);
346
}
347
 
348
TYPED_TEST_P(ModRMTestFixture, Mod10RM100)
349
{
350
    TypeParam decoder;
351
 
352
    decoder.get_registers()->set(SI, 0x100);
353
 
354
    decoder.set_instruction({0x84, 0xff, 0xff});
355
    decoder.decode();
356
 
357
    TestFixture::validate_effective_address(decoder, 0xff);
358
}
359
 
360
TYPED_TEST_P(ModRMTestFixture, Mod10RM101)
361
{
362
    TypeParam decoder;
363
 
364
    decoder.get_registers()->set(DI, 0x100);
365
 
366
    decoder.set_instruction({0x85, 0xff, 0xff});
367
    decoder.decode();
368
 
369
    TestFixture::validate_effective_address(decoder, 0xff);
370
}
371
 
372
TYPED_TEST_P(ModRMTestFixture, Mod10RM110)
373
{
374
    TypeParam decoder;
375
 
376
    decoder.get_registers()->set(BP, 0x100);
377
 
378
    decoder.set_instruction({0x86, 0xff, 0xff});
379
 
380
    decoder.decode();
381
 
382
    TestFixture::validate_effective_address(decoder, 0xff);
383
}
384
 
385
TYPED_TEST_P(ModRMTestFixture, Mod10RM111)
386
{
387
    TypeParam decoder;
388
 
389
    decoder.get_registers()->set(BX, 0x100);
390
 
391
    decoder.set_instruction({0x87, 0x78, 0x20});
392
    decoder.decode();
393
 
394
    TestFixture::validate_effective_address(decoder, 0x2178);
395
}
396
 
397
REGISTER_TYPED_TEST_CASE_P(ModRMTestFixture,
398
                           Regreg16,
399
                           RegReg8,
400
                           Mod00RM000,
401
                           Mod00RM001,
402
                           Mod00RM010,
403
                           Mod00RM011,
404
                           Mod00RM100,
405
                           Mod00RM101,
406
                           Mod00RM110,
407
                           Mod00RM111,
408
                           Mod01RM000,
409
                           Mod01RM001,
410
                           Mod01RM010,
411
                           Mod01RM011,
412
                           Mod01RM100,
413
                           Mod01RM101,
414
                           Mod01RM110,
415
                           Mod01RM111,
416
                           Mod10RM000,
417
                           Mod10RM001,
418
                           Mod10RM010,
419
                           Mod10RM011,
420
                           Mod10RM100,
421
                           Mod10RM101,
422
                           Mod10RM110,
423
                           Mod10RM111);

powered by: WebSVN 2.1.0

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