gem5 v24.0.0.0
Loading...
Searching...
No Matches
fs_workload.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Huawei International
3 * All rights reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
30
31#include "arch/riscv/faults.hh"
34#include "base/loader/symtab.hh"
35#include "cpu/pc_event.hh"
36#include "kern/linux/events.hh"
38#include "sim/sim_exit.hh"
39#include "sim/system.hh"
40
41namespace gem5
42{
43
44namespace RiscvISA
45{
46
47void
49{
51
52 if (params().dtb_filename != "") {
53 inform("Loading DTB file: %s at address %#x\n", params().dtb_filename,
54 params().dtb_addr);
55
56 auto *dtb_file = new loader::DtbFile(params().dtb_filename);
57
58 if (!dtb_file->addBootCmdLine(
59 commandLine.c_str(), commandLine.size())) {
60 warn("couldn't append bootargs to DTB file: %s\n",
61 params().dtb_filename);
62 }
63
64 dtb_file->buildImage().offset(params().dtb_addr)
65 .write(system->physProxy);
66 delete dtb_file;
67
68 for (auto *tc: system->threads) {
69 tc->setReg(int_reg::A1, params().dtb_addr);
70 }
71 } else {
72 warn("No DTB file specified\n");
73 }
74
75 for (auto *tc: system->threads) {
77 tc->activate();
78 }
79}
80
81void
89
90void
92{
93 const std::string dmesg_output = name() + ".dmesg";
94 if (params().exit_on_kernel_panic) {
96 "panic", "Kernel panic in simulated system.",
97 dmesg_output, params().on_panic
98 );
99 warn_if(!kernelPanicPcEvent, "Failed to find kernel symbol 'panic'");
100 }
101}
102
103void
105{
106 const std::string dmesg_output = name() + ".dmesg";
107 if (params().exit_on_kernel_oops) {
109 "oops_exit", "Kernel oops in simulated system.",
110 dmesg_output, params().on_oops
111 );
113 "Failed to find kernel symbol 'oops_exit'");
114 }
115}
116
117void
119{
120 if (params().bootloader_filename != "") {
121 Addr bootloader_paddr_offset = params().bootloader_addr;
122 bootloader = loader::createObjectFile(params().bootloader_filename);
124 auto renamedBootloaderSymbolTable = \
126 bootloader_paddr_offset
127 )->functionSymbols()->rename(
128 [](const std::string &name) {
129 return "bootloader." + name;
130 }
131 );
132 loader::debugSymbolTable.insert(*renamedBootloaderSymbolTable);
133 }
134}
135
136void
138{
139 if (params().object_file != "") {
140 kernel = loader::createObjectFile(params().object_file);
142 auto renamedKernelSymbolTable = \
144 [](const std::string &name) {
145 return "kernel." + name;
146 }
147 );
148 loader::debugSymbolTable.insert(*renamedKernelSymbolTable);
149 }
150}
151
152void
154{
155 if (params().bootloader_filename != "") {
156 Addr bootloader_addr_offset = params().bootloader_addr;
157 bootloader->buildImage().offset(bootloader_addr_offset).write(
159 );
160 delete bootloader;
161
162 inform("Loaded bootloader \'%s\' at 0x%llx\n",
163 params().bootloader_filename,
164 bootloader_addr_offset);
165 } else {
166 inform("Bootloader is not specified.\n");
167 }
168}
169
170void
172{
173 if (params().object_file != "") {
174 Addr kernel_paddr_offset = params().kernel_addr;
175 kernel->buildImage().offset(kernel_paddr_offset).write(
177 );
178 delete kernel;
179
180 inform("Loaded kernel \'%s\' at 0x%llx\n",
181 params().object_file,
182 kernel_paddr_offset);
183 } else {
184 inform("Kernel is not specified.\n");
185 }
186}
187
188
189void
191{
192 if (params().dtb_filename != "") {
193 auto *dtb_file = new loader::DtbFile(params().dtb_filename);
194
195 dtb_file->buildImage().offset(params().dtb_addr)
196 .write(system->physProxy);
197 delete dtb_file;
198
199 inform("Loaded DTB \'%s\' at 0x%llx\n",
200 params().dtb_filename,
201 params().dtb_addr);
202
203 for (auto *tc: system->threads) {
204 tc->setReg(int_reg::A1, params().dtb_addr);
205 }
206 } else {
207 inform("DTB file is not specified.\n");
208 }
209}
210
211void
213{
214 const std::string dmesg_output = name() + ".dmesg";
215 if (params().exit_on_kernel_panic) {
217 kernelSymbolTable, "panic", "Kernel panic in simulated system.",
218 dmesg_output, params().on_panic
219 );
220 }
221}
222
223void
225{
226 const std::string dmesg_output = name() + ".dmesg";
227 if (params().exit_on_kernel_oops) {
229 kernelSymbolTable, "oops_exit", "Kernel oops in simulated system.",
230 dmesg_output, params().on_oops
231 );
232 }
233}
234
235void
237{
239 loadKernel();
240 loadDtb();
241
242 for (auto *tc: system->threads) {
244 tc->activate();
245 }
246}
247
248void
256
257void
259{
260 bootloaderSymbolTable.serialize("bootloader_symbol_table", checkpoint);
261 kernelSymbolTable.serialize("kernel_symbol_table", checkpoint);
262}
263
264void
266{
267 bootloaderSymbolTable.unserialize("bootloader_symbol_table", checkpoint);
268 kernelSymbolTable.unserialize("kernel_symbol_table", checkpoint);
269}
270
271} // namespace RiscvISA
272} // namespace gem5
const std::string commandLine
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
T * addKernelFuncEvent(const char *lbl, Args... args)
Add a function-based event to a kernel symbol.
virtual std::string name() const
Definition named.hh:47
PCEvent * kernelPanicPcEvent
Event to halt the simulator if the kernel calls panic() or oops_exit()
void serialize(CheckpointOut &checkpoint) const override
Serialize an object.
void unserialize(CheckpointIn &checkpoint) override
Unserialize an object.
void startup() override
startup() is the final initialization call before simulation.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
void startup() override
startup() is the final initialization call before simulation.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
PCEvent * kernelPanicPcEvent
Event to halt the simulator if the kernel calls panic() or oops_exit()
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
Definition faults.cc:171
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition system.hh:323
Threads threads
Definition system.hh:310
void startup() override
startup() is the final initialization call before simulation.
Definition workload.cc:93
T * addFuncEvent(const loader::SymbolTable &symtab, const char *lbl, const std::string &desc, Args... args)
Add a function-based event to the given function, to be looked up in the specified symbol table.
Definition workload.hh:139
System * system
Definition workload.hh:81
virtual MemoryImage buildImage() const =0
MemoryImage & offset(Addr by)
bool write(const PortProxy &proxy) const
const SymbolTable & symtab() const
SymbolTablePtr functionSymbols() const
Generates a new symbol table containing only function symbols.
Definition symtab.hh:402
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 offset(Addr addr_offset) const
Generate a new table by applying an offset to the symbols of the current table.
Definition symtab.hh:316
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
This implements an image file format to support loading and modifying flattened device tree blobs for...
const Params & params() const
virtual void startup()
startup() is the final initialization call before simulation.
Definition sim_object.cc:96
#define warn(...)
Definition logging.hh:256
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition logging.hh:283
#define inform(...)
Definition logging.hh:257
constexpr RegId A1
Definition int.hh:102
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

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0