1 |
2 |
alfik |
/////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// $Id: bochs.h 11689 2013-05-24 17:58:49Z vruppert $
|
3 |
|
|
/////////////////////////////////////////////////////////////////////////
|
4 |
|
|
//
|
5 |
|
|
// Copyright (C) 2001-2013 The Bochs Project
|
6 |
|
|
//
|
7 |
|
|
// This library is free software; you can redistribute it and/or
|
8 |
|
|
// modify it under the terms of the GNU Lesser General Public
|
9 |
|
|
// License as published by the Free Software Foundation; either
|
10 |
|
|
// version 2 of the License, or (at your option) any later version.
|
11 |
|
|
//
|
12 |
|
|
// This library 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 GNU
|
15 |
|
|
// Lesser General Public License for more details.
|
16 |
|
|
//
|
17 |
|
|
// You should have received a copy of the GNU Lesser General Public
|
18 |
|
|
// License along with this library; if not, write to the Free Software
|
19 |
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
20 |
|
|
|
21 |
|
|
//
|
22 |
|
|
// bochs.h is the master header file for all C++ code. It includes all
|
23 |
|
|
// the system header files needed by bochs, and also includes all the bochs
|
24 |
|
|
// C++ header files. Because bochs.h and the files that it includes has
|
25 |
|
|
// structure and class definitions, it cannot be called from C code.
|
26 |
|
|
//
|
27 |
|
|
|
28 |
|
|
#ifndef BX_BOCHS_H
|
29 |
|
|
# define BX_BOCHS_H 1
|
30 |
|
|
|
31 |
|
|
#include "config.h" /* generated by configure script from config.h.in */
|
32 |
|
|
|
33 |
|
|
#ifndef __QNXNTO__
|
34 |
|
|
extern "C" {
|
35 |
|
|
#endif
|
36 |
|
|
|
37 |
|
|
#ifdef WIN32
|
38 |
|
|
// In a win32 compile (including cygwin), windows.h is required for several
|
39 |
|
|
// files in gui and iodev. It is important to include it here in a header
|
40 |
|
|
// file so that WIN32-specific data types can be used in fields of classes.
|
41 |
|
|
#include <windows.h>
|
42 |
|
|
#endif
|
43 |
|
|
|
44 |
|
|
#include <stdarg.h>
|
45 |
|
|
#include <stdio.h>
|
46 |
|
|
#include <stdlib.h>
|
47 |
|
|
#if defined(__sun__)
|
48 |
|
|
#undef EAX
|
49 |
|
|
#undef ECX
|
50 |
|
|
#undef EDX
|
51 |
|
|
#undef EBX
|
52 |
|
|
#undef ESP
|
53 |
|
|
#undef EBP
|
54 |
|
|
#undef ESI
|
55 |
|
|
#undef EDI
|
56 |
|
|
#undef EIP
|
57 |
|
|
#undef CS
|
58 |
|
|
#undef DS
|
59 |
|
|
#undef ES
|
60 |
|
|
#undef SS
|
61 |
|
|
#undef FS
|
62 |
|
|
#undef GS
|
63 |
|
|
#endif
|
64 |
|
|
#include <assert.h>
|
65 |
|
|
#include <errno.h>
|
66 |
|
|
|
67 |
|
|
#ifndef WIN32
|
68 |
|
|
# include <unistd.h>
|
69 |
|
|
#else
|
70 |
|
|
# include <io.h>
|
71 |
|
|
#endif
|
72 |
|
|
#include <time.h>
|
73 |
|
|
#if BX_WITH_MACOS
|
74 |
|
|
# include <types.h>
|
75 |
|
|
# include <stat.h>
|
76 |
|
|
# include <cstdio>
|
77 |
|
|
# include <unistd.h>
|
78 |
|
|
#elif BX_WITH_CARBON
|
79 |
|
|
# include <sys/types.h>
|
80 |
|
|
# include <sys/stat.h>
|
81 |
|
|
# include <sys/param.h> /* for MAXPATHLEN */
|
82 |
|
|
# include <sys/time.h>
|
83 |
|
|
# include <utime.h>
|
84 |
|
|
#else
|
85 |
|
|
# ifndef WIN32
|
86 |
|
|
# include <sys/time.h>
|
87 |
|
|
# endif
|
88 |
|
|
# include <sys/types.h>
|
89 |
|
|
# include <sys/stat.h>
|
90 |
|
|
#endif
|
91 |
|
|
#include <ctype.h>
|
92 |
|
|
#include <string.h>
|
93 |
|
|
#include <fcntl.h>
|
94 |
|
|
#include <limits.h>
|
95 |
|
|
#ifdef macintosh
|
96 |
|
|
# define SuperDrive "[fd:]"
|
97 |
|
|
#endif
|
98 |
|
|
|
99 |
|
|
#ifndef __QNXNTO__
|
100 |
|
|
}
|
101 |
|
|
#endif
|
102 |
|
|
|
103 |
|
|
#include "osdep.h" /* platform dependent includes and defines */
|
104 |
|
|
#include "bx_debug/debug.h"
|
105 |
|
|
#include "gui/siminterface.h"
|
106 |
|
|
|
107 |
|
|
// BX_SHARE_PATH should be defined by the makefile. If not, give it
|
108 |
|
|
// a value of NULL to avoid compile problems.
|
109 |
|
|
#ifndef BX_SHARE_PATH
|
110 |
|
|
#define BX_SHARE_PATH NULL
|
111 |
|
|
#endif
|
112 |
|
|
|
113 |
|
|
// prototypes
|
114 |
|
|
int bx_begin_simulation(int argc, char *argv[]);
|
115 |
|
|
void bx_stop_simulation();
|
116 |
|
|
char *bx_find_bochsrc(void);
|
117 |
|
|
int bx_parse_cmdline(int arg, int argc, char *argv[]);
|
118 |
|
|
int bx_read_configuration(const char *rcfile);
|
119 |
|
|
int bx_write_configuration(const char *rcfile, int overwrite);
|
120 |
|
|
void bx_reset_options(void);
|
121 |
|
|
void bx_set_log_actions_by_device(bx_bool panic_flag);
|
122 |
|
|
// special config parameter and options functions for plugins
|
123 |
|
|
void bx_init_std_nic_options(const char *name, bx_list_c *menu);
|
124 |
|
|
void bx_init_usb_options(const char *usb_name, const char *pname, int maxports);
|
125 |
|
|
int bx_parse_param_from_list(const char *context, const char *input, bx_list_c *list);
|
126 |
|
|
int bx_parse_nic_params(const char *context, const char *param, bx_list_c *base);
|
127 |
|
|
int bx_parse_usb_port_params(const char *context, bx_bool devopt,
|
128 |
|
|
const char *param, int maxports, bx_list_c *base);
|
129 |
|
|
int bx_write_param_list(FILE *fp, bx_list_c *base, const char *optname, bx_bool multiline);
|
130 |
|
|
int bx_write_usb_options(FILE *fp, int maxports, bx_list_c *base);
|
131 |
|
|
Bit32u crc32(const Bit8u *buf, int len);
|
132 |
|
|
// for param-tree testing only
|
133 |
|
|
void print_tree(bx_param_c *node, int level = 0);
|
134 |
|
|
|
135 |
|
|
//
|
136 |
|
|
// some macros to interface the CPU and memory to external environment
|
137 |
|
|
// so that these functions can be redirected to the debugger when
|
138 |
|
|
// needed.
|
139 |
|
|
//
|
140 |
|
|
|
141 |
|
|
#define BXRS_PARAM_SPECIAL(parent, name, maxvalue, save_handler, restore_handler) \
|
142 |
|
|
{ \
|
143 |
|
|
bx_param_num_c *param = new bx_param_num_c(parent, #name, "", "", 0, maxvalue, 0); \
|
144 |
|
|
param->set_base(BASE_HEX); \
|
145 |
|
|
param->set_sr_handlers(this, save_handler, restore_handler); \
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
#define BXRS_PARAM_SPECIAL64(parent, name, save_handler, restore_handler) \
|
149 |
|
|
BXRS_PARAM_SPECIAL(parent, name, BX_MAX_BIT64U, save_handler, restore_handler)
|
150 |
|
|
#define BXRS_PARAM_SPECIAL32(parent, name, save_handler, restore_handler) \
|
151 |
|
|
BXRS_PARAM_SPECIAL(parent, name, BX_MAX_BIT32U, save_handler, restore_handler)
|
152 |
|
|
#define BXRS_PARAM_SPECIAL16(parent, name, save_handler, restore_handler) \
|
153 |
|
|
BXRS_PARAM_SPECIAL(parent, name, BX_MAX_BIT16U, save_handler, restore_handler)
|
154 |
|
|
#define BXRS_PARAM_SPECIAL8(parent, name, save_handler, restore_handler) \
|
155 |
|
|
BXRS_PARAM_SPECIAL(parent, name, BX_MAX_BIT8U, save_handler, restore_handler)
|
156 |
|
|
|
157 |
|
|
#define BXRS_HEX_PARAM_SIMPLE32(parent, name) \
|
158 |
|
|
new bx_shadow_num_c(parent, #name, (Bit32u*)&(name), BASE_HEX)
|
159 |
|
|
#define BXRS_HEX_PARAM_SIMPLE64(parent, name) \
|
160 |
|
|
new bx_shadow_num_c(parent, #name, (Bit64u*)&(name), BASE_HEX)
|
161 |
|
|
|
162 |
|
|
#define BXRS_HEX_PARAM_SIMPLE(parent, name) \
|
163 |
|
|
new bx_shadow_num_c(parent, #name, &(name), BASE_HEX)
|
164 |
|
|
#define BXRS_HEX_PARAM_FIELD(parent, name, field) \
|
165 |
|
|
new bx_shadow_num_c(parent, #name, &(field), BASE_HEX)
|
166 |
|
|
|
167 |
|
|
#define BXRS_DEC_PARAM_SIMPLE(parent, name) \
|
168 |
|
|
new bx_shadow_num_c(parent, #name, &(name), BASE_DEC)
|
169 |
|
|
#define BXRS_DEC_PARAM_FIELD(parent, name, field) \
|
170 |
|
|
new bx_shadow_num_c(parent, #name, &(field), BASE_DEC)
|
171 |
|
|
|
172 |
|
|
#define BXRS_PARAM_BOOL(parent, name, field) \
|
173 |
|
|
new bx_shadow_bool_c(parent, #name, (bx_bool*)(&(field)))
|
174 |
|
|
|
175 |
|
|
// =-=-=-=-=-=-=- Normal optimized use -=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
176 |
|
|
// some pc_systems functions just redirect to the IO devices so optimize
|
177 |
|
|
// by eliminating call here
|
178 |
|
|
//
|
179 |
|
|
// #define BX_INP(addr, len) bx_pc_system.inp(addr, len)
|
180 |
|
|
// #define BX_OUTP(addr, val, len) bx_pc_system.outp(addr, val, len)
|
181 |
|
|
#define BX_INP(addr, len) bx_devices.inp(addr, len)
|
182 |
|
|
#define BX_OUTP(addr, val, len) bx_devices.outp(addr, val, len)
|
183 |
|
|
#define BX_TICK1() bx_pc_system.tick1()
|
184 |
|
|
#define BX_TICKN(n) bx_pc_system.tickn(n)
|
185 |
|
|
#define BX_INTR bx_pc_system.INTR
|
186 |
|
|
#define BX_RAISE_INTR() bx_pc_system.raise_INTR()
|
187 |
|
|
#define BX_CLEAR_INTR() bx_pc_system.clear_INTR()
|
188 |
|
|
#define BX_HRQ bx_pc_system.HRQ
|
189 |
|
|
|
190 |
|
|
#if BX_SUPPORT_SMP
|
191 |
|
|
#define BX_CPU(x) (bx_cpu_array[x])
|
192 |
|
|
#else
|
193 |
|
|
#define BX_CPU(x) (&bx_cpu)
|
194 |
|
|
#endif
|
195 |
|
|
|
196 |
|
|
#define BX_MEM(x) (&bx_mem)
|
197 |
|
|
|
198 |
|
|
#define BX_SET_ENABLE_A20(enabled) bx_pc_system.set_enable_a20(enabled)
|
199 |
|
|
#define BX_GET_ENABLE_A20() bx_pc_system.get_enable_a20()
|
200 |
|
|
|
201 |
|
|
#if BX_SUPPORT_A20
|
202 |
|
|
# define A20ADDR(x) ((bx_phy_address)(x) & bx_pc_system.a20_mask)
|
203 |
|
|
#else
|
204 |
|
|
# define A20ADDR(x) ((bx_phy_address)(x))
|
205 |
|
|
#endif
|
206 |
|
|
|
207 |
|
|
// you can't use static member functions on the CPU, if there are going
|
208 |
|
|
// to be 2 cpus. Check this early on.
|
209 |
|
|
#if BX_SUPPORT_SMP
|
210 |
|
|
# if BX_USE_CPU_SMF
|
211 |
|
|
# error For SMP simulation, BX_USE_CPU_SMF must be 0.
|
212 |
|
|
# endif
|
213 |
|
|
#endif
|
214 |
|
|
|
215 |
|
|
//
|
216 |
|
|
// Ways for the the external environment to report back information
|
217 |
|
|
// to the debugger.
|
218 |
|
|
//
|
219 |
|
|
|
220 |
|
|
#if BX_DEBUGGER
|
221 |
|
|
# define BX_DBG_ASYNC_INTR bx_guard.async.irq
|
222 |
|
|
# define BX_DBG_ASYNC_DMA bx_guard.async.dma
|
223 |
|
|
|
224 |
|
|
# define BX_DBG_DMA_REPORT(addr, len, what, val) \
|
225 |
|
|
if (bx_guard.report.dma) bx_dbg_dma_report(addr, len, what, val)
|
226 |
|
|
# define BX_DBG_IAC_REPORT(vector, irq) \
|
227 |
|
|
if (bx_guard.report.irq) bx_dbg_iac_report(vector, irq)
|
228 |
|
|
# define BX_DBG_A20_REPORT(val) \
|
229 |
|
|
if (bx_guard.report.a20) bx_dbg_a20_report(val)
|
230 |
|
|
# define BX_DBG_IO_REPORT(port, size, op, val) \
|
231 |
|
|
if (bx_guard.report.io) bx_dbg_io_report(port, size, op, val)
|
232 |
|
|
# define BX_DBG_LIN_MEMORY_ACCESS(cpu, lin, phy, len, pl, rw, data) \
|
233 |
|
|
bx_dbg_lin_memory_access(cpu, lin, phy, len, pl, rw, data)
|
234 |
|
|
# define BX_DBG_PHY_MEMORY_ACCESS(cpu, phy, len, rw, why, data) \
|
235 |
|
|
bx_dbg_phy_memory_access(cpu, phy, len, rw, why, data)
|
236 |
|
|
#else // #if BX_DEBUGGER
|
237 |
|
|
// debugger not compiled in, use empty stubs
|
238 |
|
|
# define BX_DBG_ASYNC_INTR 1
|
239 |
|
|
# define BX_DBG_ASYNC_DMA 1
|
240 |
|
|
# define BX_DBG_DMA_REPORT(addr, len, what, val) /* empty */
|
241 |
|
|
# define BX_DBG_IAC_REPORT(vector, irq) /* empty */
|
242 |
|
|
# define BX_DBG_A20_REPORT(val) /* empty */
|
243 |
|
|
# define BX_DBG_IO_REPORT(port, size, op, val) /* empty */
|
244 |
|
|
//AO# define BX_DBG_LIN_MEMORY_ACCESS(cpu, lin, phy, len, pl, rw, data) /* empty */
|
245 |
|
|
//AO# define BX_DBG_PHY_MEMORY_ACCESS(cpu, phy, len, rw, attr, data) /* empty */
|
246 |
|
|
#endif // #if BX_DEBUGGER
|
247 |
|
|
|
248 |
|
|
//AO start
|
249 |
|
|
void bx_dbg_lin_memory_access(unsigned cpu, bx_address lin, bx_phy_address phy, unsigned len, unsigned pl, unsigned rw, Bit8u *data);
|
250 |
|
|
void bx_dbg_phy_memory_access(unsigned cpu, bx_phy_address phy, unsigned len, unsigned rw, unsigned attr, Bit8u *data);
|
251 |
|
|
|
252 |
|
|
# define BX_DBG_LIN_MEMORY_ACCESS(cpu, lin, phy, len, pl, rw, data) \
|
253 |
|
|
bx_dbg_lin_memory_access(cpu, lin, phy, len, pl, rw, data)
|
254 |
|
|
# define BX_DBG_PHY_MEMORY_ACCESS(cpu, phy, len, rw, why, data) \
|
255 |
|
|
bx_dbg_phy_memory_access(cpu, phy, len, rw, why, data)
|
256 |
|
|
//AO end
|
257 |
|
|
|
258 |
|
|
#define MAGIC_LOGNUM 0x12345678
|
259 |
|
|
|
260 |
|
|
typedef class BOCHSAPI logfunctions
|
261 |
|
|
{
|
262 |
|
|
char *name;
|
263 |
|
|
char *prefix;
|
264 |
|
|
int onoff[N_LOGLEV];
|
265 |
|
|
class iofunctions *logio;
|
266 |
|
|
// default log actions for all devices, declared and initialized
|
267 |
|
|
// in logio.cc.
|
268 |
|
|
BOCHSAPI_CYGONLY static int default_onoff[N_LOGLEV];
|
269 |
|
|
public:
|
270 |
|
|
logfunctions(void);
|
271 |
|
|
logfunctions(class iofunctions *);
|
272 |
|
|
~logfunctions(void);
|
273 |
|
|
|
274 |
|
|
void info(const char *fmt, ...) BX_CPP_AttrPrintf(2, 3);
|
275 |
|
|
void error(const char *fmt, ...) BX_CPP_AttrPrintf(2, 3);
|
276 |
|
|
void panic(const char *fmt, ...) BX_CPP_AttrPrintf(2, 3);
|
277 |
|
|
void ldebug(const char *fmt, ...) BX_CPP_AttrPrintf(2, 3);
|
278 |
|
|
void fatal (const char *prefix, const char *fmt, va_list ap, int exit_status);
|
279 |
|
|
void ask (int level, const char *prefix, const char *fmt, va_list ap);
|
280 |
|
|
void put(const char *p);
|
281 |
|
|
void put(const char *n, const char *p);
|
282 |
|
|
void setio(class iofunctions *);
|
283 |
|
|
void setonoff(int loglev, int value) {
|
284 |
|
|
assert (loglev >= 0 && loglev < N_LOGLEV);
|
285 |
|
|
onoff[loglev] = value;
|
286 |
|
|
}
|
287 |
|
|
const char *get_name() const { return name; }
|
288 |
|
|
const char *getprefix() const { return prefix; }
|
289 |
|
|
int getonoff(int level) const {
|
290 |
|
|
assert (level>=0 && level<N_LOGLEV);
|
291 |
|
|
return onoff[level];
|
292 |
|
|
}
|
293 |
|
|
static void set_default_action(int loglev, int action) {
|
294 |
|
|
assert (loglev >= 0 && loglev < N_LOGLEV);
|
295 |
|
|
assert (action >= 0 && action < N_ACT);
|
296 |
|
|
default_onoff[loglev] = action;
|
297 |
|
|
}
|
298 |
|
|
static int get_default_action(int loglev) {
|
299 |
|
|
assert (loglev >= 0 && loglev < N_LOGLEV);
|
300 |
|
|
return default_onoff[loglev];
|
301 |
|
|
}
|
302 |
|
|
} logfunc_t;
|
303 |
|
|
|
304 |
|
|
#define BX_LOGPREFIX_SIZE 51
|
305 |
|
|
|
306 |
|
|
class BOCHSAPI iofunctions {
|
307 |
|
|
int magic;
|
308 |
|
|
char logprefix[BX_LOGPREFIX_SIZE];
|
309 |
|
|
FILE *logfd;
|
310 |
|
|
class logfunctions *log;
|
311 |
|
|
void init(void);
|
312 |
|
|
void flush(void);
|
313 |
|
|
|
314 |
|
|
// Log Class types
|
315 |
|
|
public:
|
316 |
|
|
iofunctions(void);
|
317 |
|
|
iofunctions(FILE *);
|
318 |
|
|
iofunctions(int);
|
319 |
|
|
iofunctions(const char *);
|
320 |
|
|
~iofunctions(void);
|
321 |
|
|
|
322 |
|
|
void out(int level, const char *pre, const char *fmt, va_list ap);
|
323 |
|
|
|
324 |
|
|
void init_log(const char *fn);
|
325 |
|
|
void init_log(int fd);
|
326 |
|
|
void init_log(FILE *fs);
|
327 |
|
|
void exit_log();
|
328 |
|
|
void set_log_prefix(const char *prefix);
|
329 |
|
|
int get_n_logfns() const { return n_logfn; }
|
330 |
|
|
logfunc_t *get_logfn(int index) { return logfn_list[index]; }
|
331 |
|
|
void add_logfn(logfunc_t *fn);
|
332 |
|
|
void remove_logfn(logfunc_t *fn);
|
333 |
|
|
void set_log_action(int loglevel, int action);
|
334 |
|
|
const char *getlevel(int i) const;
|
335 |
|
|
const char *getaction(int i) const;
|
336 |
|
|
|
337 |
|
|
protected:
|
338 |
|
|
int n_logfn;
|
339 |
|
|
#define MAX_LOGFNS 512
|
340 |
|
|
logfunc_t *logfn_list[MAX_LOGFNS];
|
341 |
|
|
const char *logfn;
|
342 |
|
|
};
|
343 |
|
|
|
344 |
|
|
typedef class BOCHSAPI iofunctions iofunc_t;
|
345 |
|
|
|
346 |
|
|
#define SAFE_GET_IOFUNC() \
|
347 |
|
|
((io==NULL)? (io=new iofunc_t("/dev/stderr")) : io)
|
348 |
|
|
#define SAFE_GET_GENLOG() \
|
349 |
|
|
((genlog==NULL)? (genlog=new logfunc_t(SAFE_GET_IOFUNC())) : genlog)
|
350 |
|
|
|
351 |
|
|
#if BX_NO_LOGGING
|
352 |
|
|
|
353 |
|
|
#define BX_INFO(x)
|
354 |
|
|
#define BX_DEBUG(x)
|
355 |
|
|
#define BX_ERROR(x)
|
356 |
|
|
#define BX_PANIC(x) (LOG_THIS panic) x
|
357 |
|
|
|
358 |
|
|
#define BX_ASSERT(x)
|
359 |
|
|
|
360 |
|
|
#else
|
361 |
|
|
|
362 |
|
|
#define BX_INFO(x) (LOG_THIS info) x
|
363 |
|
|
#define BX_DEBUG(x) (LOG_THIS ldebug) x
|
364 |
|
|
#define BX_ERROR(x) (LOG_THIS error) x
|
365 |
|
|
#define BX_PANIC(x) (LOG_THIS panic) x
|
366 |
|
|
|
367 |
|
|
#if BX_ASSERT_ENABLE
|
368 |
|
|
#define BX_ASSERT(x) do {if (!(x)) BX_PANIC(("failed assertion \"%s\" at %s:%d\n", #x, __FILE__, __LINE__));} while (0)
|
369 |
|
|
#else
|
370 |
|
|
#define BX_ASSERT(x)
|
371 |
|
|
#endif
|
372 |
|
|
|
373 |
|
|
#endif
|
374 |
|
|
|
375 |
|
|
BOCHSAPI extern iofunc_t *io;
|
376 |
|
|
BOCHSAPI extern logfunc_t *genlog;
|
377 |
|
|
|
378 |
|
|
#ifndef UNUSED
|
379 |
|
|
# define UNUSED(x) ((void)x)
|
380 |
|
|
#endif
|
381 |
|
|
|
382 |
|
|
//Generic MAX and MIN Functions
|
383 |
|
|
#define BX_MAX(a,b) ((a) > (b) ? (a) : (b))
|
384 |
|
|
#define BX_MIN(a,b) ((a) < (b) ? (a) : (b))
|
385 |
|
|
|
386 |
|
|
#if BX_SUPPORT_X86_64
|
387 |
|
|
#define FMT_ADDRX FMT_ADDRX64
|
388 |
|
|
#else
|
389 |
|
|
#define FMT_ADDRX FMT_ADDRX32
|
390 |
|
|
#endif
|
391 |
|
|
|
392 |
|
|
#if BX_PHY_ADDRESS_LONG
|
393 |
|
|
#define FMT_PHY_ADDRX FMT_PHY_ADDRX64
|
394 |
|
|
#else
|
395 |
|
|
#define FMT_PHY_ADDRX FMT_ADDRX32
|
396 |
|
|
#endif
|
397 |
|
|
|
398 |
|
|
#define FMT_LIN_ADDRX FMT_ADDRX
|
399 |
|
|
|
400 |
|
|
#if BX_GDBSTUB
|
401 |
|
|
// defines for GDB stub
|
402 |
|
|
void bx_gdbstub_init(void);
|
403 |
|
|
void bx_gdbstub_break(void);
|
404 |
|
|
int bx_gdbstub_check(unsigned int eip);
|
405 |
|
|
#define GDBSTUB_STOP_NO_REASON (0xac0)
|
406 |
|
|
|
407 |
|
|
#if BX_SUPPORT_SMP
|
408 |
|
|
#error GDB stub was written for single processor support. If multiprocessor support is added, then we can remove this check.
|
409 |
|
|
// The big problem is knowing which CPU gdb is referring to. In other words,
|
410 |
|
|
// what should we put for "n" in BX_CPU(n)->dbg_xlate_linear2phy() and
|
411 |
|
|
// BX_CPU(n)->dword.eip, etc.
|
412 |
|
|
#endif
|
413 |
|
|
#endif
|
414 |
|
|
|
415 |
|
|
typedef struct {
|
416 |
|
|
bx_bool interrupts;
|
417 |
|
|
bx_bool exceptions;
|
418 |
|
|
bx_bool print_timestamps;
|
419 |
|
|
#if BX_DEBUGGER
|
420 |
|
|
bx_bool magic_break_enabled;
|
421 |
|
|
#endif
|
422 |
|
|
#if BX_GDBSTUB
|
423 |
|
|
bx_bool gdbstub_enabled;
|
424 |
|
|
#endif
|
425 |
|
|
#if BX_SUPPORT_APIC
|
426 |
|
|
bx_bool apic;
|
427 |
|
|
#endif
|
428 |
|
|
#if BX_DEBUG_LINUX
|
429 |
|
|
bx_bool linux_syscall;
|
430 |
|
|
#endif
|
431 |
|
|
} bx_debug_t;
|
432 |
|
|
|
433 |
|
|
#if BX_SHOW_IPS
|
434 |
|
|
BOCHSAPI_MSVCONLY void bx_show_ips_handler(void);
|
435 |
|
|
#endif
|
436 |
|
|
void CDECL bx_signal_handler(int signum);
|
437 |
|
|
int bx_atexit(void);
|
438 |
|
|
BOCHSAPI extern bx_debug_t bx_dbg;
|
439 |
|
|
|
440 |
|
|
#if BX_SUPPORT_APIC
|
441 |
|
|
// determinted by XAPIC option
|
442 |
|
|
BOCHSAPI extern Bit32u apic_id_mask;
|
443 |
|
|
#endif
|
444 |
|
|
|
445 |
|
|
// memory access type (read/write/execute/rw)
|
446 |
|
|
#define BX_READ 0
|
447 |
|
|
#define BX_WRITE 1
|
448 |
|
|
#define BX_EXECUTE 2
|
449 |
|
|
#define BX_RW 3
|
450 |
|
|
|
451 |
|
|
// types of reset
|
452 |
|
|
#define BX_RESET_SOFTWARE 10
|
453 |
|
|
#define BX_RESET_HARDWARE 11
|
454 |
|
|
|
455 |
|
|
#include "memory/memory.h"
|
456 |
|
|
#include "pc_system.h"
|
457 |
|
|
#include "gui/gui.h"
|
458 |
|
|
|
459 |
|
|
/* --- EXTERNS --- */
|
460 |
|
|
|
461 |
|
|
#if BX_GUI_SIGHANDLER
|
462 |
|
|
extern bx_bool bx_gui_sighandler;
|
463 |
|
|
#endif
|
464 |
|
|
|
465 |
|
|
// This value controls how often each I/O device's timer handler
|
466 |
|
|
// gets called. The timer is set up in iodev/devices.cc.
|
467 |
|
|
#define BX_IODEV_HANDLER_PERIOD 1000 // microseconds
|
468 |
|
|
|
469 |
|
|
#define BX_PATHNAME_LEN 512
|
470 |
|
|
|
471 |
|
|
#define BX_KBD_XT_TYPE 0
|
472 |
|
|
#define BX_KBD_AT_TYPE 1
|
473 |
|
|
#define BX_KBD_MF_TYPE 2
|
474 |
|
|
|
475 |
|
|
#define BX_N_OPTROM_IMAGES 4
|
476 |
|
|
#define BX_N_OPTRAM_IMAGES 4
|
477 |
|
|
#define BX_N_SERIAL_PORTS 4
|
478 |
|
|
#define BX_N_PARALLEL_PORTS 2
|
479 |
|
|
#define BX_N_USB_UHCI_PORTS 2
|
480 |
|
|
#define BX_N_USB_OHCI_PORTS 2
|
481 |
|
|
#define BX_N_USB_XHCI_PORTS 4
|
482 |
|
|
#define BX_N_USB_HUB_PORTS 8
|
483 |
|
|
#define BX_N_PCI_SLOTS 5
|
484 |
|
|
#define BX_N_USER_PLUGINS 8
|
485 |
|
|
|
486 |
|
|
void bx_center_print(FILE *file, const char *line, unsigned maxwidth);
|
487 |
|
|
|
488 |
|
|
#include "instrument.h"
|
489 |
|
|
|
490 |
|
|
BX_CPP_INLINE Bit16u bx_bswap16(Bit16u val16)
|
491 |
|
|
{
|
492 |
|
|
return (val16<<8) | (val16>>8);
|
493 |
|
|
}
|
494 |
|
|
|
495 |
|
|
#if !defined(__MORPHOS__)
|
496 |
|
|
#if BX_HAVE___BUILTIN_BSWAP32
|
497 |
|
|
#define bx_bswap32 __builtin_bswap32
|
498 |
|
|
#else
|
499 |
|
|
BX_CPP_INLINE Bit32u bx_bswap32(Bit32u val32)
|
500 |
|
|
{
|
501 |
|
|
val32 = ((val32<<8) & 0xFF00FF00) | ((val32>>8) & 0x00FF00FF);
|
502 |
|
|
return (val32<<16) | (val32>>16);
|
503 |
|
|
}
|
504 |
|
|
#endif
|
505 |
|
|
|
506 |
|
|
#if BX_HAVE___BUILTIN_BSWAP64
|
507 |
|
|
#define bx_bswap64 __builtin_bswap64
|
508 |
|
|
#else
|
509 |
|
|
BX_CPP_INLINE Bit64u bx_bswap64(Bit64u val64)
|
510 |
|
|
{
|
511 |
|
|
Bit32u lo = bx_bswap32((Bit32u)(val64 >> 32));
|
512 |
|
|
Bit32u hi = bx_bswap32((Bit32u)(val64 & 0xFFFFFFFF));
|
513 |
|
|
return ((Bit64u)hi << 32) | (Bit64u)lo;
|
514 |
|
|
}
|
515 |
|
|
#endif
|
516 |
|
|
#endif // !MorphOS
|
517 |
|
|
|
518 |
|
|
// These are some convenience macros which abstract out accesses between
|
519 |
|
|
// a variable in native byte ordering to/from guest (x86) memory, which is
|
520 |
|
|
// always in little endian format. You must deal with alignment (if your
|
521 |
|
|
// system cares) and endian rearranging. Don't assume anything. You could
|
522 |
|
|
// put some platform specific asm() statements here, to make use of native
|
523 |
|
|
// instructions to help perform these operations more efficiently than C++.
|
524 |
|
|
|
525 |
|
|
#ifdef BX_LITTLE_ENDIAN
|
526 |
|
|
|
527 |
|
|
#define WriteHostWordToLittleEndian(hostPtr, nativeVar16) \
|
528 |
|
|
*((Bit16u*)(hostPtr)) = (nativeVar16)
|
529 |
|
|
#define WriteHostDWordToLittleEndian(hostPtr, nativeVar32) \
|
530 |
|
|
*((Bit32u*)(hostPtr)) = (nativeVar32)
|
531 |
|
|
#define WriteHostQWordToLittleEndian(hostPtr, nativeVar64) \
|
532 |
|
|
*((Bit64u*)(hostPtr)) = (nativeVar64)
|
533 |
|
|
|
534 |
|
|
#define ReadHostWordFromLittleEndian(hostPtr, nativeVar16) \
|
535 |
|
|
(nativeVar16) = *((Bit16u*)(hostPtr))
|
536 |
|
|
#define ReadHostDWordFromLittleEndian(hostPtr, nativeVar32) \
|
537 |
|
|
(nativeVar32) = *((Bit32u*)(hostPtr))
|
538 |
|
|
#define ReadHostQWordFromLittleEndian(hostPtr, nativeVar64) \
|
539 |
|
|
(nativeVar64) = *((Bit64u*)(hostPtr))
|
540 |
|
|
|
541 |
|
|
#else
|
542 |
|
|
|
543 |
|
|
#ifdef __MORPHOS__
|
544 |
|
|
|
545 |
|
|
#define bx_bswap16 bx_ppc_bswap16
|
546 |
|
|
#define bx_bswap32 bx_ppc_bswap32
|
547 |
|
|
#define bx_bswap64 bx_ppc_bswap64
|
548 |
|
|
|
549 |
|
|
#define WriteHostWordToLittleEndian(hostPtr, nativeVar16) { \
|
550 |
|
|
bx_ppc_store_le16((Bit16u *)(hostPtr), (Bit16u)(nativeVar16)); \
|
551 |
|
|
}
|
552 |
|
|
#define WriteHostDWordToLittleEndian(hostPtr, nativeVar32) { \
|
553 |
|
|
bx_ppc_store_le32((Bit32u *)(hostPtr), (Bit32u)(nativeVar32)); \
|
554 |
|
|
}
|
555 |
|
|
#define WriteHostQWordToLittleEndian(hostPtr, nativeVar64) { \
|
556 |
|
|
bx_ppc_store_le64((Bit64u *)(hostPtr), (Bit64u)(nativeVar64)); \
|
557 |
|
|
}
|
558 |
|
|
|
559 |
|
|
#define ReadHostWordFromLittleEndian(hostPtr, nativeVar16) { \
|
560 |
|
|
(nativeVar16) = bx_ppc_load_le16((Bit16u *)(hostPtr)); \
|
561 |
|
|
}
|
562 |
|
|
#define ReadHostDWordFromLittleEndian(hostPtr, nativeVar32) { \
|
563 |
|
|
(nativeVar32) = bx_ppc_load_le32((Bit32u *)(hostPtr)); \
|
564 |
|
|
}
|
565 |
|
|
#define ReadHostQWordFromLittleEndian(hostPtr, nativeVar64) { \
|
566 |
|
|
(nativeVar64) = bx_ppc_load_le64((Bit64u *)(hostPtr)); \
|
567 |
|
|
}
|
568 |
|
|
|
569 |
|
|
#else
|
570 |
|
|
|
571 |
|
|
#define WriteHostWordToLittleEndian(hostPtr, nativeVar16) { \
|
572 |
|
|
*(Bit16u *)(hostPtr) = bx_bswap16((Bit16u)(nativeVar16)); \
|
573 |
|
|
}
|
574 |
|
|
#define WriteHostDWordToLittleEndian(hostPtr, nativeVar32) { \
|
575 |
|
|
*(Bit32u *)(hostPtr) = bx_bswap32((Bit32u)(nativeVar32)); \
|
576 |
|
|
}
|
577 |
|
|
#define WriteHostQWordToLittleEndian(hostPtr, nativeVar64) { \
|
578 |
|
|
*(Bit64u *)(hostPtr) = bx_bswap64((Bit64u)(nativeVar64)); \
|
579 |
|
|
}
|
580 |
|
|
|
581 |
|
|
#define ReadHostWordFromLittleEndian(hostPtr, nativeVar16) { \
|
582 |
|
|
(nativeVar16) = bx_bswap16(*(Bit16u *)(hostPtr)); \
|
583 |
|
|
}
|
584 |
|
|
#define ReadHostDWordFromLittleEndian(hostPtr, nativeVar32) { \
|
585 |
|
|
(nativeVar32) = bx_bswap32(*(Bit32u *)(hostPtr)); \
|
586 |
|
|
}
|
587 |
|
|
#define ReadHostQWordFromLittleEndian(hostPtr, nativeVar64) { \
|
588 |
|
|
(nativeVar64) = bx_bswap64(*(Bit64u *)(hostPtr)); \
|
589 |
|
|
}
|
590 |
|
|
|
591 |
|
|
#endif
|
592 |
|
|
|
593 |
|
|
#endif
|
594 |
|
|
|
595 |
|
|
#define CopyHostWordLittleEndian(hostAddrDst, hostAddrSrc) \
|
596 |
|
|
(* (Bit16u *)(hostAddrDst)) = (* (Bit16u *)(hostAddrSrc));
|
597 |
|
|
#define CopyHostDWordLittleEndian(hostAddrDst, hostAddrSrc) \
|
598 |
|
|
(* (Bit32u *)(hostAddrDst)) = (* (Bit32u *)(hostAddrSrc));
|
599 |
|
|
#define CopyHostQWordLittleEndian(hostAddrDst, hostAddrSrc) \
|
600 |
|
|
(* (Bit64u *)(hostAddrDst)) = (* (Bit64u *)(hostAddrSrc));
|
601 |
|
|
|
602 |
|
|
#endif /* BX_BOCHS_H */
|