baddev.cc revision 1722
112952Sgabeblack@google.com/* 212952Sgabeblack@google.com * Copyright (c) 2004 The Regents of The University of Michigan 312952Sgabeblack@google.com * All rights reserved. 412952Sgabeblack@google.com * 512952Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612952Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712952Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912952Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112952Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212952Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312952Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412952Sgabeblack@google.com * this software without specific prior written permission. 1512952Sgabeblack@google.com * 1612952Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712952Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812952Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912952Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012952Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112952Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212952Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312952Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412952Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512952Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612952Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712952Sgabeblack@google.com */ 2812952Sgabeblack@google.com 2912952Sgabeblack@google.com/** @file 3012952Sgabeblack@google.com * BadDevice implemenation 3112957Sgabeblack@google.com */ 3212957Sgabeblack@google.com 3312957Sgabeblack@google.com#include <deque> 3412953Sgabeblack@google.com#include <string> 3513102Sgabeblack@google.com#include <vector> 3612998Sgabeblack@google.com 3712998Sgabeblack@google.com#include "base/trace.hh" 3812952Sgabeblack@google.com#include "cpu/exec_context.hh" 3912952Sgabeblack@google.com#include "dev/baddev.hh" 4012952Sgabeblack@google.com#include "dev/platform.hh" 4112952Sgabeblack@google.com#include "mem/bus/bus.hh" 4212957Sgabeblack@google.com#include "mem/bus/pio_interface.hh" 4313063Sgabeblack@google.com#include "mem/bus/pio_interface_impl.hh" 4412957Sgabeblack@google.com#include "mem/functional_mem/memory_control.hh" 4513063Sgabeblack@google.com#include "sim/builder.hh" 4612957Sgabeblack@google.com#include "sim/system.hh" 4712957Sgabeblack@google.com 4812957Sgabeblack@google.comusing namespace std; 4912957Sgabeblack@google.com 5012957Sgabeblack@google.comBadDevice::BadDevice(const string &name, Addr a, MemoryController *mmu, 5112962Sgabeblack@google.com HierParams *hier, Bus *bus, const string &devicename) 5212962Sgabeblack@google.com : PioDevice(name, NULL), addr(a), devname(devicename) 5312962Sgabeblack@google.com{ 5412962Sgabeblack@google.com mmu->add_child(this, RangeSize(addr, size)); 5512962Sgabeblack@google.com 5612962Sgabeblack@google.com if (bus) { 5712962Sgabeblack@google.com pioInterface = newPioInterface(name, hier, bus, this, 5812957Sgabeblack@google.com &BadDevice::cacheAccess); 5912957Sgabeblack@google.com pioInterface->addAddrRange(RangeSize(addr, size)); 6012957Sgabeblack@google.com } 6112957Sgabeblack@google.com 6212957Sgabeblack@google.com} 6312957Sgabeblack@google.com 6412957Sgabeblack@google.comFault 6512957Sgabeblack@google.comBadDevice::read(MemReqPtr &req, uint8_t *data) 6612957Sgabeblack@google.com{ 6712957Sgabeblack@google.com 6812957Sgabeblack@google.com panic("Device %s not imlpmented\n", devname); 6912957Sgabeblack@google.com return No_Fault; 7012957Sgabeblack@google.com} 7112957Sgabeblack@google.com 7212957Sgabeblack@google.comFault 7312957Sgabeblack@google.comBadDevice::write(MemReqPtr &req, const uint8_t *data) 7412957Sgabeblack@google.com{ 7512957Sgabeblack@google.com panic("Device %s not imlpmented\n", devname); 7612957Sgabeblack@google.com return No_Fault; 7712957Sgabeblack@google.com} 7812957Sgabeblack@google.com 7912957Sgabeblack@google.comTick 8012957Sgabeblack@google.comBadDevice::cacheAccess(MemReqPtr &req) 8112957Sgabeblack@google.com{ 8212957Sgabeblack@google.com return curTick; 8312957Sgabeblack@google.com} 8412957Sgabeblack@google.com 8512957Sgabeblack@google.comBEGIN_DECLARE_SIM_OBJECT_PARAMS(BadDevice) 8612957Sgabeblack@google.com 8712957Sgabeblack@google.com SimObjectParam<Platform *> platform; 8812957Sgabeblack@google.com SimObjectParam<MemoryController *> mmu; 8912957Sgabeblack@google.com Param<Addr> addr; 9012957Sgabeblack@google.com SimObjectParam<HierParams *> hier; 9113189Sgabeblack@google.com SimObjectParam<Bus*> io_bus; 9212957Sgabeblack@google.com Param<Tick> pio_latency; 9312957Sgabeblack@google.com Param<string> devicename; 9412957Sgabeblack@google.com 9512957Sgabeblack@google.comEND_DECLARE_SIM_OBJECT_PARAMS(BadDevice) 9612957Sgabeblack@google.com 9712957Sgabeblack@google.comBEGIN_INIT_SIM_OBJECT_PARAMS(BadDevice) 9812957Sgabeblack@google.com 9912957Sgabeblack@google.com INIT_PARAM(platform, "Platform"), 10012957Sgabeblack@google.com INIT_PARAM(mmu, "Memory Controller"), 10112957Sgabeblack@google.com INIT_PARAM(addr, "Device Address"), 10212957Sgabeblack@google.com INIT_PARAM_DFLT(hier, "Hierarchy global variables", &defaultHierParams), 10312957Sgabeblack@google.com INIT_PARAM_DFLT(io_bus, "The IO Bus to attach to", NULL), 10412957Sgabeblack@google.com INIT_PARAM_DFLT(pio_latency, "Programmed IO latency", 1000), 10512957Sgabeblack@google.com INIT_PARAM(devicename, "Name of device to error on") 10612957Sgabeblack@google.com 10712957Sgabeblack@google.comEND_INIT_SIM_OBJECT_PARAMS(BadDevice) 10813075Sgabeblack@google.com 10913075Sgabeblack@google.comCREATE_SIM_OBJECT(BadDevice) 11013075Sgabeblack@google.com{ 11113075Sgabeblack@google.com return new BadDevice(getInstanceName(), addr, mmu, hier, io_bus, 11213075Sgabeblack@google.com devicename); 11313075Sgabeblack@google.com} 11413075Sgabeblack@google.com 11513075Sgabeblack@google.comREGISTER_SIM_OBJECT("BadDevice", BadDevice) 11613189Sgabeblack@google.com