2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2021-01-24 13:16:22 +03:00
|
|
|
// Copyright (C) 2001-2021 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2010-02-12 01:12:17 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-04-10 05:58:07 +04:00
|
|
|
//
|
2008-02-06 01:57:43 +03:00
|
|
|
// bochs.h is the master header file for all C++ code. It includes all
|
2001-04-10 05:58:07 +04:00
|
|
|
// the system header files needed by bochs, and also includes all the bochs
|
2008-02-06 01:57:43 +03:00
|
|
|
// C++ header files. Because bochs.h and the files that it includes has
|
2001-04-10 05:58:07 +04:00
|
|
|
// structure and class definitions, it cannot be called from C code.
|
2008-02-06 01:57:43 +03:00
|
|
|
//
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#ifndef BX_BOCHS_H
|
|
|
|
# define BX_BOCHS_H 1
|
|
|
|
|
2001-09-27 03:33:14 +04:00
|
|
|
#include "config.h" /* generated by configure script from config.h.in */
|
|
|
|
|
2004-11-22 16:14:54 +03:00
|
|
|
#ifndef __QNXNTO__
|
2001-04-10 05:04:59 +04:00
|
|
|
extern "C" {
|
2004-11-22 16:14:54 +03:00
|
|
|
#endif
|
2002-10-04 01:07:04 +04:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
// In a win32 compile (including cygwin), windows.h is required for several
|
|
|
|
// files in gui and iodev. It is important to include it here in a header
|
|
|
|
// file so that WIN32-specific data types can be used in fields of classes.
|
2014-02-15 04:23:36 +04:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2002-10-04 01:07:04 +04:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2006-10-31 22:26:34 +03:00
|
|
|
#if defined(__sun__)
|
|
|
|
#undef EAX
|
|
|
|
#undef ECX
|
|
|
|
#undef EDX
|
|
|
|
#undef EBX
|
|
|
|
#undef ESP
|
|
|
|
#undef EBP
|
|
|
|
#undef ESI
|
|
|
|
#undef EDI
|
|
|
|
#undef EIP
|
|
|
|
#undef CS
|
|
|
|
#undef DS
|
|
|
|
#undef ES
|
|
|
|
#undef SS
|
|
|
|
#undef FS
|
|
|
|
#undef GS
|
|
|
|
#endif
|
2001-06-08 00:31:20 +04:00
|
|
|
#include <assert.h>
|
2003-05-03 20:37:18 +04:00
|
|
|
#include <errno.h>
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
# include <unistd.h>
|
|
|
|
#else
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
#include <time.h>
|
2001-09-26 04:11:23 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-04-10 05:04:59 +04:00
|
|
|
# include <types.h>
|
|
|
|
# include <stat.h>
|
2002-12-12 18:29:45 +03:00
|
|
|
# include <cstdio>
|
|
|
|
# include <unistd.h>
|
2001-09-26 04:11:23 +04:00
|
|
|
#elif BX_WITH_CARBON
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <sys/param.h> /* for MAXPATHLEN */
|
2007-12-20 21:32:14 +03:00
|
|
|
# include <sys/time.h>
|
2001-04-10 05:04:59 +04:00
|
|
|
# include <utime.h>
|
|
|
|
#else
|
|
|
|
# ifndef WIN32
|
|
|
|
# include <sys/time.h>
|
|
|
|
# endif
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
2003-08-04 20:03:09 +04:00
|
|
|
#include <limits.h>
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef macintosh
|
|
|
|
# define SuperDrive "[fd:]"
|
|
|
|
#endif
|
2004-11-22 16:14:54 +03:00
|
|
|
|
|
|
|
#ifndef __QNXNTO__
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-22 16:14:54 +03:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-02-06 01:57:43 +03:00
|
|
|
#include "osdep.h" /* platform dependent includes and defines */
|
2006-09-26 23:16:10 +04:00
|
|
|
#include "bx_debug/debug.h"
|
2001-06-08 11:20:07 +04:00
|
|
|
#include "gui/siminterface.h"
|
|
|
|
|
2005-07-31 19:35:01 +04:00
|
|
|
// BX_SHARE_PATH should be defined by the makefile. If not, give it
|
|
|
|
// a value of NULL to avoid compile problems.
|
|
|
|
#ifndef BX_SHARE_PATH
|
|
|
|
#define BX_SHARE_PATH NULL
|
|
|
|
#endif
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
// prototypes
|
2011-12-25 12:52:34 +04:00
|
|
|
int bx_begin_simulation(int argc, char *argv[]);
|
2006-03-12 01:40:32 +03:00
|
|
|
void bx_stop_simulation();
|
|
|
|
char *bx_find_bochsrc(void);
|
2017-04-22 13:17:54 +03:00
|
|
|
const char *get_builtin_variable(const char *varname);
|
2011-12-25 12:52:34 +04:00
|
|
|
int bx_parse_cmdline(int arg, int argc, char *argv[]);
|
|
|
|
int bx_read_configuration(const char *rcfile);
|
|
|
|
int bx_write_configuration(const char *rcfile, int overwrite);
|
2012-01-07 18:14:53 +04:00
|
|
|
void bx_reset_options(void);
|
2021-01-30 18:16:00 +03:00
|
|
|
void bx_set_log_actions_by_device(bool panic_flag);
|
2012-01-07 18:14:53 +04:00
|
|
|
// special config parameter and options functions for plugins
|
2011-12-25 12:52:34 +04:00
|
|
|
void bx_init_std_nic_options(const char *name, bx_list_c *menu);
|
2012-01-08 16:43:46 +04:00
|
|
|
void bx_init_usb_options(const char *usb_name, const char *pname, int maxports);
|
2013-01-26 22:17:23 +04:00
|
|
|
int bx_parse_param_from_list(const char *context, const char *input, bx_list_c *list);
|
2011-12-25 12:52:34 +04:00
|
|
|
int bx_parse_nic_params(const char *context, const char *param, bx_list_c *base);
|
2021-01-30 18:16:00 +03:00
|
|
|
int bx_parse_usb_port_params(const char *context, bool devopt,
|
2012-01-07 18:14:53 +04:00
|
|
|
const char *param, int maxports, bx_list_c *base);
|
2020-12-03 23:30:10 +03:00
|
|
|
int bx_split_option_list(const char *msg, const char *rawopt, char **argv, int max_argv);
|
2021-01-30 18:16:00 +03:00
|
|
|
int bx_write_param_list(FILE *fp, bx_list_c *base, const char *optname, bool multiline);
|
2012-01-07 18:14:53 +04:00
|
|
|
int bx_write_usb_options(FILE *fp, int maxports, bx_list_c *base);
|
2014-10-14 19:59:10 +04:00
|
|
|
|
2006-01-28 19:16:03 +03:00
|
|
|
Bit32u crc32(const Bit8u *buf, int len);
|
2014-10-14 19:59:10 +04:00
|
|
|
|
|
|
|
// used to print param tree from debugger
|
2021-01-30 18:16:00 +03:00
|
|
|
void print_tree(bx_param_c *node, int level = 0, bool xml = false);
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2014-10-14 19:59:10 +04:00
|
|
|
#if BX_ENABLE_STATISTICS
|
|
|
|
// print statistics
|
|
|
|
void print_statistics_tree(bx_param_c *node, int level = 0);
|
|
|
|
#define INC_STAT(stat) (++(stat))
|
|
|
|
#else
|
|
|
|
#define INC_STAT(stat)
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// some macros to interface the CPU and memory to external environment
|
|
|
|
// so that these functions can be redirected to the debugger when
|
|
|
|
// needed.
|
|
|
|
//
|
|
|
|
|
2007-09-28 23:52:08 +04:00
|
|
|
#define BXRS_PARAM_SPECIAL(parent, name, maxvalue, save_handler, restore_handler) \
|
|
|
|
{ \
|
2006-05-28 21:07:57 +04:00
|
|
|
bx_param_num_c *param = new bx_param_num_c(parent, #name, "", "", 0, maxvalue, 0); \
|
|
|
|
param->set_base(BASE_HEX); \
|
|
|
|
param->set_sr_handlers(this, save_handler, restore_handler); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BXRS_PARAM_SPECIAL64(parent, name, save_handler, restore_handler) \
|
|
|
|
BXRS_PARAM_SPECIAL(parent, name, BX_MAX_BIT64U, save_handler, restore_handler)
|
|
|
|
#define BXRS_PARAM_SPECIAL32(parent, name, save_handler, restore_handler) \
|
|
|
|
BXRS_PARAM_SPECIAL(parent, name, BX_MAX_BIT32U, save_handler, restore_handler)
|
|
|
|
#define BXRS_PARAM_SPECIAL16(parent, name, save_handler, restore_handler) \
|
|
|
|
BXRS_PARAM_SPECIAL(parent, name, BX_MAX_BIT16U, save_handler, restore_handler)
|
|
|
|
#define BXRS_PARAM_SPECIAL8(parent, name, save_handler, restore_handler) \
|
|
|
|
BXRS_PARAM_SPECIAL(parent, name, BX_MAX_BIT8U, save_handler, restore_handler)
|
|
|
|
|
2008-04-18 20:47:45 +04:00
|
|
|
#define BXRS_HEX_PARAM_SIMPLE32(parent, name) \
|
|
|
|
new bx_shadow_num_c(parent, #name, (Bit32u*)&(name), BASE_HEX)
|
|
|
|
#define BXRS_HEX_PARAM_SIMPLE64(parent, name) \
|
|
|
|
new bx_shadow_num_c(parent, #name, (Bit64u*)&(name), BASE_HEX)
|
|
|
|
|
2006-05-28 21:07:57 +04:00
|
|
|
#define BXRS_HEX_PARAM_SIMPLE(parent, name) \
|
|
|
|
new bx_shadow_num_c(parent, #name, &(name), BASE_HEX)
|
|
|
|
#define BXRS_HEX_PARAM_FIELD(parent, name, field) \
|
|
|
|
new bx_shadow_num_c(parent, #name, &(field), BASE_HEX)
|
|
|
|
|
|
|
|
#define BXRS_DEC_PARAM_SIMPLE(parent, name) \
|
|
|
|
new bx_shadow_num_c(parent, #name, &(name), BASE_DEC)
|
|
|
|
#define BXRS_DEC_PARAM_FIELD(parent, name, field) \
|
|
|
|
new bx_shadow_num_c(parent, #name, &(field), BASE_DEC)
|
|
|
|
|
|
|
|
#define BXRS_PARAM_BOOL(parent, name, field) \
|
|
|
|
new bx_shadow_bool_c(parent, #name, (bx_bool*)(&(field)))
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// =-=-=-=-=-=-=- Normal optimized use -=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
// some pc_systems functions just redirect to the IO devices so optimize
|
|
|
|
// by eliminating call here
|
|
|
|
//
|
|
|
|
// #define BX_INP(addr, len) bx_pc_system.inp(addr, len)
|
|
|
|
// #define BX_OUTP(addr, val, len) bx_pc_system.outp(addr, val, len)
|
|
|
|
#define BX_INP(addr, len) bx_devices.inp(addr, len)
|
|
|
|
#define BX_OUTP(addr, val, len) bx_devices.outp(addr, val, len)
|
|
|
|
#define BX_TICK1() bx_pc_system.tick1()
|
2001-05-23 12:16:07 +04:00
|
|
|
#define BX_TICKN(n) bx_pc_system.tickn(n)
|
2001-04-10 05:04:59 +04:00
|
|
|
#define BX_INTR bx_pc_system.INTR
|
2012-10-03 19:49:45 +04:00
|
|
|
#define BX_RAISE_INTR() bx_pc_system.raise_INTR()
|
|
|
|
#define BX_CLEAR_INTR() bx_pc_system.clear_INTR()
|
2011-08-31 20:33:12 +04:00
|
|
|
#define BX_HRQ bx_pc_system.HRQ
|
2002-06-16 19:02:28 +04:00
|
|
|
|
2006-01-18 21:35:38 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2001-06-05 21:35:08 +04:00
|
|
|
#define BX_CPU(x) (bx_cpu_array[x])
|
2006-01-18 21:35:38 +03:00
|
|
|
#else
|
|
|
|
#define BX_CPU(x) (&bx_cpu)
|
2006-01-15 22:35:39 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BX_MEM(x) (&bx_mem)
|
2001-06-05 21:35:08 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#define BX_SET_ENABLE_A20(enabled) bx_pc_system.set_enable_a20(enabled)
|
|
|
|
#define BX_GET_ENABLE_A20() bx_pc_system.get_enable_a20()
|
|
|
|
|
2004-10-30 01:15:48 +04:00
|
|
|
#if BX_SUPPORT_A20
|
2008-10-02 10:49:20 +04:00
|
|
|
# define A20ADDR(x) ((bx_phy_address)(x) & bx_pc_system.a20_mask)
|
2004-10-30 01:15:48 +04:00
|
|
|
#else
|
2008-10-02 10:49:20 +04:00
|
|
|
# define A20ADDR(x) ((bx_phy_address)(x))
|
2004-10-30 01:15:48 +04:00
|
|
|
#endif
|
|
|
|
|
2001-05-23 12:16:07 +04:00
|
|
|
// you can't use static member functions on the CPU, if there are going
|
|
|
|
// to be 2 cpus. Check this early on.
|
2006-01-18 21:35:38 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
|
|
|
# if BX_USE_CPU_SMF
|
2001-05-23 12:16:07 +04:00
|
|
|
# error For SMP simulation, BX_USE_CPU_SMF must be 0.
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// Ways for the the external environment to report back information
|
|
|
|
// to the debugger.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
|
|
|
# define BX_DBG_ASYNC_INTR bx_guard.async.irq
|
|
|
|
# define BX_DBG_ASYNC_DMA bx_guard.async.dma
|
|
|
|
|
|
|
|
# define BX_DBG_DMA_REPORT(addr, len, what, val) \
|
|
|
|
if (bx_guard.report.dma) bx_dbg_dma_report(addr, len, what, val)
|
|
|
|
# define BX_DBG_IAC_REPORT(vector, irq) \
|
|
|
|
if (bx_guard.report.irq) bx_dbg_iac_report(vector, irq)
|
|
|
|
# define BX_DBG_A20_REPORT(val) \
|
|
|
|
if (bx_guard.report.a20) bx_dbg_a20_report(val)
|
2007-10-09 23:49:23 +04:00
|
|
|
# define BX_DBG_IO_REPORT(port, size, op, val) \
|
|
|
|
if (bx_guard.report.io) bx_dbg_io_report(port, size, op, val)
|
2015-02-19 23:23:08 +03:00
|
|
|
# define BX_DBG_LIN_MEMORY_ACCESS(cpu, lin, phy, len, memtype, rw, data) \
|
|
|
|
bx_dbg_lin_memory_access(cpu, lin, phy, len, memtype, rw, data)
|
|
|
|
# define BX_DBG_PHY_MEMORY_ACCESS(cpu, phy, len, memtype, rw, why, data) \
|
|
|
|
bx_dbg_phy_memory_access(cpu, phy, len, memtype, rw, why, data)
|
2001-04-10 05:04:59 +04:00
|
|
|
#else // #if BX_DEBUGGER
|
|
|
|
// debugger not compiled in, use empty stubs
|
|
|
|
# define BX_DBG_ASYNC_INTR 1
|
|
|
|
# define BX_DBG_ASYNC_DMA 1
|
2015-02-19 23:23:08 +03:00
|
|
|
# define BX_DBG_DMA_REPORT(addr, len, what, val) /* empty */
|
|
|
|
# define BX_DBG_IAC_REPORT(vector, irq) /* empty */
|
|
|
|
# define BX_DBG_A20_REPORT(val) /* empty */
|
|
|
|
# define BX_DBG_IO_REPORT(port, size, op, val) /* empty */
|
|
|
|
# define BX_DBG_LIN_MEMORY_ACCESS(cpu, lin, phy, len, memtype, rw, data) /* empty */
|
|
|
|
# define BX_DBG_PHY_MEMORY_ACCESS(cpu, phy, len, memtype, rw, attr, data) /* empty */
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif // #if BX_DEBUGGER
|
|
|
|
|
2021-01-30 21:05:55 +03:00
|
|
|
#include "logio.h"
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#ifndef UNUSED
|
|
|
|
# define UNUSED(x) ((void)x)
|
|
|
|
#endif
|
|
|
|
|
2011-03-16 01:18:40 +03:00
|
|
|
//Generic MAX and MIN Functions
|
|
|
|
#define BX_MAX(a,b) ((a) > (b) ? (a) : (b))
|
|
|
|
#define BX_MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
2005-01-13 22:03:40 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
2006-01-19 21:32:39 +03:00
|
|
|
#define FMT_ADDRX FMT_ADDRX64
|
2005-01-13 22:03:40 +03:00
|
|
|
#else
|
2006-01-19 21:32:39 +03:00
|
|
|
#define FMT_ADDRX FMT_ADDRX32
|
2005-01-13 22:03:40 +03:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-11 00:39:53 +04:00
|
|
|
#if BX_PHY_ADDRESS_LONG
|
2013-02-13 01:26:23 +04:00
|
|
|
#define FMT_PHY_ADDRX FMT_PHY_ADDRX64
|
2008-05-11 00:39:53 +04:00
|
|
|
#else
|
|
|
|
#define FMT_PHY_ADDRX FMT_ADDRX32
|
|
|
|
#endif
|
|
|
|
|
2008-05-10 02:33:37 +04:00
|
|
|
#define FMT_LIN_ADDRX FMT_ADDRX
|
|
|
|
|
2002-10-03 09:29:15 +04:00
|
|
|
#if BX_GDBSTUB
|
|
|
|
// defines for GDB stub
|
2006-10-26 21:27:04 +04:00
|
|
|
void bx_gdbstub_init(void);
|
2006-10-29 11:48:30 +03:00
|
|
|
void bx_gdbstub_break(void);
|
2002-10-03 09:29:15 +04:00
|
|
|
int bx_gdbstub_check(unsigned int eip);
|
|
|
|
#define GDBSTUB_STOP_NO_REASON (0xac0)
|
2002-10-22 16:50:56 +04:00
|
|
|
|
2006-01-18 21:35:38 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2002-10-22 16:50:56 +04:00
|
|
|
#error GDB stub was written for single processor support. If multiprocessor support is added, then we can remove this check.
|
|
|
|
// The big problem is knowing which CPU gdb is referring to. In other words,
|
|
|
|
// what should we put for "n" in BX_CPU(n)->dbg_xlate_linear2phy() and
|
|
|
|
// BX_CPU(n)->dword.eip, etc.
|
|
|
|
#endif
|
2002-10-03 09:29:15 +04:00
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
typedef struct {
|
2021-01-30 18:16:00 +03:00
|
|
|
bool interrupts;
|
|
|
|
bool exceptions;
|
|
|
|
bool print_timestamps;
|
2008-01-22 00:36:58 +03:00
|
|
|
#if BX_DEBUGGER
|
2021-01-30 18:16:00 +03:00
|
|
|
bool magic_break_enabled;
|
2007-10-13 02:11:25 +04:00
|
|
|
#endif
|
2005-03-16 19:36:31 +03:00
|
|
|
#if BX_GDBSTUB
|
2021-01-30 18:16:00 +03:00
|
|
|
bool gdbstub_enabled;
|
2004-11-06 13:50:03 +03:00
|
|
|
#endif
|
2001-06-12 17:07:43 +04:00
|
|
|
#if BX_SUPPORT_APIC
|
2021-01-30 18:16:00 +03:00
|
|
|
bool apic;
|
2001-05-23 12:16:07 +04:00
|
|
|
#endif
|
|
|
|
#if BX_DEBUG_LINUX
|
2021-01-30 18:16:00 +03:00
|
|
|
bool linux_syscall;
|
2001-05-23 12:16:07 +04:00
|
|
|
#endif
|
2008-02-08 00:08:55 +03:00
|
|
|
} bx_debug_t;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2012-08-26 16:32:10 +04:00
|
|
|
#if BX_SHOW_IPS
|
|
|
|
BOCHSAPI_MSVCONLY void bx_show_ips_handler(void);
|
|
|
|
#endif
|
|
|
|
void CDECL bx_signal_handler(int signum);
|
2002-04-18 04:22:20 +04:00
|
|
|
int bx_atexit(void);
|
2002-10-25 01:07:56 +04:00
|
|
|
BOCHSAPI extern bx_debug_t bx_dbg;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-04-21 17:27:42 +04:00
|
|
|
#if BX_SUPPORT_APIC
|
2010-05-15 13:23:50 +04:00
|
|
|
// determinted by XAPIC option
|
|
|
|
BOCHSAPI extern Bit32u apic_id_mask;
|
2011-04-21 17:27:42 +04:00
|
|
|
#endif
|
2010-05-15 13:23:50 +04:00
|
|
|
|
2008-12-06 01:34:42 +03:00
|
|
|
// memory access type (read/write/execute/rw)
|
2019-12-20 10:42:07 +03:00
|
|
|
enum {
|
|
|
|
BX_READ = 0,
|
|
|
|
BX_WRITE = 1,
|
|
|
|
BX_EXECUTE = 2,
|
|
|
|
BX_RW = 3,
|
|
|
|
#if BX_SUPPORT_CET
|
|
|
|
BX_SHADOW_STACK_READ = 4,
|
|
|
|
BX_SHADOW_STACK_WRITE = 5,
|
|
|
|
BX_SHADOW_STACK_INVALID = 6, // can't execute shadow stack
|
|
|
|
BX_SHADOW_STACK_RW = 7,
|
|
|
|
#endif
|
|
|
|
};
|
2004-12-17 01:21:35 +03:00
|
|
|
|
2009-11-15 23:50:41 +03:00
|
|
|
// types of reset
|
|
|
|
#define BX_RESET_SOFTWARE 10
|
|
|
|
#define BX_RESET_HARDWARE 11
|
|
|
|
|
2016-08-12 20:06:14 +03:00
|
|
|
#include "memory/memory-bochs.h"
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "pc_system.h"
|
|
|
|
#include "gui/gui.h"
|
|
|
|
|
|
|
|
/* --- EXTERNS --- */
|
|
|
|
|
2002-11-11 20:09:57 +03:00
|
|
|
#if BX_GUI_SIGHANDLER
|
2021-01-30 18:16:00 +03:00
|
|
|
extern bool bx_gui_sighandler;
|
2002-11-11 20:09:57 +03:00
|
|
|
#endif
|
|
|
|
|
2012-10-30 21:25:33 +04:00
|
|
|
// This value controls how often each I/O device's timer handler
|
2002-03-26 16:59:35 +03:00
|
|
|
// gets called. The timer is set up in iodev/devices.cc.
|
2012-10-30 21:25:33 +04:00
|
|
|
#define BX_IODEV_HANDLER_PERIOD 1000 // microseconds
|
2001-06-10 00:01:12 +04:00
|
|
|
|
2001-06-08 11:20:07 +04:00
|
|
|
#define BX_PATHNAME_LEN 512
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-12-12 13:43:36 +03:00
|
|
|
#define BX_KBD_XT_TYPE 0
|
|
|
|
#define BX_KBD_AT_TYPE 1
|
2008-02-06 01:57:43 +03:00
|
|
|
#define BX_KBD_MF_TYPE 2
|
2001-12-12 13:43:36 +03:00
|
|
|
|
2002-09-03 12:34:17 +04:00
|
|
|
#define BX_N_OPTROM_IMAGES 4
|
2006-02-17 00:44:17 +03:00
|
|
|
#define BX_N_OPTRAM_IMAGES 4
|
2004-01-18 03:18:44 +03:00
|
|
|
#define BX_N_SERIAL_PORTS 4
|
2004-01-28 00:38:51 +03:00
|
|
|
#define BX_N_PARALLEL_PORTS 2
|
2004-06-29 23:24:34 +04:00
|
|
|
#define BX_N_PCI_SLOTS 5
|
2002-09-03 12:34:17 +04:00
|
|
|
|
2008-01-01 21:12:31 +03:00
|
|
|
void bx_center_print(FILE *file, const char *line, unsigned maxwidth);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#include "instrument.h"
|
|
|
|
|
2011-12-29 02:43:18 +04:00
|
|
|
BX_CPP_INLINE Bit16u bx_bswap16(Bit16u val16)
|
|
|
|
{
|
|
|
|
return (val16<<8) | (val16>>8);
|
|
|
|
}
|
|
|
|
|
2013-05-24 21:58:49 +04:00
|
|
|
#if !defined(__MORPHOS__)
|
2011-12-29 02:43:18 +04:00
|
|
|
#if BX_HAVE___BUILTIN_BSWAP32
|
|
|
|
#define bx_bswap32 __builtin_bswap32
|
|
|
|
#else
|
|
|
|
BX_CPP_INLINE Bit32u bx_bswap32(Bit32u val32)
|
|
|
|
{
|
|
|
|
val32 = ((val32<<8) & 0xFF00FF00) | ((val32>>8) & 0x00FF00FF);
|
|
|
|
return (val32<<16) | (val32>>16);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_HAVE___BUILTIN_BSWAP64
|
|
|
|
#define bx_bswap64 __builtin_bswap64
|
|
|
|
#else
|
|
|
|
BX_CPP_INLINE Bit64u bx_bswap64(Bit64u val64)
|
|
|
|
{
|
|
|
|
Bit32u lo = bx_bswap32((Bit32u)(val64 >> 32));
|
|
|
|
Bit32u hi = bx_bswap32((Bit32u)(val64 & 0xFFFFFFFF));
|
|
|
|
return ((Bit64u)hi << 32) | (Bit64u)lo;
|
|
|
|
}
|
|
|
|
#endif
|
2013-05-24 21:58:49 +04:00
|
|
|
#endif // !MorphOS
|
2011-12-29 02:43:18 +04:00
|
|
|
|
2002-09-05 08:56:11 +04:00
|
|
|
// These are some convenience macros which abstract out accesses between
|
|
|
|
// a variable in native byte ordering to/from guest (x86) memory, which is
|
|
|
|
// always in little endian format. You must deal with alignment (if your
|
|
|
|
// system cares) and endian rearranging. Don't assume anything. You could
|
|
|
|
// put some platform specific asm() statements here, to make use of native
|
|
|
|
// instructions to help perform these operations more efficiently than C++.
|
|
|
|
|
2007-10-16 20:17:48 +04:00
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
2002-09-05 08:56:11 +04:00
|
|
|
|
2019-10-16 23:19:34 +03:00
|
|
|
BX_CPP_INLINE void WriteHostWordToLittleEndian(Bit16u *hostPtr, Bit16u nativeVar16)
|
|
|
|
{
|
|
|
|
*(hostPtr) = nativeVar16;
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE void WriteHostDWordToLittleEndian(Bit32u *hostPtr, Bit32u nativeVar32)
|
|
|
|
{
|
|
|
|
*(hostPtr) = nativeVar32;
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE void WriteHostQWordToLittleEndian(Bit64u *hostPtr, Bit64u nativeVar64)
|
|
|
|
{
|
2016-08-12 20:06:14 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
// Resolve problems with unaligned access
|
2019-10-16 23:19:34 +03:00
|
|
|
((Bit8u *)(hostPtr))[0] = (Bit8u) (nativeVar64);
|
|
|
|
((Bit8u *)(hostPtr))[1] = (Bit8u) ((nativeVar64)>>8);
|
|
|
|
((Bit8u *)(hostPtr))[2] = (Bit8u) ((nativeVar64)>>16);
|
|
|
|
((Bit8u *)(hostPtr))[3] = (Bit8u) ((nativeVar64)>>24);
|
|
|
|
((Bit8u *)(hostPtr))[4] = (Bit8u) ((nativeVar64)>>32);
|
|
|
|
((Bit8u *)(hostPtr))[5] = (Bit8u) ((nativeVar64)>>40);
|
|
|
|
((Bit8u *)(hostPtr))[6] = (Bit8u) ((nativeVar64)>>48);
|
|
|
|
((Bit8u *)(hostPtr))[7] = (Bit8u) ((nativeVar64)>>56);
|
2016-08-12 20:06:14 +03:00
|
|
|
#else
|
2019-10-16 23:19:34 +03:00
|
|
|
*(hostPtr) = nativeVar64;
|
2016-08-12 20:06:14 +03:00
|
|
|
#endif
|
2019-10-16 23:19:34 +03:00
|
|
|
}
|
|
|
|
|
2019-10-16 23:46:00 +03:00
|
|
|
BX_CPP_INLINE Bit16u ReadHostWordFromLittleEndian(Bit16u *hostPtr)
|
|
|
|
{
|
|
|
|
return *(hostPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE Bit32u ReadHostDWordFromLittleEndian(Bit32u *hostPtr)
|
|
|
|
{
|
|
|
|
return *(hostPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE Bit64u ReadHostQWordFromLittleEndian(Bit64u *hostPtr)
|
|
|
|
{
|
2016-08-12 20:06:14 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
// Resolve problems with unaligned access
|
2019-10-16 23:46:00 +03:00
|
|
|
Bit64u nativeVar64 = ((Bit64u) ((Bit8u *)(hostPtr))[0]) |
|
|
|
|
(((Bit64u) ((Bit8u *)(hostPtr))[1])<<8) |
|
|
|
|
(((Bit64u) ((Bit8u *)(hostPtr))[2])<<16) |
|
|
|
|
(((Bit64u) ((Bit8u *)(hostPtr))[3])<<24) |
|
|
|
|
(((Bit64u) ((Bit8u *)(hostPtr))[4])<<32) |
|
|
|
|
(((Bit64u) ((Bit8u *)(hostPtr))[5])<<40) |
|
|
|
|
(((Bit64u) ((Bit8u *)(hostPtr))[6])<<48) |
|
|
|
|
(((Bit64u) ((Bit8u *)(hostPtr))[7])<<56);
|
2020-07-19 20:23:29 +03:00
|
|
|
return nativeVar64;
|
2016-08-12 20:06:14 +03:00
|
|
|
#else
|
2019-10-16 23:46:00 +03:00
|
|
|
return *(hostPtr);
|
2016-08-12 20:06:14 +03:00
|
|
|
#endif
|
2019-10-16 23:46:00 +03:00
|
|
|
}
|
2002-09-05 08:56:11 +04:00
|
|
|
|
2019-10-16 23:46:00 +03:00
|
|
|
#else // !BX_LITTLE_ENDIAN
|
2002-09-05 08:56:11 +04:00
|
|
|
|
2013-05-24 21:58:49 +04:00
|
|
|
#ifdef __MORPHOS__
|
|
|
|
|
|
|
|
#define bx_bswap16 bx_ppc_bswap16
|
|
|
|
#define bx_bswap32 bx_ppc_bswap32
|
|
|
|
#define bx_bswap64 bx_ppc_bswap64
|
|
|
|
|
2019-10-16 23:19:34 +03:00
|
|
|
BX_CPP_INLINE void WriteHostWordToLittleEndian(Bit16u *hostPtr, Bit16u nativeVar16)
|
|
|
|
{
|
|
|
|
bx_ppc_store_le16(hostPtr, nativeVar16);
|
2013-05-24 21:58:49 +04:00
|
|
|
}
|
2019-10-16 23:19:34 +03:00
|
|
|
|
|
|
|
BX_CPP_INLINE void WriteHostDWordToLittleEndian(Bit32u *hostPtr, Bit32u nativeVar32)
|
|
|
|
{
|
|
|
|
bx_ppc_store_le32(hostPtr, nativeVar32);
|
2013-05-24 21:58:49 +04:00
|
|
|
}
|
2019-10-16 23:19:34 +03:00
|
|
|
|
|
|
|
BX_CPP_INLINE void WriteHostQWordToLittleEndian(Bit64u *hostPtr, Bit64u nativeVar64)
|
|
|
|
{
|
|
|
|
bx_ppc_store_le64(hostPtr, nativeVar64);
|
2013-05-24 21:58:49 +04:00
|
|
|
}
|
|
|
|
|
2019-10-16 23:46:00 +03:00
|
|
|
BX_CPP_INLINE Bit16u ReadHostWordFromLittleEndian(Bit16u *hostPtr)
|
|
|
|
{
|
|
|
|
return bx_ppc_load_le16(hostPtr);
|
2013-05-24 21:58:49 +04:00
|
|
|
}
|
2019-10-16 23:46:00 +03:00
|
|
|
|
|
|
|
BX_CPP_INLINE Bit32u ReadHostDWordFromLittleEndian(Bit32u *hostPtr)
|
|
|
|
{
|
|
|
|
return bx_ppc_load_le32(hostPtr);
|
2013-05-24 21:58:49 +04:00
|
|
|
}
|
2019-10-16 23:46:00 +03:00
|
|
|
|
|
|
|
BX_CPP_INLINE Bit64u ReadHostQWordFromLittleEndian(Bit64u *hostPtr)
|
|
|
|
{
|
|
|
|
return bx_ppc_load_le64(hostPtr);
|
2013-05-24 21:58:49 +04:00
|
|
|
}
|
|
|
|
|
2019-10-16 23:19:34 +03:00
|
|
|
#else // !__MORPHOS__
|
2013-05-24 21:58:49 +04:00
|
|
|
|
2019-10-16 23:19:34 +03:00
|
|
|
BX_CPP_INLINE void WriteHostWordToLittleEndian(Bit16u *hostPtr, Bit16u nativeVar16)
|
|
|
|
{
|
|
|
|
*(hostPtr) = bx_bswap16(nativeVar16);
|
2008-02-07 23:43:13 +03:00
|
|
|
}
|
2019-10-16 23:19:34 +03:00
|
|
|
|
2019-12-07 09:10:30 +03:00
|
|
|
BX_CPP_INLINE void WriteHostDWordToLittleEndian(Bit32u *hostPtr, Bit32u nativeVar32)
|
2019-10-16 23:19:34 +03:00
|
|
|
{
|
|
|
|
*(hostPtr) = bx_bswap32(nativeVar32);
|
2008-02-07 23:43:13 +03:00
|
|
|
}
|
2019-10-16 23:19:34 +03:00
|
|
|
|
2019-12-07 09:10:30 +03:00
|
|
|
BX_CPP_INLINE void WriteHostQWordToLittleEndian(Bit64u *hostPtr, Bit64u nativeVar64)
|
2019-10-16 23:19:34 +03:00
|
|
|
{
|
|
|
|
*(hostPtr) = bx_bswap64(nativeVar64);
|
2008-02-07 23:43:13 +03:00
|
|
|
}
|
|
|
|
|
2019-10-16 23:46:00 +03:00
|
|
|
BX_CPP_INLINE Bit16u ReadHostWordFromLittleEndian(Bit16u *hostPtr)
|
|
|
|
{
|
|
|
|
return bx_bswap16(*hostPtr);
|
2008-02-07 23:43:13 +03:00
|
|
|
}
|
2019-10-16 23:46:00 +03:00
|
|
|
|
|
|
|
BX_CPP_INLINE Bit32u ReadHostDWordFromLittleEndian(Bit32u *hostPtr)
|
|
|
|
{
|
|
|
|
return bx_bswap32(*hostPtr);
|
2008-02-07 23:43:13 +03:00
|
|
|
}
|
2019-10-16 23:46:00 +03:00
|
|
|
|
|
|
|
BX_CPP_INLINE Bit64u ReadHostQWordFromLittleEndian(Bit64u *hostPtr)
|
|
|
|
{
|
|
|
|
return bx_bswap64(*hostPtr);
|
2008-02-07 23:43:13 +03:00
|
|
|
}
|
|
|
|
|
2002-09-05 08:56:11 +04:00
|
|
|
#endif
|
|
|
|
|
2013-05-24 21:58:49 +04:00
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif /* BX_BOCHS_H */
|