Statistics
| Branch: | Revision:

root / hw / debugcon.c @ 5ea3c2b4

History | View | Annotate | Download (3.2 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 c9f398e5 H. Peter Anvin
    qemu_chr_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 c9f398e5 H. Peter Anvin
static ISADeviceInfo debugcon_isa_info = {
91 c9f398e5 H. Peter Anvin
    .qdev.name  = "isa-debugcon",
92 c9f398e5 H. Peter Anvin
    .qdev.size  = sizeof(ISADebugconState),
93 c9f398e5 H. Peter Anvin
    .init       = debugcon_isa_initfn,
94 c9f398e5 H. Peter Anvin
    .qdev.props = (Property[]) {
95 c9f398e5 H. Peter Anvin
        DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase, 0xe9),
96 c9f398e5 H. Peter Anvin
        DEFINE_PROP_CHR("chardev",  ISADebugconState, state.chr),
97 c9f398e5 H. Peter Anvin
        DEFINE_PROP_HEX32("readback", ISADebugconState, state.readback, 0xe9),
98 c9f398e5 H. Peter Anvin
        DEFINE_PROP_END_OF_LIST(),
99 c9f398e5 H. Peter Anvin
    },
100 c9f398e5 H. Peter Anvin
};
101 c9f398e5 H. Peter Anvin
102 c9f398e5 H. Peter Anvin
static void debugcon_register_devices(void)
103 c9f398e5 H. Peter Anvin
{
104 c9f398e5 H. Peter Anvin
    isa_qdev_register(&debugcon_isa_info);
105 c9f398e5 H. Peter Anvin
}
106 c9f398e5 H. Peter Anvin
107 c9f398e5 H. Peter Anvin
device_init(debugcon_register_devices)