Home | History | Annotate | Line # | Download | only in libx86emu
x86emu_util.c revision 1.2.4.2
      1  1.2.4.2  matt /*	$NetBSD: x86emu_util.c,v 1.2.4.2 2008/01/09 01:21:38 matt Exp $	*/
      2  1.2.4.2  matt 
      3  1.2.4.2  matt /****************************************************************************
      4  1.2.4.2  matt *
      5  1.2.4.2  matt *  Realmode X86 Emulator Library
      6  1.2.4.2  matt *
      7  1.2.4.2  matt *  Copyright (C) 1996-1999 SciTech Software, Inc.
      8  1.2.4.2  matt *  Copyright (C) David Mosberger-Tang
      9  1.2.4.2  matt *  Copyright (C) 1999 Egbert Eich
     10  1.2.4.2  matt *  Copyright (C) 2007 Joerg Sonnenberger
     11  1.2.4.2  matt *
     12  1.2.4.2  matt *  ========================================================================
     13  1.2.4.2  matt *
     14  1.2.4.2  matt *  Permission to use, copy, modify, distribute, and sell this software and
     15  1.2.4.2  matt *  its documentation for any purpose is hereby granted without fee,
     16  1.2.4.2  matt *  provided that the above copyright notice appear in all copies and that
     17  1.2.4.2  matt *  both that copyright notice and this permission notice appear in
     18  1.2.4.2  matt *  supporting documentation, and that the name of the authors not be used
     19  1.2.4.2  matt *  in advertising or publicity pertaining to distribution of the software
     20  1.2.4.2  matt *  without specific, written prior permission.  The authors makes no
     21  1.2.4.2  matt *  representations about the suitability of this software for any purpose.
     22  1.2.4.2  matt *  It is provided "as is" without express or implied warranty.
     23  1.2.4.2  matt *
     24  1.2.4.2  matt *  THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
     25  1.2.4.2  matt *  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
     26  1.2.4.2  matt *  EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
     27  1.2.4.2  matt *  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
     28  1.2.4.2  matt *  USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
     29  1.2.4.2  matt *  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
     30  1.2.4.2  matt *  PERFORMANCE OF THIS SOFTWARE.
     31  1.2.4.2  matt *
     32  1.2.4.2  matt ****************************************************************************/
     33  1.2.4.2  matt 
     34  1.2.4.2  matt #include <x86emu/x86emu.h>
     35  1.2.4.2  matt #include <x86emu/x86emu_regs.h>
     36  1.2.4.2  matt 
     37  1.2.4.2  matt #include <sys/endian.h>
     38  1.2.4.2  matt #include <sys/null.h>
     39  1.2.4.2  matt 
     40  1.2.4.2  matt /****************************************************************************
     41  1.2.4.2  matt PARAMETERS:
     42  1.2.4.2  matt addr	- Emulator memory address to read
     43  1.2.4.2  matt 
     44  1.2.4.2  matt RETURNS:
     45  1.2.4.2  matt Byte value read from emulator memory.
     46  1.2.4.2  matt 
     47  1.2.4.2  matt REMARKS:
     48  1.2.4.2  matt Reads a byte value from the emulator memory.
     49  1.2.4.2  matt ****************************************************************************/
     50  1.2.4.2  matt static uint8_t
     51  1.2.4.2  matt rdb(struct X86EMU *emu, uint32_t addr)
     52  1.2.4.2  matt {
     53  1.2.4.2  matt 	if (addr > emu->mem_size - 1)
     54  1.2.4.2  matt 		X86EMU_halt_sys(emu);
     55  1.2.4.2  matt 	return emu->mem_base[addr];
     56  1.2.4.2  matt }
     57  1.2.4.2  matt /****************************************************************************
     58  1.2.4.2  matt PARAMETERS:
     59  1.2.4.2  matt addr	- Emulator memory address to read
     60  1.2.4.2  matt 
     61  1.2.4.2  matt RETURNS:
     62  1.2.4.2  matt Word value read from emulator memory.
     63  1.2.4.2  matt 
     64  1.2.4.2  matt REMARKS:
     65  1.2.4.2  matt Reads a word value from the emulator memory.
     66  1.2.4.2  matt ****************************************************************************/
     67  1.2.4.2  matt static uint16_t
     68  1.2.4.2  matt rdw(struct X86EMU *emu, uint32_t addr)
     69  1.2.4.2  matt {
     70  1.2.4.2  matt 	if (addr > emu->mem_size - 2)
     71  1.2.4.2  matt 		X86EMU_halt_sys(emu);
     72  1.2.4.2  matt 	return le16dec(emu->mem_base + addr);
     73  1.2.4.2  matt }
     74  1.2.4.2  matt /****************************************************************************
     75  1.2.4.2  matt PARAMETERS:
     76  1.2.4.2  matt addr	- Emulator memory address to read
     77  1.2.4.2  matt 
     78  1.2.4.2  matt RETURNS:
     79  1.2.4.2  matt Long value read from emulator memory.
     80  1.2.4.2  matt REMARKS:
     81  1.2.4.2  matt Reads a long value from the emulator memory.
     82  1.2.4.2  matt ****************************************************************************/
     83  1.2.4.2  matt static uint32_t
     84  1.2.4.2  matt rdl(struct X86EMU *emu, uint32_t addr)
     85  1.2.4.2  matt {
     86  1.2.4.2  matt 	if (addr > emu->mem_size - 4)
     87  1.2.4.2  matt 		X86EMU_halt_sys(emu);
     88  1.2.4.2  matt 	return le32dec(emu->mem_base + addr);
     89  1.2.4.2  matt }
     90  1.2.4.2  matt /****************************************************************************
     91  1.2.4.2  matt PARAMETERS:
     92  1.2.4.2  matt addr	- Emulator memory address to read
     93  1.2.4.2  matt val		- Value to store
     94  1.2.4.2  matt 
     95  1.2.4.2  matt REMARKS:
     96  1.2.4.2  matt Writes a byte value to emulator memory.
     97  1.2.4.2  matt ****************************************************************************/
     98  1.2.4.2  matt static void
     99  1.2.4.2  matt wrb(struct X86EMU *emu, uint32_t addr, uint8_t val)
    100  1.2.4.2  matt {
    101  1.2.4.2  matt 	if (addr > emu->mem_size - 1)
    102  1.2.4.2  matt 		X86EMU_halt_sys(emu);
    103  1.2.4.2  matt 	emu->mem_base[addr] = val;
    104  1.2.4.2  matt }
    105  1.2.4.2  matt /****************************************************************************
    106  1.2.4.2  matt PARAMETERS:
    107  1.2.4.2  matt addr	- Emulator memory address to read
    108  1.2.4.2  matt val		- Value to store
    109  1.2.4.2  matt 
    110  1.2.4.2  matt REMARKS:
    111  1.2.4.2  matt Writes a word value to emulator memory.
    112  1.2.4.2  matt ****************************************************************************/
    113  1.2.4.2  matt static void
    114  1.2.4.2  matt wrw(struct X86EMU *emu, uint32_t addr, uint16_t val)
    115  1.2.4.2  matt {
    116  1.2.4.2  matt 	if (addr > emu->mem_size - 2)
    117  1.2.4.2  matt 		X86EMU_halt_sys(emu);
    118  1.2.4.2  matt 	le16enc(emu->mem_base + addr, val);
    119  1.2.4.2  matt }
    120  1.2.4.2  matt /****************************************************************************
    121  1.2.4.2  matt PARAMETERS:
    122  1.2.4.2  matt addr	- Emulator memory address to read
    123  1.2.4.2  matt val		- Value to store
    124  1.2.4.2  matt 
    125  1.2.4.2  matt REMARKS:
    126  1.2.4.2  matt Writes a long value to emulator memory.
    127  1.2.4.2  matt ****************************************************************************/
    128  1.2.4.2  matt static void
    129  1.2.4.2  matt wrl(struct X86EMU *emu, uint32_t addr, uint32_t val)
    130  1.2.4.2  matt {
    131  1.2.4.2  matt 	if (addr > emu->mem_size - 4)
    132  1.2.4.2  matt 		X86EMU_halt_sys(emu);
    133  1.2.4.2  matt 	le32enc(emu->mem_base + addr, val);
    134  1.2.4.2  matt }
    135  1.2.4.2  matt 
    136  1.2.4.2  matt /*----------------------------- Setup -------------------------------------*/
    137  1.2.4.2  matt 
    138  1.2.4.2  matt void
    139  1.2.4.2  matt X86EMU_init_default(struct X86EMU *emu)
    140  1.2.4.2  matt {
    141  1.2.4.2  matt 	int i;
    142  1.2.4.2  matt 
    143  1.2.4.2  matt 	emu->emu_rdb = rdb;
    144  1.2.4.2  matt 	emu->emu_rdw = rdw;
    145  1.2.4.2  matt 	emu->emu_rdl = rdl;
    146  1.2.4.2  matt 	emu->emu_wrb = wrb;
    147  1.2.4.2  matt 	emu->emu_wrw = wrw;
    148  1.2.4.2  matt 	emu->emu_wrl = wrl;
    149  1.2.4.2  matt 
    150  1.2.4.2  matt 	for (i = 0; i < 256; i++)
    151  1.2.4.2  matt 		emu->_X86EMU_intrTab[i] = NULL;
    152  1.2.4.2  matt }
    153