1 /* $NetBSD: x86emu_util.c,v 1.1 2007/11/30 20:02:50 joerg Exp $ */
3 /****************************************************************************
5 * Realmode X86 Emulator Library
7 * Copyright (C) 1996-1999 SciTech Software, Inc.
8 * Copyright (C) David Mosberger-Tang
9 * Copyright (C) 1999 Egbert Eich
10 * Copyright (C) 2007 Joerg Sonnenberger
12 * ========================================================================
14 * Permission to use, copy, modify, distribute, and sell this software and
15 * its documentation for any purpose is hereby granted without fee,
16 * provided that the above copyright notice appear in all copies and that
17 * both that copyright notice and this permission notice appear in
18 * supporting documentation, and that the name of the authors not be used
19 * in advertising or publicity pertaining to distribution of the software
20 * without specific, written prior permission. The authors makes no
21 * representations about the suitability of this software for any purpose.
22 * It is provided "as is" without express or implied warranty.
24 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
25 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
26 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
27 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
28 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
29 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
30 * PERFORMANCE OF THIS SOFTWARE.
32 ****************************************************************************/
34 #include <x86emu/x86emu.h>
35 #include <x86emu/x86emu_regs.h>
37 #include <sys/endian.h>
40 /****************************************************************************
42 addr - Emulator memory address to read
45 Byte value read from emulator memory.
48 Reads a byte value from the emulator memory.
49 ****************************************************************************/
51 rdb(struct X86EMU
*emu
, uint32_t addr
)
53 if (addr
> emu
->mem_size
- 1)
55 return emu
->mem_base
[addr
];
57 /****************************************************************************
59 addr - Emulator memory address to read
62 Word value read from emulator memory.
65 Reads a word value from the emulator memory.
66 ****************************************************************************/
68 rdw(struct X86EMU
*emu
, uint32_t addr
)
70 if (addr
> emu
->mem_size
- 2)
72 return le16dec(emu
->mem_base
+ addr
);
74 /****************************************************************************
76 addr - Emulator memory address to read
79 Long value read from emulator memory.
81 Reads a long value from the emulator memory.
82 ****************************************************************************/
84 rdl(struct X86EMU
*emu
, uint32_t addr
)
86 if (addr
> emu
->mem_size
- 4)
88 return le32dec(emu
->mem_base
+ addr
);
90 /****************************************************************************
92 addr - Emulator memory address to read
96 Writes a byte value to emulator memory.
97 ****************************************************************************/
99 wrb(struct X86EMU
*emu
, uint32_t addr
, uint8_t val
)
101 if (addr
> emu
->mem_size
- 1)
102 X86EMU_halt_sys(emu
);
103 emu
->mem_base
[addr
] = val
;
105 /****************************************************************************
107 addr - Emulator memory address to read
111 Writes a word value to emulator memory.
112 ****************************************************************************/
114 wrw(struct X86EMU
*emu
, uint32_t addr
, uint16_t val
)
116 if (addr
> emu
->mem_size
- 2)
117 X86EMU_halt_sys(emu
);
118 le16enc(emu
->mem_base
+ addr
, val
);
120 /****************************************************************************
122 addr - Emulator memory address to read
126 Writes a long value to emulator memory.
127 ****************************************************************************/
129 wrl(struct X86EMU
*emu
, uint32_t addr
, uint32_t val
)
131 if (addr
> emu
->mem_size
- 4)
132 X86EMU_halt_sys(emu
);
133 le32enc(emu
->mem_base
+ addr
, val
);
136 /*----------------------------- Setup -------------------------------------*/
139 X86EMU_init_default(struct X86EMU
*emu
)
150 for (i
= 0; i
< 256; i
++)
151 emu
->_X86EMU_intrTab
[i
] = NULL
;