system.cc revision 8706
112391Sjason@lowepower.com/*
212391Sjason@lowepower.com * Copyright (c) 2010 ARM Limited
312391Sjason@lowepower.com * All rights reserved
412391Sjason@lowepower.com *
512391Sjason@lowepower.com * The license below extends only to copyright in the software and shall
612391Sjason@lowepower.com * not be construed as granting a license to any other intellectual
712391Sjason@lowepower.com * property including but not limited to intellectual property relating
812391Sjason@lowepower.com * to a hardware implementation of the functionality of the software
912391Sjason@lowepower.com * licensed hereunder.  You may use the software subject to the license
1012391Sjason@lowepower.com * terms below provided that you ensure that this notice is replicated
1112391Sjason@lowepower.com * unmodified and in its entirety in all distributions of the software,
1212391Sjason@lowepower.com * modified or unmodified, in source code or in binary form.
1312391Sjason@lowepower.com *
1412391Sjason@lowepower.com * Copyright (c) 2002-2006 The Regents of The University of Michigan
1512391Sjason@lowepower.com * All rights reserved.
1612391Sjason@lowepower.com *
1712391Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without
1812391Sjason@lowepower.com * modification, are permitted provided that the following conditions are
1912391Sjason@lowepower.com * met: redistributions of source code must retain the above copyright
2012391Sjason@lowepower.com * notice, this list of conditions and the following disclaimer;
2112391Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright
2212391Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the
2312391Sjason@lowepower.com * documentation and/or other materials provided with the distribution;
2412391Sjason@lowepower.com * neither the name of the copyright holders nor the names of its
2512391Sjason@lowepower.com * contributors may be used to endorse or promote products derived from
2612391Sjason@lowepower.com * this software without specific prior written permission.
2712391Sjason@lowepower.com *
2812391Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2912391Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3012391Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3112391Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3212391Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3312391Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3412391Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3512391Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3612391Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3712391Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3812391Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3912391Sjason@lowepower.com *
4012391Sjason@lowepower.com * Authors: Ali Saidi
4112391Sjason@lowepower.com */
4212391Sjason@lowepower.com
4312391Sjason@lowepower.com#include <iostream>
4412391Sjason@lowepower.com
4512391Sjason@lowepower.com#include "arch/arm/system.hh"
4612391Sjason@lowepower.com#include "base/loader/object_file.hh"
4712391Sjason@lowepower.com#include "base/loader/symtab.hh"
4812391Sjason@lowepower.com#include "cpu/thread_context.hh"
4912391Sjason@lowepower.com#include "mem/physical.hh"
5012391Sjason@lowepower.com#include "mem/fs_translating_port_proxy.hh"
5112391Sjason@lowepower.com
5212391Sjason@lowepower.comusing namespace std;
5312391Sjason@lowepower.comusing namespace Linux;
5412391Sjason@lowepower.com
5512391Sjason@lowepower.comArmSystem::ArmSystem(Params *p)
5612391Sjason@lowepower.com    : System(p), bootldr(NULL)
5712391Sjason@lowepower.com{
5812391Sjason@lowepower.com    debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk");
5912391Sjason@lowepower.com}
6012391Sjason@lowepower.com
6112391Sjason@lowepower.comvoid
6212391Sjason@lowepower.comArmSystem::initState()
6312391Sjason@lowepower.com{
6412391Sjason@lowepower.com    // Moved from the constructor to here since it relies on the
6512391Sjason@lowepower.com    // address map being resolved in the interconnect
6612391Sjason@lowepower.com
6712391Sjason@lowepower.com    // Call the initialisation of the super class
6812391Sjason@lowepower.com    System::initState();
6912391Sjason@lowepower.com
7012391Sjason@lowepower.com    const Params* p = params();
7112391Sjason@lowepower.com
7212391Sjason@lowepower.com    if ((p->boot_loader == "") != (p->boot_loader_mem == NULL))
7312391Sjason@lowepower.com        fatal("If boot_loader is specifed, memory to load it must be also.\n");
7412391Sjason@lowepower.com
7512391Sjason@lowepower.com    if (p->boot_loader != "") {
7612391Sjason@lowepower.com        bootldr = createObjectFile(p->boot_loader);
7712391Sjason@lowepower.com
7812391Sjason@lowepower.com        if (!bootldr)
7912391Sjason@lowepower.com            fatal("Could not read bootloader: %s\n", p->boot_loader);
8012391Sjason@lowepower.com
8112391Sjason@lowepower.com        bootldr->loadSections(physProxy);
8212391Sjason@lowepower.com        bootldr->loadGlobalSymbols(debugSymbolTable);
8312391Sjason@lowepower.com
8412391Sjason@lowepower.com        uint8_t jump_to_bl[] =
8512391Sjason@lowepower.com        {
8612391Sjason@lowepower.com            0x07, 0xf0, 0xa0, 0xe1  // branch to r7
8712391Sjason@lowepower.com        };
8812391Sjason@lowepower.com        physProxy->writeBlob(0x0, jump_to_bl, sizeof(jump_to_bl));
8912391Sjason@lowepower.com
9012391Sjason@lowepower.com        inform("Using bootloader at address %#x\n", bootldr->entryPoint());
9112391Sjason@lowepower.com    }
9212391Sjason@lowepower.com
9312391Sjason@lowepower.com    if (bootldr) {
9412391Sjason@lowepower.com        // Put the address of the boot loader into r7 so we know
9512391Sjason@lowepower.com        // where to branch to after the reset fault
9612391Sjason@lowepower.com        // All other values needed by the boot loader to know what to do
9712391Sjason@lowepower.com        for (int i = 0; i < threadContexts.size(); i++) {
9812391Sjason@lowepower.com            threadContexts[i]->setIntReg(3, kernelEntry & loadAddrMask);
9912391Sjason@lowepower.com            threadContexts[i]->setIntReg(4, params()->gic_cpu_addr);
10012391Sjason@lowepower.com            threadContexts[i]->setIntReg(5, params()->flags_addr);
10112391Sjason@lowepower.com            threadContexts[i]->setIntReg(7, bootldr->entryPoint());
10212391Sjason@lowepower.com        }
10312391Sjason@lowepower.com        if (!p->gic_cpu_addr || !p->flags_addr)
10412391Sjason@lowepower.com            fatal("gic_cpu_addr && flags_addr must be set with bootloader\n");
10512391Sjason@lowepower.com    } else {
10612391Sjason@lowepower.com        // Set the initial PC to be at start of the kernel code
10712391Sjason@lowepower.com        threadContexts[0]->pcState(kernelEntry & loadAddrMask);
10812391Sjason@lowepower.com    }
10912391Sjason@lowepower.com    for (int i = 0; i < threadContexts.size(); i++) {
11012391Sjason@lowepower.com        if (p->midr_regval) {
11112391Sjason@lowepower.com            threadContexts[i]->setMiscReg(ArmISA::MISCREG_MIDR,
11212391Sjason@lowepower.com                                          p->midr_regval);
11312391Sjason@lowepower.com        }
11412391Sjason@lowepower.com    }
11512391Sjason@lowepower.com
11612391Sjason@lowepower.com}
11712391Sjason@lowepower.com
11812391Sjason@lowepower.comArmSystem::~ArmSystem()
11912391Sjason@lowepower.com{
12012391Sjason@lowepower.com    if (debugPrintkEvent)
12112391Sjason@lowepower.com        delete debugPrintkEvent;
12212391Sjason@lowepower.com}
12312391Sjason@lowepower.com
12412391Sjason@lowepower.com
12512391Sjason@lowepower.comArmSystem *
12612391Sjason@lowepower.comArmSystemParams::create()
12712391Sjason@lowepower.com{
12812391Sjason@lowepower.com    return new ArmSystem(this);
12912391Sjason@lowepower.com}
13012391Sjason@lowepower.com