pc.cc revision 5844
15389Sgblack@eecs.umich.edu/* 25446Sgblack@eecs.umich.edu * Copyright (c) 2008 The Regents of The University of Michigan 35389Sgblack@eecs.umich.edu * All rights reserved. 45389Sgblack@eecs.umich.edu * 55389Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 65389Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 75389Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 85389Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 95389Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 105389Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 115389Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 125389Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 135389Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 145389Sgblack@eecs.umich.edu * this software without specific prior written permission. 155389Sgblack@eecs.umich.edu * 165389Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175389Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185389Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195389Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205389Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215389Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225389Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235389Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245389Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255389Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265389Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275389Sgblack@eecs.umich.edu * 285389Sgblack@eecs.umich.edu * Authors: Gabe Black 295389Sgblack@eecs.umich.edu */ 305389Sgblack@eecs.umich.edu 315389Sgblack@eecs.umich.edu/** @file 325389Sgblack@eecs.umich.edu * Implementation of PC platform. 335389Sgblack@eecs.umich.edu */ 345389Sgblack@eecs.umich.edu 355389Sgblack@eecs.umich.edu#include <deque> 365389Sgblack@eecs.umich.edu#include <string> 375389Sgblack@eecs.umich.edu#include <vector> 385389Sgblack@eecs.umich.edu 395654Sgblack@eecs.umich.edu#include "arch/x86/intmessage.hh" 405389Sgblack@eecs.umich.edu#include "arch/x86/x86_traits.hh" 415389Sgblack@eecs.umich.edu#include "cpu/intr_control.hh" 425478Snate@binkert.org#include "dev/terminal.hh" 435643Sgblack@eecs.umich.edu#include "dev/x86/i82094aa.hh" 445636Sgblack@eecs.umich.edu#include "dev/x86/i8254.hh" 455830Sgblack@eecs.umich.edu#include "dev/x86/i8259.hh" 465389Sgblack@eecs.umich.edu#include "dev/x86/pc.hh" 475637Sgblack@eecs.umich.edu#include "dev/x86/south_bridge.hh" 485389Sgblack@eecs.umich.edu#include "sim/system.hh" 495389Sgblack@eecs.umich.edu 505389Sgblack@eecs.umich.eduusing namespace std; 515389Sgblack@eecs.umich.eduusing namespace TheISA; 525389Sgblack@eecs.umich.edu 535638Sgblack@eecs.umich.eduPc::Pc(const Params *p) 545389Sgblack@eecs.umich.edu : Platform(p), system(p->system) 555389Sgblack@eecs.umich.edu{ 565446Sgblack@eecs.umich.edu southBridge = NULL; 575389Sgblack@eecs.umich.edu // set the back pointer from the system to myself 585389Sgblack@eecs.umich.edu system->platform = this; 595389Sgblack@eecs.umich.edu} 605389Sgblack@eecs.umich.edu 615446Sgblack@eecs.umich.eduvoid 625638Sgblack@eecs.umich.eduPc::init() 635446Sgblack@eecs.umich.edu{ 645446Sgblack@eecs.umich.edu assert(southBridge); 655643Sgblack@eecs.umich.edu 665643Sgblack@eecs.umich.edu /* 675643Sgblack@eecs.umich.edu * Initialize the timer. 685643Sgblack@eecs.umich.edu */ 695636Sgblack@eecs.umich.edu I8254 & timer = *southBridge->pit; 705446Sgblack@eecs.umich.edu //Timer 0, mode 2, no bcd, 16 bit count 715446Sgblack@eecs.umich.edu timer.writeControl(0x34); 725446Sgblack@eecs.umich.edu //Timer 0, latch command 735446Sgblack@eecs.umich.edu timer.writeControl(0x00); 745446Sgblack@eecs.umich.edu //Write a 16 bit count of 0 755635Sgblack@eecs.umich.edu timer.writeCounter(0, 0); 765635Sgblack@eecs.umich.edu timer.writeCounter(0, 0); 775643Sgblack@eecs.umich.edu 785643Sgblack@eecs.umich.edu /* 795643Sgblack@eecs.umich.edu * Initialize the I/O APIC. 805643Sgblack@eecs.umich.edu */ 815643Sgblack@eecs.umich.edu I82094AA & ioApic = *southBridge->ioApic; 825643Sgblack@eecs.umich.edu I82094AA::RedirTableEntry entry = 0; 835654Sgblack@eecs.umich.edu entry.deliveryMode = DeliveryMode::ExtInt; 845643Sgblack@eecs.umich.edu entry.vector = 0x20; 855643Sgblack@eecs.umich.edu ioApic.writeReg(0x10, entry.bottomDW); 865643Sgblack@eecs.umich.edu ioApic.writeReg(0x11, entry.topDW); 875829Sgblack@eecs.umich.edu entry.deliveryMode = DeliveryMode::Fixed; 885829Sgblack@eecs.umich.edu entry.vector = 0x24; 895829Sgblack@eecs.umich.edu ioApic.writeReg(0x18, entry.bottomDW); 905829Sgblack@eecs.umich.edu ioApic.writeReg(0x19, entry.topDW); 915829Sgblack@eecs.umich.edu entry.mask = 1; 925829Sgblack@eecs.umich.edu entry.vector = 0x21; 935829Sgblack@eecs.umich.edu ioApic.writeReg(0x12, entry.bottomDW); 945829Sgblack@eecs.umich.edu ioApic.writeReg(0x13, entry.topDW); 955829Sgblack@eecs.umich.edu entry.vector = 0x20; 965829Sgblack@eecs.umich.edu ioApic.writeReg(0x14, entry.bottomDW); 975829Sgblack@eecs.umich.edu ioApic.writeReg(0x15, entry.topDW); 985829Sgblack@eecs.umich.edu entry.vector = 0x28; 995829Sgblack@eecs.umich.edu ioApic.writeReg(0x20, entry.bottomDW); 1005829Sgblack@eecs.umich.edu ioApic.writeReg(0x21, entry.topDW); 1015829Sgblack@eecs.umich.edu entry.vector = 0x2C; 1025829Sgblack@eecs.umich.edu ioApic.writeReg(0x28, entry.bottomDW); 1035829Sgblack@eecs.umich.edu ioApic.writeReg(0x29, entry.topDW); 1045843Sgblack@eecs.umich.edu entry.vector = 0x2E; 1055843Sgblack@eecs.umich.edu ioApic.writeReg(0x2C, entry.bottomDW); 1065843Sgblack@eecs.umich.edu ioApic.writeReg(0x2D, entry.topDW); 1075843Sgblack@eecs.umich.edu entry.vector = 0x30; 1085843Sgblack@eecs.umich.edu ioApic.writeReg(0x30, entry.bottomDW); 1095843Sgblack@eecs.umich.edu ioApic.writeReg(0x31, entry.topDW); 1105446Sgblack@eecs.umich.edu} 1115446Sgblack@eecs.umich.edu 1125389Sgblack@eecs.umich.eduTick 1135638Sgblack@eecs.umich.eduPc::intrFrequency() 1145389Sgblack@eecs.umich.edu{ 1155844Sgblack@eecs.umich.edu panic("Need implementation for intrFrequency\n"); 1165389Sgblack@eecs.umich.edu M5_DUMMY_RETURN 1175389Sgblack@eecs.umich.edu} 1185389Sgblack@eecs.umich.edu 1195389Sgblack@eecs.umich.eduvoid 1205638Sgblack@eecs.umich.eduPc::postConsoleInt() 1215389Sgblack@eecs.umich.edu{ 1225830Sgblack@eecs.umich.edu southBridge->ioApic->signalInterrupt(4); 1235830Sgblack@eecs.umich.edu southBridge->pic1->signalInterrupt(4); 1245389Sgblack@eecs.umich.edu} 1255389Sgblack@eecs.umich.edu 1265389Sgblack@eecs.umich.eduvoid 1275638Sgblack@eecs.umich.eduPc::clearConsoleInt() 1285389Sgblack@eecs.umich.edu{ 1295389Sgblack@eecs.umich.edu warn_once("Don't know what interrupt to clear for console.\n"); 1305389Sgblack@eecs.umich.edu //panic("Need implementation\n"); 1315389Sgblack@eecs.umich.edu} 1325389Sgblack@eecs.umich.edu 1335389Sgblack@eecs.umich.eduvoid 1345638Sgblack@eecs.umich.eduPc::postPciInt(int line) 1355389Sgblack@eecs.umich.edu{ 1365842Sgblack@eecs.umich.edu southBridge->ioApic->signalInterrupt(line); 1375389Sgblack@eecs.umich.edu} 1385389Sgblack@eecs.umich.edu 1395389Sgblack@eecs.umich.eduvoid 1405638Sgblack@eecs.umich.eduPc::clearPciInt(int line) 1415389Sgblack@eecs.umich.edu{ 1425842Sgblack@eecs.umich.edu warn_once("Tried to clear PCI interrupt %d\n", line); 1435389Sgblack@eecs.umich.edu} 1445389Sgblack@eecs.umich.edu 1455389Sgblack@eecs.umich.eduAddr 1465638Sgblack@eecs.umich.eduPc::pciToDma(Addr pciAddr) const 1475389Sgblack@eecs.umich.edu{ 1485844Sgblack@eecs.umich.edu return pciAddr; 1495389Sgblack@eecs.umich.edu} 1505389Sgblack@eecs.umich.edu 1515389Sgblack@eecs.umich.eduAddr 1525834Sgblack@eecs.umich.eduPc::calcPciConfigAddr(int bus, int dev, int func) 1535389Sgblack@eecs.umich.edu{ 1545389Sgblack@eecs.umich.edu assert(func < 8); 1555389Sgblack@eecs.umich.edu assert(dev < 32); 1565389Sgblack@eecs.umich.edu assert(bus == 0); 1575389Sgblack@eecs.umich.edu return (PhysAddrPrefixPciConfig | (func << 8) | (dev << 11)); 1585389Sgblack@eecs.umich.edu} 1595389Sgblack@eecs.umich.edu 1605834Sgblack@eecs.umich.eduAddr 1615834Sgblack@eecs.umich.eduPc::calcPciIOAddr(Addr addr) 1625834Sgblack@eecs.umich.edu{ 1635834Sgblack@eecs.umich.edu return PhysAddrPrefixIO + addr; 1645834Sgblack@eecs.umich.edu} 1655834Sgblack@eecs.umich.edu 1665834Sgblack@eecs.umich.eduAddr 1675834Sgblack@eecs.umich.eduPc::calcPciMemAddr(Addr addr) 1685834Sgblack@eecs.umich.edu{ 1695834Sgblack@eecs.umich.edu return addr; 1705834Sgblack@eecs.umich.edu} 1715834Sgblack@eecs.umich.edu 1725638Sgblack@eecs.umich.eduPc * 1735638Sgblack@eecs.umich.eduPcParams::create() 1745389Sgblack@eecs.umich.edu{ 1755638Sgblack@eecs.umich.edu return new Pc(this); 1765389Sgblack@eecs.umich.edu} 177