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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [rtl/] [TestSegmentOverride.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 <VSegmentOverride.h>
20
 
21
#include "VerilogTestbench.h"
22
 
23
class SegmentOverrideTestFixture : public VerilogTestbench<VSegmentOverride>,
24
                                   public ::testing::Test
25
{
26
public:
27
    void add_override(uint8_t segnum)
28
    {
29
        after_n_cycles(0, [segnum, this] {
30
            this->dut.microcode_sr_rd_sel = segnum;
31
            this->dut.segment_override = 1;
32
            after_n_cycles(1, [&] { this->dut.segment_override = 0; });
33
        });
34
    }
35
 
36
    void next_instruction()
37
    {
38
        after_n_cycles(0, [&] {
39
            this->dut.next_instruction = 1;
40
            after_n_cycles(1, [&] { this->dut.next_instruction = 0; });
41
        });
42
    }
43
};
44
 
45
// How to select a segment:
46
//
47
// - If the microcode forces a segment, use it.
48
// - If not, and there is a segment override, use that.
49
// - If not forced and not overriden, then use the default that the microcode
50
// specifies, unless BP is used as a base register, in which case use SS.
51
 
52
TEST_F(SegmentOverrideTestFixture, UseSSIfBPIsBase)
53
{
54
    this->dut.bp_is_base = 1;
55
    this->dut.microcode_sr_rd_sel = 3;
56
    cycle();
57
    ASSERT_EQ(this->dut.sr_rd_sel, 2);
58
}
59
 
60
TEST_F(SegmentOverrideTestFixture, UseMicrocodeIfNotBPIsBase)
61
{
62
    this->dut.bp_is_base = 0;
63
    this->dut.microcode_sr_rd_sel = 3;
64
    cycle();
65
    ASSERT_EQ(this->dut.sr_rd_sel, 3);
66
}
67
 
68
TEST_F(SegmentOverrideTestFixture, Override)
69
{
70
    add_override(0);
71
    this->dut.bp_is_base = 0;
72
    this->dut.microcode_sr_rd_sel = 3;
73
    cycle();
74
    ASSERT_EQ(this->dut.sr_rd_sel, 0);
75
}
76
 
77
TEST_F(SegmentOverrideTestFixture, NextInstructionClearsOverride)
78
{
79
    add_override(0);
80
    this->dut.microcode_sr_rd_sel = 3;
81
    cycle();
82
 
83
    this->dut.microcode_sr_rd_sel = 2;
84
    next_instruction();
85
    cycle();
86
 
87
    ASSERT_EQ(this->dut.sr_rd_sel, 2);
88
}
89
 
90
TEST_F(SegmentOverrideTestFixture, ForceWins)
91
{
92
    add_override(0);
93
    cycle();
94
 
95
    this->dut.force_segment = 1;
96
    this->dut.bp_is_base = 1;
97
    this->dut.microcode_sr_rd_sel = 1;
98
 
99
    cycle();
100
 
101
    this->dut.microcode_sr_rd_sel = 1;
102
    this->dut.eval();
103
 
104
    ASSERT_EQ(this->dut.sr_rd_sel, 1);
105
}

powered by: WebSVN 2.1.0

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