system.cc revision 10810:683ab55819fd
1/* 2 * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com> 3 * All rights reserved. 4 * 5 * This software was developed by the University of Cambridge Computer 6 * Laboratory as part of the CTSRD Project, with support from the UK Higher 7 * Education Innovation Fund (HEIF). 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are 11 * met: redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer; 13 * redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution; 16 * neither the name of the copyright holders nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include "arch/arm/freebsd/system.hh" 34 35#include "arch/arm/isa_traits.hh" 36#include "arch/arm/utility.hh" 37#include "arch/generic/freebsd/threadinfo.hh" 38#include "base/loader/dtb_object.hh" 39#include "base/loader/object_file.hh" 40#include "base/loader/symtab.hh" 41#include "cpu/base.hh" 42#include "cpu/pc_event.hh" 43#include "cpu/thread_context.hh" 44#include "debug/Loader.hh" 45#include "kern/freebsd/events.hh" 46#include "mem/fs_translating_port_proxy.hh" 47#include "mem/physical.hh" 48#include "sim/stat_control.hh" 49 50using namespace ArmISA; 51using namespace FreeBSD; 52 53FreebsdArmSystem::FreebsdArmSystem(Params *p) 54 : GenericArmSystem(p), dumpStatsPCEventF(nullptr), 55 enableContextSwitchStatsDump(p->enable_context_switch_stats_dump), 56 taskFile(nullptr), kernelPanicEvent(nullptr), kernelOopsEvent(nullptr), 57 bootReleaseAddr(p->boot_release_addr) 58{ 59 if (p->panic_on_panic) { 60 kernelPanicEvent = addKernelFuncEventOrPanic<PanicPCEvent>( 61 "panic", "Kernel panic in simulated kernel"); 62 } else { 63#ifndef NDEBUG 64 kernelPanicEvent = addKernelFuncEventOrPanic<BreakPCEvent>("panic"); 65#endif 66 } 67 68 if (p->panic_on_oops) { 69 kernelOopsEvent = addKernelFuncEventOrPanic<PanicPCEvent>( 70 "oops_exit", "Kernel oops in guest"); 71 } 72 73 uDelaySkipEvent = addKernelFuncEvent<UDelayEvent>( 74 "DELAY", "DELAY", 1000, 0); 75} 76 77bool 78FreebsdArmSystem::adderBootUncacheable(Addr a) 79{ 80 81 return false; 82} 83 84void 85FreebsdArmSystem::initState() 86{ 87 // Moved from the constructor to here since it relies on the 88 // address map being resolved in the interconnect 89 90 // Call the initialisation of the super class 91 GenericArmSystem::initState(); 92 93 // Load symbols at physical address, we might not want 94 // to do this permanently, for but early bootup work 95 // it is helpful. 96 if (params()->early_kernel_symbols) { 97 kernel->loadGlobalSymbols(kernelSymtab, loadAddrMask); 98 kernel->loadGlobalSymbols(debugSymbolTable, loadAddrMask); 99 } 100 101 // Setup boot data structure 102 Addr addr = 0; 103 104 // Check if the kernel image has a symbol that tells us it supports 105 // device trees. 106 bool kernel_has_fdt_support = 107 kernelSymtab->findAddress("fdt_get_range", addr); 108 bool dtb_file_specified = params()->dtb_filename != ""; 109 110 if (!dtb_file_specified) 111 fatal("dtb file is not specified\n"); 112 113 if (!kernel_has_fdt_support) 114 fatal("kernel must have fdt support\n"); 115 116 // Kernel supports flattened device tree and dtb file specified. 117 // Using Device Tree Blob to describe system configuration. 118 inform("Loading DTB file: %s at address %#x\n", params()->dtb_filename, 119 params()->atags_addr + loadAddrOffset); 120 121 ObjectFile *dtb_file = createObjectFile(params()->dtb_filename, true); 122 if (!dtb_file) { 123 fatal("couldn't load DTB file: %s\n", params()->dtb_filename); 124 } 125 126 DtbObject *_dtb_file = dynamic_cast<DtbObject*>(dtb_file); 127 128 if (_dtb_file) { 129 if (!_dtb_file->addBootCmdLine(params()->boot_osflags.c_str(), 130 params()->boot_osflags.size())) { 131 warn("couldn't append bootargs to DTB file: %s\n", 132 params()->dtb_filename); 133 } 134 } else { 135 warn("dtb_file cast failed; couldn't append bootargs " 136 "to DTB file: %s\n", params()->dtb_filename); 137 } 138 139 Addr ra = _dtb_file->findReleaseAddr(); 140 if (ra) 141 bootReleaseAddr = ra & ~ULL(0x7F); 142 143 dtb_file->setTextBase(params()->atags_addr + loadAddrOffset); 144 dtb_file->loadSections(physProxy); 145 delete dtb_file; 146 147 // Kernel boot requirements to set up r0, r1 and r2 in ARMv7 148 for (int i = 0; i < threadContexts.size(); i++) { 149 threadContexts[i]->setIntReg(0, 0); 150 threadContexts[i]->setIntReg(1, params()->machine_type); 151 threadContexts[i]->setIntReg(2, params()->atags_addr + loadAddrOffset); 152 } 153} 154 155FreebsdArmSystem::~FreebsdArmSystem() 156{ 157 if (uDelaySkipEvent) 158 delete uDelaySkipEvent; 159 if (constUDelaySkipEvent) 160 delete constUDelaySkipEvent; 161 162 if (dumpStatsPCEventF) 163 delete dumpStatsPCEventF; 164} 165 166FreebsdArmSystem * 167FreebsdArmSystemParams::create() 168{ 169 return new FreebsdArmSystem(this); 170} 171 172void 173FreebsdArmSystem::startup() 174{ 175} 176