Commit 477e3edf8be5f0b998d19766198b6cf6b847557f
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
vl.c
| @@ -260,6 +260,35 @@ QEMUTimer *icount_vm_timer; | @@ -260,6 +260,35 @@ QEMUTimer *icount_vm_timer; | ||
| 260 | target_phys_addr_t isa_mem_base = 0; | 260 | target_phys_addr_t isa_mem_base = 0; |
| 261 | PicState2 *isa_pic; | 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 | static uint32_t default_ioport_readb(void *opaque, uint32_t address) | 292 | static uint32_t default_ioport_readb(void *opaque, uint32_t address) |
| 264 | { | 293 | { |
| 265 | #ifdef DEBUG_UNUSED_IOPORT | 294 | #ifdef DEBUG_UNUSED_IOPORT |
| @@ -279,17 +308,17 @@ static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data) | @@ -279,17 +308,17 @@ static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data) | ||
| 279 | static uint32_t default_ioport_readw(void *opaque, uint32_t address) | 308 | static uint32_t default_ioport_readw(void *opaque, uint32_t address) |
| 280 | { | 309 | { |
| 281 | uint32_t data; | 310 | uint32_t data; |
| 282 | - data = ioport_read_table[0][address](ioport_opaque[address], address); | 311 | + data = ioport_read(0, address); |
| 283 | address = (address + 1) & (MAX_IOPORTS - 1); | 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 | return data; | 314 | return data; |
| 286 | } | 315 | } |
| 287 | 316 | ||
| 288 | static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) | 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 | address = (address + 1) & (MAX_IOPORTS - 1); | 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 | static uint32_t default_ioport_readl(void *opaque, uint32_t address) | 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,20 +336,6 @@ static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data) | ||
| 307 | #endif | 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 | /* size is the word size in byte */ | 339 | /* size is the word size in byte */ |
| 325 | int register_ioport_read(int start, int length, int size, | 340 | int register_ioport_read(int start, int length, int size, |
| 326 | IOPortReadFunc *func, void *opaque) | 341 | IOPortReadFunc *func, void *opaque) |
| @@ -394,7 +409,7 @@ void cpu_outb(CPUState *env, int addr, int val) | @@ -394,7 +409,7 @@ void cpu_outb(CPUState *env, int addr, int val) | ||
| 394 | if (loglevel & CPU_LOG_IOPORT) | 409 | if (loglevel & CPU_LOG_IOPORT) |
| 395 | fprintf(logfile, "outb: %04x %02x\n", addr, val); | 410 | fprintf(logfile, "outb: %04x %02x\n", addr, val); |
| 396 | #endif | 411 | #endif |
| 397 | - ioport_write_table[0][addr](ioport_opaque[addr], addr, val); | 412 | + ioport_write(0, addr, val); |
| 398 | #ifdef USE_KQEMU | 413 | #ifdef USE_KQEMU |
| 399 | if (env) | 414 | if (env) |
| 400 | env->last_io_time = cpu_get_time_fast(); | 415 | env->last_io_time = cpu_get_time_fast(); |
| @@ -407,7 +422,7 @@ void cpu_outw(CPUState *env, int addr, int val) | @@ -407,7 +422,7 @@ void cpu_outw(CPUState *env, int addr, int val) | ||
| 407 | if (loglevel & CPU_LOG_IOPORT) | 422 | if (loglevel & CPU_LOG_IOPORT) |
| 408 | fprintf(logfile, "outw: %04x %04x\n", addr, val); | 423 | fprintf(logfile, "outw: %04x %04x\n", addr, val); |
| 409 | #endif | 424 | #endif |
| 410 | - ioport_write_table[1][addr](ioport_opaque[addr], addr, val); | 425 | + ioport_write(1, addr, val); |
| 411 | #ifdef USE_KQEMU | 426 | #ifdef USE_KQEMU |
| 412 | if (env) | 427 | if (env) |
| 413 | env->last_io_time = cpu_get_time_fast(); | 428 | env->last_io_time = cpu_get_time_fast(); |
| @@ -420,7 +435,7 @@ void cpu_outl(CPUState *env, int addr, int val) | @@ -420,7 +435,7 @@ void cpu_outl(CPUState *env, int addr, int val) | ||
| 420 | if (loglevel & CPU_LOG_IOPORT) | 435 | if (loglevel & CPU_LOG_IOPORT) |
| 421 | fprintf(logfile, "outl: %04x %08x\n", addr, val); | 436 | fprintf(logfile, "outl: %04x %08x\n", addr, val); |
| 422 | #endif | 437 | #endif |
| 423 | - ioport_write_table[2][addr](ioport_opaque[addr], addr, val); | 438 | + ioport_write(2, addr, val); |
| 424 | #ifdef USE_KQEMU | 439 | #ifdef USE_KQEMU |
| 425 | if (env) | 440 | if (env) |
| 426 | env->last_io_time = cpu_get_time_fast(); | 441 | env->last_io_time = cpu_get_time_fast(); |
| @@ -430,7 +445,7 @@ void cpu_outl(CPUState *env, int addr, int val) | @@ -430,7 +445,7 @@ void cpu_outl(CPUState *env, int addr, int val) | ||
| 430 | int cpu_inb(CPUState *env, int addr) | 445 | int cpu_inb(CPUState *env, int addr) |
| 431 | { | 446 | { |
| 432 | int val; | 447 | int val; |
| 433 | - val = ioport_read_table[0][addr](ioport_opaque[addr], addr); | 448 | + val = ioport_read(0, addr); |
| 434 | #ifdef DEBUG_IOPORT | 449 | #ifdef DEBUG_IOPORT |
| 435 | if (loglevel & CPU_LOG_IOPORT) | 450 | if (loglevel & CPU_LOG_IOPORT) |
| 436 | fprintf(logfile, "inb : %04x %02x\n", addr, val); | 451 | fprintf(logfile, "inb : %04x %02x\n", addr, val); |
| @@ -445,7 +460,7 @@ int cpu_inb(CPUState *env, int addr) | @@ -445,7 +460,7 @@ int cpu_inb(CPUState *env, int addr) | ||
| 445 | int cpu_inw(CPUState *env, int addr) | 460 | int cpu_inw(CPUState *env, int addr) |
| 446 | { | 461 | { |
| 447 | int val; | 462 | int val; |
| 448 | - val = ioport_read_table[1][addr](ioport_opaque[addr], addr); | 463 | + val = ioport_read(1, addr); |
| 449 | #ifdef DEBUG_IOPORT | 464 | #ifdef DEBUG_IOPORT |
| 450 | if (loglevel & CPU_LOG_IOPORT) | 465 | if (loglevel & CPU_LOG_IOPORT) |
| 451 | fprintf(logfile, "inw : %04x %04x\n", addr, val); | 466 | fprintf(logfile, "inw : %04x %04x\n", addr, val); |
| @@ -460,7 +475,7 @@ int cpu_inw(CPUState *env, int addr) | @@ -460,7 +475,7 @@ int cpu_inw(CPUState *env, int addr) | ||
| 460 | int cpu_inl(CPUState *env, int addr) | 475 | int cpu_inl(CPUState *env, int addr) |
| 461 | { | 476 | { |
| 462 | int val; | 477 | int val; |
| 463 | - val = ioport_read_table[2][addr](ioport_opaque[addr], addr); | 478 | + val = ioport_read(2, addr); |
| 464 | #ifdef DEBUG_IOPORT | 479 | #ifdef DEBUG_IOPORT |
| 465 | if (loglevel & CPU_LOG_IOPORT) | 480 | if (loglevel & CPU_LOG_IOPORT) |
| 466 | fprintf(logfile, "inl : %04x %08x\n", addr, val); | 481 | fprintf(logfile, "inl : %04x %08x\n", addr, val); |
| @@ -8832,8 +8847,6 @@ int main(int argc, char **argv) | @@ -8832,8 +8847,6 @@ int main(int argc, char **argv) | ||
| 8832 | register_savevm("timer", 0, 2, timer_save, timer_load, NULL); | 8847 | register_savevm("timer", 0, 2, timer_save, timer_load, NULL); |
| 8833 | register_savevm("ram", 0, 2, ram_save, ram_load, NULL); | 8848 | register_savevm("ram", 0, 2, ram_save, ram_load, NULL); |
| 8834 | 8849 | ||
| 8835 | - init_ioports(); | ||
| 8836 | - | ||
| 8837 | /* terminal init */ | 8850 | /* terminal init */ |
| 8838 | memset(&display_state, 0, sizeof(display_state)); | 8851 | memset(&display_state, 0, sizeof(display_state)); |
| 8839 | if (nographic) { | 8852 | if (nographic) { |