gem5  v20.1.0.0
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 
35  _loadAddrMask(p.load_addr_mask), _loadAddrOffset(p.load_addr_offset),
36  commandLine(p.command_line)
37 {
38  if (params().object_file == "") {
39  inform("No kernel set for full system simulation. "
40  "Assuming you know what you're doing.");
41  } else {
42  kernelObj = Loader::createObjectFile(params().object_file);
43  inform("kernel located at: %s", params().object_file);
44 
46  "Could not load kernel file %s", params().object_file);
47 
49 
50  _start = image.minAddr();
51  _end = image.maxAddr();
52 
53  // If load_addr_mask is set to 0x0, then calculate the smallest mask to
54  // cover all kernel addresses so gem5 can relocate the kernel to a new
55  // offset.
56  if (_loadAddrMask == 0)
58 
59  image.move([this](Addr a) {
60  return (a & _loadAddrMask) + _loadAddrOffset;
61  });
62 
65  }
66 
67  // Loading only needs to happen once and after memory system is
68  // connected so it will happen in initState()
69 
70  std::vector<Addr> extras_addrs = p.extras_addrs;
71  if (extras_addrs.empty())
72  extras_addrs.resize(p.extras.size(), MaxAddr);
73  fatal_if(p.extras.size() != extras_addrs.size(),
74  "Additional kernel objects, not all load addresses specified\n");
75  for (int ker_idx = 0; ker_idx < p.extras.size(); ker_idx++) {
76  const std::string &obj_name = p.extras[ker_idx];
77  const bool raw = extras_addrs[ker_idx] != MaxAddr;
78  auto *obj = Loader::createObjectFile(obj_name, raw);
79  fatal_if(!obj, "Failed to build additional kernel object '%s'.\n",
80  obj_name);
81  extras.push_back(obj);
82  }
83 }
84 
85 void
87 {
88  auto &phys_mem = system->physProxy;
92  auto mapper = [this](Addr a) {
93  return (a & _loadAddrMask) + _loadAddrOffset;
94  };
95  if (params().object_file != "") {
96  if (params().addr_check) {
97  // Validate kernel mapping before loading binary
98  fatal_if(!system->isMemAddr(mapper(_start)) ||
99  !system->isMemAddr(mapper(_end)),
100  "Kernel is mapped to invalid location (not memory). "
101  "start (%#x) - end (%#x) %#x:%#x\n",
102  _start, _end, mapper(_start), mapper(_end));
103  }
104  // Load program sections into memory
105  image.write(phys_mem);
106 
107  DPRINTF(Loader, "Kernel start = %#x\n", _start);
108  DPRINTF(Loader, "Kernel end = %#x\n", _end);
109  DPRINTF(Loader, "Kernel entry = %#x\n", kernelObj->entryPoint());
110  DPRINTF(Loader, "Kernel loaded...\n");
111  }
112 
113  std::vector<Addr> extras_addrs = params().extras_addrs;
114  if (extras_addrs.empty())
115  extras_addrs.resize(params().extras.size(), MaxAddr);
116  for (int idx = 0; idx < extras.size(); idx++) {
117  const Addr load_addr = extras_addrs[idx];
118  auto image = extras[idx]->buildImage();
119  if (load_addr != MaxAddr)
120  image = image.offset(load_addr);
121  else
122  image = image.move(mapper);
123  image.write(phys_mem);
124  }
125 }
126 
127 void
129 {
130  kernelSymtab.serialize("symtab", cp);
131 }
132 
133 void
135 {
136  kernelSymtab.unserialize("symtab", cp);
137 }
138 
140 KernelWorkloadParams::create()
141 {
142  return new KernelWorkload(*this);
143 }
Loader::MemoryImage::offset
MemoryImage & offset(Addr by)
Definition: memory_image.hh:121
system.hh
KernelWorkload::image
Loader::MemoryImage image
Definition: kernel_workload.hh:50
Loader::MemoryImage::write
bool write(const PortProxy &proxy) const
Definition: memory_image.cc:50
Loader::MemoryImage::move
MemoryImage & move(std::function< Addr(Addr)> mapper)
Definition: memory_image.cc:59
System::physProxy
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:324
Workload
Definition: workload.hh:40
findMsbSet
int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:234
KernelWorkload
Definition: kernel_workload.hh:42
Loader::createObjectFile
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Definition: object_file.cc:61
KernelWorkload::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: kernel_workload.cc:134
Workload::system
System * system
Definition: workload.hh:64
Loader::ImageFile::buildImage
virtual MemoryImage buildImage() const =0
std::vector< Addr >
Loader::SymbolTable::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Definition: symtab.cc:136
MaxAddr
const Addr MaxAddr
Definition: types.hh:166
Loader::MemoryImage::maxAddr
Addr maxAddr() const
Definition: memory_image.hh:131
KernelWorkload::_end
Addr _end
Definition: kernel_workload.hh:67
KernelWorkload::kernelSymtab
Loader::SymbolTable kernelSymtab
Definition: kernel_workload.hh:74
Loader
Definition: process.hh:39
Loader::debugSymbolTable
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:47
cp
Definition: cprintf.cc:40
KernelWorkload::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: kernel_workload.cc:86
Loader::ObjectFile::entryPoint
Addr entryPoint() const
Definition: object_file.hh:108
Loader::ObjectFile::symtab
const SymbolTable & symtab() const
Definition: object_file.hh:102
ArmISA::a
Bitfield< 8 > a
Definition: miscregs_types.hh:62
KernelWorkload::params
const Params & params() const
Definition: kernel_workload.hh:79
KernelWorkload::_loadAddrOffset
Addr _loadAddrOffset
Offset that should be used for binary/symbol loading.
Definition: kernel_workload.hh:65
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
KernelWorkload::_start
Addr _start
Definition: kernel_workload.hh:67
KernelWorkload::kernelObj
Loader::ObjectFile * kernelObj
Definition: kernel_workload.hh:71
Loader::SymbolTable::unserialize
void unserialize(const std::string &base, CheckpointIn &cp, Symbol::Binding default_binding=Symbol::Binding::Global)
Definition: symtab.cc:150
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Loader::MemoryImage::minAddr
Addr minAddr() const
Definition: memory_image.hh:140
KernelWorkload::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: kernel_workload.cc:128
KernelWorkload::Params
KernelWorkloadParams Params
Definition: kernel_workload.hh:45
inform
#define inform(...)
Definition: logging.hh:240
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
Loader::SymbolTable::insert
bool insert(const Symbol &symbol)
Definition: symtab.cc:58
kernel_workload.hh
KernelWorkload::extras
std::vector< Loader::ObjectFile * > extras
Definition: kernel_workload.hh:69
KernelWorkload::KernelWorkload
KernelWorkload(const Params &p)
Definition: kernel_workload.cc:34
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
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:219
CheckpointIn
Definition: serialize.hh:67
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:417
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
KernelWorkload::_loadAddrMask
Addr _loadAddrMask
Mask that should be anded for binary/symbol loading.
Definition: kernel_workload.hh:58

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17