No empty .Rs/.Re
[netbsd-mini2440.git] / common / lib / libx86emu / x86emu_util.c
blobc28dbbf582f262ea33a316aa87a9c9c7c8d20bbf
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>
38 #include <sys/null.h>
40 /****************************************************************************
41 PARAMETERS:
42 addr - Emulator memory address to read
44 RETURNS:
45 Byte value read from emulator memory.
47 REMARKS:
48 Reads a byte value from the emulator memory.
49 ****************************************************************************/
50 static uint8_t
51 rdb(struct X86EMU *emu, uint32_t addr)
53 if (addr > emu->mem_size - 1)
54 X86EMU_halt_sys(emu);
55 return emu->mem_base[addr];
57 /****************************************************************************
58 PARAMETERS:
59 addr - Emulator memory address to read
61 RETURNS:
62 Word value read from emulator memory.
64 REMARKS:
65 Reads a word value from the emulator memory.
66 ****************************************************************************/
67 static uint16_t
68 rdw(struct X86EMU *emu, uint32_t addr)
70 if (addr > emu->mem_size - 2)
71 X86EMU_halt_sys(emu);
72 return le16dec(emu->mem_base + addr);
74 /****************************************************************************
75 PARAMETERS:
76 addr - Emulator memory address to read
78 RETURNS:
79 Long value read from emulator memory.
80 REMARKS:
81 Reads a long value from the emulator memory.
82 ****************************************************************************/
83 static uint32_t
84 rdl(struct X86EMU *emu, uint32_t addr)
86 if (addr > emu->mem_size - 4)
87 X86EMU_halt_sys(emu);
88 return le32dec(emu->mem_base + addr);
90 /****************************************************************************
91 PARAMETERS:
92 addr - Emulator memory address to read
93 val - Value to store
95 REMARKS:
96 Writes a byte value to emulator memory.
97 ****************************************************************************/
98 static void
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 /****************************************************************************
106 PARAMETERS:
107 addr - Emulator memory address to read
108 val - Value to store
110 REMARKS:
111 Writes a word value to emulator memory.
112 ****************************************************************************/
113 static void
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 /****************************************************************************
121 PARAMETERS:
122 addr - Emulator memory address to read
123 val - Value to store
125 REMARKS:
126 Writes a long value to emulator memory.
127 ****************************************************************************/
128 static void
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 -------------------------------------*/
138 void
139 X86EMU_init_default(struct X86EMU *emu)
141 int i;
143 emu->emu_rdb = rdb;
144 emu->emu_rdw = rdw;
145 emu->emu_rdl = rdl;
146 emu->emu_wrb = wrb;
147 emu->emu_wrw = wrw;
148 emu->emu_wrl = wrl;
150 for (i = 0; i < 256; i++)
151 emu->_X86EMU_intrTab[i] = NULL;