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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestBound.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, BoundInvalidOperand)
24
{
25
    write_mem16(VEC_INVALID_OPCODE + 2, 0x8000, CS); // CS
26
    write_mem16(VEC_INVALID_OPCODE + 0, 0x0100, CS); // IP
27
 
28
    write_reg(SP, 0x100);
29
    write_reg(CS, 0x7c00);
30
    write_reg(IP, 0x0001);
31
 
32
    set_instruction({0x62, 0xd8});
33
    emulate();
34
 
35
    EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(), FLAGS_STUCK_BITS);
36
    EXPECT_EQ(read_reg(CS), 0x8000);
37
    EXPECT_EQ(read_reg(IP), 0x0100);
38
    EXPECT_EQ(read_reg(SP), 0x0100 - 6);
39
 
40
    EXPECT_EQ(read_mem16(0x100 - 2, SS), FLAGS_STUCK_BITS);
41
    EXPECT_EQ(read_mem16(0x100 - 4, SS), 0x7c00);
42
    // Return to the following instruction
43
    EXPECT_EQ(read_mem16(0x100 - 6, SS), 0x0003);
44
}
45
 
46
struct BoundParams {
47
    int16_t lower;
48
    int16_t upper;
49
    int16_t v;
50
    bool trap_expected;
51
};
52
 
53
class BoundFixture : public EmulateFixture,
54
                     public ::testing::WithParamInterface<BoundParams>
55
{
56
};
57
TEST_P(BoundFixture, Bound)
58
{
59
    auto p = GetParam();
60
 
61
    write_mem16(VEC_BOUND + 2, 0x8000, CS); // CS
62
    write_mem16(VEC_BOUND + 0, 0x0100, CS); // IP
63
 
64
    write_reg(SP, 0x100);
65
    write_reg(CS, 0x7c00);
66
    write_reg(IP, 0x0001);
67
 
68
    // bound ax, [bx]
69
    set_instruction({0x62, 0x07});
70
    write_mem16(0x1000, p.lower);
71
    write_mem16(0x1002, p.upper);
72
    write_reg(BX, 0x1000);
73
    write_reg(AX, p.v);
74
 
75
    emulate();
76
 
77
    if (p.trap_expected) {
78
        EXPECT_EQ(read_reg(CS), 0x8000);
79
        EXPECT_EQ(read_reg(IP), 0x0100);
80
        EXPECT_EQ(read_reg(SP), 0x0100 - 6);
81
 
82
        EXPECT_EQ(read_mem16(0x100 - 2, SS), FLAGS_STUCK_BITS);
83
        EXPECT_EQ(read_mem16(0x100 - 4, SS), 0x7c00);
84
        // Return to the following instruction
85
        EXPECT_EQ(read_mem16(0x100 - 6, SS), 0x0003);
86
        EXPECT_EQ(read_flags(), FLAGS_STUCK_BITS);
87
    } else {
88
        EXPECT_EQ(read_reg(CS), 0x7c00);
89
        EXPECT_EQ(read_reg(IP), 0x0003);
90
        EXPECT_EQ(read_flags(), FLAGS_STUCK_BITS);
91
    }
92
}
93
INSTANTIATE_TEST_CASE_P(Bound,
94
                        BoundFixture,
95
                        ::testing::Values(BoundParams{100, 200, 150, false},
96
                                          BoundParams{100, 200, 100, false},
97
                                          BoundParams{100, 200, 200, false},
98
                                          BoundParams{100, 200, 99, true},
99
                                          BoundParams{100, 200, 201, true},
100
                                          BoundParams{-8, -4, -10, true},
101
                                          BoundParams{-8, -4, -2, true},
102
                                          BoundParams{-8, -4, -6, false},
103
                                          BoundParams{-8, -4, -6, false}));

powered by: WebSVN 2.1.0

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