gem5  v20.0.0.3
kernel_workload.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Google Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "sim/kernel_workload.hh"
29 
30 #include "debug/Loader.hh"
31 #include "params/KernelWorkload.hh"
32 #include "sim/system.hh"
33 
34 KernelWorkload::KernelWorkload(const Params &p) : Workload(&p), _params(p),
35  _loadAddrMask(p.load_addr_mask), _loadAddrOffset(p.load_addr_offset),
36  kernelSymtab(new Loader::SymbolTable), commandLine(p.command_line)
37 {
40 
41  if (params().object_file == "") {
42  inform("No kernel set for full system simulation. "
43  "Assuming you know what you're doing.");
44  } else {
45  kernelObj = Loader::createObjectFile(params().object_file);
46  inform("kernel located at: %s", params().object_file);
47 
49  "Could not load kernel file %s", params().object_file);
50 
52 
53  _start = image.minAddr();
54  _end = image.maxAddr();
55 
56  // If load_addr_mask is set to 0x0, then calculate the smallest mask to
57  // cover all kernel addresses so gem5 can relocate the kernel to a new
58  // offset.
59  if (_loadAddrMask == 0)
61 
62  image.move([this](Addr a) {
63  return (a & _loadAddrMask) + _loadAddrOffset;
64  });
65 
66  // load symbols
68  "Could not load kernel symbols.");
69 
71  "Could not load kernel local symbols.");
72 
74  "Could not load kernel symbols.");
75 
77  "Could not load kernel local symbols.");
78  }
79 
80  // Loading only needs to happen once and after memory system is
81  // connected so it will happen in initState()
82 
83  std::vector<Addr> extras_addrs = p.extras_addrs;
84  if (extras_addrs.empty())
85  extras_addrs.resize(p.extras.size(), MaxAddr);
86  fatal_if(p.extras.size() != extras_addrs.size(),
87  "Additional kernel objects, not all load addresses specified\n");
88  for (int ker_idx = 0; ker_idx < p.extras.size(); ker_idx++) {
89  const std::string &obj_name = p.extras[ker_idx];
90  const bool raw = extras_addrs[ker_idx] != MaxAddr;
91  auto *obj = Loader::createObjectFile(obj_name, raw);
92  fatal_if(!obj, "Failed to build additional kernel object '%s'.\n",
93  obj_name);
94  extras.push_back(obj);
95  }
96 }
97 
99 {
100  delete kernelSymtab;
101 }
102 
103 void
105 {
106  auto &phys_mem = system->physProxy;
110  auto mapper = [this](Addr a) {
111  return (a & _loadAddrMask) + _loadAddrOffset;
112  };
113  if (params().object_file != "") {
114  if (params().addr_check) {
115  // Validate kernel mapping before loading binary
116  fatal_if(!system->isMemAddr(mapper(_start)) ||
117  !system->isMemAddr(mapper(_end)),
118  "Kernel is mapped to invalid location (not memory). "
119  "start (%#x) - end (%#x) %#x:%#x\n",
120  _start, _end, mapper(_start), mapper(_end));
121  }
122  // Load program sections into memory
123  image.write(phys_mem);
124 
125  DPRINTF(Loader, "Kernel start = %#x\n", _start);
126  DPRINTF(Loader, "Kernel end = %#x\n", _end);
127  DPRINTF(Loader, "Kernel entry = %#x\n", kernelObj->entryPoint());
128  DPRINTF(Loader, "Kernel loaded...\n");
129  }
130 
131  std::vector<Addr> extras_addrs = params().extras_addrs;
132  if (extras_addrs.empty())
133  extras_addrs.resize(params().extras.size(), MaxAddr);
134  for (int idx = 0; idx < extras.size(); idx++) {
135  const Addr load_addr = extras_addrs[idx];
136  auto image = extras[idx]->buildImage();
137  if (load_addr != MaxAddr)
138  image = image.offset(load_addr);
139  else
140  image = image.move(mapper);
141  image.write(phys_mem);
142  }
143 }
144 
145 void
147 {
148  kernelSymtab->serialize("symtab", cp);
149 }
150 
151 void
153 {
154  kernelSymtab->unserialize("symtab", cp);
155 }
156 
158 KernelWorkloadParams::create()
159 {
160  return new KernelWorkload(*this);
161 }
virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
Definition: object_file.hh:87
#define DPRINTF(x,...)
Definition: trace.hh:225
Loader::SymbolTable * kernelSymtab
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Definition: object_file.cc:61
KernelWorkloadParams Params
const Addr MaxAddr
Definition: types.hh:164
std::vector< Loader::ObjectFile * > extras
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Bitfield< 8 > a
virtual MemoryImage buildImage() const =0
MemoryImage & move(std::function< Addr(Addr)> mapper)
Definition: memory_image.cc:59
const Params & params() const
Addr maxAddr() const
Definition: cprintf.cc:40
Addr _loadAddrMask
Mask that should be anded for binary/symbol loading.
Loader::ObjectFile * kernelObj
Loader::MemoryImage image
Addr minAddr() const
bool write(const PortProxy &proxy) const
Definition: memory_image.cc:50
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:210
#define inform(...)
Definition: logging.hh:209
bool isMemAddr(Addr addr) const
Check if a physical address is within a range of a memory that is part of the global address map...
Definition: system.cc:354
MemoryImage & offset(Addr by)
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: symtab.cc:128
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:199
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::ostream CheckpointOut
Definition: serialize.hh:63
void serialize(const std::string &base, CheckpointOut &cp) const
Definition: symtab.cc:114
Addr entryPoint() const
Definition: object_file.hh:128
int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:203
SymbolTable * debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:46
Bitfield< 3, 0 > mask
Definition: types.hh:62
System * system
Definition: workload.hh:47
Bitfield< 0 > p
Addr _loadAddrOffset
Offset that should be used for binary/symbol loading.
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
Definition: object_file.hh:93
KernelWorkload(const Params &p)

Generated on Fri Jul 3 2020 15:53:04 for gem5 by doxygen 1.8.13