2 * Copyright 2019 Google Inc.
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.
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.
28 #ifndef __SIM_KERNEL_WORKLOAD_HH__
29 #define __SIM_KERNEL_WORKLOAD_HH__
34 #include "base/loader/object_file.hh"
35 #include "base/loader/symtab.hh"
36 #include "base/types.hh"
37 #include "params/KernelWorkload.hh"
38 #include "sim/workload.hh"
42 class KernelWorkload : public Workload
45 using Params = KernelWorkloadParams;
48 const Params &_params;
50 Loader::MemoryImage image;
52 /** Mask that should be anded for binary/symbol loading.
53 * This allows one two different OS requirements for the same ISA to be
54 * handled. Some OSes are compiled for a virtual address and need to be
55 * loaded into physical memory that starts at address 0, while other
56 * bare metal tools generate images that start at address 0.
60 /** Offset that should be used for binary/symbol loading.
61 * This further allows more flexibility than the loadAddrMask allows alone
62 * in loading kernels and similar. The loadAddrOffset is applied after the
69 std::vector<Loader::ObjectFile *> extras;
71 Loader::ObjectFile *kernelObj = nullptr;
72 // Keep a separate copy of the kernel's symbol table so we can add things
74 Loader::SymbolTable kernelSymtab;
76 const std::string commandLine;
79 const Params ¶ms() const { return _params; }
81 Addr start() const { return _start; }
82 Addr end() const { return _end; }
83 Addr loadAddrMask() const { return _loadAddrMask; }
84 Addr loadAddrOffset() const { return _loadAddrOffset; }
86 KernelWorkload(const Params &p);
88 Addr getEntry() const override { return kernelObj->entryPoint(); }
90 getArch() const override
92 return kernelObj->getArch();
95 const Loader::SymbolTable &
96 symtab(ThreadContext *tc) override
102 insertSymbol(const Loader::Symbol &symbol) override
104 return kernelSymtab.insert(symbol);
107 void initState() override;
109 void serialize(CheckpointOut &cp) const override;
110 void unserialize(CheckpointIn &cp) override;
114 * Add a function-based event to a kernel symbol.
116 * These functions work like their addFuncEvent() and
117 * addFuncEventOrPanic() counterparts. The only difference is that
118 * they automatically use the kernel symbol table. All arguments
119 * are forwarded to the underlying method.
121 * @see addFuncEvent()
122 * @see addFuncEventOrPanic()
124 * @param lbl Function to hook the event to.
125 * @param args Arguments to be passed to addFuncEvent
127 template <class T, typename... Args>
129 addKernelFuncEvent(const char *lbl, Args... args)
131 return addFuncEvent<T>(kernelSymtab, lbl, std::forward<Args>(args)...);
134 template <class T, typename... Args>
136 addKernelFuncEventOrPanic(const char *lbl, Args... args)
138 T *e = addFuncEvent<T>(kernelSymtab, lbl, std::forward<Args>(args)...);
139 panic_if(!e, "Failed to find kernel symbol '%s'", lbl);
145 #endif // __SIM_KERNEL_WORKLOAD_HH__