gem5  v22.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 
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
#define DPRINTF(x,...)
Definition: trace.hh:186
loader::SymbolTable kernelSymtab
void serialize(CheckpointOut &cp) const override
Serialize an object.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
loader::ObjectFile * kernelObj
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Addr _loadAddrOffset
Offset that should be used for binary/symbol loading.
Addr _loadAddrMask
Mask that should be anded for binary/symbol loading.
loader::MemoryImage image
KernelWorkload(const Params &p)
std::vector< loader::ObjectFile * > extras
virtual std::string name() const
Definition: named.hh:47
SimObjectParams Params
Definition: sim_object.hh:170
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:288
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:326
System * system
Definition: workload.hh:80
virtual MemoryImage buildImage() const =0
MemoryImage & offset(Addr by)
bool write(const PortProxy &proxy) const
Definition: memory_image.cc:54
MemoryImage & move(std::function< Addr(Addr)> mapper)
Definition: memory_image.cc:63
const SymbolTable & symtab() const
Definition: object_file.hh:131
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
SymbolTablePtr mask(Addr m) const
Generate a new table by a mask to the symbols of the current table.
Definition: symtab.hh:233
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize the table's contents.
Definition: symtab.cc:93
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
Definition: symtab.cc:55
constexpr int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:260
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
const Params & params() const
Definition: sim_object.hh:176
#define inform(...)
Definition: logging.hh:247
Bitfield< 8 > a
Definition: misc_types.hh:66
Bitfield< 54 > p
Definition: pagetable.hh:70
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:44
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Definition: object_file.cc:135
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
const Addr MaxAddr
Definition: types.hh:171

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1