pc.cc revision 6658
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" 416658Snate@binkert.org#include "config/the_isa.hh" 425389Sgblack@eecs.umich.edu#include "cpu/intr_control.hh" 435478Snate@binkert.org#include "dev/terminal.hh" 445643Sgblack@eecs.umich.edu#include "dev/x86/i82094aa.hh" 455636Sgblack@eecs.umich.edu#include "dev/x86/i8254.hh" 465830Sgblack@eecs.umich.edu#include "dev/x86/i8259.hh" 475389Sgblack@eecs.umich.edu#include "dev/x86/pc.hh" 485637Sgblack@eecs.umich.edu#include "dev/x86/south_bridge.hh" 495389Sgblack@eecs.umich.edu#include "sim/system.hh" 505389Sgblack@eecs.umich.edu 515389Sgblack@eecs.umich.eduusing namespace std; 525389Sgblack@eecs.umich.eduusing namespace TheISA; 535389Sgblack@eecs.umich.edu 545638Sgblack@eecs.umich.eduPc::Pc(const Params *p) 555389Sgblack@eecs.umich.edu : Platform(p), system(p->system) 565389Sgblack@eecs.umich.edu{ 575446Sgblack@eecs.umich.edu southBridge = NULL; 585389Sgblack@eecs.umich.edu // set the back pointer from the system to myself 595389Sgblack@eecs.umich.edu system->platform = this; 605389Sgblack@eecs.umich.edu} 615389Sgblack@eecs.umich.edu 625446Sgblack@eecs.umich.eduvoid 635638Sgblack@eecs.umich.eduPc::init() 645446Sgblack@eecs.umich.edu{ 655446Sgblack@eecs.umich.edu assert(southBridge); 665643Sgblack@eecs.umich.edu 675643Sgblack@eecs.umich.edu /* 685643Sgblack@eecs.umich.edu * Initialize the timer. 695643Sgblack@eecs.umich.edu */ 705636Sgblack@eecs.umich.edu I8254 & timer = *southBridge->pit; 715446Sgblack@eecs.umich.edu //Timer 0, mode 2, no bcd, 16 bit count 725446Sgblack@eecs.umich.edu timer.writeControl(0x34); 735446Sgblack@eecs.umich.edu //Timer 0, latch command 745446Sgblack@eecs.umich.edu timer.writeControl(0x00); 755446Sgblack@eecs.umich.edu //Write a 16 bit count of 0 765635Sgblack@eecs.umich.edu timer.writeCounter(0, 0); 775635Sgblack@eecs.umich.edu timer.writeCounter(0, 0); 785643Sgblack@eecs.umich.edu 795643Sgblack@eecs.umich.edu /* 805643Sgblack@eecs.umich.edu * Initialize the I/O APIC. 815643Sgblack@eecs.umich.edu */ 825643Sgblack@eecs.umich.edu I82094AA & ioApic = *southBridge->ioApic; 835643Sgblack@eecs.umich.edu I82094AA::RedirTableEntry entry = 0; 845654Sgblack@eecs.umich.edu entry.deliveryMode = DeliveryMode::ExtInt; 855643Sgblack@eecs.umich.edu entry.vector = 0x20; 865643Sgblack@eecs.umich.edu ioApic.writeReg(0x10, entry.bottomDW); 875643Sgblack@eecs.umich.edu ioApic.writeReg(0x11, entry.topDW); 885829Sgblack@eecs.umich.edu entry.deliveryMode = DeliveryMode::Fixed; 895829Sgblack@eecs.umich.edu entry.vector = 0x24; 905829Sgblack@eecs.umich.edu ioApic.writeReg(0x18, entry.bottomDW); 915829Sgblack@eecs.umich.edu ioApic.writeReg(0x19, entry.topDW); 925829Sgblack@eecs.umich.edu entry.mask = 1; 935829Sgblack@eecs.umich.edu entry.vector = 0x21; 945829Sgblack@eecs.umich.edu ioApic.writeReg(0x12, entry.bottomDW); 955829Sgblack@eecs.umich.edu ioApic.writeReg(0x13, entry.topDW); 965829Sgblack@eecs.umich.edu entry.vector = 0x20; 975829Sgblack@eecs.umich.edu ioApic.writeReg(0x14, entry.bottomDW); 985829Sgblack@eecs.umich.edu ioApic.writeReg(0x15, entry.topDW); 995829Sgblack@eecs.umich.edu entry.vector = 0x28; 1005829Sgblack@eecs.umich.edu ioApic.writeReg(0x20, entry.bottomDW); 1015829Sgblack@eecs.umich.edu ioApic.writeReg(0x21, entry.topDW); 1025829Sgblack@eecs.umich.edu entry.vector = 0x2C; 1035829Sgblack@eecs.umich.edu ioApic.writeReg(0x28, entry.bottomDW); 1045829Sgblack@eecs.umich.edu ioApic.writeReg(0x29, entry.topDW); 1055843Sgblack@eecs.umich.edu entry.vector = 0x2E; 1065843Sgblack@eecs.umich.edu ioApic.writeReg(0x2C, entry.bottomDW); 1075843Sgblack@eecs.umich.edu ioApic.writeReg(0x2D, entry.topDW); 1085843Sgblack@eecs.umich.edu entry.vector = 0x30; 1095843Sgblack@eecs.umich.edu ioApic.writeReg(0x30, entry.bottomDW); 1105843Sgblack@eecs.umich.edu ioApic.writeReg(0x31, entry.topDW); 1116073Sgblack@eecs.umich.edu 1126073Sgblack@eecs.umich.edu /* 1136073Sgblack@eecs.umich.edu * Mask the PICs. I'm presuming the BIOS/bootloader would have cleared 1146073Sgblack@eecs.umich.edu * these out and masked them before passing control to the OS. 1156073Sgblack@eecs.umich.edu */ 1166073Sgblack@eecs.umich.edu southBridge->pic1->maskAll(); 1176073Sgblack@eecs.umich.edu southBridge->pic2->maskAll(); 1185446Sgblack@eecs.umich.edu} 1195446Sgblack@eecs.umich.edu 1205389Sgblack@eecs.umich.eduTick 1215638Sgblack@eecs.umich.eduPc::intrFrequency() 1225389Sgblack@eecs.umich.edu{ 1235844Sgblack@eecs.umich.edu panic("Need implementation for intrFrequency\n"); 1245389Sgblack@eecs.umich.edu M5_DUMMY_RETURN 1255389Sgblack@eecs.umich.edu} 1265389Sgblack@eecs.umich.edu 1275389Sgblack@eecs.umich.eduvoid 1285638Sgblack@eecs.umich.eduPc::postConsoleInt() 1295389Sgblack@eecs.umich.edu{ 1305830Sgblack@eecs.umich.edu southBridge->ioApic->signalInterrupt(4); 1315830Sgblack@eecs.umich.edu southBridge->pic1->signalInterrupt(4); 1325389Sgblack@eecs.umich.edu} 1335389Sgblack@eecs.umich.edu 1345389Sgblack@eecs.umich.eduvoid 1355638Sgblack@eecs.umich.eduPc::clearConsoleInt() 1365389Sgblack@eecs.umich.edu{ 1375389Sgblack@eecs.umich.edu warn_once("Don't know what interrupt to clear for console.\n"); 1385389Sgblack@eecs.umich.edu //panic("Need implementation\n"); 1395389Sgblack@eecs.umich.edu} 1405389Sgblack@eecs.umich.edu 1415389Sgblack@eecs.umich.eduvoid 1425638Sgblack@eecs.umich.eduPc::postPciInt(int line) 1435389Sgblack@eecs.umich.edu{ 1445842Sgblack@eecs.umich.edu southBridge->ioApic->signalInterrupt(line); 1455389Sgblack@eecs.umich.edu} 1465389Sgblack@eecs.umich.edu 1475389Sgblack@eecs.umich.eduvoid 1485638Sgblack@eecs.umich.eduPc::clearPciInt(int line) 1495389Sgblack@eecs.umich.edu{ 1505842Sgblack@eecs.umich.edu warn_once("Tried to clear PCI interrupt %d\n", line); 1515389Sgblack@eecs.umich.edu} 1525389Sgblack@eecs.umich.edu 1535389Sgblack@eecs.umich.eduAddr 1545638Sgblack@eecs.umich.eduPc::pciToDma(Addr pciAddr) const 1555389Sgblack@eecs.umich.edu{ 1565844Sgblack@eecs.umich.edu return pciAddr; 1575389Sgblack@eecs.umich.edu} 1585389Sgblack@eecs.umich.edu 1595389Sgblack@eecs.umich.eduAddr 1605834Sgblack@eecs.umich.eduPc::calcPciConfigAddr(int bus, int dev, int func) 1615389Sgblack@eecs.umich.edu{ 1625389Sgblack@eecs.umich.edu assert(func < 8); 1635389Sgblack@eecs.umich.edu assert(dev < 32); 1645389Sgblack@eecs.umich.edu assert(bus == 0); 1655389Sgblack@eecs.umich.edu return (PhysAddrPrefixPciConfig | (func << 8) | (dev << 11)); 1665389Sgblack@eecs.umich.edu} 1675389Sgblack@eecs.umich.edu 1685834Sgblack@eecs.umich.eduAddr 1695834Sgblack@eecs.umich.eduPc::calcPciIOAddr(Addr addr) 1705834Sgblack@eecs.umich.edu{ 1715834Sgblack@eecs.umich.edu return PhysAddrPrefixIO + addr; 1725834Sgblack@eecs.umich.edu} 1735834Sgblack@eecs.umich.edu 1745834Sgblack@eecs.umich.eduAddr 1755834Sgblack@eecs.umich.eduPc::calcPciMemAddr(Addr addr) 1765834Sgblack@eecs.umich.edu{ 1775834Sgblack@eecs.umich.edu return addr; 1785834Sgblack@eecs.umich.edu} 1795834Sgblack@eecs.umich.edu 1805638Sgblack@eecs.umich.eduPc * 1815638Sgblack@eecs.umich.eduPcParams::create() 1825389Sgblack@eecs.umich.edu{ 1835638Sgblack@eecs.umich.edu return new Pc(this); 1845389Sgblack@eecs.umich.edu} 185