Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KLg8K-0000nj-AL for qemu-devel@nongnu.org; Wed, 23 Jul 2008 11:20:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KLg8I-0000nC-P5 for qemu-devel@nongnu.org; Wed, 23 Jul 2008 11:20:03 -0400 Received: from [199.232.76.173] (port=33222 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KLg8I-0000n4-GG for qemu-devel@nongnu.org; Wed, 23 Jul 2008 11:20:02 -0400 Received: from savannah.gnu.org ([199.232.41.3]:54467 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KLg8H-0002iq-WE for qemu-devel@nongnu.org; Wed, 23 Jul 2008 11:20:02 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1KLg8G-0003VN-SZ for qemu-devel@nongnu.org; Wed, 23 Jul 2008 15:20:00 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1KLg8G-0003VJ-Hd for qemu-devel@nongnu.org; Wed, 23 Jul 2008 15:20:00 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Wed, 23 Jul 2008 15:20:00 +0000 Subject: [Qemu-devel] [4927] Save 3MB ioport table memory (Samuel Thibault) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 4927 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4927 Author: aliguori Date: 2008-07-23 15:19:59 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Save 3MB ioport table memory (Samuel Thibault) Save 1.5MB (32bit) or 3MB (64bit) memory by keeping ioport tables sparse and use a test against NULL instead. Signed-off-by: Samuel Thibault Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/vl.c Modified: trunk/vl.c =================================================================== --- trunk/vl.c 2008-07-23 13:29:23 UTC (rev 4926) +++ trunk/vl.c 2008-07-23 15:19:59 UTC (rev 4927) @@ -260,6 +260,35 @@ target_phys_addr_t isa_mem_base = 0; PicState2 *isa_pic; +static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl; +static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel; + +static uint32_t ioport_read(int index, uint32_t address) +{ + static IOPortReadFunc *default_func[3] = { + default_ioport_readb, + default_ioport_readw, + default_ioport_readl + }; + IOPortReadFunc *func = ioport_read_table[index][address]; + if (!func) + func = default_func[index]; + return func(ioport_opaque[address], address); +} + +static void ioport_write(int index, uint32_t address, uint32_t data) +{ + static IOPortWriteFunc *default_func[3] = { + default_ioport_writeb, + default_ioport_writew, + default_ioport_writel + }; + IOPortWriteFunc *func = ioport_write_table[index][address]; + if (!func) + func = default_func[index]; + func(ioport_opaque[address], address, data); +} + static uint32_t default_ioport_readb(void *opaque, uint32_t address) { #ifdef DEBUG_UNUSED_IOPORT @@ -279,17 +308,17 @@ static uint32_t default_ioport_readw(void *opaque, uint32_t address) { uint32_t data; - data = ioport_read_table[0][address](ioport_opaque[address], address); + data = ioport_read(0, address); address = (address + 1) & (MAX_IOPORTS - 1); - data |= ioport_read_table[0][address](ioport_opaque[address], address) << 8; + data |= ioport_read(0, address) << 8; return data; } static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) { - ioport_write_table[0][address](ioport_opaque[address], address, data & 0xff); + ioport_write(0, address, data & 0xff); address = (address + 1) & (MAX_IOPORTS - 1); - ioport_write_table[0][address](ioport_opaque[address], address, (data >> 8) & 0xff); + ioport_write(0, address, (data >> 8) & 0xff); } static uint32_t default_ioport_readl(void *opaque, uint32_t address) @@ -307,20 +336,6 @@ #endif } -static void init_ioports(void) -{ - int i; - - for(i = 0; i < MAX_IOPORTS; i++) { - ioport_read_table[0][i] = default_ioport_readb; - ioport_write_table[0][i] = default_ioport_writeb; - ioport_read_table[1][i] = default_ioport_readw; - ioport_write_table[1][i] = default_ioport_writew; - ioport_read_table[2][i] = default_ioport_readl; - ioport_write_table[2][i] = default_ioport_writel; - } -} - /* size is the word size in byte */ int register_ioport_read(int start, int length, int size, IOPortReadFunc *func, void *opaque) @@ -394,7 +409,7 @@ if (loglevel & CPU_LOG_IOPORT) fprintf(logfile, "outb: %04x %02x\n", addr, val); #endif - ioport_write_table[0][addr](ioport_opaque[addr], addr, val); + ioport_write(0, addr, val); #ifdef USE_KQEMU if (env) env->last_io_time = cpu_get_time_fast(); @@ -407,7 +422,7 @@ if (loglevel & CPU_LOG_IOPORT) fprintf(logfile, "outw: %04x %04x\n", addr, val); #endif - ioport_write_table[1][addr](ioport_opaque[addr], addr, val); + ioport_write(1, addr, val); #ifdef USE_KQEMU if (env) env->last_io_time = cpu_get_time_fast(); @@ -420,7 +435,7 @@ if (loglevel & CPU_LOG_IOPORT) fprintf(logfile, "outl: %04x %08x\n", addr, val); #endif - ioport_write_table[2][addr](ioport_opaque[addr], addr, val); + ioport_write(2, addr, val); #ifdef USE_KQEMU if (env) env->last_io_time = cpu_get_time_fast(); @@ -430,7 +445,7 @@ int cpu_inb(CPUState *env, int addr) { int val; - val = ioport_read_table[0][addr](ioport_opaque[addr], addr); + val = ioport_read(0, addr); #ifdef DEBUG_IOPORT if (loglevel & CPU_LOG_IOPORT) fprintf(logfile, "inb : %04x %02x\n", addr, val); @@ -445,7 +460,7 @@ int cpu_inw(CPUState *env, int addr) { int val; - val = ioport_read_table[1][addr](ioport_opaque[addr], addr); + val = ioport_read(1, addr); #ifdef DEBUG_IOPORT if (loglevel & CPU_LOG_IOPORT) fprintf(logfile, "inw : %04x %04x\n", addr, val); @@ -460,7 +475,7 @@ int cpu_inl(CPUState *env, int addr) { int val; - val = ioport_read_table[2][addr](ioport_opaque[addr], addr); + val = ioport_read(2, addr); #ifdef DEBUG_IOPORT if (loglevel & CPU_LOG_IOPORT) fprintf(logfile, "inl : %04x %08x\n", addr, val); @@ -8832,8 +8847,6 @@ register_savevm("timer", 0, 2, timer_save, timer_load, NULL); register_savevm("ram", 0, 2, ram_save, ram_load, NULL); - init_ioports(); - /* terminal init */ memset(&display_state, 0, sizeof(display_state)); if (nographic) {