system.cc revision 9385:25ebe5e13a07
12391SN/A/*
28931Sandreas.hansson@arm.com * Copyright (c) 2010 ARM Limited
38931Sandreas.hansson@arm.com * All rights reserved
48931Sandreas.hansson@arm.com *
58931Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68931Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78931Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88931Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98931Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108931Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118931Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128931Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138931Sandreas.hansson@arm.com *
142391SN/A * Copyright (c) 2002-2006 The Regents of The University of Michigan
152391SN/A * All rights reserved.
162391SN/A *
172391SN/A * Redistribution and use in source and binary forms, with or without
182391SN/A * modification, are permitted provided that the following conditions are
192391SN/A * met: redistributions of source code must retain the above copyright
202391SN/A * notice, this list of conditions and the following disclaimer;
212391SN/A * redistributions in binary form must reproduce the above copyright
222391SN/A * notice, this list of conditions and the following disclaimer in the
232391SN/A * documentation and/or other materials provided with the distribution;
242391SN/A * neither the name of the copyright holders nor the names of its
252391SN/A * contributors may be used to endorse or promote products derived from
262391SN/A * this software without specific prior written permission.
272391SN/A *
282391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665SN/A *
402665SN/A * Authors: Ali Saidi
418931Sandreas.hansson@arm.com */
422391SN/A
432391SN/A#include <iostream>
448931Sandreas.hansson@arm.com
458931Sandreas.hansson@arm.com#include "arch/arm/system.hh"
468931Sandreas.hansson@arm.com#include "base/loader/object_file.hh"
472391SN/A#include "base/loader/symtab.hh"
482391SN/A#include "cpu/thread_context.hh"
4912492Sodanrc@yahoo.com.br#include "mem/physical.hh"
5012492Sodanrc@yahoo.com.br#include "mem/fs_translating_port_proxy.hh"
512391SN/A
5213853Sgabeblack@google.comusing namespace std;
532462SN/Ausing namespace Linux;
548931Sandreas.hansson@arm.com
558719SN/AArmSystem::ArmSystem(Params *p)
562462SN/A    : System(p), bootldr(NULL), multiProc(p->multi_proc)
579053Sdam.sunwoo@arm.com{
589053Sdam.sunwoo@arm.com    if (p->boot_loader != "") {
599053Sdam.sunwoo@arm.com        bootldr = createObjectFile(p->boot_loader);
608931Sandreas.hansson@arm.com
619293Sandreas.hansson@arm.com        if (!bootldr)
629293Sandreas.hansson@arm.com            fatal("Could not read bootloader: %s\n", p->boot_loader);
639293Sandreas.hansson@arm.com
649293Sandreas.hansson@arm.com        bootldr->loadGlobalSymbols(debugSymbolTable);
659293Sandreas.hansson@arm.com
669293Sandreas.hansson@arm.com    }
679293Sandreas.hansson@arm.com    debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk");
689293Sandreas.hansson@arm.com}
699293Sandreas.hansson@arm.com
709293Sandreas.hansson@arm.comvoid
719293Sandreas.hansson@arm.comArmSystem::initState()
729293Sandreas.hansson@arm.com{
739293Sandreas.hansson@arm.com    // Moved from the constructor to here since it relies on the
749293Sandreas.hansson@arm.com    // address map being resolved in the interconnect
759293Sandreas.hansson@arm.com
769293Sandreas.hansson@arm.com    // Call the initialisation of the super class
779293Sandreas.hansson@arm.com    System::initState();
7811005Sandreas.sandberg@arm.com
799293Sandreas.hansson@arm.com    const Params* p = params();
809293Sandreas.hansson@arm.com
819293Sandreas.hansson@arm.com    if (bootldr) {
829293Sandreas.hansson@arm.com        bootldr->loadSections(physProxy);
8312749Sgiacomo.travaglini@arm.com
849293Sandreas.hansson@arm.com        uint8_t jump_to_bl[] =
859293Sandreas.hansson@arm.com        {
869293Sandreas.hansson@arm.com            0x07, 0xf0, 0xa0, 0xe1  // branch to r7
879293Sandreas.hansson@arm.com        };
8812749Sgiacomo.travaglini@arm.com        physProxy.writeBlob(0x0, jump_to_bl, sizeof(jump_to_bl));
8912749Sgiacomo.travaglini@arm.com
909293Sandreas.hansson@arm.com        inform("Using bootloader at address %#x\n", bootldr->entryPoint());
919293Sandreas.hansson@arm.com
929293Sandreas.hansson@arm.com        // Put the address of the boot loader into r7 so we know
939293Sandreas.hansson@arm.com        // where to branch to after the reset fault
949293Sandreas.hansson@arm.com        // All other values needed by the boot loader to know what to do
959293Sandreas.hansson@arm.com        if (!p->gic_cpu_addr || !p->flags_addr)
969293Sandreas.hansson@arm.com            fatal("gic_cpu_addr && flags_addr must be set with bootloader\n");
979293Sandreas.hansson@arm.com
988931Sandreas.hansson@arm.com        for (int i = 0; i < threadContexts.size(); i++) {
998931Sandreas.hansson@arm.com            threadContexts[i]->setIntReg(3, kernelEntry & loadAddrMask);
1008931Sandreas.hansson@arm.com            threadContexts[i]->setIntReg(4, params()->gic_cpu_addr);
1018931Sandreas.hansson@arm.com            threadContexts[i]->setIntReg(5, params()->flags_addr);
1028931Sandreas.hansson@arm.com            threadContexts[i]->setIntReg(7, bootldr->entryPoint());
1038931Sandreas.hansson@arm.com        }
1048931Sandreas.hansson@arm.com    } else {
1052391SN/A        // Set the initial PC to be at start of the kernel code
1066107SN/A        threadContexts[0]->pcState(kernelEntry & loadAddrMask);
1076107SN/A    }
1088931Sandreas.hansson@arm.com}
1099235Sandreas.hansson@arm.com
1102413SN/AArmSystem::~ArmSystem()
1118931Sandreas.hansson@arm.com{
1128931Sandreas.hansson@arm.com    if (debugPrintkEvent)
1132413SN/A        delete debugPrintkEvent;
11413853Sgabeblack@google.com}
11513853Sgabeblack@google.com
11613853Sgabeblack@google.com
1178931Sandreas.hansson@arm.comArmSystem *
11811614Sdavid.j.hashe@gmail.comArmSystemParams::create()
1192413SN/A{
1208931Sandreas.hansson@arm.com    return new ArmSystem(this);
12111614Sdavid.j.hashe@gmail.com}
12211614Sdavid.j.hashe@gmail.com