gem5  v19.0.0.0
system.cc
Go to the documentation of this file.
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 
34 
35 #include "arch/arm/isa_traits.hh"
36 #include "arch/arm/utility.hh"
38 #include "base/loader/dtb_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"
47 #include "mem/physical.hh"
48 #include "sim/stat_control.hh"
49 
50 using namespace ArmISA;
51 using namespace FreeBSD;
52 
54  : GenericArmSystem(p),
55  enableContextSwitchStatsDump(p->enable_context_switch_stats_dump),
56  taskFile(nullptr), kernelPanicEvent(nullptr), kernelOopsEvent(nullptr)
57 {
58  if (p->panic_on_panic) {
59  kernelPanicEvent = addKernelFuncEventOrPanic<PanicPCEvent>(
60  "panic", "Kernel panic in simulated kernel");
61  } else {
62 #ifndef NDEBUG
63  kernelPanicEvent = addKernelFuncEventOrPanic<BreakPCEvent>("panic");
64 #endif
65  }
66 
67  if (p->panic_on_oops) {
68  kernelOopsEvent = addKernelFuncEventOrPanic<PanicPCEvent>(
69  "oops_exit", "Kernel oops in guest");
70  }
71 
72  uDelaySkipEvent = addKernelFuncEvent<UDelayEvent>(
73  "DELAY", "DELAY", 1000, 0);
74 }
75 
76 void
78 {
79  // Moved from the constructor to here since it relies on the
80  // address map being resolved in the interconnect
81 
82  // Call the initialisation of the super class
84 
85  // Load symbols at physical address, we might not want
86  // to do this permanently, for but early bootup work
87  // it is helpful.
88  if (params()->early_kernel_symbols) {
91  }
92 
93  // Setup boot data structure
94  Addr addr = 0;
95 
96  // Check if the kernel image has a symbol that tells us it supports
97  // device trees.
98  bool kernel_has_fdt_support =
99  kernelSymtab->findAddress("fdt_get_range", addr);
100  bool dtb_file_specified = params()->dtb_filename != "";
101 
102  if (!dtb_file_specified)
103  fatal("dtb file is not specified\n");
104 
105  if (!kernel_has_fdt_support)
106  fatal("kernel must have fdt support\n");
107 
108  // Kernel supports flattened device tree and dtb file specified.
109  // Using Device Tree Blob to describe system configuration.
110  inform("Loading DTB file: %s at address %#x\n", params()->dtb_filename,
111  params()->atags_addr + loadAddrOffset);
112 
113  DtbFile *dtb_file = new DtbFile(params()->dtb_filename);
114 
115  if (!dtb_file->addBootCmdLine(params()->boot_osflags.c_str(),
116  params()->boot_osflags.size())) {
117  warn("couldn't append bootargs to DTB file: %s\n",
118  params()->dtb_filename);
119  }
120 
121  Addr ra = dtb_file->findReleaseAddr();
122  if (ra)
123  bootReleaseAddr = ra & ~ULL(0x7F);
124 
125  dtb_file->buildImage().
126  offset(params()->atags_addr + loadAddrOffset).write(physProxy);
127  delete dtb_file;
128 
129  // Kernel boot requirements to set up r0, r1 and r2 in ARMv7
130  for (int i = 0; i < threadContexts.size(); i++) {
131  threadContexts[i]->setIntReg(0, 0);
132  threadContexts[i]->setIntReg(1, params()->machine_type);
133  threadContexts[i]->setIntReg(2, params()->atags_addr + loadAddrOffset);
134  }
135 }
136 
138 {
139  if (uDelaySkipEvent)
140  delete uDelaySkipEvent;
142  delete constUDelaySkipEvent;
143 }
144 
146 FreebsdArmSystemParams::create()
147 {
148  return new FreebsdArmSystem(this);
149 }
150 
151 void
153 {
154 }
virtual void initState()
Initialise the system.
Definition: system.cc:319
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:175
Bitfield< 7 > i
FreebsdArmSystemParams Params
Boilerplate params code.
Definition: system.hh:51
ip6_addr_t addr
Definition: inet.hh:335
SymbolTable * debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:45
Bitfield< 23, 0 > offset
Definition: types.hh:154
Definition: ccregs.hh:42
Addr bootReleaseAddr
Definition: system.hh:113
const Params * params() const
Definition: system.hh:53
FreeBSD::UDelayEvent * uDelaySkipEvent
PC based event to skip udelay(<time>) calls and quiesce the processor for the appropriate amount of t...
Definition: system.hh:95
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:218
void startup()
startup() is the final initialization call before simulation.
Definition: system.cc:152
#define inform(...)
Definition: logging.hh:213
bool findAddress(const std::string &symbol, Addr &address) const
Definition: symtab.hh:97
Addr loadAddrMask
Mask that should be anded for binary/symbol loading.
Definition: system.hh:245
std::vector< ThreadContext * > threadContexts
Definition: system.hh:190
Addr findReleaseAddr()
Parse the DTB file enough to find the provided release address and return it.
Definition: dtb_file.cc:129
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define ULL(N)
uint64_t constant
Definition: types.hh:50
SymbolTable * kernelSymtab
kernel symbol table
Definition: system.hh:221
Bitfield< 20, 16 > ra
Definition: types.hh:47
This implements an image file format to support loading and modifying flattened device tree blobs for...
ObjectFile * kernel
Object pointer for the kernel code.
Definition: system.hh:224
FreebsdArmSystem(Params *p)
Definition: system.cc:53
MemoryImage buildImage() const override
Definition: dtb_file.cc:150
PCEvent * kernelPanicEvent
Event to halt the simulator if the kernel calls panic()
Definition: system.hh:85
bool addBootCmdLine(const char *_args, size_t len)
Adds the passed in Command Line options for the kernel to the proper location in the device tree...
Definition: dtb_file.cc:61
PCEvent * kernelOopsEvent
Event to halt the simulator if the kernel calls oopses.
Definition: system.hh:88
TranslatingPortProxy Object Declaration for FS.
void initState()
Initialise the system.
Definition: system.cc:77
#define warn(...)
Definition: logging.hh:212
Addr loadAddrOffset
Offset that should be used for binary/symbol loading.
Definition: system.hh:252
Bitfield< 0 > p
virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
Definition: object_file.hh:90
FreeBSD::UDelayEvent * constUDelaySkipEvent
Another PC based skip event for const_udelay().
Definition: system.hh:102

Generated on Fri Feb 28 2020 16:26:55 for gem5 by doxygen 1.8.13