Commit 329939776005fad213086e54b038ccd39054e2bc
Committed by
Anthony Liguori
1 parent
89e671e3
split out ioport related stuffs from vl.c into ioport.c.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
7 changed files
with
317 additions
and
248 deletions
Makefile.target
| @@ -489,7 +489,7 @@ endif #CONFIG_BSD_USER | @@ -489,7 +489,7 @@ endif #CONFIG_BSD_USER | ||
| 489 | ifndef CONFIG_USER_ONLY | 489 | ifndef CONFIG_USER_ONLY |
| 490 | 490 | ||
| 491 | obj-y = vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \ | 491 | obj-y = vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \ |
| 492 | - gdbstub.o gdbstub-xml.o msix.o | 492 | + gdbstub.o gdbstub-xml.o msix.o ioport.o |
| 493 | # virtio has to be here due to weird dependency between PCI and virtio-net. | 493 | # virtio has to be here due to weird dependency between PCI and virtio-net. |
| 494 | # need to fix this properly | 494 | # need to fix this properly |
| 495 | obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o | 495 | obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o |
cpu-all.h
| @@ -837,17 +837,7 @@ void cpu_set_log_filename(const char *filename); | @@ -837,17 +837,7 @@ void cpu_set_log_filename(const char *filename); | ||
| 837 | int cpu_str_to_log_mask(const char *str); | 837 | int cpu_str_to_log_mask(const char *str); |
| 838 | 838 | ||
| 839 | /* IO ports API */ | 839 | /* IO ports API */ |
| 840 | - | ||
| 841 | -/* NOTE: as these functions may be even used when there is an isa | ||
| 842 | - brige on non x86 targets, we always defined them */ | ||
| 843 | -#ifndef NO_CPU_IO_DEFS | ||
| 844 | -void cpu_outb(CPUState *env, int addr, int val); | ||
| 845 | -void cpu_outw(CPUState *env, int addr, int val); | ||
| 846 | -void cpu_outl(CPUState *env, int addr, int val); | ||
| 847 | -int cpu_inb(CPUState *env, int addr); | ||
| 848 | -int cpu_inw(CPUState *env, int addr); | ||
| 849 | -int cpu_inl(CPUState *env, int addr); | ||
| 850 | -#endif | 840 | +#include "ioport.h" |
| 851 | 841 | ||
| 852 | /* memory API */ | 842 | /* memory API */ |
| 853 | 843 |
hw/hw.h
| @@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
| 10 | #include "cpu-common.h" | 10 | #include "cpu-common.h" |
| 11 | #endif | 11 | #endif |
| 12 | 12 | ||
| 13 | +#include "ioport.h" | ||
| 13 | #include "irq.h" | 14 | #include "irq.h" |
| 14 | 15 | ||
| 15 | /* VM Load/Save */ | 16 | /* VM Load/Save */ |
| @@ -266,8 +267,4 @@ void qemu_register_reset(QEMUResetHandler *func, void *opaque); | @@ -266,8 +267,4 @@ void qemu_register_reset(QEMUResetHandler *func, void *opaque); | ||
| 266 | typedef int QEMUBootSetHandler(void *opaque, const char *boot_device); | 267 | typedef int QEMUBootSetHandler(void *opaque, const char *boot_device); |
| 267 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque); | 268 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque); |
| 268 | 269 | ||
| 269 | -/* These should really be in isa.h, but are here to make pc.h happy. */ | ||
| 270 | -typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data); | ||
| 271 | -typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address); | ||
| 272 | - | ||
| 273 | #endif | 270 | #endif |
hw/isa.h
| @@ -2,13 +2,9 @@ | @@ -2,13 +2,9 @@ | ||
| 2 | #define HW_ISA_H | 2 | #define HW_ISA_H |
| 3 | /* ISA bus */ | 3 | /* ISA bus */ |
| 4 | 4 | ||
| 5 | -extern target_phys_addr_t isa_mem_base; | 5 | +#include "ioport.h" |
| 6 | 6 | ||
| 7 | -int register_ioport_read(int start, int length, int size, | ||
| 8 | - IOPortReadFunc *func, void *opaque); | ||
| 9 | -int register_ioport_write(int start, int length, int size, | ||
| 10 | - IOPortWriteFunc *func, void *opaque); | ||
| 11 | -void isa_unassign_ioport(int start, int length); | 7 | +extern target_phys_addr_t isa_mem_base; |
| 12 | 8 | ||
| 13 | void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size); | 9 | void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size); |
| 14 | 10 |
ioport.c
0 → 100644
| 1 | +/* | ||
| 2 | + * QEMU System Emulator | ||
| 3 | + * | ||
| 4 | + * Copyright (c) 2003-2008 Fabrice Bellard | ||
| 5 | + * | ||
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | + * of this software and associated documentation files (the "Software"), to deal | ||
| 8 | + * in the Software without restriction, including without limitation the rights | ||
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | + * copies of the Software, and to permit persons to whom the Software is | ||
| 11 | + * furnished to do so, subject to the following conditions: | ||
| 12 | + * | ||
| 13 | + * The above copyright notice and this permission notice shall be included in | ||
| 14 | + * all copies or substantial portions of the Software. | ||
| 15 | + * | ||
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| 19 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 22 | + * THE SOFTWARE. | ||
| 23 | + */ | ||
| 24 | +/* | ||
| 25 | + * splitted out ioport related stuffs from vl.c. | ||
| 26 | + */ | ||
| 27 | + | ||
| 28 | +#include "ioport.h" | ||
| 29 | + | ||
| 30 | +/***********************************************************/ | ||
| 31 | +/* IO Port */ | ||
| 32 | + | ||
| 33 | +//#define DEBUG_UNUSED_IOPORT | ||
| 34 | +//#define DEBUG_IOPORT | ||
| 35 | + | ||
| 36 | +#ifdef DEBUG_IOPORT | ||
| 37 | +# define LOG_IOPORT(...) qemu_log_mask(CPU_LOG_IOPORT, ## __VA_ARGS__) | ||
| 38 | +#else | ||
| 39 | +# define LOG_IOPORT(...) do { } while (0) | ||
| 40 | +#endif | ||
| 41 | + | ||
| 42 | +/* XXX: use a two level table to limit memory usage */ | ||
| 43 | + | ||
| 44 | +static void *ioport_opaque[MAX_IOPORTS]; | ||
| 45 | +static IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; | ||
| 46 | +static IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; | ||
| 47 | + | ||
| 48 | +static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl; | ||
| 49 | +static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel; | ||
| 50 | + | ||
| 51 | +static uint32_t ioport_read(int index, uint32_t address) | ||
| 52 | +{ | ||
| 53 | + static IOPortReadFunc *default_func[3] = { | ||
| 54 | + default_ioport_readb, | ||
| 55 | + default_ioport_readw, | ||
| 56 | + default_ioport_readl | ||
| 57 | + }; | ||
| 58 | + IOPortReadFunc *func = ioport_read_table[index][address]; | ||
| 59 | + if (!func) | ||
| 60 | + func = default_func[index]; | ||
| 61 | + return func(ioport_opaque[address], address); | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +static void ioport_write(int index, uint32_t address, uint32_t data) | ||
| 65 | +{ | ||
| 66 | + static IOPortWriteFunc *default_func[3] = { | ||
| 67 | + default_ioport_writeb, | ||
| 68 | + default_ioport_writew, | ||
| 69 | + default_ioport_writel | ||
| 70 | + }; | ||
| 71 | + IOPortWriteFunc *func = ioport_write_table[index][address]; | ||
| 72 | + if (!func) | ||
| 73 | + func = default_func[index]; | ||
| 74 | + func(ioport_opaque[address], address, data); | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +static uint32_t default_ioport_readb(void *opaque, uint32_t address) | ||
| 78 | +{ | ||
| 79 | +#ifdef DEBUG_UNUSED_IOPORT | ||
| 80 | + fprintf(stderr, "unused inb: port=0x%04x\n", address); | ||
| 81 | +#endif | ||
| 82 | + return 0xff; | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data) | ||
| 86 | +{ | ||
| 87 | +#ifdef DEBUG_UNUSED_IOPORT | ||
| 88 | + fprintf(stderr, "unused outb: port=0x%04x data=0x%02x\n", address, data); | ||
| 89 | +#endif | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +/* default is to make two byte accesses */ | ||
| 93 | +static uint32_t default_ioport_readw(void *opaque, uint32_t address) | ||
| 94 | +{ | ||
| 95 | + uint32_t data; | ||
| 96 | + data = ioport_read(0, address); | ||
| 97 | + address = (address + 1) & (MAX_IOPORTS - 1); | ||
| 98 | + data |= ioport_read(0, address) << 8; | ||
| 99 | + return data; | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) | ||
| 103 | +{ | ||
| 104 | + ioport_write(0, address, data & 0xff); | ||
| 105 | + address = (address + 1) & (MAX_IOPORTS - 1); | ||
| 106 | + ioport_write(0, address, (data >> 8) & 0xff); | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | +static uint32_t default_ioport_readl(void *opaque, uint32_t address) | ||
| 110 | +{ | ||
| 111 | +#ifdef DEBUG_UNUSED_IOPORT | ||
| 112 | + fprintf(stderr, "unused inl: port=0x%04x\n", address); | ||
| 113 | +#endif | ||
| 114 | + return 0xffffffff; | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data) | ||
| 118 | +{ | ||
| 119 | +#ifdef DEBUG_UNUSED_IOPORT | ||
| 120 | + fprintf(stderr, "unused outl: port=0x%04x data=0x%02x\n", address, data); | ||
| 121 | +#endif | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +/* size is the word size in byte */ | ||
| 125 | +int register_ioport_read(int start, int length, int size, | ||
| 126 | + IOPortReadFunc *func, void *opaque) | ||
| 127 | +{ | ||
| 128 | + int i, bsize; | ||
| 129 | + | ||
| 130 | + if (size == 1) { | ||
| 131 | + bsize = 0; | ||
| 132 | + } else if (size == 2) { | ||
| 133 | + bsize = 1; | ||
| 134 | + } else if (size == 4) { | ||
| 135 | + bsize = 2; | ||
| 136 | + } else { | ||
| 137 | + hw_error("register_ioport_read: invalid size"); | ||
| 138 | + return -1; | ||
| 139 | + } | ||
| 140 | + for(i = start; i < start + length; i += size) { | ||
| 141 | + ioport_read_table[bsize][i] = func; | ||
| 142 | + if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque) | ||
| 143 | + hw_error("register_ioport_read: invalid opaque"); | ||
| 144 | + ioport_opaque[i] = opaque; | ||
| 145 | + } | ||
| 146 | + return 0; | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +/* size is the word size in byte */ | ||
| 150 | +int register_ioport_write(int start, int length, int size, | ||
| 151 | + IOPortWriteFunc *func, void *opaque) | ||
| 152 | +{ | ||
| 153 | + int i, bsize; | ||
| 154 | + | ||
| 155 | + if (size == 1) { | ||
| 156 | + bsize = 0; | ||
| 157 | + } else if (size == 2) { | ||
| 158 | + bsize = 1; | ||
| 159 | + } else if (size == 4) { | ||
| 160 | + bsize = 2; | ||
| 161 | + } else { | ||
| 162 | + hw_error("register_ioport_write: invalid size"); | ||
| 163 | + return -1; | ||
| 164 | + } | ||
| 165 | + for(i = start; i < start + length; i += size) { | ||
| 166 | + ioport_write_table[bsize][i] = func; | ||
| 167 | + if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque) | ||
| 168 | + hw_error("register_ioport_write: invalid opaque"); | ||
| 169 | + ioport_opaque[i] = opaque; | ||
| 170 | + } | ||
| 171 | + return 0; | ||
| 172 | +} | ||
| 173 | + | ||
| 174 | +void isa_unassign_ioport(int start, int length) | ||
| 175 | +{ | ||
| 176 | + int i; | ||
| 177 | + | ||
| 178 | + for(i = start; i < start + length; i++) { | ||
| 179 | + ioport_read_table[0][i] = default_ioport_readb; | ||
| 180 | + ioport_read_table[1][i] = default_ioport_readw; | ||
| 181 | + ioport_read_table[2][i] = default_ioport_readl; | ||
| 182 | + | ||
| 183 | + ioport_write_table[0][i] = default_ioport_writeb; | ||
| 184 | + ioport_write_table[1][i] = default_ioport_writew; | ||
| 185 | + ioport_write_table[2][i] = default_ioport_writel; | ||
| 186 | + | ||
| 187 | + ioport_opaque[i] = NULL; | ||
| 188 | + } | ||
| 189 | +} | ||
| 190 | + | ||
| 191 | +/***********************************************************/ | ||
| 192 | + | ||
| 193 | +void cpu_outb(CPUState *env, int addr, int val) | ||
| 194 | +{ | ||
| 195 | + LOG_IOPORT("outb: %04x %02x\n", addr, val); | ||
| 196 | + ioport_write(0, addr, val); | ||
| 197 | +#ifdef CONFIG_KQEMU | ||
| 198 | + if (env) | ||
| 199 | + env->last_io_time = cpu_get_time_fast(); | ||
| 200 | +#endif | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +void cpu_outw(CPUState *env, int addr, int val) | ||
| 204 | +{ | ||
| 205 | + LOG_IOPORT("outw: %04x %04x\n", addr, val); | ||
| 206 | + ioport_write(1, addr, val); | ||
| 207 | +#ifdef CONFIG_KQEMU | ||
| 208 | + if (env) | ||
| 209 | + env->last_io_time = cpu_get_time_fast(); | ||
| 210 | +#endif | ||
| 211 | +} | ||
| 212 | + | ||
| 213 | +void cpu_outl(CPUState *env, int addr, int val) | ||
| 214 | +{ | ||
| 215 | + LOG_IOPORT("outl: %04x %08x\n", addr, val); | ||
| 216 | + ioport_write(2, addr, val); | ||
| 217 | +#ifdef CONFIG_KQEMU | ||
| 218 | + if (env) | ||
| 219 | + env->last_io_time = cpu_get_time_fast(); | ||
| 220 | +#endif | ||
| 221 | +} | ||
| 222 | + | ||
| 223 | +int cpu_inb(CPUState *env, int addr) | ||
| 224 | +{ | ||
| 225 | + int val; | ||
| 226 | + val = ioport_read(0, addr); | ||
| 227 | + LOG_IOPORT("inb : %04x %02x\n", addr, val); | ||
| 228 | +#ifdef CONFIG_KQEMU | ||
| 229 | + if (env) | ||
| 230 | + env->last_io_time = cpu_get_time_fast(); | ||
| 231 | +#endif | ||
| 232 | + return val; | ||
| 233 | +} | ||
| 234 | + | ||
| 235 | +int cpu_inw(CPUState *env, int addr) | ||
| 236 | +{ | ||
| 237 | + int val; | ||
| 238 | + val = ioport_read(1, addr); | ||
| 239 | + LOG_IOPORT("inw : %04x %04x\n", addr, val); | ||
| 240 | +#ifdef CONFIG_KQEMU | ||
| 241 | + if (env) | ||
| 242 | + env->last_io_time = cpu_get_time_fast(); | ||
| 243 | +#endif | ||
| 244 | + return val; | ||
| 245 | +} | ||
| 246 | + | ||
| 247 | +int cpu_inl(CPUState *env, int addr) | ||
| 248 | +{ | ||
| 249 | + int val; | ||
| 250 | + val = ioport_read(2, addr); | ||
| 251 | + LOG_IOPORT("inl : %04x %08x\n", addr, val); | ||
| 252 | +#ifdef CONFIG_KQEMU | ||
| 253 | + if (env) | ||
| 254 | + env->last_io_time = cpu_get_time_fast(); | ||
| 255 | +#endif | ||
| 256 | + return val; | ||
| 257 | +} | ||
| 258 | + |
ioport.h
0 → 100644
| 1 | +/* | ||
| 2 | + * defines ioport related functions | ||
| 3 | + * | ||
| 4 | + * Copyright (c) 2003 Fabrice Bellard | ||
| 5 | + * | ||
| 6 | + * This library is free software; you can redistribute it and/or | ||
| 7 | + * modify it under the terms of the GNU Lesser General Public | ||
| 8 | + * License as published by the Free Software Foundation; either | ||
| 9 | + * version 2 of the License, or (at your option) any later version. | ||
| 10 | + * | ||
| 11 | + * This library is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | + * Lesser General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public | ||
| 17 | + * License along with this library; if not, write to the Free Software | ||
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | +/************************************************************************** | ||
| 22 | + * IO ports API | ||
| 23 | + */ | ||
| 24 | + | ||
| 25 | +#ifndef IOPORT_H | ||
| 26 | +#define IOPORT_H | ||
| 27 | + | ||
| 28 | +#include "qemu-common.h" | ||
| 29 | + | ||
| 30 | +#define MAX_IOPORTS (64 * 1024) | ||
| 31 | + | ||
| 32 | +/* These should really be in isa.h, but are here to make pc.h happy. */ | ||
| 33 | +typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data); | ||
| 34 | +typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address); | ||
| 35 | + | ||
| 36 | +int register_ioport_read(int start, int length, int size, | ||
| 37 | + IOPortReadFunc *func, void *opaque); | ||
| 38 | +int register_ioport_write(int start, int length, int size, | ||
| 39 | + IOPortWriteFunc *func, void *opaque); | ||
| 40 | +void isa_unassign_ioport(int start, int length); | ||
| 41 | + | ||
| 42 | + | ||
| 43 | +/* NOTE: as these functions may be even used when there is an isa | ||
| 44 | + brige on non x86 targets, we always defined them */ | ||
| 45 | +#if !defined(NO_CPU_IO_DEFS) && defined(NEED_CPU_H) | ||
| 46 | +void cpu_outb(CPUState *env, int addr, int val); | ||
| 47 | +void cpu_outw(CPUState *env, int addr, int val); | ||
| 48 | +void cpu_outl(CPUState *env, int addr, int val); | ||
| 49 | +int cpu_inb(CPUState *env, int addr); | ||
| 50 | +int cpu_inw(CPUState *env, int addr); | ||
| 51 | +int cpu_inl(CPUState *env, int addr); | ||
| 52 | +#endif | ||
| 53 | + | ||
| 54 | +#endif /* IOPORT_H */ |
vl.c
| @@ -167,18 +167,9 @@ int main(int argc, char **argv) | @@ -167,18 +167,9 @@ int main(int argc, char **argv) | ||
| 167 | 167 | ||
| 168 | #include "slirp/libslirp.h" | 168 | #include "slirp/libslirp.h" |
| 169 | 169 | ||
| 170 | -//#define DEBUG_UNUSED_IOPORT | ||
| 171 | -//#define DEBUG_IOPORT | ||
| 172 | //#define DEBUG_NET | 170 | //#define DEBUG_NET |
| 173 | //#define DEBUG_SLIRP | 171 | //#define DEBUG_SLIRP |
| 174 | 172 | ||
| 175 | - | ||
| 176 | -#ifdef DEBUG_IOPORT | ||
| 177 | -# define LOG_IOPORT(...) qemu_log_mask(CPU_LOG_IOPORT, ## __VA_ARGS__) | ||
| 178 | -#else | ||
| 179 | -# define LOG_IOPORT(...) do { } while (0) | ||
| 180 | -#endif | ||
| 181 | - | ||
| 182 | #define DEFAULT_RAM_SIZE 128 | 173 | #define DEFAULT_RAM_SIZE 128 |
| 183 | 174 | ||
| 184 | /* Max number of USB devices that can be specified on the commandline. */ | 175 | /* Max number of USB devices that can be specified on the commandline. */ |
| @@ -187,14 +178,8 @@ int main(int argc, char **argv) | @@ -187,14 +178,8 @@ int main(int argc, char **argv) | ||
| 187 | /* Max number of bluetooth switches on the commandline. */ | 178 | /* Max number of bluetooth switches on the commandline. */ |
| 188 | #define MAX_BT_CMDLINE 10 | 179 | #define MAX_BT_CMDLINE 10 |
| 189 | 180 | ||
| 190 | -/* XXX: use a two level table to limit memory usage */ | ||
| 191 | -#define MAX_IOPORTS 65536 | ||
| 192 | - | ||
| 193 | static const char *data_dir; | 181 | static const char *data_dir; |
| 194 | const char *bios_name = NULL; | 182 | const char *bios_name = NULL; |
| 195 | -static void *ioport_opaque[MAX_IOPORTS]; | ||
| 196 | -static IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; | ||
| 197 | -static IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; | ||
| 198 | /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available | 183 | /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available |
| 199 | to store the VM snapshots */ | 184 | to store the VM snapshots */ |
| 200 | DriveInfo drives_table[MAX_DRIVES+1]; | 185 | DriveInfo drives_table[MAX_DRIVES+1]; |
| @@ -294,217 +279,6 @@ uint8_t qemu_uuid[16]; | @@ -294,217 +279,6 @@ uint8_t qemu_uuid[16]; | ||
| 294 | target_phys_addr_t isa_mem_base = 0; | 279 | target_phys_addr_t isa_mem_base = 0; |
| 295 | PicState2 *isa_pic; | 280 | PicState2 *isa_pic; |
| 296 | 281 | ||
| 297 | -static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl; | ||
| 298 | -static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel; | ||
| 299 | - | ||
| 300 | -static uint32_t ioport_read(int index, uint32_t address) | ||
| 301 | -{ | ||
| 302 | - static IOPortReadFunc *default_func[3] = { | ||
| 303 | - default_ioport_readb, | ||
| 304 | - default_ioport_readw, | ||
| 305 | - default_ioport_readl | ||
| 306 | - }; | ||
| 307 | - IOPortReadFunc *func = ioport_read_table[index][address]; | ||
| 308 | - if (!func) | ||
| 309 | - func = default_func[index]; | ||
| 310 | - return func(ioport_opaque[address], address); | ||
| 311 | -} | ||
| 312 | - | ||
| 313 | -static void ioport_write(int index, uint32_t address, uint32_t data) | ||
| 314 | -{ | ||
| 315 | - static IOPortWriteFunc *default_func[3] = { | ||
| 316 | - default_ioport_writeb, | ||
| 317 | - default_ioport_writew, | ||
| 318 | - default_ioport_writel | ||
| 319 | - }; | ||
| 320 | - IOPortWriteFunc *func = ioport_write_table[index][address]; | ||
| 321 | - if (!func) | ||
| 322 | - func = default_func[index]; | ||
| 323 | - func(ioport_opaque[address], address, data); | ||
| 324 | -} | ||
| 325 | - | ||
| 326 | -static uint32_t default_ioport_readb(void *opaque, uint32_t address) | ||
| 327 | -{ | ||
| 328 | -#ifdef DEBUG_UNUSED_IOPORT | ||
| 329 | - fprintf(stderr, "unused inb: port=0x%04x\n", address); | ||
| 330 | -#endif | ||
| 331 | - return 0xff; | ||
| 332 | -} | ||
| 333 | - | ||
| 334 | -static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data) | ||
| 335 | -{ | ||
| 336 | -#ifdef DEBUG_UNUSED_IOPORT | ||
| 337 | - fprintf(stderr, "unused outb: port=0x%04x data=0x%02x\n", address, data); | ||
| 338 | -#endif | ||
| 339 | -} | ||
| 340 | - | ||
| 341 | -/* default is to make two byte accesses */ | ||
| 342 | -static uint32_t default_ioport_readw(void *opaque, uint32_t address) | ||
| 343 | -{ | ||
| 344 | - uint32_t data; | ||
| 345 | - data = ioport_read(0, address); | ||
| 346 | - address = (address + 1) & (MAX_IOPORTS - 1); | ||
| 347 | - data |= ioport_read(0, address) << 8; | ||
| 348 | - return data; | ||
| 349 | -} | ||
| 350 | - | ||
| 351 | -static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) | ||
| 352 | -{ | ||
| 353 | - ioport_write(0, address, data & 0xff); | ||
| 354 | - address = (address + 1) & (MAX_IOPORTS - 1); | ||
| 355 | - ioport_write(0, address, (data >> 8) & 0xff); | ||
| 356 | -} | ||
| 357 | - | ||
| 358 | -static uint32_t default_ioport_readl(void *opaque, uint32_t address) | ||
| 359 | -{ | ||
| 360 | -#ifdef DEBUG_UNUSED_IOPORT | ||
| 361 | - fprintf(stderr, "unused inl: port=0x%04x\n", address); | ||
| 362 | -#endif | ||
| 363 | - return 0xffffffff; | ||
| 364 | -} | ||
| 365 | - | ||
| 366 | -static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data) | ||
| 367 | -{ | ||
| 368 | -#ifdef DEBUG_UNUSED_IOPORT | ||
| 369 | - fprintf(stderr, "unused outl: port=0x%04x data=0x%02x\n", address, data); | ||
| 370 | -#endif | ||
| 371 | -} | ||
| 372 | - | ||
| 373 | -/* size is the word size in byte */ | ||
| 374 | -int register_ioport_read(int start, int length, int size, | ||
| 375 | - IOPortReadFunc *func, void *opaque) | ||
| 376 | -{ | ||
| 377 | - int i, bsize; | ||
| 378 | - | ||
| 379 | - if (size == 1) { | ||
| 380 | - bsize = 0; | ||
| 381 | - } else if (size == 2) { | ||
| 382 | - bsize = 1; | ||
| 383 | - } else if (size == 4) { | ||
| 384 | - bsize = 2; | ||
| 385 | - } else { | ||
| 386 | - hw_error("register_ioport_read: invalid size"); | ||
| 387 | - return -1; | ||
| 388 | - } | ||
| 389 | - for(i = start; i < start + length; i += size) { | ||
| 390 | - ioport_read_table[bsize][i] = func; | ||
| 391 | - if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque) | ||
| 392 | - hw_error("register_ioport_read: invalid opaque"); | ||
| 393 | - ioport_opaque[i] = opaque; | ||
| 394 | - } | ||
| 395 | - return 0; | ||
| 396 | -} | ||
| 397 | - | ||
| 398 | -/* size is the word size in byte */ | ||
| 399 | -int register_ioport_write(int start, int length, int size, | ||
| 400 | - IOPortWriteFunc *func, void *opaque) | ||
| 401 | -{ | ||
| 402 | - int i, bsize; | ||
| 403 | - | ||
| 404 | - if (size == 1) { | ||
| 405 | - bsize = 0; | ||
| 406 | - } else if (size == 2) { | ||
| 407 | - bsize = 1; | ||
| 408 | - } else if (size == 4) { | ||
| 409 | - bsize = 2; | ||
| 410 | - } else { | ||
| 411 | - hw_error("register_ioport_write: invalid size"); | ||
| 412 | - return -1; | ||
| 413 | - } | ||
| 414 | - for(i = start; i < start + length; i += size) { | ||
| 415 | - ioport_write_table[bsize][i] = func; | ||
| 416 | - if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque) | ||
| 417 | - hw_error("register_ioport_write: invalid opaque"); | ||
| 418 | - ioport_opaque[i] = opaque; | ||
| 419 | - } | ||
| 420 | - return 0; | ||
| 421 | -} | ||
| 422 | - | ||
| 423 | -void isa_unassign_ioport(int start, int length) | ||
| 424 | -{ | ||
| 425 | - int i; | ||
| 426 | - | ||
| 427 | - for(i = start; i < start + length; i++) { | ||
| 428 | - ioport_read_table[0][i] = default_ioport_readb; | ||
| 429 | - ioport_read_table[1][i] = default_ioport_readw; | ||
| 430 | - ioport_read_table[2][i] = default_ioport_readl; | ||
| 431 | - | ||
| 432 | - ioport_write_table[0][i] = default_ioport_writeb; | ||
| 433 | - ioport_write_table[1][i] = default_ioport_writew; | ||
| 434 | - ioport_write_table[2][i] = default_ioport_writel; | ||
| 435 | - | ||
| 436 | - ioport_opaque[i] = NULL; | ||
| 437 | - } | ||
| 438 | -} | ||
| 439 | - | ||
| 440 | -/***********************************************************/ | ||
| 441 | - | ||
| 442 | -void cpu_outb(CPUState *env, int addr, int val) | ||
| 443 | -{ | ||
| 444 | - LOG_IOPORT("outb: %04x %02x\n", addr, val); | ||
| 445 | - ioport_write(0, addr, val); | ||
| 446 | -#ifdef CONFIG_KQEMU | ||
| 447 | - if (env) | ||
| 448 | - env->last_io_time = cpu_get_time_fast(); | ||
| 449 | -#endif | ||
| 450 | -} | ||
| 451 | - | ||
| 452 | -void cpu_outw(CPUState *env, int addr, int val) | ||
| 453 | -{ | ||
| 454 | - LOG_IOPORT("outw: %04x %04x\n", addr, val); | ||
| 455 | - ioport_write(1, addr, val); | ||
| 456 | -#ifdef CONFIG_KQEMU | ||
| 457 | - if (env) | ||
| 458 | - env->last_io_time = cpu_get_time_fast(); | ||
| 459 | -#endif | ||
| 460 | -} | ||
| 461 | - | ||
| 462 | -void cpu_outl(CPUState *env, int addr, int val) | ||
| 463 | -{ | ||
| 464 | - LOG_IOPORT("outl: %04x %08x\n", addr, val); | ||
| 465 | - ioport_write(2, addr, val); | ||
| 466 | -#ifdef CONFIG_KQEMU | ||
| 467 | - if (env) | ||
| 468 | - env->last_io_time = cpu_get_time_fast(); | ||
| 469 | -#endif | ||
| 470 | -} | ||
| 471 | - | ||
| 472 | -int cpu_inb(CPUState *env, int addr) | ||
| 473 | -{ | ||
| 474 | - int val; | ||
| 475 | - val = ioport_read(0, addr); | ||
| 476 | - LOG_IOPORT("inb : %04x %02x\n", addr, val); | ||
| 477 | -#ifdef CONFIG_KQEMU | ||
| 478 | - if (env) | ||
| 479 | - env->last_io_time = cpu_get_time_fast(); | ||
| 480 | -#endif | ||
| 481 | - return val; | ||
| 482 | -} | ||
| 483 | - | ||
| 484 | -int cpu_inw(CPUState *env, int addr) | ||
| 485 | -{ | ||
| 486 | - int val; | ||
| 487 | - val = ioport_read(1, addr); | ||
| 488 | - LOG_IOPORT("inw : %04x %04x\n", addr, val); | ||
| 489 | -#ifdef CONFIG_KQEMU | ||
| 490 | - if (env) | ||
| 491 | - env->last_io_time = cpu_get_time_fast(); | ||
| 492 | -#endif | ||
| 493 | - return val; | ||
| 494 | -} | ||
| 495 | - | ||
| 496 | -int cpu_inl(CPUState *env, int addr) | ||
| 497 | -{ | ||
| 498 | - int val; | ||
| 499 | - val = ioport_read(2, addr); | ||
| 500 | - LOG_IOPORT("inl : %04x %08x\n", addr, val); | ||
| 501 | -#ifdef CONFIG_KQEMU | ||
| 502 | - if (env) | ||
| 503 | - env->last_io_time = cpu_get_time_fast(); | ||
| 504 | -#endif | ||
| 505 | - return val; | ||
| 506 | -} | ||
| 507 | - | ||
| 508 | /***********************************************************/ | 282 | /***********************************************************/ |
| 509 | void hw_error(const char *fmt, ...) | 283 | void hw_error(const char *fmt, ...) |
| 510 | { | 284 | { |