2 JPC-RR: A x86 PC Hardware Emulator
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
;
33 * Converts a pair of microcode and x86 offset arrays into an instruction source.
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
;
50 * Constructs an instruction source backed by the given arrays.
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
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
;
74 public boolean getNext() {
75 if (operationEnd
>= microcodes
.length
) {
79 operationStart
= readOffset
= operationEnd
++;
82 while ((operationEnd
< microcodes
.length
) && (positions
[operationEnd
] == positions
[operationEnd
- 1])) {
86 x86End
= positions
[operationEnd
- 1];
91 public int getMicrocode() {
92 if (readOffset
< operationEnd
) {
93 return microcodes
[readOffset
++];
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
;