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
;
32 import org
.jpc
.emulator
.processor
.Processor
;
35 public class TraceTrap
extends AbstractHardwareComponent
implements TimerResponsive
37 private long traceFlags
;
38 private boolean trapActive
;
39 private Timer trapTimer
;
40 private Processor processor
;
41 public final static long TRACE_STOP_VRETRACE_START
= 0x00000001;
42 public final static long TRACE_STOP_VRETRACE_END
= 0x00000002;
43 public final static long TRACE_STOP_IMMEDIATE
= 0x80000000;
52 public void setTrapTime(long trapTime
)
54 trapTimer
.setExpiry(trapTime
);
57 public void clearTrapTime()
62 public synchronized boolean getAndClearTrapActive()
64 boolean tmp
= trapActive
;
66 processor
.eflagsMachineHalt
= false;
70 public synchronized void setTrapFlag(long flag
, boolean status
)
76 System
.err
.println("Informational: Trap flags now " + traceFlags
+ ".");
79 public synchronized void setTrapFlags(long flags
)
81 long oldFlags
= traceFlags
;
83 if(oldFlags
!= traceFlags
)
84 System
.err
.println("Informational: Trap flags now " + traceFlags
+ ".");
87 public synchronized long getTrapFlags()
92 public synchronized void doPotentialTrap(long flag
)
94 if(((traceFlags
| TRACE_STOP_IMMEDIATE
) & flag
) != 0) {
95 System
.err
.println("Informational: Doing trap because of " + (traceFlags
& flag
) + ".");
97 processor
.eflagsMachineHalt
= true;
101 public boolean initialised()
103 return (trapTimer
!= null && processor
!= null);
106 public boolean updated()
108 return (trapTimer
!= null && processor
!= null);
111 public void updateComponent(HardwareComponent component
)
113 //Nothing to do here.
116 public void acceptComponent(HardwareComponent component
)
118 if((component
instanceof Clock
) && component
.initialised())
119 trapTimer
= ((Clock
)component
).newTimer(this);
120 if((component
instanceof Processor
) && component
.initialised())
121 processor
= (Processor
)component
;
124 public void dumpStatusPartial(StatusDumper output
)
126 super.dumpStatusPartial(output
);
127 //As PC can't be savestated when running and traps only matter when its running, don't savestate the
131 public void dumpStatus(StatusDumper output
)
133 if(output
.dumped(this))
136 output
.println("#" + output
.objectNumber(this) + ": TraceTrap:");
137 dumpStatusPartial(output
);
141 public void dumpSRPartial(SRDumper output
) throws IOException
143 super.dumpSRPartial(output
);
144 output
.dumpObject(processor
);
145 output
.dumpObject(trapTimer
);
148 public TraceTrap(SRLoader input
) throws IOException
151 processor
= (Processor
)input
.loadObject();
152 trapTimer
= (Timer
)input
.loadObject();
155 public void callback()
157 doPotentialTrap(TRACE_STOP_IMMEDIATE
);
160 public int getTimerType()