dtod.cc revision 3943
113312Sgabeblack@google.com/* 213312Sgabeblack@google.com * Copyright (c) 2004-2006 The Regents of The University of Michigan 313312Sgabeblack@google.com * All rights reserved. 413312Sgabeblack@google.com * 513312Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 613312Sgabeblack@google.com * modification, are permitted provided that the following conditions are 713312Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 813312Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 913312Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1013312Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1113312Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1213312Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1313312Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1413312Sgabeblack@google.com * this software without specific prior written permission. 1513312Sgabeblack@google.com * 1613312Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713312Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813312Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913312Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013312Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113312Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213312Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313312Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413312Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513312Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613312Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713312Sgabeblack@google.com * 2813312Sgabeblack@google.com * Authors: Ali Saidi 2913312Sgabeblack@google.com */ 3013312Sgabeblack@google.com 3113312Sgabeblack@google.com/** @file 3213312Sgabeblack@google.com * Time of date device implementation 3313316Sgabeblack@google.com */ 3413312Sgabeblack@google.com#include <sys/time.h> 3513312Sgabeblack@google.com 3613312Sgabeblack@google.com#include <deque> 3713316Sgabeblack@google.com#include <string> 3813312Sgabeblack@google.com#include <vector> 3913312Sgabeblack@google.com 4013312Sgabeblack@google.com#include "base/trace.hh" 4113312Sgabeblack@google.com#include "dev/sparc/dtod.hh" 4213312Sgabeblack@google.com#include "dev/platform.hh" 4313312Sgabeblack@google.com#include "mem/packet_access.hh" 4413312Sgabeblack@google.com#include "mem/port.hh" 4513312Sgabeblack@google.com#include "sim/builder.hh" 4613312Sgabeblack@google.com#include "sim/system.hh" 4713312Sgabeblack@google.com 4813312Sgabeblack@google.comusing namespace std; 4913312Sgabeblack@google.comusing namespace TheISA; 5013312Sgabeblack@google.com 5113312Sgabeblack@google.comDumbTOD::DumbTOD(Params *p) 5213312Sgabeblack@google.com : BasicPioDevice(p) 5313312Sgabeblack@google.com{ 5413312Sgabeblack@google.com pioSize = 0x08; 5513312Sgabeblack@google.com 5613312Sgabeblack@google.com struct tm tm; 5713312Sgabeblack@google.com parseTime(p->init_time, &tm); 5813312Sgabeblack@google.com todTime = timegm(&tm); 5913312Sgabeblack@google.com 6013312Sgabeblack@google.com DPRINTFN("Real-time clock set to %s\n", asctime(&tm)); 6113312Sgabeblack@google.com DPRINTFN("Real-time clock set to %d\n", todTime); 6213312Sgabeblack@google.com} 6313312Sgabeblack@google.com 6413312Sgabeblack@google.comTick 6513312Sgabeblack@google.comDumbTOD::read(PacketPtr pkt) 6613312Sgabeblack@google.com{ 6713312Sgabeblack@google.com assert(pkt->result == Packet::Unknown); 6813312Sgabeblack@google.com assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize); 6913312Sgabeblack@google.com assert(pkt->getSize() == 8); 7013312Sgabeblack@google.com 7113312Sgabeblack@google.com pkt->allocate(); 7213312Sgabeblack@google.com pkt->set(todTime); 7313312Sgabeblack@google.com todTime += 1000; 7413312Sgabeblack@google.com 7513312Sgabeblack@google.com pkt->result = Packet::Success; 7613312Sgabeblack@google.com return pioDelay; 7713312Sgabeblack@google.com} 7813312Sgabeblack@google.com 7913312Sgabeblack@google.comTick 8013312Sgabeblack@google.comDumbTOD::write(PacketPtr pkt) 8113312Sgabeblack@google.com{ 8213312Sgabeblack@google.com panic("Dumb tod device doesn't support writes\n"); 8313312Sgabeblack@google.com} 8413312Sgabeblack@google.com 8513312Sgabeblack@google.comBEGIN_DECLARE_SIM_OBJECT_PARAMS(DumbTOD) 8613312Sgabeblack@google.com 8713312Sgabeblack@google.com Param<Addr> pio_addr; 8813312Sgabeblack@google.com Param<Tick> pio_latency; 8913312Sgabeblack@google.com SimObjectParam<Platform *> platform; 9013312Sgabeblack@google.com SimObjectParam<System *> system; 9113312Sgabeblack@google.com VectorParam<int> time; 9213312Sgabeblack@google.com 9313312Sgabeblack@google.comEND_DECLARE_SIM_OBJECT_PARAMS(DumbTOD) 9413312Sgabeblack@google.com 9513312Sgabeblack@google.comBEGIN_INIT_SIM_OBJECT_PARAMS(DumbTOD) 9613401Sgabeblack@google.com 9713401Sgabeblack@google.com INIT_PARAM(pio_addr, "Device Address"), 9813401Sgabeblack@google.com INIT_PARAM(pio_latency, "Programmed IO latency"), 9913312Sgabeblack@google.com INIT_PARAM(platform, "platform"), 10013312Sgabeblack@google.com INIT_PARAM(system, "system object"), 10113312Sgabeblack@google.com INIT_PARAM(time, "") 10213312Sgabeblack@google.com 10313312Sgabeblack@google.comEND_INIT_SIM_OBJECT_PARAMS(DumbTOD) 10413312Sgabeblack@google.com 10513312Sgabeblack@google.comCREATE_SIM_OBJECT(DumbTOD) 10613312Sgabeblack@google.com{ 10713312Sgabeblack@google.com DumbTOD::Params *p = new DumbTOD::Params; 10813312Sgabeblack@google.com p->name =getInstanceName(); 10913312Sgabeblack@google.com p->pio_addr = pio_addr; 11013313Sgabeblack@google.com p->pio_delay = pio_latency; 11113313Sgabeblack@google.com p->platform = platform; 11213316Sgabeblack@google.com p->system = system; 11313316Sgabeblack@google.com p->init_time = time; 11413323Sgabeblack@google.com return new DumbTOD(p); 11513323Sgabeblack@google.com} 11613323Sgabeblack@google.com 11713323Sgabeblack@google.comREGISTER_SIM_OBJECT("DumbTOD", DumbTOD) 11813323Sgabeblack@google.com