Clean up emulator internal error messages
[jpcrr.git] / org / jpc / emulator / memory / codeblock / ArrayBackedInstructionSource.java
blobb40e4a73aeaf63d8cb6447c038fc2feb3ad4f5a9
1 /*
2 JPC-RR: A x86 PC Hardware Emulator
3 Release 1
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009 H. Ilari Liusvaara
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Based on JPC x86 PC Hardware emulator,
22 A project from the Physics Dept, The University of Oxford
24 Details about original JPC can be found at:
26 www-jpc.physics.ox.ac.uk
30 package org.jpc.emulator.memory.codeblock;
32 /**
33 * Converts a pair of microcode and x86 offset arrays into an instruction source.
34 * <p>
35 * This is used by the <code>FASTCompiler</code> to convert the arrays backing
36 * an interpreted codeblock into an instruction source.
37 * @author Chris Dennis
39 public class ArrayBackedInstructionSource implements InstructionSource {
41 private int[] microcodes;
42 private int[] positions;
43 private int readOffset;
44 private int operationEnd;
45 private int operationStart;
46 private int x86Start;
47 private int x86End;
49 /**
50 * Constructs an instruction source backed by the given arrays.
51 * <p>
52 * Copies of these arrays are not taken, but in turn the arrays supplied are
53 * not modified. Care must be taken to avoid modifying the supplied arrays
54 * in other code.
55 * @param microcodes array of microcode values
56 * @param positions array of x86 offsets
58 public ArrayBackedInstructionSource(int[] microcodes, int[] positions) {
59 this.microcodes = microcodes;
60 this.positions = positions;
62 x86Start = 0;
63 x86End = 0;
66 public void reset() {
67 x86Start = 0;
68 x86End = 0;
69 readOffset=0;
70 operationEnd=0;
71 operationStart=0;
74 public boolean getNext() {
75 if (operationEnd >= microcodes.length) {
76 return false;
79 operationStart = readOffset = operationEnd++;
80 x86Start = x86End;
82 while ((operationEnd < microcodes.length) && (positions[operationEnd] == positions[operationEnd - 1])) {
83 operationEnd++;
86 x86End = positions[operationEnd - 1];
88 return true;
91 public int getMicrocode() {
92 if (readOffset < operationEnd) {
93 return microcodes[readOffset++];
94 } else {
95 System.err.println("Critical error: Attempting to read past end of microcode array.");
96 throw new IllegalStateException("Read past end of microcode array");
100 public int getLength() {
101 return operationEnd - operationStart;
104 public int getX86Length() {
105 return x86End - x86Start;