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 int debug_exit_initfn(ISADevice *dev) 39 { 40 ISADebugExitState *isa = ISA_DEBUG_EXIT_DEVICE(dev); 41 42 memory_region_init_io(&isa->io, &debug_exit_ops, isa, 43 TYPE_ISA_DEBUG_EXIT_DEVICE, isa->iosize); 44 memory_region_add_subregion(isa_address_space_io(dev), 45 isa->iobase, &isa->io); 46 return 0; 47 } 48 49 static Property debug_exit_properties[] = { 50 DEFINE_PROP_HEX32("iobase", ISADebugExitState, iobase, 0x501), 51 DEFINE_PROP_HEX32("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 ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); 59 ic->init = debug_exit_initfn; 60 dc->props = debug_exit_properties; 61 } 62 63 static const TypeInfo debug_exit_info = { 64 .name = TYPE_ISA_DEBUG_EXIT_DEVICE, 65 .parent = TYPE_ISA_DEVICE, 66 .instance_size = sizeof(ISADebugExitState), 67 .class_init = debug_exit_class_initfn, 68 }; 69 70 static void debug_exit_register_types(void) 71 { 72 type_register_static(&debug_exit_info); 73 } 74 75 type_init(debug_exit_register_types) 76