MMU.java

1
// Copyright © 2004-2006 University of Helsinki, Department of Computer Science
2
// Copyright © 2012 various contributors
3
// This software is released under GNU Lesser General Public License 2.1.
4
// The license text is at http://www.gnu.org/licenses/lgpl-2.1.html
5
6
package fi.helsinki.cs.titokone.devices;
7
8
import fi.helsinki.cs.titokone.*;
9
import fi.helsinki.cs.ttk91.TTK91AddressOutOfBounds;
10
11
import java.util.HashMap;
12
13
/**
14
 * a nice nastiness of a device which registers itself as an io device
15
 * and takes over memory management.
16
 * <p/>
17
 * write to port 0 to map memory
18
 * 0xFFFFFFFF will reset MMU
19
 * to map memory write 3 values "from" "to" and "length"
20
 * currently only 1 mapping can be active at one time.
21
 * new mapping will overwrite the old one
22
 * <p/>
23
 * reading port 0 will tell you the state of mapping command
24
 * 0=from,1=to,2=length
25
 * NOTE: currently virtual memory size is fixed to the "physical memory"
26
 * size together with MMAPped devices. MMU can only be used
27
 * to move memory to a more convenient place
28
 */
29
public abstract class MMU
30
        implements IODevice,
31
        RandomAccessMemory,
32
        InterruptGenerator {
33 9
    int from = 0, to = 0, length = 0;
34 3
    int count = 0;
35
36
    public MMU() {
37
    }
38
39
    public void link(Interruptable il) {
40
        //just a reservation
41
    }
42
43
    public void reset() {
44 3
        from = 0;
45 3
        to = 0;
46 3
        length = 0;
47 3
        count = 0;
48
    }
49
50
    public int getPortCount() {
51 3
        return 5; //reserve a couple ports
52
    }
53
54
    public int getPort(int i) {
55 5
        if (i < 0 || i >= getPortCount()) {
56 1
            throw new RuntimeException("shouldnt happen");
57
        }
58 1
        return count;
59
    }
60
61
    public void setPort(int i, int value) {
62 5
        if (i < 0 || i >= getPortCount()) {
63 1
            throw new RuntimeException("shouldnt happen");
64
        }
65
        switch (count) {
66
            case 0:
67 3
                if (value == 0xffffffff) {
68 3
                    count = 0;
69 3
                    from = 0;
70 3
                    to = 0;
71
                } else {
72 1
                    from = value;
73 4
                    count++;
74
                }
75
                break;
76
            case 1:
77 1
                to = value;
78 4
                count++;
79
                break;
80
            case 2:
81 1
                length = value;
82 3
                count = 0;
83
                break;
84
        }
85
    }
86
87
    public void update() {
88
    }
89
90
    public int getSize() {
91 3
        return getMem().getSize();
92
    }
93
94
    public int getCodeAreaSize() {
95 3
        return getMem().getCodeAreaSize();
96
    }
97
98
    public int getDataAreaSize() {
99 3
        return getMem().getDataAreaSize();
100
    }
101
102
    public MemoryLine getMemoryLine(int index) {
103 4
        return getMem().getMemoryLine(mapslot(index));
104
    }
105
106
    public MemoryLine[] getMemoryLines() {
107 2
        MemoryLine[] ret = getMem().getMemoryLines();
108 3
        if (from != 0 || to != 0 || length != 0) {
109 5
            for (int i = 0; i < length; i++) {
110 4
                ret[to + i] = getMem().getMemoryLine(from + i);
111
            }
112
        }
113 1
        return ret;
114
    }
115
116
    public void setSymbolTable(SymbolTable symbols) {
117 2
        getMem().setSymbolTable(symbols);
118
    }
119
120
    public void setMemoryLine(int index, MemoryLine memoryLine)
121
            throws TTK91AddressOutOfBounds {
122 3
        getMem().setMemoryLine(mapslot(index), memoryLine);
123
    }
124
125
    public void setCodeAreaLength(int size) {
126 2
        getMem().setCodeAreaLength(size);
127
    }
128
129
    public void setDataAreaLength(int size) {
130 2
        getMem().setDataAreaLength(size);
131
    }
132
133
    public int getMemoryReferences() {
134 3
        return getMem().getMemoryReferences();
135
    }
136
137
    public int getValue(int memoryslot) {
138 3
        return getMemoryLine(memoryslot).getBinary();
139
    }
140
141
    protected int mapslot(int slot) {
142 3
        if (from != 0 || to != 0 || length != 0) {
143 3
            return slot - to + from;
144
        }
145
146 1
        return slot;
147
    }
148
149
    public HashMap<String, Integer> getSymbolTable() {
150 3
        return getMem().getSymbolTable();
151
    }
152
153
    public int[] getMemory() {
154 1
        MemoryLine[] temp = getMemoryLines();
155
        int[] ret = new int[temp.length];
156 5
        for (int i = 0; i < temp.length; i++) {
157 1
            ret[i] = temp[i].getBinary();
158
        }
159 1
        return ret;
160
    }
161
162
    public int[] getCodeArea() {
163 1
        int[] codeArea = new int[getCodeAreaSize()];
164 5
        for (int i = 0; i < codeArea.length; i++) {
165 2
            codeArea[i] = getMemoryLine(i).getBinary();
166
        }
167 1
        return codeArea;
168
    }
169
170
    public int[] getDataArea() {
171 1
        int cz = getCodeAreaSize();
172 1
        int[] dataArea = new int[getDataAreaSize()];
173 5
        for (int i = 0; i < dataArea.length; i++) {
174 3
            dataArea[i] = getMemoryLine(i + cz).getBinary();
175
        }
176 1
        return dataArea;
177
    }
178
179
    /**
180
     * override this to return the memory instance currently active.
181
     */
182
    protected abstract RandomAccessMemory getMem();
183
184
}

Mutations

33

Substituted 0 with 1 : SURVIVED

Removed assignment to member variable from : SURVIVED

Substituted 0 with 1 : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

Removed assignment to member variable to : SURVIVED

Substituted 0 with 1 : SURVIVED

Substituted 0 with 1 : SURVIVED

Substituted 0 with 1 : SURVIVED

Substituted 0 with 1 : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

Removed assignment to member variable length : SURVIVED

34

Removed assignment to member variable count : SURVIVED

Substituted 0 with 1 : SURVIVED

Substituted 0 with 1 : SURVIVED

44

Substituted 0 with 1 : SURVIVED

Substituted 0 with 1 : SURVIVED

Removed assignment to member variable from : SURVIVED

45

Substituted 0 with 1 : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

Substituted 0 with 1 : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

Removed assignment to member variable to : SURVIVED

46

Substituted 0 with 1 : SURVIVED

Substituted 0 with 1 : SURVIVED

Removed assignment to member variable length : SURVIVED

47

Substituted 0 with 1 : SURVIVED

Substituted 0 with 1 : SURVIVED

Removed assignment to member variable count : SURVIVED

51

Substituted 5 with 6 : SURVIVED

Substituted 5 with -1 : SURVIVED

replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED

55

negated conditional : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/devices/MMU::getPortCount : NO_COVERAGE

changed conditional boundary : NO_COVERAGE

changed conditional boundary : NO_COVERAGE

negated conditional : NO_COVERAGE

56

removed call to java/lang/RuntimeException::<init> : NO_COVERAGE

58

replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE

62

changed conditional boundary : NO_COVERAGE

negated conditional : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/devices/MMU::getPortCount : NO_COVERAGE

changed conditional boundary : NO_COVERAGE

negated conditional : NO_COVERAGE

63

removed call to java/lang/RuntimeException::<init> : NO_COVERAGE

67

Substituted -1 with 0 : NO_COVERAGE

Substituted -1 with 1 : NO_COVERAGE

negated conditional : NO_COVERAGE

68

Substituted 0 with 1 : NO_COVERAGE

Removed assignment to member variable count : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

69

Removed assignment to member variable from : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

70

Substituted 0 with 1 : NO_COVERAGE

Removed assignment to member variable to : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

72

Removed assignment to member variable from : NO_COVERAGE

73

Substituted 1 with 0 : NO_COVERAGE

Removed assignment to member variable count : NO_COVERAGE

Replaced integer addition with subtraction : NO_COVERAGE

Substituted 1 with 0 : NO_COVERAGE

77

Removed assignment to member variable to : NO_COVERAGE

78

Removed assignment to member variable count : NO_COVERAGE

Substituted 1 with 0 : NO_COVERAGE

Substituted 1 with 0 : NO_COVERAGE

Replaced integer addition with subtraction : NO_COVERAGE

81

Removed assignment to member variable length : NO_COVERAGE

82

Substituted 0 with 1 : NO_COVERAGE

Removed assignment to member variable count : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

91

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : KILLED -> fi.helsinki.cs.titokone.ControlTest.testChangeMemorySize(fi.helsinki.cs.titokone.ControlTest)

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getSize : KILLED -> fi.helsinki.cs.titokone.ControlTest.testChangeMemorySize(fi.helsinki.cs.titokone.ControlTest)

replaced return of integer sized value with (x == 0 ? 1 : 0) : KILLED -> fi.helsinki.cs.titokone.ControlTest.testChangeMemorySize(fi.helsinki.cs.titokone.ControlTest)

95

replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getCodeAreaSize : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : NO_COVERAGE

99

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getDataAreaSize : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : NO_COVERAGE

replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE

103

mutated return of Object value for fi/helsinki/cs/titokone/devices/MMU::getMemoryLine to ( if (x != null) null else throw new RuntimeException ) : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getMemoryLine : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

removed call to fi/helsinki/cs/titokone/devices/MMU::mapslot : SURVIVED

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

107

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getMemoryLines : NO_COVERAGE

108

negated conditional : NO_COVERAGE

negated conditional : NO_COVERAGE

negated conditional : NO_COVERAGE

109

Substituted 0 with 1 : NO_COVERAGE

changed conditional boundary : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

Changed increment from 1 to -1 : NO_COVERAGE

negated conditional : NO_COVERAGE

110

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : NO_COVERAGE

Replaced integer addition with subtraction : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getMemoryLine : NO_COVERAGE

Replaced integer addition with subtraction : NO_COVERAGE

113

mutated return of Object value for fi/helsinki/cs/titokone/devices/MMU::getMemoryLines to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE

117

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::setSymbolTable : NO_COVERAGE

122

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::setMemoryLine : SURVIVED

removed call to fi/helsinki/cs/titokone/devices/MMU::mapslot : SURVIVED

126

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::setCodeAreaLength : SURVIVED

130

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::setDataAreaLength : SURVIVED

134

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getMemoryReferences : NO_COVERAGE

replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE

138

removed call to fi/helsinki/cs/titokone/devices/MMU::getMemoryLine : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest)

replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED

removed call to fi/helsinki/cs/titokone/MemoryLine::getBinary : SURVIVED

142

negated conditional : SURVIVED

negated conditional : SURVIVED

negated conditional : SURVIVED

143

Replaced integer addition with subtraction : NO_COVERAGE

Replaced integer subtraction with addition : NO_COVERAGE

replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE

146

replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED

150

mutated return of Object value for fi/helsinki/cs/titokone/devices/MMU::getSymbolTable to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getSymbolTable : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/devices/MMU::getMem : NO_COVERAGE

154

removed call to fi/helsinki/cs/titokone/devices/MMU::getMemoryLines : NO_COVERAGE

156

negated conditional : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

Changed increment from 1 to -1 : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

changed conditional boundary : NO_COVERAGE

157

removed call to fi/helsinki/cs/titokone/MemoryLine::getBinary : NO_COVERAGE

159

mutated return of Object value for fi/helsinki/cs/titokone/devices/MMU::getMemory to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE

163

removed call to fi/helsinki/cs/titokone/devices/MMU::getCodeAreaSize : NO_COVERAGE

164

negated conditional : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

Changed increment from 1 to -1 : NO_COVERAGE

changed conditional boundary : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

165

removed call to fi/helsinki/cs/titokone/devices/MMU::getMemoryLine : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/MemoryLine::getBinary : NO_COVERAGE

167

mutated return of Object value for fi/helsinki/cs/titokone/devices/MMU::getCodeArea to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE

171

removed call to fi/helsinki/cs/titokone/devices/MMU::getCodeAreaSize : NO_COVERAGE

172

removed call to fi/helsinki/cs/titokone/devices/MMU::getDataAreaSize : NO_COVERAGE

173

Substituted 0 with 1 : NO_COVERAGE

Changed increment from 1 to -1 : NO_COVERAGE

changed conditional boundary : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

negated conditional : NO_COVERAGE

174

removed call to fi/helsinki/cs/titokone/MemoryLine::getBinary : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/devices/MMU::getMemoryLine : NO_COVERAGE

Replaced integer addition with subtraction : NO_COVERAGE

176

mutated return of Object value for fi/helsinki/cs/titokone/devices/MMU::getDataArea to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 0.27