2
0

debugcon.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * QEMU Bochs-style debug console ("port E9") emulation
  3. *
  4. * Copyright (c) 2003-2004 Fabrice Bellard
  5. * Copyright (c) 2008 Citrix Systems, Inc.
  6. * Copyright (c) Intel Corporation; author: H. Peter Anvin
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include "hw.h"
  27. #include "char/char.h"
  28. #include "isa.h"
  29. #include "pc.h"
  30. #define TYPE_ISA_DEBUGCON_DEVICE "isa-debugcon"
  31. #define ISA_DEBUGCON_DEVICE(obj) \
  32. OBJECT_CHECK(ISADebugconState, (obj), TYPE_ISA_DEBUGCON_DEVICE)
  33. //#define DEBUG_DEBUGCON
  34. typedef struct DebugconState {
  35. MemoryRegion io;
  36. CharDriverState *chr;
  37. uint32_t readback;
  38. } DebugconState;
  39. typedef struct ISADebugconState {
  40. ISADevice parent_obj;
  41. uint32_t iobase;
  42. DebugconState state;
  43. } ISADebugconState;
  44. static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
  45. unsigned width)
  46. {
  47. DebugconState *s = opaque;
  48. unsigned char ch = val;
  49. #ifdef DEBUG_DEBUGCON
  50. printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
  51. #endif
  52. qemu_chr_fe_write(s->chr, &ch, 1);
  53. }
  54. static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width)
  55. {
  56. DebugconState *s = opaque;
  57. #ifdef DEBUG_DEBUGCON
  58. printf("debugcon: read addr=0x%04x\n", addr);
  59. #endif
  60. return s->readback;
  61. }
  62. static const MemoryRegionOps debugcon_ops = {
  63. .read = debugcon_ioport_read,
  64. .write = debugcon_ioport_write,
  65. .valid.min_access_size = 1,
  66. .valid.max_access_size = 1,
  67. .endianness = DEVICE_LITTLE_ENDIAN,
  68. };
  69. static void debugcon_init_core(DebugconState *s)
  70. {
  71. if (!s->chr) {
  72. fprintf(stderr, "Can't create debugcon device, empty char device\n");
  73. exit(1);
  74. }
  75. qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
  76. }
  77. static int debugcon_isa_initfn(ISADevice *dev)
  78. {
  79. ISADebugconState *isa = ISA_DEBUGCON_DEVICE(dev);
  80. DebugconState *s = &isa->state;
  81. debugcon_init_core(s);
  82. memory_region_init_io(&s->io, &debugcon_ops, s,
  83. TYPE_ISA_DEBUGCON_DEVICE, 1);
  84. memory_region_add_subregion(isa_address_space_io(dev),
  85. isa->iobase, &s->io);
  86. return 0;
  87. }
  88. static Property debugcon_isa_properties[] = {
  89. DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase, 0xe9),
  90. DEFINE_PROP_CHR("chardev", ISADebugconState, state.chr),
  91. DEFINE_PROP_HEX32("readback", ISADebugconState, state.readback, 0xe9),
  92. DEFINE_PROP_END_OF_LIST(),
  93. };
  94. static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
  95. {
  96. DeviceClass *dc = DEVICE_CLASS(klass);
  97. ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
  98. ic->init = debugcon_isa_initfn;
  99. dc->props = debugcon_isa_properties;
  100. }
  101. static const TypeInfo debugcon_isa_info = {
  102. .name = TYPE_ISA_DEBUGCON_DEVICE,
  103. .parent = TYPE_ISA_DEVICE,
  104. .instance_size = sizeof(ISADebugconState),
  105. .class_init = debugcon_isa_class_initfn,
  106. };
  107. static void debugcon_register_types(void)
  108. {
  109. type_register_static(&debugcon_isa_info);
  110. }
  111. type_init(debugcon_register_types)