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
.processor
;
34 import org
.jpc
.emulator
.memory
.AddressSpace
;
35 import org
.jpc
.emulator
.SRLoader
;
36 import org
.jpc
.emulator
.SRDumper
;
37 import org
.jpc
.emulator
.StatusDumper
;
41 * @author Chris Dennis
43 public final class RealModeSegment
extends Segment
50 private boolean defaultSize
= false;
51 private boolean segment
= true;
52 private boolean present
= true;
54 public void dumpStatusPartial(StatusDumper output
)
56 super.dumpStatusPartial(output
);
57 output
.println("\tselector " + selector
+ " base " + base
+ " limit " + limit
+ " rpl " + rpl
);
58 output
.println("\tdefaultSize " + defaultSize
+ " segment " + segment
+ " present " + present
);
61 public void dumpStatus(StatusDumper output
)
63 if(output
.dumped(this))
66 output
.println("#" + output
.objectNumber(this) + ": RealModeSegment:");
67 dumpStatusPartial(output
);
71 public void dumpSRPartial(SRDumper output
) throws IOException
73 super.dumpSRPartial(output
);
74 output
.dumpInt(selector
);
78 output
.dumpLong(limit
);
79 output
.dumpBoolean(defaultSize
);
80 output
.dumpBoolean(segment
);
81 output
.dumpBoolean(present
);
84 public RealModeSegment(SRLoader input
) throws IOException
87 selector
= input
.loadInt();
88 base
= input
.loadInt();
89 type
= input
.loadInt();
90 rpl
= input
.loadInt();
91 limit
= input
.loadLong();
92 defaultSize
= input
.loadBoolean();
93 segment
= input
.loadBoolean();
94 present
= input
.loadBoolean();
98 public RealModeSegment(AddressSpace memory
, int selector
)
101 this.selector
= selector
;
102 base
= selector
<< 4;
105 type
= ProtectedModeSegment
.TYPE_DATA_WRITABLE
| ProtectedModeSegment
.TYPE_ACCESSED
;
108 public RealModeSegment(AddressSpace memory
, Segment ancestor
)
111 selector
= ancestor
.getSelector();
112 base
= ancestor
.getBase();
113 type
= ancestor
.getType();
114 limit
= 0xffffffffL
& ancestor
.getLimit();
115 defaultSize
= ancestor
.getDefaultSizeFlag();
116 segment
= !ancestor
.isSystem();
117 present
= ancestor
.isPresent();
118 rpl
= ancestor
.getRPL();
121 public boolean getDefaultSizeFlag()
126 public int getLimit()
136 public int getSelector()
141 public boolean setSelector(int selector
)
143 this.selector
= selector
;
144 base
= selector
<< 4;
145 type
= ProtectedModeSegment
.TYPE_DATA_WRITABLE
| ProtectedModeSegment
.TYPE_ACCESSED
;
149 public void checkAddress(int offset
)
151 if ((0xffffffffL
& offset
) > limit
)
153 System
.err
.println("Emulated: RM Segment Limit exceeded: offset=" + Integer
.toHexString(offset
) +
154 ", limit=" + Long
.toHexString(limit
));
155 throw new ProcessorException(ProcessorException
.Type
.GENERAL_PROTECTION
, 0, true);
159 public int translateAddressRead(int offset
)
161 //checkAddress(offset);
162 return base
+ offset
;
165 public int translateAddressWrite(int offset
)
167 //checkAddress(offset);
168 return base
+ offset
;
181 public boolean isPresent()
186 public boolean isSystem()
193 System
.err
.println("Critical error: RM segment getDPL()");
194 throw new IllegalStateException("RM segment getDPL: " + getClass().toString());
197 public void setRPL(int cpl
)
199 System
.err
.println("Critical error: RM segment setRPL()");
200 throw new IllegalStateException("RM segment setRPL: " + getClass().toString());
203 public void printState()
205 System
.out
.println("RM Segment");
206 System
.out
.println("selector: " + Integer
.toHexString(selector
));
207 System
.out
.println("base: " + Integer
.toHexString(base
));
208 System
.out
.println("rpl: " + Integer
.toHexString(rpl
));
209 System
.out
.println("limit: " + Long
.toHexString(limit
));
210 System
.out
.println("type: " + Integer
.toHexString(type
));
211 System
.out
.println("defaultSize: " + defaultSize
);
212 System
.out
.println("segment: " + segment
);
213 System
.out
.println("present: " + present
);