2 JPC-RR: A x86 PC Hardware Emulator
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009-2010 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
.StatusDumper
;
35 import org
.jpc
.emulator
.SRLoader
;
36 import org
.jpc
.emulator
.SRDumper
;
37 import org
.jpc
.emulator
.memory
.AddressSpace
;
41 * @author Chris Dennis
43 public class DescriptorTableSegment
extends Segment
45 private final int base
;
46 private final long limit
;
48 public void dumpStatusPartial(StatusDumper output
)
50 super.dumpStatusPartial(output
);
51 output
.println("\tbase " + base
+ " limit " + limit
);
54 public void dumpStatus(StatusDumper output
)
56 if(output
.dumped(this))
59 output
.println("#" + output
.objectNumber(this) + ": DescriptorTableSegment:");
60 dumpStatusPartial(output
);
64 public void dumpSRPartial(SRDumper output
) throws IOException
66 super.dumpSRPartial(output
);
68 output
.dumpLong(limit
);
71 public DescriptorTableSegment(SRLoader input
) throws IOException
74 base
= input
.loadInt();
75 limit
= input
.loadLong();
78 public DescriptorTableSegment(AddressSpace memory
, int base
, int limit
)
82 this.limit
= 0xffffffffL
& limit
;
95 public int getSelector()
97 System
.err
.println("Critical error: No selector for a descriptor table segment.");
98 throw new IllegalStateException("No selector for a descriptor table segment");
101 public boolean setSelector(int selector
)
103 System
.err
.println("Critical error: Can not set selector for a descriptor table segment.");
104 throw new IllegalStateException("Cannot set a selector for a descriptor table segment");
107 public void checkAddress(int offset
)
109 if ((0xffffffffL
& offset
) > limit
)
111 System
.err
.println("Emulated: Offset beyond end of Descriptor Table Segment: Offset=" +
112 Integer
.toHexString(offset
) + ", limit=" + Long
.toHexString(limit
));
113 throw new ProcessorException(ProcessorException
.Type
.GENERAL_PROTECTION
, offset
, true);
117 public int translateAddressRead(int offset
)
119 checkAddress(offset
);
120 return base
+ offset
;
123 public int translateAddressWrite(int offset
)
125 checkAddress(offset
);
126 return base
+ offset
;
131 System
.err
.println("Critical error: Descriptor Table Segment getDPL().");
132 throw new IllegalStateException("[LG]DTR getDPL(): " + getClass().toString());
137 System
.err
.println("Critical error: Descriptor Table Segment getRPL().");
138 throw new IllegalStateException("[LG]DTR getRPL(): " + getClass().toString());
141 public void setRPL(int cpl
)
143 System
.err
.println("Critical error: Descriptor Table Segment setRPL().");
144 throw new IllegalStateException("[LG]DTR setDPL(): " + getClass().toString());
147 public boolean getDefaultSizeFlag()
149 System
.err
.println("Critical error: Descriptor Table Segment getDefaultSizeFlag().");
150 throw new IllegalStateException("[LG]DTR getDefaultSizeFlag(): " + getClass().toString());
155 System
.err
.println("Critical error: Descriptor Table Segment getType().");
156 throw new IllegalStateException("[LG]DTR getType(): " + getClass().toString());
159 public boolean isPresent()
164 public boolean isSystem()
169 public void printState()
171 System
.out
.println("Descriptor Table Segment");
172 System
.out
.print("base: " + Integer
.toHexString(base
));
173 System
.out
.println("limit: " + Long
.toHexString(limit
));