Some coding style fixes
[jpcrr.git] / org / jpc / emulator / TraceTrap.java
blob8ce3156169fba64f8e244372a8ee8166995b03c3
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;
32 import org.jpc.emulator.processor.Processor;
33 import java.io.*;
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;
45 public TraceTrap()
47 traceFlags = 0;
48 trapActive = false;
49 trapTimer = null;
52 public void setTrapTime(long trapTime)
54 trapTimer.setExpiry(trapTime);
57 public void clearTrapTime()
59 trapTimer.disable();
62 public synchronized boolean getAndClearTrapActive()
64 boolean tmp = trapActive;
65 trapActive = false;
66 processor.eflagsMachineHalt = false;
67 return tmp;
70 public synchronized void setTrapFlag(long flag, boolean status)
72 if(status)
73 traceFlags |= flag;
74 else
75 traceFlags &= ~flag;
76 System.err.println("Informational: Trap flags now " + traceFlags + ".");
79 public synchronized void setTrapFlags(long flags)
81 long oldFlags = traceFlags;
82 traceFlags = flags;
83 if(oldFlags != traceFlags)
84 System.err.println("Informational: Trap flags now " + traceFlags + ".");
87 public synchronized long getTrapFlags()
89 return traceFlags;
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) + ".");
96 trapActive = true;
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
128 //traps.
131 public void dumpStatus(StatusDumper output)
133 if(output.dumped(this))
134 return;
136 output.println("#" + output.objectNumber(this) + ": TraceTrap:");
137 dumpStatusPartial(output);
138 output.endObject();
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
150 super(input);
151 processor = (Processor)input.loadObject();
152 trapTimer = (Timer)input.loadObject();
155 public void callback()
157 doPotentialTrap(TRACE_STOP_IMMEDIATE);
160 public int getTimerType()
162 return 8;