gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
29
30#include "debug/Loader.hh"
31#include "params/KernelWorkload.hh"
32#include "sim/system.hh"
33
34namespace 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 {
46 inform("kernel located at: %s", params().object_file);
47
49 "Could not load kernel file %s", params().object_file);
50
52
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([](const std::string &name) {
70 return "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
95void
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
137void
139{
140 kernelSymtab.serialize("symtab", cp);
141}
142
143void
148
149} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
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
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:323
System * system
Definition workload.hh:81
virtual MemoryImage buildImage() const =0
MemoryImage & offset(Addr by)
bool write(const PortProxy &proxy) const
MemoryImage & move(std::function< Addr(Addr)> mapper)
const SymbolTable & symtab() const
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:127
SymbolTablePtr mask(Addr m) const
Generate a new table by a mask to the symbols of the current table.
Definition symtab.hh:335
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize the table's contents.
Definition symtab.cc:107
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
Definition symtab.cc:66
STL vector class.
Definition stl.hh:37
constexpr int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition bitfield.hh:279
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
const Params & params() const
#define inform(...)
Definition logging.hh:257
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 0 > p
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition symtab.cc:55
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
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 Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0