| 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 | ||
| 10 | import java.util.ArrayList; | |
| 11 | ||
| 12 | /** | |
| 13 | * a simple programmable interrupt controller with 32 lines | |
| 14 | * ports: | |
| 15 | * 0-command port/state port | |
| 16 | * read to get the state of which interrupts are high | |
| 17 | * write to send commands | |
| 18 | * -0 -> clear all interrupts | |
| 19 | * -1 -> inhibit all interrupts | |
| 20 | * -2 -> re-enable interrupts | |
| 21 | * 1-interrupt enable port | |
| 22 | * read- to see which interrupts are enabled | |
| 23 | * write to enable/disable interrupts | |
| 24 | * to clear a specific interrupt , disable and re-enable it | |
| 25 | */ | |
| 26 | public class Pic | |
| 27 | implements IODevice, | |
| 28 | Interruptable, | |
| 29 | InterruptGenerator { | |
| 30 | protected Interruptable processor; | |
| 31 | 3 | protected int enabled = 0; |
| 32 | 3 | protected int flagged = 0; |
| 33 | 3 | protected int seen = 0; |
| 34 | 3 | protected boolean disabled = false; |
| 35 | 2 | protected ArrayList<InterruptGenerator> generators = |
| 36 | new ArrayList<InterruptGenerator>(); | |
| 37 | ||
| 38 | public int getPortCount() { | |
| 39 | 3 | return 2; |
| 40 | } | |
| 41 | ||
| 42 | @Override | |
| 43 | public int getPort(int n) { | |
| 44 | 1 | if (n == 0) { |
| 45 | 1 | return flagged; //show what interrupts are high |
| 46 | 3 | } else if (n == 1) { |
| 47 | 1 | return enabled; //show enabled interrupts |
| 48 | } | |
| 49 | 5 | throw new RuntimeException("should not be possible " + n); |
| 50 | } | |
| 51 | ||
| 52 | @Override | |
| 53 | public void setPort(int n, int value) { | |
| 54 | 1 | if (n == 0) { |
| 55 | switch (value) { | |
| 56 | case 0: | |
| 57 | 3 | flagged = 0; |
| 58 | return; //clear | |
| 59 | case 1: | |
| 60 | 3 | disabled = true; |
| 61 | return; //disable | |
| 62 | case 2: | |
| 63 | 3 | disabled = false; |
| 64 | return; //re-enable | |
| 65 | } | |
| 66 | 3 | } else if (n == 1) { |
| 67 | 2 | flagged = flagged & value; |
| 68 | 1 | enabled = value; //set enabled interrupts |
| 69 | return; | |
| 70 | } | |
| 71 | 5 | throw new RuntimeException("should not be possible " + n); |
| 72 | } | |
| 73 | ||
| 74 | public void reset() { | |
| 75 | 3 | enabled = 0; |
| 76 | 3 | flagged = 0; |
| 77 | 3 | seen = 0; |
| 78 | 3 | disabled = false; |
| 79 | } | |
| 80 | ||
| 81 | public void update() { | |
| 82 | 1 | if (!disabled) { |
| 83 | 7 | if (((~seen) & flagged & enabled) > 0) { |
| 84 | 1 | processor.flagInterrupt(this); |
| 85 | } | |
| 86 | 2 | seen = (flagged & enabled); |
| 87 | } | |
| 88 | } | |
| 89 | ||
| 90 | public void link(Interruptable il) { | |
| 91 | 1 | if (processor == null) { |
| 92 | 1 | processor = il; |
| 93 | } | |
| 94 | } | |
| 95 | ||
| 96 | public void flagInterrupt(InterruptGenerator ig) { | |
| 97 | 2 | int i = 0; |
| 98 | 4 | for (InterruptGenerator igg : generators) { |
| 99 | 1 | if (ig == igg) { |
| 100 | break; | |
| 101 | } | |
| 102 | 1 | i++; |
| 103 | } | |
| 104 | 5 | flagged |= (1 << i); |
| 105 | } | |
| 106 | ||
| 107 | public void add(InterruptGenerator ig) { | |
| 108 | 1 | generators.add(ig); |
| 109 | } | |
| 110 | } | |
Mutations | ||
| 31 |
Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Removed assignment to member variable enabled : SURVIVED |
|
| 32 |
Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Removed assignment to member variable flagged : SURVIVED |
|
| 33 |
Removed assignment to member variable seen : SURVIVED Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED |
|
| 34 |
Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Removed assignment to member variable disabled : SURVIVED |
|
| 35 |
removed call to java/util/ArrayList::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testGetApplicationDefinitions(fi.helsinki.cs.titokone.ControlTest) Removed assignment to member variable generators : KILLED -> fi.helsinki.cs.titokone.ControlTest.testGetApplicationDefinitions(fi.helsinki.cs.titokone.ControlTest) |
|
| 39 |
Substituted 2 with 3 : SURVIVED Substituted 2 with 3 : SURVIVED replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED |
|
| 44 |
negated conditional : NO_COVERAGE |
|
| 45 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 46 |
Substituted 1 with 0 : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 47 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 49 |
removed call to java/lang/StringBuilder::toString : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/StringBuilder::<init> : NO_COVERAGE removed call to java/lang/RuntimeException::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE |
|
| 54 |
negated conditional : NO_COVERAGE |
|
| 57 |
Substituted 0 with 1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE Removed assignment to member variable flagged : NO_COVERAGE |
|
| 60 |
Substituted 1 with 0 : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE Removed assignment to member variable disabled : NO_COVERAGE |
|
| 63 |
Substituted 0 with 1 : NO_COVERAGE Removed assignment to member variable disabled : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE |
|
| 66 |
Substituted 1 with 0 : NO_COVERAGE negated conditional : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE |
|
| 67 |
Replaced bitwise AND with OR : NO_COVERAGE Removed assignment to member variable flagged : NO_COVERAGE |
|
| 68 |
Removed assignment to member variable enabled : NO_COVERAGE |
|
| 71 |
removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/RuntimeException::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/StringBuilder::toString : NO_COVERAGE removed call to java/lang/StringBuilder::<init> : NO_COVERAGE |
|
| 75 |
Removed assignment to member variable enabled : SURVIVED Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED |
|
| 76 |
Removed assignment to member variable flagged : SURVIVED Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED |
|
| 77 |
Substituted 0 with 1 : SURVIVED Removed assignment to member variable seen : SURVIVED Substituted 0 with 1 : SURVIVED |
|
| 78 |
Substituted 0 with 1 : SURVIVED Removed assignment to member variable disabled : SURVIVED Substituted 0 with 1 : SURVIVED |
|
| 82 |
negated conditional : NO_COVERAGE |
|
| 83 |
Substituted -1 with 1 : NO_COVERAGE changed conditional boundary : NO_COVERAGE Substituted -1 with 0 : NO_COVERAGE Replaced XOR with AND : NO_COVERAGE Replaced bitwise AND with OR : NO_COVERAGE Replaced bitwise AND with OR : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 84 |
removed call to fi/helsinki/cs/titokone/Interruptable::flagInterrupt : NO_COVERAGE |
|
| 86 |
Replaced bitwise AND with OR : NO_COVERAGE Removed assignment to member variable seen : NO_COVERAGE |
|
| 91 |
negated conditional : SURVIVED |
|
| 92 |
Removed assignment to member variable processor : SURVIVED |
|
| 97 |
Substituted 0 with 1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE |
|
| 98 |
removed call to java/util/ArrayList::iterator : NO_COVERAGE negated conditional : NO_COVERAGE removed call to java/util/Iterator::next : NO_COVERAGE removed call to java/util/Iterator::hasNext : NO_COVERAGE |
|
| 99 |
negated conditional : NO_COVERAGE |
|
| 102 |
Changed increment from 1 to -1 : NO_COVERAGE |
|
| 104 |
Replaced Shift Left with Shift Right : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE Replaced bitwise OR with AND : NO_COVERAGE Removed assignment to member variable flagged : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE |
|
| 108 |
removed call to java/util/ArrayList::add : SURVIVED |