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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [sim/] [common/] [RegisterFile.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 "RegisterFile.h"
19
 
20
#include <cstdlib>
21
#include <cassert>
22
 
23
RegisterFile::RegisterFile()
24
{
25
    reset();
26
}
27
 
28
void RegisterFile::reset()
29
{
30
    for (int i = 0; i < NUM_16BIT_REGS; ++i)
31
        registers[i] = 0;
32
 
33
    flags = FLAGS_STUCK_BITS;
34
    written = false;
35
}
36
 
37
void RegisterFile::set(GPR regnum, uint16_t value)
38
{
39
    assert(regnum < NUM_REGS);
40
 
41
    if (regnum != IP)
42
        written = false;
43
 
44
    switch (regnum) {
45
    case AL:
46
        registers[AX] &= 0xff00;
47
        registers[AX] |= value & 0x00ff;
48
        break;
49
    case CL:
50
        registers[CX] &= 0xff00;
51
        registers[CX] |= value & 0x00ff;
52
        break;
53
    case DL:
54
        registers[DX] &= 0xff00;
55
        registers[DX] |= value & 0x00ff;
56
        break;
57
    case BL:
58
        registers[BX] &= 0xff00;
59
        registers[BX] |= value & 0x00ff;
60
        break;
61
    case AH:
62
        registers[AX] &= 0x00ff;
63
        registers[AX] |= value << 8;
64
        break;
65
    case CH:
66
        registers[CX] &= 0x00ff;
67
        registers[CX] |= value << 8;
68
        break;
69
    case DH:
70
        registers[DX] &= 0x00ff;
71
        registers[DX] |= value << 8;
72
        break;
73
    case BH:
74
        registers[BX] &= 0x00ff;
75
        registers[BX] |= value << 8;
76
        break;
77
    case 0 ... NUM_16BIT_REGS - 1: registers[regnum] = value; break;
78
    default: __builtin_unreachable();
79
    }
80
}
81
 
82
uint16_t RegisterFile::get(GPR regnum) const
83
{
84
    assert(regnum < NUM_REGS);
85
 
86
    switch (regnum) {
87
    case AL: return registers[AX] & 0x00ff;
88
    case CL: return registers[CX] & 0x00ff;
89
    case DL: return registers[DX] & 0x00ff;
90
    case BL: return registers[BX] & 0x00ff;
91
    case AH: return registers[AX] >> 8;
92
    case CH: return registers[CX] >> 8;
93
    case DH: return registers[DX] >> 8;
94
    case BH: return registers[BX] >> 8;
95
    case 0 ... NUM_16BIT_REGS - 1: return registers[regnum];
96
    default: __builtin_unreachable();
97
    }
98
}
99
 
100
uint16_t RegisterFile::get_flags() const
101
{
102
    return flags | FLAGS_STUCK_BITS;
103
}
104
 
105
bool RegisterFile::get_flag(enum Flag f) const
106
{
107
    return !!(flags & f);
108
}
109
 
110
void RegisterFile::set_flags(uint16_t val, uint16_t mask)
111
{
112
    const uint16_t reserved_mask = (1 << 1) | (1 << 3) | (1 << 5);
113
    const uint16_t valid_mask = (CF | PF | AF | ZF | SF | TF | IF | DF | OF);
114
    mask &= ~reserved_mask;
115
    mask &= valid_mask;
116
    flags &= ~mask;
117
    flags |= (val & mask) | FLAGS_STUCK_BITS;
118
 
119
    written = true;
120
}
121
 
122
bool RegisterFile::has_written() const
123
{
124
    return written;
125
}
126
 
127
void RegisterFile::clear_has_written()
128
{
129
    written = false;
130
}

powered by: WebSVN 2.1.0

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