Commit 477e3edf8be5f0b998d19766198b6cf6b847557f

Authored by aliguori
1 parent 23e6c399

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 <samuel.thibault@eu.citrix.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4927 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 39 additions and 26 deletions
... ... @@ -260,6 +260,35 @@ QEMUTimer *icount_vm_timer;
260 260 target_phys_addr_t isa_mem_base = 0;
261 261 PicState2 *isa_pic;
262 262  
  263 +static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl;
  264 +static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel;
  265 +
  266 +static uint32_t ioport_read(int index, uint32_t address)
  267 +{
  268 + static IOPortReadFunc *default_func[3] = {
  269 + default_ioport_readb,
  270 + default_ioport_readw,
  271 + default_ioport_readl
  272 + };
  273 + IOPortReadFunc *func = ioport_read_table[index][address];
  274 + if (!func)
  275 + func = default_func[index];
  276 + return func(ioport_opaque[address], address);
  277 +}
  278 +
  279 +static void ioport_write(int index, uint32_t address, uint32_t data)
  280 +{
  281 + static IOPortWriteFunc *default_func[3] = {
  282 + default_ioport_writeb,
  283 + default_ioport_writew,
  284 + default_ioport_writel
  285 + };
  286 + IOPortWriteFunc *func = ioport_write_table[index][address];
  287 + if (!func)
  288 + func = default_func[index];
  289 + func(ioport_opaque[address], address, data);
  290 +}
  291 +
263 292 static uint32_t default_ioport_readb(void *opaque, uint32_t address)
264 293 {
265 294 #ifdef DEBUG_UNUSED_IOPORT
... ... @@ -279,17 +308,17 @@ static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data)
279 308 static uint32_t default_ioport_readw(void *opaque, uint32_t address)
280 309 {
281 310 uint32_t data;
282   - data = ioport_read_table[0][address](ioport_opaque[address], address);
  311 + data = ioport_read(0, address);
283 312 address = (address + 1) & (MAX_IOPORTS - 1);
284   - data |= ioport_read_table[0][address](ioport_opaque[address], address) << 8;
  313 + data |= ioport_read(0, address) << 8;
285 314 return data;
286 315 }
287 316  
288 317 static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
289 318 {
290   - ioport_write_table[0][address](ioport_opaque[address], address, data & 0xff);
  319 + ioport_write(0, address, data & 0xff);
291 320 address = (address + 1) & (MAX_IOPORTS - 1);
292   - ioport_write_table[0][address](ioport_opaque[address], address, (data >> 8) & 0xff);
  321 + ioport_write(0, address, (data >> 8) & 0xff);
293 322 }
294 323  
295 324 static uint32_t default_ioport_readl(void *opaque, uint32_t address)
... ... @@ -307,20 +336,6 @@ static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data)
307 336 #endif
308 337 }
309 338  
310   -static void init_ioports(void)
311   -{
312   - int i;
313   -
314   - for(i = 0; i < MAX_IOPORTS; i++) {
315   - ioport_read_table[0][i] = default_ioport_readb;
316   - ioport_write_table[0][i] = default_ioport_writeb;
317   - ioport_read_table[1][i] = default_ioport_readw;
318   - ioport_write_table[1][i] = default_ioport_writew;
319   - ioport_read_table[2][i] = default_ioport_readl;
320   - ioport_write_table[2][i] = default_ioport_writel;
321   - }
322   -}
323   -
324 339 /* size is the word size in byte */
325 340 int register_ioport_read(int start, int length, int size,
326 341 IOPortReadFunc *func, void *opaque)
... ... @@ -394,7 +409,7 @@ void cpu_outb(CPUState *env, int addr, int val)
394 409 if (loglevel & CPU_LOG_IOPORT)
395 410 fprintf(logfile, "outb: %04x %02x\n", addr, val);
396 411 #endif
397   - ioport_write_table[0][addr](ioport_opaque[addr], addr, val);
  412 + ioport_write(0, addr, val);
398 413 #ifdef USE_KQEMU
399 414 if (env)
400 415 env->last_io_time = cpu_get_time_fast();
... ... @@ -407,7 +422,7 @@ void cpu_outw(CPUState *env, int addr, int val)
407 422 if (loglevel & CPU_LOG_IOPORT)
408 423 fprintf(logfile, "outw: %04x %04x\n", addr, val);
409 424 #endif
410   - ioport_write_table[1][addr](ioport_opaque[addr], addr, val);
  425 + ioport_write(1, addr, val);
411 426 #ifdef USE_KQEMU
412 427 if (env)
413 428 env->last_io_time = cpu_get_time_fast();
... ... @@ -420,7 +435,7 @@ void cpu_outl(CPUState *env, int addr, int val)
420 435 if (loglevel & CPU_LOG_IOPORT)
421 436 fprintf(logfile, "outl: %04x %08x\n", addr, val);
422 437 #endif
423   - ioport_write_table[2][addr](ioport_opaque[addr], addr, val);
  438 + ioport_write(2, addr, val);
424 439 #ifdef USE_KQEMU
425 440 if (env)
426 441 env->last_io_time = cpu_get_time_fast();
... ... @@ -430,7 +445,7 @@ void cpu_outl(CPUState *env, int addr, int val)
430 445 int cpu_inb(CPUState *env, int addr)
431 446 {
432 447 int val;
433   - val = ioport_read_table[0][addr](ioport_opaque[addr], addr);
  448 + val = ioport_read(0, addr);
434 449 #ifdef DEBUG_IOPORT
435 450 if (loglevel & CPU_LOG_IOPORT)
436 451 fprintf(logfile, "inb : %04x %02x\n", addr, val);
... ... @@ -445,7 +460,7 @@ int cpu_inb(CPUState *env, int addr)
445 460 int cpu_inw(CPUState *env, int addr)
446 461 {
447 462 int val;
448   - val = ioport_read_table[1][addr](ioport_opaque[addr], addr);
  463 + val = ioport_read(1, addr);
449 464 #ifdef DEBUG_IOPORT
450 465 if (loglevel & CPU_LOG_IOPORT)
451 466 fprintf(logfile, "inw : %04x %04x\n", addr, val);
... ... @@ -460,7 +475,7 @@ int cpu_inw(CPUState *env, int addr)
460 475 int cpu_inl(CPUState *env, int addr)
461 476 {
462 477 int val;
463   - val = ioport_read_table[2][addr](ioport_opaque[addr], addr);
  478 + val = ioport_read(2, addr);
464 479 #ifdef DEBUG_IOPORT
465 480 if (loglevel & CPU_LOG_IOPORT)
466 481 fprintf(logfile, "inl : %04x %08x\n", addr, val);
... ... @@ -8832,8 +8847,6 @@ int main(int argc, char **argv)
8832 8847 register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
8833 8848 register_savevm("ram", 0, 2, ram_save, ram_load, NULL);
8834 8849  
8835   - init_ioports();
8836   -
8837 8850 /* terminal init */
8838 8851 memset(&display_state, 0, sizeof(display_state));
8839 8852 if (nographic) {
... ...