debugexit.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include "qemu/osdep.h"
  10. #include "hw/isa/isa.h"
  11. #include "hw/qdev-properties.h"
  12. #include "qemu/module.h"
  13. #include "qom/object.h"
  14. #define TYPE_ISA_DEBUG_EXIT_DEVICE "isa-debug-exit"
  15. OBJECT_DECLARE_SIMPLE_TYPE(ISADebugExitState, ISA_DEBUG_EXIT_DEVICE)
  16. struct ISADebugExitState {
  17. ISADevice parent_obj;
  18. uint32_t iobase;
  19. uint32_t iosize;
  20. MemoryRegion io;
  21. };
  22. static uint64_t debug_exit_read(void *opaque, hwaddr addr, unsigned size)
  23. {
  24. return 0;
  25. }
  26. static void debug_exit_write(void *opaque, hwaddr addr, uint64_t val,
  27. unsigned width)
  28. {
  29. exit((val << 1) | 1);
  30. }
  31. static const MemoryRegionOps debug_exit_ops = {
  32. .read = debug_exit_read,
  33. .write = debug_exit_write,
  34. .valid.min_access_size = 1,
  35. .valid.max_access_size = 4,
  36. .endianness = DEVICE_LITTLE_ENDIAN,
  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. memory_region_init_io(&isa->io, OBJECT(dev), &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. }
  47. static Property debug_exit_properties[] = {
  48. DEFINE_PROP_UINT32("iobase", ISADebugExitState, iobase, 0x501),
  49. DEFINE_PROP_UINT32("iosize", ISADebugExitState, iosize, 0x02),
  50. DEFINE_PROP_END_OF_LIST(),
  51. };
  52. static void debug_exit_class_initfn(ObjectClass *klass, void *data)
  53. {
  54. DeviceClass *dc = DEVICE_CLASS(klass);
  55. dc->realize = debug_exit_realizefn;
  56. device_class_set_props(dc, debug_exit_properties);
  57. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  58. }
  59. static const TypeInfo debug_exit_info = {
  60. .name = TYPE_ISA_DEBUG_EXIT_DEVICE,
  61. .parent = TYPE_ISA_DEVICE,
  62. .instance_size = sizeof(ISADebugExitState),
  63. .class_init = debug_exit_class_initfn,
  64. };
  65. static void debug_exit_register_types(void)
  66. {
  67. type_register_static(&debug_exit_info);
  68. }
  69. type_init(debug_exit_register_types)