H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Bochs-style debug console ("port E9") emulation |
| 3 | * |
| 4 | * Copyright (c) 2003-2004 Fabrice Bellard |
| 5 | * Copyright (c) 2008 Citrix Systems, Inc. |
| 6 | * Copyright (c) Intel Corporation; author: H. Peter Anvin |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #include "hw.h" |
| 28 | #include "qemu-char.h" |
| 29 | #include "isa.h" |
| 30 | #include "pc.h" |
| 31 | |
| 32 | //#define DEBUG_DEBUGCON |
| 33 | |
| 34 | typedef struct DebugconState { |
| 35 | CharDriverState *chr; |
| 36 | uint32_t readback; |
| 37 | } DebugconState; |
| 38 | |
| 39 | typedef struct ISADebugconState { |
| 40 | ISADevice dev; |
| 41 | uint32_t iobase; |
| 42 | DebugconState state; |
| 43 | } ISADebugconState; |
| 44 | |
| 45 | static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
| 46 | { |
| 47 | DebugconState *s = opaque; |
| 48 | unsigned char ch = val; |
| 49 | |
| 50 | #ifdef DEBUG_DEBUGCON |
| 51 | printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val); |
| 52 | #endif |
| 53 | |
Anthony Liguori | 2cc6e0a | 2011-08-15 11:17:28 -0500 | [diff] [blame] | 54 | qemu_chr_fe_write(s->chr, &ch, 1); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | |
| 58 | static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr) |
| 59 | { |
| 60 | DebugconState *s = opaque; |
| 61 | |
| 62 | #ifdef DEBUG_DEBUGCON |
Adam Lackorzynski | 0534163 | 2010-04-01 23:45:25 +0200 | [diff] [blame] | 63 | printf("debugcon: read addr=0x%04x\n", addr); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | return s->readback; |
| 67 | } |
| 68 | |
| 69 | static void debugcon_init_core(DebugconState *s) |
| 70 | { |
| 71 | if (!s->chr) { |
| 72 | fprintf(stderr, "Can't create debugcon device, empty char device\n"); |
| 73 | exit(1); |
| 74 | } |
| 75 | |
| 76 | qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s); |
| 77 | } |
| 78 | |
| 79 | static int debugcon_isa_initfn(ISADevice *dev) |
| 80 | { |
| 81 | ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev); |
| 82 | DebugconState *s = &isa->state; |
| 83 | |
| 84 | debugcon_init_core(s); |
| 85 | register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s); |
| 86 | register_ioport_read(isa->iobase, 1, 1, debugcon_ioport_read, s); |
| 87 | return 0; |
| 88 | } |
| 89 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 90 | static Property debugcon_isa_properties[] = { |
| 91 | DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase, 0xe9), |
| 92 | DEFINE_PROP_CHR("chardev", ISADebugconState, state.chr), |
| 93 | DEFINE_PROP_HEX32("readback", ISADebugconState, state.readback, 0xe9), |
| 94 | DEFINE_PROP_END_OF_LIST(), |
| 95 | }; |
| 96 | |
Anthony Liguori | 8f04ee0 | 2011-12-04 11:52:49 -0600 | [diff] [blame] | 97 | static void debugcon_isa_class_initfn(ObjectClass *klass, void *data) |
| 98 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 99 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 8f04ee0 | 2011-12-04 11:52:49 -0600 | [diff] [blame] | 100 | ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); |
| 101 | ic->init = debugcon_isa_initfn; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 102 | dc->props = debugcon_isa_properties; |
Anthony Liguori | 8f04ee0 | 2011-12-04 11:52:49 -0600 | [diff] [blame] | 103 | } |
| 104 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 105 | static TypeInfo debugcon_isa_info = { |
| 106 | .name = "isa-debugcon", |
| 107 | .parent = TYPE_ISA_DEVICE, |
| 108 | .instance_size = sizeof(ISADebugconState), |
| 109 | .class_init = debugcon_isa_class_initfn, |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 112 | static void debugcon_register_types(void) |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 113 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 114 | type_register_static(&debugcon_isa_info); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 117 | type_init(debugcon_register_types) |