cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

pvpanic.c (1634B)


      1/*
      2 * QEMU simulated pvpanic device.
      3 *
      4 * Copyright Fujitsu, Corp. 2013
      5 *
      6 * Authors:
      7 *     Wen Congyang <wency@cn.fujitsu.com>
      8 *     Hu Tao <hutao@cn.fujitsu.com>
      9 *
     10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
     11 * See the COPYING file in the top-level directory.
     12 *
     13 */
     14
     15#include "qemu/osdep.h"
     16#include "qemu/log.h"
     17#include "qemu/module.h"
     18#include "sysemu/runstate.h"
     19
     20#include "hw/nvram/fw_cfg.h"
     21#include "hw/qdev-properties.h"
     22#include "hw/misc/pvpanic.h"
     23#include "qom/object.h"
     24
     25static void handle_event(int event)
     26{
     27    static bool logged;
     28
     29    if (event & ~(PVPANIC_PANICKED | PVPANIC_CRASHLOADED) && !logged) {
     30        qemu_log_mask(LOG_GUEST_ERROR, "pvpanic: unknown event %#x.\n", event);
     31        logged = true;
     32    }
     33
     34    if (event & PVPANIC_PANICKED) {
     35        qemu_system_guest_panicked(NULL);
     36        return;
     37    }
     38
     39    if (event & PVPANIC_CRASHLOADED) {
     40        qemu_system_guest_crashloaded(NULL);
     41        return;
     42    }
     43}
     44
     45/* return supported events on read */
     46static uint64_t pvpanic_read(void *opaque, hwaddr addr, unsigned size)
     47{
     48    PVPanicState *pvp = opaque;
     49    return pvp->events;
     50}
     51
     52static void pvpanic_write(void *opaque, hwaddr addr, uint64_t val,
     53                                 unsigned size)
     54{
     55    handle_event(val);
     56}
     57
     58static const MemoryRegionOps pvpanic_ops = {
     59    .read = pvpanic_read,
     60    .write = pvpanic_write,
     61    .impl = {
     62        .min_access_size = 1,
     63        .max_access_size = 1,
     64    },
     65};
     66
     67void pvpanic_setup_io(PVPanicState *s, DeviceState *dev, unsigned size)
     68{
     69    memory_region_init_io(&s->mr, OBJECT(dev), &pvpanic_ops, s, "pvpanic", size);
     70}