i8254.cc revision 10642
110448Snilay@cs.wisc.edu/* 210448Snilay@cs.wisc.edu * Copyright (c) 2008 The Regents of The University of Michigan 310448Snilay@cs.wisc.edu * All rights reserved. 410448Snilay@cs.wisc.edu * 510448Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without 610448Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are 710448Snilay@cs.wisc.edu * met: redistributions of source code must retain the above copyright 810448Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer; 910448Snilay@cs.wisc.edu * redistributions in binary form must reproduce the above copyright 1010448Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the 1110448Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution; 1210448Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its 1310448Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from 1410448Snilay@cs.wisc.edu * this software without specific prior written permission. 1510448Snilay@cs.wisc.edu * 1610448Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1710448Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1810448Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1910448Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2010448Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2110448Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2210447Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2310447Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2410447Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2510447Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2610447Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2710447Snilay@cs.wisc.edu * 2810447Snilay@cs.wisc.edu * Authors: Gabe Black 2910447Snilay@cs.wisc.edu */ 3010447Snilay@cs.wisc.edu 3110447Snilay@cs.wisc.edu#include "debug/I8254.hh" 3210447Snilay@cs.wisc.edu#include "dev/x86/i8254.hh" 3310447Snilay@cs.wisc.edu#include "dev/x86/intdev.hh" 3410447Snilay@cs.wisc.edu#include "mem/packet.hh" 3510447Snilay@cs.wisc.edu#include "mem/packet_access.hh" 3610447Snilay@cs.wisc.edu 3710447Snilay@cs.wisc.eduvoid 3810447Snilay@cs.wisc.eduX86ISA::I8254::counterInterrupt(unsigned int num) 3910447Snilay@cs.wisc.edu{ 4010447Snilay@cs.wisc.edu DPRINTF(I8254, "Interrupt from counter %d.\n", num); 4110447Snilay@cs.wisc.edu if (num == 0) { 4210447Snilay@cs.wisc.edu intPin->raise(); 4310447Snilay@cs.wisc.edu //XXX This is a hack. 4410447Snilay@cs.wisc.edu intPin->lower(); 4510447Snilay@cs.wisc.edu } 4610447Snilay@cs.wisc.edu} 4710447Snilay@cs.wisc.edu 4810447Snilay@cs.wisc.eduTick 4910447Snilay@cs.wisc.eduX86ISA::I8254::read(PacketPtr pkt) 5010447Snilay@cs.wisc.edu{ 5110447Snilay@cs.wisc.edu assert(pkt->getSize() == 1); 5210447Snilay@cs.wisc.edu Addr offset = pkt->getAddr() - pioAddr; 5310447Snilay@cs.wisc.edu if (offset < 3) { 5410447Snilay@cs.wisc.edu pkt->set(pit.readCounter(offset)); 5510447Snilay@cs.wisc.edu } else if (offset == 3) { 56 pkt->set(uint8_t(-1)); 57 } else { 58 panic("Read from undefined i8254 register.\n"); 59 } 60 pkt->makeAtomicResponse(); 61 return latency; 62} 63 64Tick 65X86ISA::I8254::write(PacketPtr pkt) 66{ 67 assert(pkt->getSize() == 1); 68 Addr offset = pkt->getAddr() - pioAddr; 69 if (offset < 3) { 70 pit.writeCounter(offset, pkt->get<uint8_t>()); 71 } else if (offset == 3) { 72 pit.writeControl(pkt->get<uint8_t>()); 73 } else { 74 panic("Write to undefined i8254 register.\n"); 75 } 76 pkt->makeAtomicResponse(); 77 return latency; 78} 79 80void 81X86ISA::I8254::serialize(std::ostream &os) 82{ 83 pit.serialize("pit", os); 84} 85 86void 87X86ISA::I8254::unserialize(Checkpoint *cp, const std::string §ion) 88{ 89 pit.unserialize("pit", cp, section); 90} 91 92void 93X86ISA::I8254::startup() 94{ 95 pit.startup(); 96} 97 98X86ISA::I8254 * 99I8254Params::create() 100{ 101 return new X86ISA::I8254(this); 102} 103