xref: /openbmc/qemu/hw/misc/debugexit.c (revision 2038f8c8)
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 "qemu/osdep.h"
11 #include "hw/isa/isa.h"
12 #include "hw/qdev-properties.h"
13 #include "qemu/module.h"
14 
15 #define TYPE_ISA_DEBUG_EXIT_DEVICE "isa-debug-exit"
16 #define ISA_DEBUG_EXIT_DEVICE(obj) \
17      OBJECT_CHECK(ISADebugExitState, (obj), TYPE_ISA_DEBUG_EXIT_DEVICE)
18 
19 typedef struct ISADebugExitState {
20     ISADevice parent_obj;
21 
22     uint32_t iobase;
23     uint32_t iosize;
24     MemoryRegion io;
25 } ISADebugExitState;
26 
27 static uint64_t debug_exit_read(void *opaque, hwaddr addr, unsigned size)
28 {
29     return 0;
30 }
31 
32 static void debug_exit_write(void *opaque, hwaddr addr, uint64_t val,
33                              unsigned width)
34 {
35     exit((val << 1) | 1);
36 }
37 
38 static const MemoryRegionOps debug_exit_ops = {
39     .read = debug_exit_read,
40     .write = debug_exit_write,
41     .valid.min_access_size = 1,
42     .valid.max_access_size = 4,
43     .endianness = DEVICE_LITTLE_ENDIAN,
44 };
45 
46 static void debug_exit_realizefn(DeviceState *d, Error **errp)
47 {
48     ISADevice *dev = ISA_DEVICE(d);
49     ISADebugExitState *isa = ISA_DEBUG_EXIT_DEVICE(d);
50 
51     memory_region_init_io(&isa->io, OBJECT(dev), &debug_exit_ops, isa,
52                           TYPE_ISA_DEBUG_EXIT_DEVICE, isa->iosize);
53     memory_region_add_subregion(isa_address_space_io(dev),
54                                 isa->iobase, &isa->io);
55 }
56 
57 static Property debug_exit_properties[] = {
58     DEFINE_PROP_UINT32("iobase", ISADebugExitState, iobase, 0x501),
59     DEFINE_PROP_UINT32("iosize", ISADebugExitState, iosize, 0x02),
60     DEFINE_PROP_END_OF_LIST(),
61 };
62 
63 static void debug_exit_class_initfn(ObjectClass *klass, void *data)
64 {
65     DeviceClass *dc = DEVICE_CLASS(klass);
66 
67     dc->realize = debug_exit_realizefn;
68     dc->props = debug_exit_properties;
69     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
70 }
71 
72 static const TypeInfo debug_exit_info = {
73     .name          = TYPE_ISA_DEBUG_EXIT_DEVICE,
74     .parent        = TYPE_ISA_DEVICE,
75     .instance_size = sizeof(ISADebugExitState),
76     .class_init    = debug_exit_class_initfn,
77 };
78 
79 static void debug_exit_register_types(void)
80 {
81     type_register_static(&debug_exit_info);
82 }
83 
84 type_init(debug_exit_register_types)
85