Clean up emulator internal error messages
[jpcrr.git] / org / jpc / emulator / processor / RealModeSegment.java
blob7f5041721cfa8b1402ba4b8bae2c971b78fdba3e
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.processor;
32 import java.io.*;
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;
39 /**
41 * @author Chris Dennis
43 public final class RealModeSegment extends Segment
45 private int selector;
46 private int base;
47 private int type;
48 private long limit;
49 private int rpl;
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))
64 return;
66 output.println("#" + output.objectNumber(this) + ": RealModeSegment:");
67 dumpStatusPartial(output);
68 output.endObject();
71 public void dumpSRPartial(SRDumper output) throws IOException
73 super.dumpSRPartial(output);
74 output.dumpInt(selector);
75 output.dumpInt(base);
76 output.dumpInt(type);
77 output.dumpInt(rpl);
78 output.dumpLong(limit);
79 output.dumpBoolean(defaultSize);
80 output.dumpBoolean(segment);
81 output.dumpBoolean(present);
84 public RealModeSegment(SRLoader input) throws IOException
86 super(input);
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)
100 super(memory, true);
101 this.selector = selector;
102 base = selector << 4;
103 limit = 0xffffL;
104 rpl = 0;
105 type = ProtectedModeSegment.TYPE_DATA_WRITABLE | ProtectedModeSegment.TYPE_ACCESSED;
108 public RealModeSegment(AddressSpace memory, Segment ancestor)
110 super(memory, true);
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()
123 return defaultSize;
126 public int getLimit()
128 return (int)limit;
131 public int getBase()
133 return base;
136 public int getSelector()
138 return selector;
141 public boolean setSelector(int selector)
143 this.selector = selector;
144 base = selector << 4;
145 type = ProtectedModeSegment.TYPE_DATA_WRITABLE | ProtectedModeSegment.TYPE_ACCESSED;
146 return true;
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;
171 public int getRPL()
173 return rpl;
176 public int getType()
178 return type;
181 public boolean isPresent()
183 return present;
186 public boolean isSystem()
188 return !segment;
191 public int getDPL()
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);