Add wait for PC to stop function to Lua
[jpcrr.git] / org / jpc / emulator / motherboard / SystemBIOS.java
blobbbe97fb6a9968ba6f8127fc9215361064aea0613
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.motherboard;
32 import java.io.*;
33 import org.jpc.emulator.*;
35 /**
36 * This class provides a <code>Bios</code> implementation for the emulated
37 * machines system bios. The system bios is loaded so that it runs up to address
38 * 0x100000 (1M).
39 * <p>
40 * IO ports <code>0x400-0x403</code> are registered for debugging output. Byte
41 * writes cause ASCII characters to be written to standard output, and word
42 * writes indicate a BIOS panic at the written value line number.
43 * <p>
44 * IO port <code>0x8900</code> is registered for system shutdown requests.
45 * Currently this triggers a debugging output, but does not actually shutdown
46 * the machine.
47 * @author Chris Dennis
49 public class SystemBIOS extends Bios implements IOPortCapable
51 private boolean ioportRegistered;
53 /**
54 * Loads the system bios from the resource <code>image</code>.
55 * @param image system bios resource name.
56 * @throws java.io.IOException propogated from the resource load.
57 * @throws java.util.MissingResourceException propogated from the resource load
59 public SystemBIOS(String image) throws IOException
61 super(image);
62 ioportRegistered = false;
65 public void dumpStatusPartial(StatusDumper output)
67 super.dumpStatusPartial(output);
68 output.println("\tioportRegistered " + ioportRegistered);
71 public void dumpStatus(StatusDumper output)
73 if(output.dumped(this))
74 return;
76 output.println("#" + output.objectNumber(this) + ": SystemBIOS:");
77 dumpStatusPartial(output);
78 output.endObject();
81 public void dumpSRPartial(SRDumper output) throws IOException
83 super.dumpSRPartial(output);
84 output.dumpBoolean(ioportRegistered);
87 public SystemBIOS(SRLoader input) throws IOException
89 super(input);
90 ioportRegistered = input.loadBoolean();
93 public int[] ioPortsRequested()
95 return new int[]{0x400, 0x401, 0x402, 0x403, 0x8900};
98 public void ioPortWriteByte(int address, int data)
100 switch (address) {
101 /* Bochs BIOS Messages */
102 case 0x402:
103 case 0x403:
104 print(data);
105 break;
106 case 0x8900:
107 System.err.println("Emulated: attempted system shutdown");
108 break;
109 default:
113 public void ioPortWriteWord(int address, int data)
115 switch (address) {
116 /* Bochs BIOS Messages */
117 case 0x400:
118 case 0x401:
119 System.err.println("Emulated CRITICAL: panic in rombios.c at line " + data + ".");
123 public int ioPortReadByte(int address)
125 return 0xff;
128 public int ioPortReadWord(int address)
130 return 0xffff;
133 public int ioPortReadLong(int address)
135 return 0xffffffff;
138 public void ioPortWriteLong(int address, int data)
142 protected int loadAddress()
144 return 0x100000 - length();
147 public boolean initialised()
149 return super.initialised() && ioportRegistered;
152 public void acceptComponent(HardwareComponent component)
154 super.acceptComponent(component);
156 if ((component instanceof IOPortHandler) && component.initialised()) {
157 ((IOPortHandler) component).registerIOPortCapable(this);
158 ioportRegistered = true;
162 public void reset()
164 super.reset();
165 ioportRegistered = false;