system.cc revision 10037
12567SN/A/* 210037SARM gem5 Developers * Copyright (c) 2010, 2012-2013 ARM Limited 37585SAli.Saidi@arm.com * All rights reserved 47585SAli.Saidi@arm.com * 57585SAli.Saidi@arm.com * The license below extends only to copyright in the software and shall 67585SAli.Saidi@arm.com * not be construed as granting a license to any other intellectual 77585SAli.Saidi@arm.com * property including but not limited to intellectual property relating 87585SAli.Saidi@arm.com * to a hardware implementation of the functionality of the software 97585SAli.Saidi@arm.com * licensed hereunder. You may use the software subject to the license 107585SAli.Saidi@arm.com * terms below provided that you ensure that this notice is replicated 117585SAli.Saidi@arm.com * unmodified and in its entirety in all distributions of the software, 127585SAli.Saidi@arm.com * modified or unmodified, in source code or in binary form. 137585SAli.Saidi@arm.com * 142567SN/A * Copyright (c) 2002-2006 The Regents of The University of Michigan 152567SN/A * All rights reserved. 162567SN/A * 172567SN/A * Redistribution and use in source and binary forms, with or without 182567SN/A * modification, are permitted provided that the following conditions are 192567SN/A * met: redistributions of source code must retain the above copyright 202567SN/A * notice, this list of conditions and the following disclaimer; 212567SN/A * redistributions in binary form must reproduce the above copyright 222567SN/A * notice, this list of conditions and the following disclaimer in the 232567SN/A * documentation and/or other materials provided with the distribution; 242567SN/A * neither the name of the copyright holders nor the names of its 252567SN/A * contributors may be used to endorse or promote products derived from 262567SN/A * this software without specific prior written permission. 272567SN/A * 282567SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292567SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302567SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312567SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322567SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332567SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342567SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352567SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362567SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372567SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382567SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665SN/A * 402665SN/A * Authors: Ali Saidi 412567SN/A */ 422567SN/A 438229Snate@binkert.org#include <iostream> 448229Snate@binkert.org 456757SAli.Saidi@ARM.com#include "arch/arm/system.hh" 468286SAli.Saidi@ARM.com#include "base/loader/object_file.hh" 478286SAli.Saidi@ARM.com#include "base/loader/symtab.hh" 488286SAli.Saidi@ARM.com#include "cpu/thread_context.hh" 498286SAli.Saidi@ARM.com#include "mem/physical.hh" 508706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh" 5110037SARM gem5 Developers#include "sim/full_system.hh" 522567SN/A 537650SAli.Saidi@ARM.comusing namespace std; 547650SAli.Saidi@ARM.comusing namespace Linux; 552567SN/A 566757SAli.Saidi@ARM.comArmSystem::ArmSystem(Params *p) 5710037SARM gem5 Developers : System(p), bootldr(NULL), _haveSecurity(p->have_security), 5810037SARM gem5 Developers _haveLPAE(p->have_lpae), 5910037SARM gem5 Developers _haveVirtualization(p->have_virtualization), 6010037SARM gem5 Developers _haveGenericTimer(p->have_generic_timer), 6110037SARM gem5 Developers _highestELIs64(p->highest_el_is_64), 6210037SARM gem5 Developers _resetAddr64(p->reset_addr_64), 6310037SARM gem5 Developers _physAddrRange64(p->phys_addr_range_64), 6410037SARM gem5 Developers _haveLargeAsid64(p->have_large_asid_64), 6510037SARM gem5 Developers multiProc(p->multi_proc) 662567SN/A{ 6710037SARM gem5 Developers // Check if the physical address range is valid 6810037SARM gem5 Developers if (_highestELIs64 && ( 6910037SARM gem5 Developers _physAddrRange64 < 32 || 7010037SARM gem5 Developers _physAddrRange64 > 48 || 7110037SARM gem5 Developers (_physAddrRange64 % 4 != 0 && _physAddrRange64 != 42))) { 7210037SARM gem5 Developers fatal("Invalid physical address range (%d)\n", _physAddrRange64); 7310037SARM gem5 Developers } 7410037SARM gem5 Developers 758885SAli.Saidi@ARM.com if (p->boot_loader != "") { 768885SAli.Saidi@ARM.com bootldr = createObjectFile(p->boot_loader); 778885SAli.Saidi@ARM.com 788885SAli.Saidi@ARM.com if (!bootldr) 798885SAli.Saidi@ARM.com fatal("Could not read bootloader: %s\n", p->boot_loader); 808885SAli.Saidi@ARM.com 8110037SARM gem5 Developers if ((bootldr->getArch() == ObjectFile::Arm64) && !_highestELIs64) { 8210037SARM gem5 Developers warn("Highest ARM exception-level set to AArch32 but bootloader " 8310037SARM gem5 Developers "is for AArch64. Assuming you wanted these to match.\n"); 8410037SARM gem5 Developers _highestELIs64 = true; 8510037SARM gem5 Developers } else if ((bootldr->getArch() == ObjectFile::Arm) && _highestELIs64) { 8610037SARM gem5 Developers warn("Highest ARM exception-level set to AArch64 but bootloader " 8710037SARM gem5 Developers "is for AArch32. Assuming you wanted these to match.\n"); 8810037SARM gem5 Developers _highestELIs64 = false; 8910037SARM gem5 Developers } 9010037SARM gem5 Developers 918885SAli.Saidi@ARM.com bootldr->loadGlobalSymbols(debugSymbolTable); 928885SAli.Saidi@ARM.com 938885SAli.Saidi@ARM.com } 948885SAli.Saidi@ARM.com debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk"); 958706Sandreas.hansson@arm.com} 968706Sandreas.hansson@arm.com 978706Sandreas.hansson@arm.comvoid 988706Sandreas.hansson@arm.comArmSystem::initState() 998706Sandreas.hansson@arm.com{ 1008706Sandreas.hansson@arm.com // Moved from the constructor to here since it relies on the 1018706Sandreas.hansson@arm.com // address map being resolved in the interconnect 1028706Sandreas.hansson@arm.com 1038706Sandreas.hansson@arm.com // Call the initialisation of the super class 1048706Sandreas.hansson@arm.com System::initState(); 1058706Sandreas.hansson@arm.com 1068706Sandreas.hansson@arm.com const Params* p = params(); 1072567SN/A 1088885SAli.Saidi@ARM.com if (bootldr) { 1098706Sandreas.hansson@arm.com bootldr->loadSections(physProxy); 1108286SAli.Saidi@ARM.com 11110037SARM gem5 Developers uint8_t jump_to_bl_32[] = 1128286SAli.Saidi@ARM.com { 11310037SARM gem5 Developers 0x07, 0xf0, 0xa0, 0xe1 // branch to r7 in aarch32 1148286SAli.Saidi@ARM.com }; 11510037SARM gem5 Developers 11610037SARM gem5 Developers uint8_t jump_to_bl_64[] = 11710037SARM gem5 Developers { 11810037SARM gem5 Developers 0xe0, 0x00, 0x1f, 0xd6 // instruction "br x7" in aarch64 11910037SARM gem5 Developers }; 12010037SARM gem5 Developers 12110037SARM gem5 Developers // write the jump to branch table into address 0 12210037SARM gem5 Developers if (!_highestELIs64) 12310037SARM gem5 Developers physProxy.writeBlob(0x0, jump_to_bl_32, sizeof(jump_to_bl_32)); 12410037SARM gem5 Developers else 12510037SARM gem5 Developers physProxy.writeBlob(0x0, jump_to_bl_64, sizeof(jump_to_bl_64)); 1268286SAli.Saidi@ARM.com 1278286SAli.Saidi@ARM.com inform("Using bootloader at address %#x\n", bootldr->entryPoint()); 1288286SAli.Saidi@ARM.com 1298286SAli.Saidi@ARM.com // Put the address of the boot loader into r7 so we know 1308286SAli.Saidi@ARM.com // where to branch to after the reset fault 1318286SAli.Saidi@ARM.com // All other values needed by the boot loader to know what to do 1328885SAli.Saidi@ARM.com if (!p->gic_cpu_addr || !p->flags_addr) 1338885SAli.Saidi@ARM.com fatal("gic_cpu_addr && flags_addr must be set with bootloader\n"); 1348885SAli.Saidi@ARM.com 1358286SAli.Saidi@ARM.com for (int i = 0; i < threadContexts.size(); i++) { 13610037SARM gem5 Developers if (!_highestELIs64) 13710037SARM gem5 Developers threadContexts[i]->setIntReg(3, (kernelEntry & loadAddrMask) + 13810037SARM gem5 Developers loadAddrOffset); 1398286SAli.Saidi@ARM.com threadContexts[i]->setIntReg(4, params()->gic_cpu_addr); 1408286SAli.Saidi@ARM.com threadContexts[i]->setIntReg(5, params()->flags_addr); 1418286SAli.Saidi@ARM.com threadContexts[i]->setIntReg(7, bootldr->entryPoint()); 1428286SAli.Saidi@ARM.com } 14310037SARM gem5 Developers inform("Using kernel entry physical address at %#x\n", 14410037SARM gem5 Developers (kernelEntry & loadAddrMask) + loadAddrOffset); 1458286SAli.Saidi@ARM.com } else { 1468286SAli.Saidi@ARM.com // Set the initial PC to be at start of the kernel code 14710037SARM gem5 Developers if (!_highestELIs64) 14810037SARM gem5 Developers threadContexts[0]->pcState((kernelEntry & loadAddrMask) + 14910037SARM gem5 Developers loadAddrOffset); 1508286SAli.Saidi@ARM.com } 1512567SN/A} 1522567SN/A 15310037SARM gem5 DevelopersGenericTimer::ArchTimer * 15410037SARM gem5 DevelopersArmSystem::getArchTimer(int cpu_id) const 15510037SARM gem5 Developers{ 15610037SARM gem5 Developers if (_genericTimer) { 15710037SARM gem5 Developers return _genericTimer->getArchTimer(cpu_id); 15810037SARM gem5 Developers } 15910037SARM gem5 Developers return NULL; 16010037SARM gem5 Developers} 16110037SARM gem5 Developers 16210037SARM gem5 DevelopersGenericTimer::SystemCounter * 16310037SARM gem5 DevelopersArmSystem::getSystemCounter() const 16410037SARM gem5 Developers{ 16510037SARM gem5 Developers if (_genericTimer) { 16610037SARM gem5 Developers return _genericTimer->getSystemCounter(); 16710037SARM gem5 Developers } 16810037SARM gem5 Developers return NULL; 16910037SARM gem5 Developers} 17010037SARM gem5 Developers 17110037SARM gem5 Developersbool 17210037SARM gem5 DevelopersArmSystem::haveSecurity(ThreadContext *tc) 17310037SARM gem5 Developers{ 17410037SARM gem5 Developers if (!FullSystem) 17510037SARM gem5 Developers return false; 17610037SARM gem5 Developers 17710037SARM gem5 Developers ArmSystem *a_sys = dynamic_cast<ArmSystem *>(tc->getSystemPtr()); 17810037SARM gem5 Developers assert(a_sys); 17910037SARM gem5 Developers return a_sys->haveSecurity(); 18010037SARM gem5 Developers} 18110037SARM gem5 Developers 18210037SARM gem5 Developers 1836757SAli.Saidi@ARM.comArmSystem::~ArmSystem() 1842567SN/A{ 1858286SAli.Saidi@ARM.com if (debugPrintkEvent) 1868286SAli.Saidi@ARM.com delete debugPrintkEvent; 1872567SN/A} 1882567SN/A 18910037SARM gem5 Developersbool 19010037SARM gem5 DevelopersArmSystem::haveLPAE(ThreadContext *tc) 19110037SARM gem5 Developers{ 19210037SARM gem5 Developers if (!FullSystem) 19310037SARM gem5 Developers return false; 1946757SAli.Saidi@ARM.com 19510037SARM gem5 Developers ArmSystem *a_sys = dynamic_cast<ArmSystem *>(tc->getSystemPtr()); 19610037SARM gem5 Developers assert(a_sys); 19710037SARM gem5 Developers return a_sys->haveLPAE(); 19810037SARM gem5 Developers} 19910037SARM gem5 Developers 20010037SARM gem5 Developersbool 20110037SARM gem5 DevelopersArmSystem::haveVirtualization(ThreadContext *tc) 20210037SARM gem5 Developers{ 20310037SARM gem5 Developers if (!FullSystem) 20410037SARM gem5 Developers return false; 20510037SARM gem5 Developers 20610037SARM gem5 Developers ArmSystem *a_sys = dynamic_cast<ArmSystem *>(tc->getSystemPtr()); 20710037SARM gem5 Developers assert(a_sys); 20810037SARM gem5 Developers return a_sys->haveVirtualization(); 20910037SARM gem5 Developers} 21010037SARM gem5 Developers 21110037SARM gem5 Developersbool 21210037SARM gem5 DevelopersArmSystem::highestELIs64(ThreadContext *tc) 21310037SARM gem5 Developers{ 21410037SARM gem5 Developers return dynamic_cast<ArmSystem *>(tc->getSystemPtr())->highestELIs64(); 21510037SARM gem5 Developers} 21610037SARM gem5 Developers 21710037SARM gem5 DevelopersExceptionLevel 21810037SARM gem5 DevelopersArmSystem::highestEL(ThreadContext *tc) 21910037SARM gem5 Developers{ 22010037SARM gem5 Developers return dynamic_cast<ArmSystem *>(tc->getSystemPtr())->highestEL(); 22110037SARM gem5 Developers} 22210037SARM gem5 Developers 22310037SARM gem5 DevelopersAddr 22410037SARM gem5 DevelopersArmSystem::resetAddr64(ThreadContext *tc) 22510037SARM gem5 Developers{ 22610037SARM gem5 Developers return dynamic_cast<ArmSystem *>(tc->getSystemPtr())->resetAddr64(); 22710037SARM gem5 Developers} 22810037SARM gem5 Developers 22910037SARM gem5 Developersuint8_t 23010037SARM gem5 DevelopersArmSystem::physAddrRange(ThreadContext *tc) 23110037SARM gem5 Developers{ 23210037SARM gem5 Developers return dynamic_cast<ArmSystem *>(tc->getSystemPtr())->physAddrRange(); 23310037SARM gem5 Developers} 23410037SARM gem5 Developers 23510037SARM gem5 DevelopersAddr 23610037SARM gem5 DevelopersArmSystem::physAddrMask(ThreadContext *tc) 23710037SARM gem5 Developers{ 23810037SARM gem5 Developers return dynamic_cast<ArmSystem *>(tc->getSystemPtr())->physAddrMask(); 23910037SARM gem5 Developers} 24010037SARM gem5 Developers 24110037SARM gem5 Developersbool 24210037SARM gem5 DevelopersArmSystem::haveLargeAsid64(ThreadContext *tc) 24310037SARM gem5 Developers{ 24410037SARM gem5 Developers return dynamic_cast<ArmSystem *>(tc->getSystemPtr())->haveLargeAsid64(); 24510037SARM gem5 Developers} 2466757SAli.Saidi@ARM.comArmSystem * 2476757SAli.Saidi@ARM.comArmSystemParams::create() 2482567SN/A{ 2496757SAli.Saidi@ARM.com return new ArmSystem(this); 2502567SN/A} 251