qemu/hw/misc/debugexit.c
<<
>>
Prefs
   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/hw.h"
  12#include "hw/isa/isa.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
  19typedef struct ISADebugExitState {
  20    ISADevice parent_obj;
  21
  22    uint32_t iobase;
  23    uint32_t iosize;
  24    MemoryRegion io;
  25} ISADebugExitState;
  26
  27static uint64_t debug_exit_read(void *opaque, hwaddr addr, unsigned size)
  28{
  29    return 0;
  30}
  31
  32static void debug_exit_write(void *opaque, hwaddr addr, uint64_t val,
  33                             unsigned width)
  34{
  35    exit((val << 1) | 1);
  36}
  37
  38static 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
  46static 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
  57static 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
  63static 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
  72static 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
  79static void debug_exit_register_types(void)
  80{
  81    type_register_static(&debug_exit_info);
  82}
  83
  84type_init(debug_exit_register_types)
  85