ia64/xen-unstable

changeset 17033:7e189fc27f4f

ioemu: save 3MB of ioport tables (on 64bit machines)
by keeping then initialized to NULL and check for it in the handlers.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Feb 11 14:47:19 2008 +0000 (2008-02-11)
parents a1b83b3b0449
children e3b7f1793f0c
files tools/ioemu/vl.c
line diff
     1.1 --- a/tools/ioemu/vl.c	Mon Feb 11 14:47:06 2008 +0000
     1.2 +++ b/tools/ioemu/vl.c	Mon Feb 11 14:47:19 2008 +0000
     1.3 @@ -227,17 +227,29 @@ void default_ioport_writeb(void *opaque,
     1.4  uint32_t default_ioport_readw(void *opaque, uint32_t address)
     1.5  {
     1.6      uint32_t data;
     1.7 -    data = ioport_read_table[0][address](ioport_opaque[address], address);
     1.8 +    IOPortReadFunc *func = ioport_read_table[0][address];
     1.9 +    if (!func)
    1.10 +	    func = default_ioport_readb;
    1.11 +    data = func(ioport_opaque[address], address);
    1.12      address = (address + 1) & (MAX_IOPORTS - 1);
    1.13 -    data |= ioport_read_table[0][address](ioport_opaque[address], address) << 8;
    1.14 +    func = ioport_read_table[0][address];
    1.15 +    if (!func)
    1.16 +	    func = default_ioport_readb;
    1.17 +    data |= func(ioport_opaque[address], address) << 8;
    1.18      return data;
    1.19  }
    1.20  
    1.21  void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
    1.22  {
    1.23 -    ioport_write_table[0][address](ioport_opaque[address], address, data & 0xff);
    1.24 +    IOPortWriteFunc *func = ioport_write_table[0][address];
    1.25 +    if (!func)
    1.26 +	    func = default_ioport_writeb;
    1.27 +    func(ioport_opaque[address], address, data & 0xff);
    1.28      address = (address + 1) & (MAX_IOPORTS - 1);
    1.29 -    ioport_write_table[0][address](ioport_opaque[address], address, (data >> 8) & 0xff);
    1.30 +    func = ioport_write_table[0][address];
    1.31 +    if (!func)
    1.32 +	    func = default_ioport_writeb;
    1.33 +    func(ioport_opaque[address], address, (data >> 8) & 0xff);
    1.34  }
    1.35  
    1.36  uint32_t default_ioport_readl(void *opaque, uint32_t address)
    1.37 @@ -257,16 +269,6 @@ void default_ioport_writel(void *opaque,
    1.38  
    1.39  void init_ioports(void)
    1.40  {
    1.41 -    int i;
    1.42 -
    1.43 -    for(i = 0; i < MAX_IOPORTS; i++) {
    1.44 -        ioport_read_table[0][i] = default_ioport_readb;
    1.45 -        ioport_write_table[0][i] = default_ioport_writeb;
    1.46 -        ioport_read_table[1][i] = default_ioport_readw;
    1.47 -        ioport_write_table[1][i] = default_ioport_writew;
    1.48 -        ioport_read_table[2][i] = default_ioport_readl;
    1.49 -        ioport_write_table[2][i] = default_ioport_writel;
    1.50 -    }
    1.51  }
    1.52  
    1.53  /* size is the word size in byte */
    1.54 @@ -338,11 +340,14 @@ void isa_unassign_ioport(int start, int 
    1.55  
    1.56  void cpu_outb(CPUState *env, int addr, int val)
    1.57  {
    1.58 +    IOPortWriteFunc *func = ioport_write_table[0][addr];
    1.59 +    if (!func)
    1.60 +	    func = default_ioport_writeb;
    1.61  #ifdef DEBUG_IOPORT
    1.62      if (loglevel & CPU_LOG_IOPORT)
    1.63          fprintf(logfile, "outb: %04x %02x\n", addr, val);
    1.64  #endif    
    1.65 -    ioport_write_table[0][addr](ioport_opaque[addr], addr, val);
    1.66 +    func(ioport_opaque[addr], addr, val);
    1.67  #ifdef USE_KQEMU
    1.68      if (env)
    1.69          env->last_io_time = cpu_get_time_fast();
    1.70 @@ -351,11 +356,14 @@ void cpu_outb(CPUState *env, int addr, i
    1.71  
    1.72  void cpu_outw(CPUState *env, int addr, int val)
    1.73  {
    1.74 +    IOPortWriteFunc *func = ioport_write_table[1][addr];
    1.75 +    if (!func)
    1.76 +	    func = default_ioport_writew;
    1.77  #ifdef DEBUG_IOPORT
    1.78      if (loglevel & CPU_LOG_IOPORT)
    1.79          fprintf(logfile, "outw: %04x %04x\n", addr, val);
    1.80  #endif    
    1.81 -    ioport_write_table[1][addr](ioport_opaque[addr], addr, val);
    1.82 +    func(ioport_opaque[addr], addr, val);
    1.83  #ifdef USE_KQEMU
    1.84      if (env)
    1.85          env->last_io_time = cpu_get_time_fast();
    1.86 @@ -364,11 +372,14 @@ void cpu_outw(CPUState *env, int addr, i
    1.87  
    1.88  void cpu_outl(CPUState *env, int addr, int val)
    1.89  {
    1.90 +    IOPortWriteFunc *func = ioport_write_table[2][addr];
    1.91 +    if (!func)
    1.92 +	    func = default_ioport_writel;
    1.93  #ifdef DEBUG_IOPORT
    1.94      if (loglevel & CPU_LOG_IOPORT)
    1.95          fprintf(logfile, "outl: %04x %08x\n", addr, val);
    1.96  #endif
    1.97 -    ioport_write_table[2][addr](ioport_opaque[addr], addr, val);
    1.98 +    func(ioport_opaque[addr], addr, val);
    1.99  #ifdef USE_KQEMU
   1.100      if (env)
   1.101          env->last_io_time = cpu_get_time_fast();
   1.102 @@ -378,7 +389,10 @@ void cpu_outl(CPUState *env, int addr, i
   1.103  int cpu_inb(CPUState *env, int addr)
   1.104  {
   1.105      int val;
   1.106 -    val = ioport_read_table[0][addr](ioport_opaque[addr], addr);
   1.107 +    IOPortReadFunc *func = ioport_read_table[0][addr];
   1.108 +    if (!func)
   1.109 +	    func = default_ioport_readb;
   1.110 +    val = func(ioport_opaque[addr], addr);
   1.111  #ifdef DEBUG_IOPORT
   1.112      if (loglevel & CPU_LOG_IOPORT)
   1.113          fprintf(logfile, "inb : %04x %02x\n", addr, val);
   1.114 @@ -393,7 +407,10 @@ int cpu_inb(CPUState *env, int addr)
   1.115  int cpu_inw(CPUState *env, int addr)
   1.116  {
   1.117      int val;
   1.118 -    val = ioport_read_table[1][addr](ioport_opaque[addr], addr);
   1.119 +    IOPortReadFunc *func = ioport_read_table[1][addr];
   1.120 +    if (!func)
   1.121 +	    func = default_ioport_readw;
   1.122 +    val = func(ioport_opaque[addr], addr);
   1.123  #ifdef DEBUG_IOPORT
   1.124      if (loglevel & CPU_LOG_IOPORT)
   1.125          fprintf(logfile, "inw : %04x %04x\n", addr, val);
   1.126 @@ -408,7 +425,10 @@ int cpu_inw(CPUState *env, int addr)
   1.127  int cpu_inl(CPUState *env, int addr)
   1.128  {
   1.129      int val;
   1.130 -    val = ioport_read_table[2][addr](ioport_opaque[addr], addr);
   1.131 +    IOPortReadFunc *func = ioport_read_table[2][addr];
   1.132 +    if (!func)
   1.133 +	    func = default_ioport_readl;
   1.134 +    val = func(ioport_opaque[addr], addr);
   1.135  #ifdef DEBUG_IOPORT
   1.136      if (loglevel & CPU_LOG_IOPORT)
   1.137          fprintf(logfile, "inl : %04x %08x\n", addr, val);