Commit ceecf1d158d324c61a7ec1ba5de57dbc8a0f8373
1 parent
9c554c1c
add an init function parameter to qemu_chr_open()
And use it for the malta emulation. Fix segfault introduced in revision 6352. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6365 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
9 changed files
with
37 additions
and
26 deletions
console.c
... | ... | @@ -1357,6 +1357,8 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const c |
1357 | 1357 | text_console_resize(s); |
1358 | 1358 | |
1359 | 1359 | qemu_chr_reset(chr); |
1360 | + if (chr->init) | |
1361 | + chr->init(chr); | |
1360 | 1362 | } |
1361 | 1363 | |
1362 | 1364 | CharDriverState *text_console_init(const char *p) | ... | ... |
gdbstub.c
hw/mips_malta.c
... | ... | @@ -418,7 +418,24 @@ static void malta_fpga_reset(void *opaque) |
418 | 418 | |
419 | 419 | s->display_text[8] = '\0'; |
420 | 420 | snprintf(s->display_text, 9, " "); |
421 | - malta_fpga_update_display(s); | |
421 | +} | |
422 | + | |
423 | +static void malta_fpga_uart_init(CharDriverState *chr) | |
424 | +{ | |
425 | + qemu_chr_printf(chr, "CBUS UART\r\n"); | |
426 | +} | |
427 | + | |
428 | +static void malta_fpga_led_init(CharDriverState *chr) | |
429 | +{ | |
430 | + qemu_chr_printf(chr, "\e[HMalta LEDBAR\r\n"); | |
431 | + qemu_chr_printf(chr, "+--------+\r\n"); | |
432 | + qemu_chr_printf(chr, "+ +\r\n"); | |
433 | + qemu_chr_printf(chr, "+--------+\r\n"); | |
434 | + qemu_chr_printf(chr, "\n"); | |
435 | + qemu_chr_printf(chr, "Malta ASCII\r\n"); | |
436 | + qemu_chr_printf(chr, "+--------+\r\n"); | |
437 | + qemu_chr_printf(chr, "+ +\r\n"); | |
438 | + qemu_chr_printf(chr, "+--------+\r\n"); | |
422 | 439 | } |
423 | 440 | |
424 | 441 | static MaltaFPGAState *malta_fpga_init(target_phys_addr_t base, CPUState *env) |
... | ... | @@ -436,19 +453,9 @@ static MaltaFPGAState *malta_fpga_init(target_phys_addr_t base, CPUState *env) |
436 | 453 | /* 0xa00 is less than a page, so will still get the right offsets. */ |
437 | 454 | cpu_register_physical_memory(base + 0xa00, 0x100000 - 0xa00, malta); |
438 | 455 | |
439 | - s->display = qemu_chr_open("fpga", "vc:320x200"); | |
440 | - qemu_chr_printf(s->display, "\e[HMalta LEDBAR\r\n"); | |
441 | - qemu_chr_printf(s->display, "+--------+\r\n"); | |
442 | - qemu_chr_printf(s->display, "+ +\r\n"); | |
443 | - qemu_chr_printf(s->display, "+--------+\r\n"); | |
444 | - qemu_chr_printf(s->display, "\n"); | |
445 | - qemu_chr_printf(s->display, "Malta ASCII\r\n"); | |
446 | - qemu_chr_printf(s->display, "+--------+\r\n"); | |
447 | - qemu_chr_printf(s->display, "+ +\r\n"); | |
448 | - qemu_chr_printf(s->display, "+--------+\r\n"); | |
449 | - | |
450 | - uart_chr = qemu_chr_open("cbus", "vc:80Cx24C"); | |
451 | - qemu_chr_printf(uart_chr, "CBUS UART\r\n"); | |
456 | + s->display = qemu_chr_open("fpga", "vc:320x200", malta_fpga_led_init); | |
457 | + | |
458 | + uart_chr = qemu_chr_open("cbus", "vc:80Cx24C", malta_fpga_uart_init); | |
452 | 459 | s->uart = |
453 | 460 | serial_mm_init(base + 0x900, 3, env->irq[2], 230400, uart_chr, 1); |
454 | 461 | ... | ... |
hw/omap1.c
... | ... | @@ -1988,7 +1988,7 @@ struct omap_uart_s *omap_uart_init(target_phys_addr_t base, |
1988 | 1988 | s->fclk = fclk; |
1989 | 1989 | s->irq = irq; |
1990 | 1990 | s->serial = serial_mm_init(base, 2, irq, omap_clk_getrate(fclk)/16, |
1991 | - chr ?: qemu_chr_open("null", "null"), 1); | |
1991 | + chr ?: qemu_chr_open("null", "null", NULL), 1); | |
1992 | 1992 | |
1993 | 1993 | return s; |
1994 | 1994 | } |
... | ... | @@ -2104,7 +2104,7 @@ void omap_uart_attach(struct omap_uart_s *s, CharDriverState *chr) |
2104 | 2104 | /* TODO: Should reuse or destroy current s->serial */ |
2105 | 2105 | s->serial = serial_mm_init(s->base, 2, s->irq, |
2106 | 2106 | omap_clk_getrate(s->fclk) / 16, |
2107 | - chr ?: qemu_chr_open("null", "null"), 1); | |
2107 | + chr ?: qemu_chr_open("null", "null", NULL), 1); | |
2108 | 2108 | } |
2109 | 2109 | |
2110 | 2110 | /* MPU Clock/Reset/Power Mode Control */ | ... | ... |
hw/omap2.c
... | ... | @@ -2161,7 +2161,7 @@ static struct omap_sti_s *omap_sti_init(struct omap_target_agent_s *ta, |
2161 | 2161 | s->irq = irq; |
2162 | 2162 | omap_sti_reset(s); |
2163 | 2163 | |
2164 | - s->chr = chr ?: qemu_chr_open("null", "null"); | |
2164 | + s->chr = chr ?: qemu_chr_open("null", "null", NULL); | |
2165 | 2165 | |
2166 | 2166 | iomemtype = l4_register_io_memory(0, omap_sti_readfn, |
2167 | 2167 | omap_sti_writefn, s); | ... | ... |
hw/usb-serial.c
... | ... | @@ -558,7 +558,7 @@ USBDevice *usb_serial_init(const char *filename) |
558 | 558 | return NULL; |
559 | 559 | |
560 | 560 | snprintf(label, sizeof(label), "usbserial%d", index++); |
561 | - cdrv = qemu_chr_open(label, filename); | |
561 | + cdrv = qemu_chr_open(label, filename, NULL); | |
562 | 562 | if (!cdrv) |
563 | 563 | goto fail; |
564 | 564 | s->cs = cdrv; | ... | ... |
qemu-char.c
... | ... | @@ -2122,7 +2122,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str, |
2122 | 2122 | static TAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs |
2123 | 2123 | = TAILQ_HEAD_INITIALIZER(chardevs); |
2124 | 2124 | |
2125 | -CharDriverState *qemu_chr_open(const char *label, const char *filename) | |
2125 | +CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*init)(struct CharDriverState *s)) | |
2126 | 2126 | { |
2127 | 2127 | const char *p; |
2128 | 2128 | CharDriverState *chr; |
... | ... | @@ -2146,7 +2146,7 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename) |
2146 | 2146 | chr = qemu_chr_open_udp(p); |
2147 | 2147 | } else |
2148 | 2148 | if (strstart(filename, "mon:", &p)) { |
2149 | - chr = qemu_chr_open(label, p); | |
2149 | + chr = qemu_chr_open(label, p, NULL); | |
2150 | 2150 | if (chr) { |
2151 | 2151 | chr = qemu_chr_open_mux(chr); |
2152 | 2152 | monitor_init(chr, !nographic); |
... | ... | @@ -2207,6 +2207,7 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename) |
2207 | 2207 | if (chr) { |
2208 | 2208 | if (!chr->filename) |
2209 | 2209 | chr->filename = qemu_strdup(filename); |
2210 | + chr->init = init; | |
2210 | 2211 | chr->label = qemu_strdup(label); |
2211 | 2212 | TAILQ_INSERT_TAIL(&chardevs, chr, next); |
2212 | 2213 | } | ... | ... |
qemu-char.h
... | ... | @@ -43,6 +43,7 @@ typedef struct { |
43 | 43 | typedef void IOEventHandler(void *opaque, int event); |
44 | 44 | |
45 | 45 | struct CharDriverState { |
46 | + void (*init)(struct CharDriverState *s); | |
46 | 47 | int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); |
47 | 48 | void (*chr_update_read_handler)(struct CharDriverState *s); |
48 | 49 | int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); |
... | ... | @@ -61,7 +62,7 @@ struct CharDriverState { |
61 | 62 | TAILQ_ENTRY(CharDriverState) next; |
62 | 63 | }; |
63 | 64 | |
64 | -CharDriverState *qemu_chr_open(const char *label, const char *filename); | |
65 | +CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*init)(struct CharDriverState *s)); | |
65 | 66 | void qemu_chr_close(CharDriverState *chr); |
66 | 67 | void qemu_chr_printf(CharDriverState *s, const char *fmt, ...); |
67 | 68 | int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len); | ... | ... |
vl.c
... | ... | @@ -5462,7 +5462,7 @@ int main(int argc, char **argv, char **envp) |
5462 | 5462 | } |
5463 | 5463 | |
5464 | 5464 | if (monitor_device) { |
5465 | - monitor_hd = qemu_chr_open("monitor", monitor_device); | |
5465 | + monitor_hd = qemu_chr_open("monitor", monitor_device, NULL); | |
5466 | 5466 | if (!monitor_hd) { |
5467 | 5467 | fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device); |
5468 | 5468 | exit(1); |
... | ... | @@ -5474,7 +5474,7 @@ int main(int argc, char **argv, char **envp) |
5474 | 5474 | if (devname && strcmp(devname, "none")) { |
5475 | 5475 | char label[32]; |
5476 | 5476 | snprintf(label, sizeof(label), "serial%d", i); |
5477 | - serial_hds[i] = qemu_chr_open(label, devname); | |
5477 | + serial_hds[i] = qemu_chr_open(label, devname, NULL); | |
5478 | 5478 | if (!serial_hds[i]) { |
5479 | 5479 | fprintf(stderr, "qemu: could not open serial device '%s'\n", |
5480 | 5480 | devname); |
... | ... | @@ -5488,7 +5488,7 @@ int main(int argc, char **argv, char **envp) |
5488 | 5488 | if (devname && strcmp(devname, "none")) { |
5489 | 5489 | char label[32]; |
5490 | 5490 | snprintf(label, sizeof(label), "parallel%d", i); |
5491 | - parallel_hds[i] = qemu_chr_open(label, devname); | |
5491 | + parallel_hds[i] = qemu_chr_open(label, devname, NULL); | |
5492 | 5492 | if (!parallel_hds[i]) { |
5493 | 5493 | fprintf(stderr, "qemu: could not open parallel device '%s'\n", |
5494 | 5494 | devname); |
... | ... | @@ -5502,7 +5502,7 @@ int main(int argc, char **argv, char **envp) |
5502 | 5502 | if (devname && strcmp(devname, "none")) { |
5503 | 5503 | char label[32]; |
5504 | 5504 | snprintf(label, sizeof(label), "virtcon%d", i); |
5505 | - virtcon_hds[i] = qemu_chr_open(label, devname); | |
5505 | + virtcon_hds[i] = qemu_chr_open(label, devname, NULL); | |
5506 | 5506 | if (!virtcon_hds[i]) { |
5507 | 5507 | fprintf(stderr, "qemu: could not open virtio console '%s'\n", |
5508 | 5508 | devname); | ... | ... |