xref: /openbmc/qemu/hw/misc/debugexit.c (revision d6032e06)
1 /*
2  * debug exit port emulation
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 or
7  * (at your option) any later version.
8  */
9 
10 #include "hw/hw.h"
11 #include "hw/isa/isa.h"
12 
13 #define TYPE_ISA_DEBUG_EXIT_DEVICE "isa-debug-exit"
14 #define ISA_DEBUG_EXIT_DEVICE(obj) \
15      OBJECT_CHECK(ISADebugExitState, (obj), TYPE_ISA_DEBUG_EXIT_DEVICE)
16 
17 typedef struct ISADebugExitState {
18     ISADevice parent_obj;
19 
20     uint32_t iobase;
21     uint32_t iosize;
22     MemoryRegion io;
23 } ISADebugExitState;
24 
25 static void debug_exit_write(void *opaque, hwaddr addr, uint64_t val,
26                              unsigned width)
27 {
28     exit((val << 1) | 1);
29 }
30 
31 static const MemoryRegionOps debug_exit_ops = {
32     .write = debug_exit_write,
33     .valid.min_access_size = 1,
34     .valid.max_access_size = 4,
35     .endianness = DEVICE_LITTLE_ENDIAN,
36 };
37 
38 static void debug_exit_realizefn(DeviceState *d, Error **errp)
39 {
40     ISADevice *dev = ISA_DEVICE(d);
41     ISADebugExitState *isa = ISA_DEBUG_EXIT_DEVICE(d);
42 
43     memory_region_init_io(&isa->io, OBJECT(dev), &debug_exit_ops, isa,
44                           TYPE_ISA_DEBUG_EXIT_DEVICE, isa->iosize);
45     memory_region_add_subregion(isa_address_space_io(dev),
46                                 isa->iobase, &isa->io);
47 }
48 
49 static Property debug_exit_properties[] = {
50     DEFINE_PROP_UINT32("iobase", ISADebugExitState, iobase, 0x501),
51     DEFINE_PROP_UINT32("iosize", ISADebugExitState, iosize, 0x02),
52     DEFINE_PROP_END_OF_LIST(),
53 };
54 
55 static void debug_exit_class_initfn(ObjectClass *klass, void *data)
56 {
57     DeviceClass *dc = DEVICE_CLASS(klass);
58 
59     dc->realize = debug_exit_realizefn;
60     dc->props = debug_exit_properties;
61     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
62 }
63 
64 static const TypeInfo debug_exit_info = {
65     .name          = TYPE_ISA_DEBUG_EXIT_DEVICE,
66     .parent        = TYPE_ISA_DEVICE,
67     .instance_size = sizeof(ISADebugExitState),
68     .class_init    = debug_exit_class_initfn,
69 };
70 
71 static void debug_exit_register_types(void)
72 {
73     type_register_static(&debug_exit_info);
74 }
75 
76 type_init(debug_exit_register_types)
77