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