gem5  v21.1.0.2
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 namespace gem5
35 {
36 
38  _loadAddrMask(p.load_addr_mask), _loadAddrOffset(p.load_addr_offset),
39  commandLine(p.command_line)
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 
67  auto initKernelSymtab = kernelSymtab.mask(_loadAddrMask)
68  ->offset(_loadAddrOffset)
69  ->rename([](std::string &name) {
70  name = "kernel_init." + name;
71  });
72 
73  loader::debugSymbolTable.insert(*initKernelSymtab);
75  }
76 
77  // Loading only needs to happen once and after memory system is
78  // connected so it will happen in initState()
79 
80  std::vector<Addr> extras_addrs = p.extras_addrs;
81  if (extras_addrs.empty())
82  extras_addrs.resize(p.extras.size(), MaxAddr);
83  fatal_if(p.extras.size() != extras_addrs.size(),
84  "Additional kernel objects, not all load addresses specified\n");
85  for (int ker_idx = 0; ker_idx < p.extras.size(); ker_idx++) {
86  const std::string &obj_name = p.extras[ker_idx];
87  const bool raw = extras_addrs[ker_idx] != MaxAddr;
88  auto *obj = loader::createObjectFile(obj_name, raw);
89  fatal_if(!obj, "Failed to build additional kernel object '%s'.\n",
90  obj_name);
91  extras.push_back(obj);
92  }
93 }
94 
95 void
97 {
98  auto &phys_mem = system->physProxy;
102  auto mapper = [this](Addr a) {
103  return (a & _loadAddrMask) + _loadAddrOffset;
104  };
105  if (params().object_file != "") {
106  if (params().addr_check) {
107  // Validate kernel mapping before loading binary
108  fatal_if(!system->isMemAddr(mapper(_start)) ||
109  !system->isMemAddr(mapper(_end)),
110  "Kernel is mapped to invalid location (not memory). "
111  "start (%#x) - end (%#x) %#x:%#x\n",
112  _start, _end, mapper(_start), mapper(_end));
113  }
114  // Load program sections into memory
115  image.write(phys_mem);
116 
117  DPRINTF(Loader, "Kernel start = %#x\n", _start);
118  DPRINTF(Loader, "Kernel end = %#x\n", _end);
119  DPRINTF(Loader, "Kernel entry = %#x\n", kernelObj->entryPoint());
120  DPRINTF(Loader, "Kernel loaded...\n");
121  }
122 
123  std::vector<Addr> extras_addrs = params().extras_addrs;
124  if (extras_addrs.empty())
125  extras_addrs.resize(params().extras.size(), MaxAddr);
126  for (int idx = 0; idx < extras.size(); idx++) {
127  const Addr load_addr = extras_addrs[idx];
128  auto image = extras[idx]->buildImage();
129  if (load_addr != MaxAddr)
130  image = image.offset(load_addr);
131  else
132  image = image.move(mapper);
133  image.write(phys_mem);
134  }
135 }
136 
137 void
139 {
140  kernelSymtab.serialize("symtab", cp);
141 }
142 
143 void
145 {
146  kernelSymtab.unserialize("symtab", cp);
147 }
148 
149 } // namespace gem5
gem5::loader::MemoryImage::maxAddr
Addr maxAddr() const
Definition: memory_image.hh:136
gem5::KernelWorkload::KernelWorkload
KernelWorkload(const Params &p)
Definition: kernel_workload.cc:37
gem5::KernelWorkload::_loadAddrMask
Addr _loadAddrMask
Mask that should be anded for binary/symbol loading.
Definition: kernel_workload.hh:56
gem5::KernelWorkload::_start
Addr _start
Definition: kernel_workload.hh:65
system.hh
gem5::KernelWorkload::_end
Addr _end
Definition: kernel_workload.hh:65
gem5::loader::ObjectFile::entryPoint
Addr entryPoint() const
Definition: object_file.hh:125
gem5::System::physProxy
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:332
gem5::loader::SymbolTable::unserialize
void unserialize(const std::string &base, CheckpointIn &cp, Symbol::Binding default_binding=Symbol::Binding::Global)
Populate the table by unserializing a checkpoint.
Definition: symtab.cc:107
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:65
std::vector< Addr >
gem5::loader::ObjectFile::symtab
const SymbolTable & symtab() const
Definition: object_file.hh:119
gem5::KernelWorkload::kernelObj
loader::ObjectFile * kernelObj
Definition: kernel_workload.hh:69
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
gem5::SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:170
gem5::System::isMemAddr
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:376
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::loader::MemoryImage::offset
MemoryImage & offset(Addr by)
Definition: memory_image.hh:126
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
gem5::MaxAddr
const Addr MaxAddr
Definition: types.hh:171
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::loader::MemoryImage::move
MemoryImage & move(std::function< Addr(Addr)> mapper)
Definition: memory_image.cc:63
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::Workload
Definition: workload.hh:47
gem5::KernelWorkload::kernelSymtab
loader::SymbolTable kernelSymtab
Definition: kernel_workload.hh:72
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::loader::createObjectFile
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Definition: object_file.cc:123
inform
#define inform(...)
Definition: logging.hh:246
gem5::loader::SymbolTable::insert
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
Definition: symtab.cc:55
gem5::loader::MemoryImage::minAddr
Addr minAddr() const
Definition: memory_image.hh:145
gem5::KernelWorkload::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: kernel_workload.cc:144
gem5::KernelWorkload::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: kernel_workload.cc:138
gem5::loader::MemoryImage::write
bool write(const PortProxy &proxy) const
Definition: memory_image.cc:54
gem5::findMsbSet
constexpr int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:263
gem5::Workload::system
System * system
Definition: workload.hh:78
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::loader::ImageFile::buildImage
virtual MemoryImage buildImage() const =0
kernel_workload.hh
gem5::loader::debugSymbolTable
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:44
gem5::KernelWorkload::extras
std::vector< loader::ObjectFile * > extras
Definition: kernel_workload.hh:67
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::KernelWorkload::image
loader::MemoryImage image
Definition: kernel_workload.hh:48
gem5::KernelWorkload::_loadAddrOffset
Addr _loadAddrOffset
Offset that should be used for binary/symbol loading.
Definition: kernel_workload.hh:63
gem5::loader::SymbolTable::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize the table's contents.
Definition: symtab.cc:93
gem5::loader::SymbolTable::mask
SymbolTablePtr mask(Addr m) const
Generate a new table by a mask to the symbols of the current table.
Definition: symtab.hh:233
gem5::KernelWorkload::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: kernel_workload.cc:96

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17