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
;
32 import org
.jpc
.emulator
.StatusDumper
;
33 import org
.jpc
.emulator
.SRLoader
;
34 import org
.jpc
.emulator
.SRDumper
;
35 import org
.jpc
.emulator
.processor
.Processor
;
36 import org
.jpc
.emulator
.processor
.ProcessorException
;
40 * Class that implements an alignment checking skin on another <code>AddressSpace</code>
41 * instance. Access that are not alignment on the correct granularity will
42 * trigger a {@link org.jpc.emulator.processor.ProcessorException} with the
43 * appropriate vector value.
44 * @author Chris Dennis
46 public class AlignmentCheckedAddressSpace
extends AddressSpace
48 private final AddressSpace addressSpace
;
51 * Constructs an address space wrapping the supplied target.
52 * @param target address space to be wrapped.
54 public AlignmentCheckedAddressSpace(AddressSpace target
)
56 addressSpace
= target
;
59 public void dumpStatusPartial(StatusDumper output
)
61 super.dumpStatusPartial(output
);
62 output
.println("\taddressSpace <object #" + output
.objectNumber(addressSpace
) + ">"); if(addressSpace
!= null) addressSpace
.dumpStatus(output
);
65 public void dumpStatus(StatusDumper output
)
67 if(output
.dumped(this))
70 output
.println("#" + output
.objectNumber(this) + ": AlignmentCheckedAddressSpace:");
71 dumpStatusPartial(output
);
75 public void dumpSRPartial(SRDumper output
) throws IOException
77 super.dumpSRPartial(output
);
78 output
.dumpObject(addressSpace
);
81 public AlignmentCheckedAddressSpace(SRLoader input
) throws IOException
84 addressSpace
= (AddressSpace
)(input
.loadObject());
88 protected Memory
getReadMemoryBlockAt(int offset
)
90 return addressSpace
.getReadMemoryBlockAt(offset
);
93 protected Memory
getWriteMemoryBlockAt(int offset
)
95 return addressSpace
.getWriteMemoryBlockAt(offset
);
98 protected void replaceBlocks(Memory oldBlock
, Memory newBlock
)
100 addressSpace
.replaceBlocks(oldBlock
, newBlock
);
103 public int executeReal(Processor cpu
, int offset
)
105 return addressSpace
.executeReal(cpu
, offset
);
108 public int executeProtected(Processor cpu
, int offset
)
110 return addressSpace
.executeReal(cpu
, offset
);
113 public int executeVirtual8086(Processor cpu
, int offset
)
115 return addressSpace
.executeReal(cpu
, offset
);
120 addressSpace
.clear();
123 public byte getByte(int offset
)
125 return addressSpace
.getByte(offset
);
128 public void setByte(int offset
, byte data
)
130 addressSpace
.setByte(offset
, data
);
134 * Throws a <code>ProcessorException</code> if the access is not aligned to
135 * a word (two-byte) boundary.
136 * @param offset address to be read.
137 * @return short value read.
139 public short getWord(int offset
)
141 if((offset
& 0x1) != 0)
142 throw ProcessorException
.ALIGNMENT_CHECK_0
;
144 return addressSpace
.getWord(offset
);
148 * Throws a <code>ProcessorException</code> if the access is not aligned to
149 * a doubleword (four-byte) boundary.
150 * @param offset address to be read.
151 * @return int value read.
153 public int getDoubleWord(int offset
)
155 if((offset
& 0x3) != 0)
156 throw ProcessorException
.ALIGNMENT_CHECK_0
;
158 return addressSpace
.getDoubleWord(offset
);
162 * Throws a <code>ProcessorException</code> if the access is not aligned to
163 * a quad-word (eight-byte) boundary.
164 * @param offset address to be read.
165 * @return int value read.
167 public long getQuadWord(int offset
)
169 if((offset
& 0x7) != 0)
170 throw ProcessorException
.ALIGNMENT_CHECK_0
;
172 return addressSpace
.getQuadWord(offset
);
176 * Throws a <code>ProcessorException</code> if the access is not aligned to
177 * a octa-word (sixteen-byte) boundary.
178 * @param offset address to be read.
179 * @return long value read.
181 public long getLowerDoubleQuadWord(int offset
)
183 if((offset
& 0xF) != 0)
184 throw ProcessorException
.ALIGNMENT_CHECK_0
;
186 return addressSpace
.getLowerDoubleQuadWord(offset
);
189 public long getUpperDoubleQuadWord(int offset
)
191 return addressSpace
.getUpperDoubleQuadWord(offset
);
195 * Throws a <code>ProcessorException</code> if the access is not aligned to
196 * a word (two-byte) boundary.
197 * @param offset address to be read.
198 * @param data value to write.
200 public void setWord(int offset
, short data
)
202 if((offset
& 0x1) != 0)
203 throw ProcessorException
.ALIGNMENT_CHECK_0
;
205 addressSpace
.setWord(offset
, data
);
209 * Throws a <code>ProcessorException</code> if the access is not aligned to
210 * a doubleword (four-byte) boundary.
211 * @param offset address to be read.
212 * @param data value to write.
214 public void setDoubleWord(int offset
, int data
)
216 if((offset
& 0x3) != 0)
217 throw ProcessorException
.ALIGNMENT_CHECK_0
;
219 addressSpace
.setDoubleWord(offset
, data
);
223 * Throws a <code>ProcessorException</code> if the access is not aligned to
224 * a quadword (eight-byte) boundary.
225 * @param offset address to be read.
226 * @param data value to write.
228 public void setQuadWord(int offset
, long data
)
230 if((offset
& 0x7) != 0)
231 throw ProcessorException
.ALIGNMENT_CHECK_0
;
233 addressSpace
.setQuadWord(offset
, data
);
237 * Throws a <code>ProcessorException</code> if the access is not aligned to
238 * a octa-word (sixteen-byte) boundary.
239 * @param offset address to be read.
240 * @param data value to write.
242 public void setLowerDoubleQuadWord(int offset
, long data
)
244 if((offset
& 0xF) != 0)
245 throw ProcessorException
.GENERAL_PROTECTION_0
;
247 addressSpace
.setLowerDoubleQuadWord(offset
, data
);
250 public void setUpperDoubleQuadWord(int offset
, long data
)
252 addressSpace
.setUpperDoubleQuadWord(offset
, data
);
255 public void copyArrayIntoContents(int address
, byte[] buffer
, int off
, int len
)
257 addressSpace
.copyArrayIntoContents(address
, buffer
, off
, len
);
260 public void copyContentsIntoArray(int address
, byte[] buffer
, int off
, int len
)
262 addressSpace
.copyContentsIntoArray(address
, buffer
, off
, len
);
265 public void loadInitialContents(int address
, byte[] buf
, int off
, int len
) {
266 throw new UnsupportedOperationException("Not supported yet.");