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 <vector>
|
19 |
|
|
#include <gtest/gtest.h>
|
20 |
|
|
|
21 |
|
|
#include "EmulateFixture.h"
|
22 |
|
|
#include "Flags.h"
|
23 |
|
|
|
24 |
|
|
class InvalidOpcodeFixture
|
25 |
|
|
: public EmulateFixture,
|
26 |
|
|
public ::testing::WithParamInterface<std::vector<uint8_t>>
|
27 |
|
|
{
|
28 |
|
|
};
|
29 |
|
|
TEST_P(InvalidOpcodeFixture, InvalidOpcode)
|
30 |
|
|
{
|
31 |
|
|
write_mem16(VEC_INVALID_OPCODE + 2, 0x8000, CS); // CS
|
32 |
|
|
write_mem16(VEC_INVALID_OPCODE + 0, 0x0100, CS); // IP
|
33 |
|
|
|
34 |
|
|
write_reg(SP, 0x100);
|
35 |
|
|
write_reg(CS, 0x7c00);
|
36 |
|
|
write_reg(IP, 0x0001);
|
37 |
|
|
write_flags(IF);
|
38 |
|
|
|
39 |
|
|
set_instruction(GetParam());
|
40 |
|
|
|
41 |
|
|
emulate();
|
42 |
|
|
|
43 |
|
|
EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(), FLAGS_STUCK_BITS);
|
44 |
|
|
EXPECT_EQ(read_reg(CS), 0x8000);
|
45 |
|
|
EXPECT_EQ(read_reg(IP), 0x0100);
|
46 |
|
|
EXPECT_EQ(read_reg(SP), 0x0100 - 6);
|
47 |
|
|
|
48 |
|
|
EXPECT_EQ(read_mem16(0x100 - 2, SS), FLAGS_STUCK_BITS | IF);
|
49 |
|
|
EXPECT_EQ(read_mem16(0x100 - 4, SS), 0x7c00);
|
50 |
|
|
// Return to the following instruction
|
51 |
|
|
EXPECT_EQ(read_mem16(0x100 - 6, SS), 0x0001 + GetParam().size());
|
52 |
|
|
}
|
53 |
|
|
INSTANTIATE_TEST_CASE_P(InvalidOpcode,
|
54 |
|
|
InvalidOpcodeFixture,
|
55 |
|
|
::testing::Values(std::vector<uint8_t>{0x0f},
|
56 |
|
|
std::vector<uint8_t>{0x63},
|
57 |
|
|
std::vector<uint8_t>{0x64},
|
58 |
|
|
std::vector<uint8_t>{0x65},
|
59 |
|
|
std::vector<uint8_t>{0x66},
|
60 |
|
|
std::vector<uint8_t>{0x67},
|
61 |
|
|
std::vector<uint8_t>{0xf1},
|
62 |
|
|
std::vector<uint8_t>{0xfe, 0xff},
|
63 |
|
|
std::vector<uint8_t>{0xff, 0xff}));
|
64 |
|
|
|
65 |
|
|
class UnimplementedOpcodeFixture
|
66 |
|
|
: public EmulateFixture,
|
67 |
|
|
public ::testing::WithParamInterface<std::vector<uint8_t>>
|
68 |
|
|
{
|
69 |
|
|
};
|
70 |
|
|
TEST_P(UnimplementedOpcodeFixture, UnimplementedOpcode)
|
71 |
|
|
{
|
72 |
|
|
set_instruction(GetParam());
|
73 |
|
|
|
74 |
|
|
emulate();
|
75 |
|
|
|
76 |
|
|
ASSERT_FALSE(instruction_had_side_effects());
|
77 |
|
|
}
|
78 |
|
|
INSTANTIATE_TEST_CASE_P(UnimplementedOpcode,
|
79 |
|
|
UnimplementedOpcodeFixture,
|
80 |
|
|
::testing::Values(
|
81 |
|
|
// inc
|
82 |
|
|
std::vector<uint8_t>{0xfe, 2 << 3},
|
83 |
|
|
std::vector<uint8_t>{0xfe, 3 << 3},
|
84 |
|
|
std::vector<uint8_t>{0xfe, 4 << 3},
|
85 |
|
|
std::vector<uint8_t>{0xfe, 5 << 3},
|
86 |
|
|
std::vector<uint8_t>{0xfe, 6 << 3},
|
87 |
|
|
// pop
|
88 |
|
|
std::vector<uint8_t>{0x8f, 1 << 3},
|
89 |
|
|
std::vector<uint8_t>{0x8f, 2 << 3},
|
90 |
|
|
std::vector<uint8_t>{0x8f, 3 << 3},
|
91 |
|
|
std::vector<uint8_t>{0x8f, 4 << 3},
|
92 |
|
|
std::vector<uint8_t>{0x8f, 5 << 3},
|
93 |
|
|
std::vector<uint8_t>{0x8f, 6 << 3},
|
94 |
|
|
std::vector<uint8_t>{0x8f, 7 << 3},
|
95 |
|
|
// mov
|
96 |
|
|
std::vector<uint8_t>{0xc6, 1 << 3},
|
97 |
|
|
std::vector<uint8_t>{0xc6, 2 << 3},
|
98 |
|
|
std::vector<uint8_t>{0xc6, 3 << 3},
|
99 |
|
|
std::vector<uint8_t>{0xc6, 4 << 3},
|
100 |
|
|
std::vector<uint8_t>{0xc6, 5 << 3},
|
101 |
|
|
std::vector<uint8_t>{0xc6, 6 << 3},
|
102 |
|
|
std::vector<uint8_t>{0xc6, 7 << 3},
|
103 |
|
|
std::vector<uint8_t>{0xc7, 1 << 3},
|
104 |
|
|
std::vector<uint8_t>{0xc7, 2 << 3},
|
105 |
|
|
std::vector<uint8_t>{0xc7, 3 << 3},
|
106 |
|
|
std::vector<uint8_t>{0xc7, 4 << 3},
|
107 |
|
|
std::vector<uint8_t>{0xc7, 5 << 3},
|
108 |
|
|
std::vector<uint8_t>{0xc7, 6 << 3},
|
109 |
|
|
std::vector<uint8_t>{0xc7, 7 << 3},
|
110 |
|
|
// lds
|
111 |
|
|
std::vector<uint8_t>{0xc5, 0xc0},
|
112 |
|
|
// les
|
113 |
|
|
std::vector<uint8_t>{0xc4, 0xc0},
|
114 |
|
|
// lea
|
115 |
|
|
std::vector<uint8_t>{0x8d, 0xc0},
|
116 |
|
|
// call indirect inter reg
|
117 |
|
|
std::vector<uint8_t>{0xff, 3 << 6 | 3 << 3}));
|