45e9809aff7304721fddb95654901b32195c9c7avboxsync/****************************************************************************
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Realmode X86 Emulator Library
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Copyright (C) 1996-1999 SciTech Software, Inc.
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Copyright (C) David Mosberger-Tang
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Copyright (C) 1999 Egbert Eich
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync* ========================================================================
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Permission to use, copy, modify, distribute, and sell this software and
45e9809aff7304721fddb95654901b32195c9c7avboxsync* its documentation for any purpose is hereby granted without fee,
45e9809aff7304721fddb95654901b32195c9c7avboxsync* provided that the above copyright notice appear in all copies and that
45e9809aff7304721fddb95654901b32195c9c7avboxsync* both that copyright notice and this permission notice appear in
45e9809aff7304721fddb95654901b32195c9c7avboxsync* supporting documentation, and that the name of the authors not be used
45e9809aff7304721fddb95654901b32195c9c7avboxsync* in advertising or publicity pertaining to distribution of the software
45e9809aff7304721fddb95654901b32195c9c7avboxsync* without specific, written prior permission. The authors makes no
45e9809aff7304721fddb95654901b32195c9c7avboxsync* representations about the suitability of this software for any purpose.
45e9809aff7304721fddb95654901b32195c9c7avboxsync* It is provided "as is" without express or implied warranty.
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
45e9809aff7304721fddb95654901b32195c9c7avboxsync* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
45e9809aff7304721fddb95654901b32195c9c7avboxsync* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
45e9809aff7304721fddb95654901b32195c9c7avboxsync* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
45e9809aff7304721fddb95654901b32195c9c7avboxsync* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
45e9809aff7304721fddb95654901b32195c9c7avboxsync* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
45e9809aff7304721fddb95654901b32195c9c7avboxsync* PERFORMANCE OF THIS SOFTWARE.
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync* ========================================================================
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Language: ANSI C
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Environment: Any
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Developer: Kendall Bennett
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Description: Header file for public specific functions.
45e9809aff7304721fddb95654901b32195c9c7avboxsync* Any application linking against us should only
45e9809aff7304721fddb95654901b32195c9c7avboxsync* include this header
45e9809aff7304721fddb95654901b32195c9c7avboxsync*
45e9809aff7304721fddb95654901b32195c9c7avboxsync****************************************************************************/
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifndef __X86EMU_X86EMU_H
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define __X86EMU_X86EMU_H
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifdef SCITECH
45e9809aff7304721fddb95654901b32195c9c7avboxsync#include "scitech.h"
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define X86API _ASMAPI
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define X86APIP _ASMAPIP
45e9809aff7304721fddb95654901b32195c9c7avboxsynctypedef int X86EMU_pioAddr;
45e9809aff7304721fddb95654901b32195c9c7avboxsync#else
45e9809aff7304721fddb95654901b32195c9c7avboxsync#include "x86emu/types.h"
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define X86API
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define X86APIP *
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync#include "x86emu/regs.h"
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/*---------------------- Macros and type definitions ----------------------*/
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifdef PACK
45e9809aff7304721fddb95654901b32195c9c7avboxsync# pragma PACK /* Don't pack structs with function pointers! */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/****************************************************************************
45e9809aff7304721fddb95654901b32195c9c7avboxsyncREMARKS:
45e9809aff7304721fddb95654901b32195c9c7avboxsyncData structure containing ponters to programmed I/O functions used by the
45e9809aff7304721fddb95654901b32195c9c7avboxsyncemulator. This is used so that the user program can hook all programmed
45e9809aff7304721fddb95654901b32195c9c7avboxsyncI/O for the emulator to handled as necessary by the user program. By
45e9809aff7304721fddb95654901b32195c9c7avboxsyncdefault the emulator contains simple functions that do not do access the
45e9809aff7304721fddb95654901b32195c9c7avboxsynchardware in any way. To allow the emualtor access the hardware, you will
45e9809aff7304721fddb95654901b32195c9c7avboxsyncneed to override the programmed I/O functions using the X86EMU_setupPioFuncs
45e9809aff7304721fddb95654901b32195c9c7avboxsyncfunction.
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncHEADER:
45e9809aff7304721fddb95654901b32195c9c7avboxsyncx86emu.h
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncMEMBERS:
45e9809aff7304721fddb95654901b32195c9c7avboxsyncinb - Function to read a byte from an I/O port
45e9809aff7304721fddb95654901b32195c9c7avboxsyncinw - Function to read a word from an I/O port
45e9809aff7304721fddb95654901b32195c9c7avboxsyncinl - Function to read a dword from an I/O port
45e9809aff7304721fddb95654901b32195c9c7avboxsyncoutb - Function to write a byte to an I/O port
45e9809aff7304721fddb95654901b32195c9c7avboxsyncoutw - Function to write a word to an I/O port
45e9809aff7304721fddb95654901b32195c9c7avboxsyncoutl - Function to write a dword to an I/O port
45e9809aff7304721fddb95654901b32195c9c7avboxsync****************************************************************************/
45e9809aff7304721fddb95654901b32195c9c7avboxsynctypedef struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync u8 (X86APIP inb)(X86EMU_pioAddr addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsync u16 (X86APIP inw)(X86EMU_pioAddr addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsync u32 (X86APIP inl)(X86EMU_pioAddr addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsync void (X86APIP outb)(X86EMU_pioAddr addr, u8 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsync void (X86APIP outw)(X86EMU_pioAddr addr, u16 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsync void (X86APIP outl)(X86EMU_pioAddr addr, u32 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsync } X86EMU_pioFuncs;
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/****************************************************************************
45e9809aff7304721fddb95654901b32195c9c7avboxsyncREMARKS:
45e9809aff7304721fddb95654901b32195c9c7avboxsyncData structure containing ponters to memory access functions used by the
45e9809aff7304721fddb95654901b32195c9c7avboxsyncemulator. This is used so that the user program can hook all memory
45e9809aff7304721fddb95654901b32195c9c7avboxsyncaccess functions as necessary for the emulator. By default the emulator
45e9809aff7304721fddb95654901b32195c9c7avboxsynccontains simple functions that only access the internal memory of the
45e9809aff7304721fddb95654901b32195c9c7avboxsyncemulator. If you need specialised functions to handle access to different
45e9809aff7304721fddb95654901b32195c9c7avboxsynctypes of memory (ie: hardware framebuffer accesses and BIOS memory access
45e9809aff7304721fddb95654901b32195c9c7avboxsyncetc), you will need to override this using the X86EMU_setupMemFuncs
45e9809aff7304721fddb95654901b32195c9c7avboxsyncfunction.
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncHEADER:
45e9809aff7304721fddb95654901b32195c9c7avboxsyncx86emu.h
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncMEMBERS:
45e9809aff7304721fddb95654901b32195c9c7avboxsyncrdb - Function to read a byte from an address
45e9809aff7304721fddb95654901b32195c9c7avboxsyncrdw - Function to read a word from an address
45e9809aff7304721fddb95654901b32195c9c7avboxsyncrdl - Function to read a dword from an address
45e9809aff7304721fddb95654901b32195c9c7avboxsyncwrb - Function to write a byte to an address
45e9809aff7304721fddb95654901b32195c9c7avboxsyncwrw - Function to write a word to an address
45e9809aff7304721fddb95654901b32195c9c7avboxsyncwrl - Function to write a dword to an address
45e9809aff7304721fddb95654901b32195c9c7avboxsync****************************************************************************/
45e9809aff7304721fddb95654901b32195c9c7avboxsynctypedef struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync u8 (X86APIP rdb)(u32 addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsync u16 (X86APIP rdw)(u32 addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsync u32 (X86APIP rdl)(u32 addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsync void (X86APIP wrb)(u32 addr, u8 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsync void (X86APIP wrw)(u32 addr, u16 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsync void (X86APIP wrl)(u32 addr, u32 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsync } X86EMU_memFuncs;
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/****************************************************************************
45e9809aff7304721fddb95654901b32195c9c7avboxsync Here are the default memory read and write
45e9809aff7304721fddb95654901b32195c9c7avboxsync function in case they are needed as fallbacks.
45e9809aff7304721fddb95654901b32195c9c7avboxsync***************************************************************************/
45e9809aff7304721fddb95654901b32195c9c7avboxsyncextern u8 X86API rdb(u32 addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncextern u16 X86API rdw(u32 addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncextern u32 X86API rdl(u32 addr);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncextern void X86API wrb(u32 addr, u8 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncextern void X86API wrw(u32 addr, u16 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncextern void X86API wrl(u32 addr, u32 val);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifdef END_PACK
45e9809aff7304721fddb95654901b32195c9c7avboxsync# pragma END_PACK
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/*--------------------- type definitions -----------------------------------*/
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsynctypedef void (X86APIP X86EMU_intrFuncs)(int num);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncextern X86EMU_intrFuncs _X86EMU_intrTab[256];
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/*-------------------------- Function Prototypes --------------------------*/
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifdef __cplusplus
45e9809aff7304721fddb95654901b32195c9c7avboxsyncextern "C" { /* Use "C" linkage when in C++ mode */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_setupMemFuncs(X86EMU_memFuncs *funcs);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_setupPioFuncs(X86EMU_pioFuncs *funcs);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_prepareForInt(int num);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* decode.c */
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_exec(void);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_halt_sys(void);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifdef DEBUG
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define HALT_SYS() \
45e9809aff7304721fddb95654901b32195c9c7avboxsync printk("halt_sys: file %s, line %d\n", __FILE__, __LINE__), \
45e9809aff7304721fddb95654901b32195c9c7avboxsync X86EMU_halt_sys()
45e9809aff7304721fddb95654901b32195c9c7avboxsync#else
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define HALT_SYS() X86EMU_halt_sys()
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* Debug options */
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_DECODE_F 0x000001 /* print decoded instruction */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_TRACE_F 0x000002 /* dump regs before/after execution */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_STEP_F 0x000004
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_DISASSEMBLE_F 0x000008
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_BREAK_F 0x000010
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_SVC_F 0x000020
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_SAVE_IP_CS_F 0x000040
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_FS_F 0x000080
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_PROC_F 0x000100
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_SYSINT_F 0x000200 /* bios system interrupts. */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_TRACECALL_F 0x000400
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_INSTRUMENT_F 0x000800
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_MEM_TRACE_F 0x001000
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_IO_TRACE_F 0x002000
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_TRACECALL_REGS_F 0x004000
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_DECODE_NOPRINT_F 0x008000
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_EXIT 0x010000
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEBUG_SYS_F (DEBUG_SVC_F|DEBUG_FS_F|DEBUG_PROC_F)
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_trace_regs(void);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_trace_xregs(void);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid X86EMU_dump_memory(u16 seg, u16 off, u32 amt);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncint X86EMU_trace_on(void);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncint X86EMU_trace_off(void);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifdef __cplusplus
45e9809aff7304721fddb95654901b32195c9c7avboxsync} /* End of "C" linkage for C++ */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif /* __X86EMU_X86EMU_H */