Statistics
| Branch: | Revision:

root / hw / debugcon.c @ c9159fe9

History | View | Annotate | Download (3.4 kB)

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