system.cc revision 3527
112952Sgabeblack@google.com/* 212952Sgabeblack@google.com * Copyright (c) 2002-2006 The Regents of The University of Michigan 312952Sgabeblack@google.com * All rights reserved. 412952Sgabeblack@google.com * 512952Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612952Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712952Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912952Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112952Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212952Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312952Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412952Sgabeblack@google.com * this software without specific prior written permission. 1512952Sgabeblack@google.com * 1612952Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712952Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812952Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912952Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012952Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112952Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212952Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312952Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412952Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512952Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612952Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712952Sgabeblack@google.com * 2812952Sgabeblack@google.com * Authors: Ali Saidi 2912952Sgabeblack@google.com */ 3012952Sgabeblack@google.com 3112957Sgabeblack@google.com#include "arch/sparc/system.hh" 3212957Sgabeblack@google.com#include "arch/vtophys.hh" 3312957Sgabeblack@google.com#include "base/remote_gdb.hh" 3413288Sgabeblack@google.com#include "base/loader/object_file.hh" 3512953Sgabeblack@google.com#include "base/loader/symtab.hh" 3613317Sgabeblack@google.com#include "base/trace.hh" 3713196Sgabeblack@google.com#include "mem/physical.hh" 3813102Sgabeblack@google.com#include "sim/byteswap.hh" 3912998Sgabeblack@google.com#include "sim/builder.hh" 4012998Sgabeblack@google.com 4112952Sgabeblack@google.com 4212952Sgabeblack@google.comusing namespace BigEndianGuest; 4312952Sgabeblack@google.com 4412952Sgabeblack@google.comSparcSystem::SparcSystem(Params *p) 4512952Sgabeblack@google.com : System(p), sysTick(0) 4612952Sgabeblack@google.com 4712952Sgabeblack@google.com{ 4812995Sgabeblack@google.com resetSymtab = new SymbolTable; 4912952Sgabeblack@google.com hypervisorSymtab = new SymbolTable; 5012952Sgabeblack@google.com openbootSymtab = new SymbolTable; 5112952Sgabeblack@google.com 5212952Sgabeblack@google.com 5312952Sgabeblack@google.com /** 5412995Sgabeblack@google.com * Load the boot code, and hypervisor into memory. 5512952Sgabeblack@google.com */ 5612952Sgabeblack@google.com // Read the reset binary 5712952Sgabeblack@google.com reset = createObjectFile(params()->reset_bin); 5812952Sgabeblack@google.com if (reset == NULL) 5912952Sgabeblack@google.com fatal("Could not load reset binary %s", params()->reset_bin); 6012952Sgabeblack@google.com 6112952Sgabeblack@google.com // Read the openboot binary 6212952Sgabeblack@google.com openboot = createObjectFile(params()->openboot_bin); 6312952Sgabeblack@google.com if (openboot == NULL) 6412952Sgabeblack@google.com fatal("Could not load openboot bianry %s", params()->openboot_bin); 6512952Sgabeblack@google.com 6612952Sgabeblack@google.com // Read the hypervisor binary 6712952Sgabeblack@google.com hypervisor = createObjectFile(params()->hypervisor_bin); 6812952Sgabeblack@google.com if (hypervisor == NULL) 6912952Sgabeblack@google.com fatal("Could not load hypervisor binary %s", params()->hypervisor_bin); 7012952Sgabeblack@google.com 7112952Sgabeblack@google.com 7212952Sgabeblack@google.com // Load reset binary into memory 7312952Sgabeblack@google.com reset->loadSections(&functionalPort, SparcISA::LoadAddrMask); 7412952Sgabeblack@google.com // Load the openboot binary 7512952Sgabeblack@google.com openboot->loadSections(&functionalPort, SparcISA::LoadAddrMask); 7612952Sgabeblack@google.com // Load the hypervisor binary 7712952Sgabeblack@google.com hypervisor->loadSections(&functionalPort, SparcISA::LoadAddrMask); 7812952Sgabeblack@google.com 7912952Sgabeblack@google.com // load symbols 8012952Sgabeblack@google.com if (!reset->loadGlobalSymbols(resetSymtab)) 8112952Sgabeblack@google.com panic("could not load reset symbols\n"); 8212952Sgabeblack@google.com 8312952Sgabeblack@google.com if (!openboot->loadGlobalSymbols(openbootSymtab)) 8412952Sgabeblack@google.com panic("could not load openboot symbols\n"); 8512952Sgabeblack@google.com 8612952Sgabeblack@google.com if (!hypervisor->loadLocalSymbols(hypervisorSymtab)) 8713133Sgabeblack@google.com panic("could not load hypervisor symbols\n"); 8812952Sgabeblack@google.com 8913133Sgabeblack@google.com // load symbols into debug table 9013133Sgabeblack@google.com if (!reset->loadGlobalSymbols(debugSymbolTable)) 9113133Sgabeblack@google.com panic("could not load reset symbols\n"); 9213133Sgabeblack@google.com 9313133Sgabeblack@google.com if (!openboot->loadGlobalSymbols(debugSymbolTable)) 9413133Sgabeblack@google.com panic("could not load openboot symbols\n"); 9513133Sgabeblack@google.com 9613133Sgabeblack@google.com if (!hypervisor->loadLocalSymbols(debugSymbolTable)) 9712952Sgabeblack@google.com panic("could not load hypervisor symbols\n"); 9812952Sgabeblack@google.com 9912952Sgabeblack@google.com 10012952Sgabeblack@google.com // @todo any fixup code over writing data in binaries on setting break 10112952Sgabeblack@google.com // events on functions should happen here. 10212952Sgabeblack@google.com 10312952Sgabeblack@google.com} 10412952Sgabeblack@google.com 10512952Sgabeblack@google.comSparcSystem::~SparcSystem() 10612952Sgabeblack@google.com{ 10712952Sgabeblack@google.com delete resetSymtab; 10812959Sgabeblack@google.com delete hypervisorSymtab; 10913133Sgabeblack@google.com delete openbootSymtab; 11012959Sgabeblack@google.com delete reset; 11112952Sgabeblack@google.com delete openboot; 11212952Sgabeblack@google.com delete hypervisor; 11312952Sgabeblack@google.com} 11412952Sgabeblack@google.com 11512952Sgabeblack@google.combool 11612952Sgabeblack@google.comSparcSystem::breakpoint() 11712952Sgabeblack@google.com{ 11812952Sgabeblack@google.com panic("Need to implement"); 11912952Sgabeblack@google.com} 12012999Sgabeblack@google.com 12113206Sgabeblack@google.comvoid 12212999Sgabeblack@google.comSparcSystem::serialize(std::ostream &os) 12312999Sgabeblack@google.com{ 12413317Sgabeblack@google.com System::serialize(os); 12512999Sgabeblack@google.com resetSymtab->serialize("reset_symtab", os); 12612999Sgabeblack@google.com hypervisorSymtab->serialize("hypervisor_symtab", os); 12712999Sgabeblack@google.com openbootSymtab->serialize("openboot_symtab", os); 12812952Sgabeblack@google.com} 12912952Sgabeblack@google.com 13012952Sgabeblack@google.com 13112952Sgabeblack@google.comvoid 13212952Sgabeblack@google.comSparcSystem::unserialize(Checkpoint *cp, const std::string §ion) 13312952Sgabeblack@google.com{ 13412952Sgabeblack@google.com System::unserialize(cp,section); 13512952Sgabeblack@google.com resetSymtab->unserialize("reset_symtab", cp, section); 13612952Sgabeblack@google.com hypervisorSymtab->unserialize("hypervisor_symtab", cp, section); 13712952Sgabeblack@google.com openbootSymtab->unserialize("openboot_symtab", cp, section); 13812952Sgabeblack@google.com} 13912952Sgabeblack@google.com 14012952Sgabeblack@google.com 14112952Sgabeblack@google.comBEGIN_DECLARE_SIM_OBJECT_PARAMS(SparcSystem) 14212952Sgabeblack@google.com 14312952Sgabeblack@google.com SimObjectParam<PhysicalMemory *> physmem; 14413102Sgabeblack@google.com SimpleEnumParam<System::MemoryMode> mem_mode; 14513317Sgabeblack@google.com 14613102Sgabeblack@google.com Param<std::string> kernel; 14713102Sgabeblack@google.com Param<std::string> reset_bin; 14813102Sgabeblack@google.com Param<std::string> hypervisor_bin; 14912952Sgabeblack@google.com Param<std::string> openboot_bin; 15012952Sgabeblack@google.com 15112952Sgabeblack@google.com Param<Tick> boot_cpu_frequency; 15212952Sgabeblack@google.com Param<std::string> boot_osflags; 15312952Sgabeblack@google.com Param<uint64_t> system_type; 15412952Sgabeblack@google.com Param<uint64_t> system_rev; 15512952Sgabeblack@google.com Param<std::string> readfile; 15612952Sgabeblack@google.com Param<unsigned int> init_param; 15712995Sgabeblack@google.com 15812998Sgabeblack@google.comEND_DECLARE_SIM_OBJECT_PARAMS(SparcSystem) 15912995Sgabeblack@google.com 16012995Sgabeblack@google.comBEGIN_INIT_SIM_OBJECT_PARAMS(SparcSystem) 16112998Sgabeblack@google.com 16212998Sgabeblack@google.com INIT_PARAM(physmem, "phsyical memory"), 16312998Sgabeblack@google.com INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)", 16412998Sgabeblack@google.com System::MemoryModeStrings), 16512998Sgabeblack@google.com INIT_PARAM(kernel, "file that contains the kernel code"), 16612998Sgabeblack@google.com INIT_PARAM(reset_bin, "file that contains the reset code"), 16712952Sgabeblack@google.com INIT_PARAM(hypervisor_bin, "file that contains the hypervisor code"), 16812952Sgabeblack@google.com INIT_PARAM(openboot_bin, "file that contains the openboot code"), 16912952Sgabeblack@google.com INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"), 17012952Sgabeblack@google.com INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 17112952Sgabeblack@google.com "a"), 17213102Sgabeblack@google.com INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34), 17313317Sgabeblack@google.com INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10), 17413317Sgabeblack@google.com INIT_PARAM_DFLT(readfile, "file to read startup script from", ""), 17513102Sgabeblack@google.com INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0) 17613102Sgabeblack@google.com 17712952Sgabeblack@google.comEND_INIT_SIM_OBJECT_PARAMS(SparcSystem) 17812952Sgabeblack@google.com 17912952Sgabeblack@google.comCREATE_SIM_OBJECT(SparcSystem) 18012952Sgabeblack@google.com{ 18112952Sgabeblack@google.com SparcSystem::Params *p = new SparcSystem::Params; 18212952Sgabeblack@google.com p->name = getInstanceName(); 18312952Sgabeblack@google.com p->boot_cpu_frequency = boot_cpu_frequency; 18412952Sgabeblack@google.com p->physmem = physmem; 18513310Sgabeblack@google.com p->mem_mode = mem_mode; 18613310Sgabeblack@google.com p->kernel_path = kernel; 18712995Sgabeblack@google.com p->reset_bin = reset_bin; 18813261Sgabeblack@google.com p->hypervisor_bin = hypervisor_bin; 18913261Sgabeblack@google.com p->openboot_bin = openboot_bin; 19012998Sgabeblack@google.com p->boot_osflags = boot_osflags; 19112998Sgabeblack@google.com p->init_param = init_param; 19212998Sgabeblack@google.com p->readfile = readfile; 19312998Sgabeblack@google.com p->system_type = system_type; 19412998Sgabeblack@google.com p->system_rev = system_rev; 19512998Sgabeblack@google.com return new SparcSystem(p); 19612952Sgabeblack@google.com} 19712952Sgabeblack@google.com 19812952Sgabeblack@google.comREGISTER_SIM_OBJECT("SparcSystem", SparcSystem) 19912952Sgabeblack@google.com 20012952Sgabeblack@google.com 20113317Sgabeblack@google.com