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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestMisc.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
#include "config.h"
23
 
24
TEST_F(EmulateFixture, Wait)
25
{
26
    // wait
27
    set_instruction({0x9b});
28
 
29
    emulate();
30
}
31
 
32
TEST_F(EmulateFixture, EscReg)
33
{
34
    // esc
35
    for (uint8_t v = 0xd8; v <= 0xdf; ++v) {
36
        reset();
37
 
38
        write_mem16(VEC_ESCAPE + 2, 0x8000, CS); // CS
39
        write_mem16(VEC_ESCAPE + 0, 0x0100, CS); // IP
40
 
41
        write_reg(SP, 0x100);
42
        write_reg(CS, 0x7c00);
43
        write_reg(IP, 0x0001);
44
 
45
        set_instruction({v, 0xc0});
46
        emulate();
47
 
48
        if (S80X86_TRAP_ESCAPE) {
49
            EXPECT_EQ(read_reg(CS), 0x8000);
50
            EXPECT_EQ(read_reg(IP), 0x0100);
51
            EXPECT_EQ(read_reg(SP), 0x0100 - 6);
52
 
53
            EXPECT_EQ(read_mem16(0x100 - 2, SS), FLAGS_STUCK_BITS);
54
            EXPECT_EQ(read_mem16(0x100 - 4, SS), 0x7c00);
55
            // Return to the same instruction
56
            EXPECT_EQ(read_mem16(0x100 - 6, SS), 0x0001);
57
        } else {
58
            EXPECT_EQ(read_reg(CS), 0x7c00);
59
            EXPECT_EQ(read_reg(IP), 0x0001 + 2);
60
        }
61
    }
62
}
63
 
64
TEST_F(EmulateFixture, EscMem)
65
{
66
    // esc
67
    for (uint8_t v = 0xd8; v <= 0xdf; ++v) {
68
        reset();
69
 
70
        write_mem16(VEC_ESCAPE + 2, 0x8000, CS); // CS
71
        write_mem16(VEC_ESCAPE + 0, 0x0100, CS); // IP
72
 
73
        write_reg(SP, 0x100);
74
        write_reg(CS, 0x7c00);
75
        write_reg(IP, 0x0001);
76
 
77
        set_instruction({v, 0x87, 0x34, 0x12});
78
        emulate();
79
 
80
        if (S80X86_TRAP_ESCAPE) {
81
            EXPECT_EQ(read_reg(CS), 0x8000);
82
            EXPECT_EQ(read_reg(IP), 0x0100);
83
            EXPECT_EQ(read_reg(SP), 0x0100 - 6);
84
 
85
            EXPECT_EQ(read_mem16(0x100 - 2, SS), FLAGS_STUCK_BITS);
86
            EXPECT_EQ(read_mem16(0x100 - 4, SS), 0x7c00);
87
            // Return to the same instruction
88
            EXPECT_EQ(read_mem16(0x100 - 6, SS), 0x0001);
89
        } else {
90
            EXPECT_EQ(read_reg(CS), 0x7c00);
91
            EXPECT_EQ(read_reg(IP), 0x0001 + 4);
92
        }
93
    }
94
}
95
 
96
TEST_F(EmulateFixture, EscMemSegmentOverride)
97
{
98
    write_mem16(VEC_ESCAPE + 2, 0x8000, CS); // CS
99
    write_mem16(VEC_ESCAPE + 0, 0x0100, CS); // IP
100
 
101
    write_reg(SP, 0x100);
102
    write_reg(CS, 0x7c00);
103
    write_reg(IP, 0x0001);
104
 
105
    // es: esc
106
    set_instruction({0x26, 0xd8, 0x87, 0x34, 0x12});
107
    emulate();
108
 
109
    if (S80X86_TRAP_ESCAPE) {
110
        EXPECT_EQ(read_reg(CS), 0x8000);
111
        EXPECT_EQ(read_reg(IP), 0x0100);
112
        EXPECT_EQ(read_reg(SP), 0x0100 - 6);
113
 
114
        EXPECT_EQ(read_mem16(0x100 - 2, SS), FLAGS_STUCK_BITS);
115
        EXPECT_EQ(read_mem16(0x100 - 4, SS), 0x7c00);
116
        // Return to the same instruction
117
        EXPECT_EQ(read_mem16(0x100 - 6, SS), 0x0001);
118
    } else {
119
        EXPECT_EQ(read_reg(CS), 0x7c00);
120
        EXPECT_EQ(read_reg(IP), 0x0001 + 5);
121
    }
122
}

powered by: WebSVN 2.1.0

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