2 * Copyright (c) 2010-2013 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2002-2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #include "arch/arm/linux/atag.hh"
44 #include "arch/arm/linux/system.hh"
45 #include "arch/arm/isa_traits.hh"
46 #include "arch/arm/utility.hh"
47 #include "arch/generic/linux/threadinfo.hh"
48 #include "base/loader/dtb_object.hh"
49 #include "base/loader/object_file.hh"
50 #include "base/loader/symtab.hh"
51 #include "cpu/base.hh"
52 #include "cpu/pc_event.hh"
53 #include "cpu/thread_context.hh"
54 #include "debug/Loader.hh"
55 #include "kern/linux/events.hh"
56 #include "mem/fs_translating_port_proxy.hh"
57 #include "mem/physical.hh"
58 #include "sim/stat_control.hh"
60 using namespace ArmISA
;
61 using namespace Linux
;
63 LinuxArmSystem::LinuxArmSystem(Params
*p
)
64 : GenericArmSystem(p
), dumpStatsPCEvent(nullptr),
65 enableContextSwitchStatsDump(p
->enable_context_switch_stats_dump
),
66 taskFile(nullptr), kernelPanicEvent(nullptr), kernelOopsEvent(nullptr),
67 bootReleaseAddr(p
->boot_release_addr
)
69 if (p
->panic_on_panic
) {
70 kernelPanicEvent
= addKernelFuncEventOrPanic
<PanicPCEvent
>(
71 "panic", "Kernel panic in simulated kernel");
74 kernelPanicEvent
= addKernelFuncEventOrPanic
<BreakPCEvent
>("panic");
78 if (p
->panic_on_oops
) {
79 kernelOopsEvent
= addKernelFuncEventOrPanic
<PanicPCEvent
>(
80 "oops_exit", "Kernel oops in guest");
83 // With ARM udelay() is #defined to __udelay
84 // newer kernels use __loop_udelay and __loop_const_udelay symbols
85 uDelaySkipEvent
= addKernelFuncEvent
<UDelayEvent
>(
86 "__loop_udelay", "__udelay", 1000, 0);
88 uDelaySkipEvent
= addKernelFuncEventOrPanic
<UDelayEvent
>(
89 "__udelay", "__udelay", 1000, 0);
91 // constant arguments to udelay() have some precomputation done ahead of
92 // time. Constant comes from code.
93 constUDelaySkipEvent
= addKernelFuncEvent
<UDelayEvent
>(
94 "__loop_const_udelay", "__const_udelay", 1000, 107374);
95 if(!constUDelaySkipEvent
)
96 constUDelaySkipEvent
= addKernelFuncEventOrPanic
<UDelayEvent
>(
97 "__const_udelay", "__const_udelay", 1000, 107374);
103 kernelSymtab
->findAddress("__secondary_data", secDataPtrAddr
);
104 kernelSymtab
->findAddress("secondary_data", secDataAddr
);
105 kernelSymtab
->findAddress("pen_release", penReleaseAddr
);
106 kernelSymtab
->findAddress("secondary_holding_pen_release", pen64ReleaseAddr
);
108 secDataPtrAddr
&= ~ULL(0x7F);
109 secDataAddr
&= ~ULL(0x7F);
110 penReleaseAddr
&= ~ULL(0x7F);
111 pen64ReleaseAddr
&= ~ULL(0x7F);
112 bootReleaseAddr
= (bootReleaseAddr
& ~ULL(0x7F)) + loadAddrOffset
;
117 LinuxArmSystem::adderBootUncacheable(Addr a
)
119 Addr block
= a
& ~ULL(0x7F);
121 if (block
== secDataPtrAddr
|| block
== secDataAddr
||
122 block
== penReleaseAddr
|| pen64ReleaseAddr
== block
||
123 block
== bootReleaseAddr
)
130 LinuxArmSystem::initState()
132 // Moved from the constructor to here since it relies on the
133 // address map being resolved in the interconnect
135 // Call the initialisation of the super class
136 GenericArmSystem::initState();
138 // Load symbols at physical address, we might not want
139 // to do this permanently, for but early bootup work
141 if (params()->early_kernel_symbols
) {
142 kernel
->loadGlobalSymbols(kernelSymtab
, loadAddrMask
);
143 kernel
->loadGlobalSymbols(debugSymbolTable
, loadAddrMask
);
146 // Setup boot data structure
148 // Check if the kernel image has a symbol that tells us it supports
150 bool kernel_has_fdt_support
=
151 kernelSymtab
->findAddress("unflatten_device_tree", addr
);
152 bool dtb_file_specified
= params()->dtb_filename
!= "";
154 if (kernel_has_fdt_support
&& dtb_file_specified
) {
155 // Kernel supports flattened device tree and dtb file specified.
156 // Using Device Tree Blob to describe system configuration.
157 inform("Loading DTB file: %s at address %#x\n", params()->dtb_filename
,
158 params()->atags_addr
+ loadAddrOffset
);
160 ObjectFile
*dtb_file
= createObjectFile(params()->dtb_filename
, true);
162 fatal("couldn't load DTB file: %s\n", params()->dtb_filename
);
165 DtbObject
*_dtb_file
= dynamic_cast<DtbObject
*>(dtb_file
);
168 if (!_dtb_file
->addBootCmdLine(params()->boot_osflags
.c_str(),
169 params()->boot_osflags
.size())) {
170 warn("couldn't append bootargs to DTB file: %s\n",
171 params()->dtb_filename
);
174 warn("dtb_file cast failed; couldn't append bootargs "
175 "to DTB file: %s\n", params()->dtb_filename
);
178 Addr ra
= _dtb_file
->findReleaseAddr();
180 bootReleaseAddr
= ra
& ~ULL(0x7F);
182 dtb_file
->setTextBase(params()->atags_addr
+ loadAddrOffset
);
183 dtb_file
->loadSections(physProxy
);
187 // Warn if the kernel supports FDT and we haven't specified one
188 if (kernel_has_fdt_support
) {
189 assert(!dtb_file_specified
);
190 warn("Kernel supports device tree, but no DTB file specified\n");
192 // Warn if the kernel doesn't support FDT and we have specified one
193 if (dtb_file_specified
) {
194 assert(!kernel_has_fdt_support
);
195 warn("DTB file specified, but no device tree support in kernel\n");
199 ac
.flags(1); // read-only
203 AddrRangeList atagRanges
= physmem
.getConfAddrRanges();
204 if (atagRanges
.size() != 1) {
205 fatal("Expected a single ATAG memory entry but got %d\n",
209 am
.memSize(atagRanges
.begin()->size());
210 am
.memStart(atagRanges
.begin()->start());
213 ad
.cmdline(params()->boot_osflags
);
215 DPRINTF(Loader
, "boot command line %d bytes: %s\n",
216 ad
.size() <<2, params()->boot_osflags
.c_str());
220 uint32_t size
= ac
.size() + am
.size() + ad
.size() + an
.size();
222 uint8_t *boot_data
= new uint8_t[size
<< 2];
224 offset
+= ac
.copyOut(boot_data
+ offset
);
225 offset
+= am
.copyOut(boot_data
+ offset
);
226 offset
+= ad
.copyOut(boot_data
+ offset
);
227 offset
+= an
.copyOut(boot_data
+ offset
);
229 DPRINTF(Loader
, "Boot atags was %d bytes in total\n", size
<< 2);
230 DDUMP(Loader
, boot_data
, size
<< 2);
232 physProxy
.writeBlob(params()->atags_addr
+ loadAddrOffset
, boot_data
,
238 // Kernel boot requirements to set up r0, r1 and r2 in ARMv7
239 for (int i
= 0; i
< threadContexts
.size(); i
++) {
240 threadContexts
[i
]->setIntReg(0, 0);
241 threadContexts
[i
]->setIntReg(1, params()->machine_type
);
242 threadContexts
[i
]->setIntReg(2, params()->atags_addr
+ loadAddrOffset
);
246 LinuxArmSystem::~LinuxArmSystem()
249 delete uDelaySkipEvent
;
250 if (constUDelaySkipEvent
)
251 delete constUDelaySkipEvent
;
253 if (dumpStatsPCEvent
)
254 delete dumpStatsPCEvent
;
258 LinuxArmSystemParams::create()
260 return new LinuxArmSystem(this);
264 LinuxArmSystem::startup()
266 if (enableContextSwitchStatsDump
) {
267 dumpStatsPCEvent
= addKernelFuncEvent
<DumpStatsPCEvent
>("__switch_to");
268 if (!dumpStatsPCEvent
)
269 panic("dumpStatsPCEvent not created!");
271 std::string task_filename
= "tasks.txt";
272 taskFile
= simout
.create(name() + "." + task_filename
);
274 for (int i
= 0; i
< _numContexts
; i
++) {
275 ThreadContext
*tc
= threadContexts
[i
];
276 uint32_t pid
= tc
->getCpuPtr()->getPid();
277 if (pid
!= Request::invldPid
) {
279 tc
->getCpuPtr()->taskId(taskMap
[pid
]);
286 LinuxArmSystem::mapPid(ThreadContext
*tc
, uint32_t pid
)
288 // Create a new unique identifier for this pid
289 std::map
<uint32_t, uint32_t>::iterator itr
= taskMap
.find(pid
);
290 if (itr
== taskMap
.end()) {
291 uint32_t map_size
= taskMap
.size();
292 if (map_size
> ContextSwitchTaskId::MaxNormalTaskId
+ 1) {
293 warn_once("Error out of identifiers for cache occupancy stats");
294 taskMap
[pid
] = ContextSwitchTaskId::Unknown
;
296 taskMap
[pid
] = map_size
;
301 /** This function is called whenever the the kernel function
302 * "__switch_to" is called to change running tasks.
304 * r0 = task_struct of the previously running process
305 * r1 = task_info of the previously running process
306 * r2 = task_info of the next process to run
309 DumpStatsPCEvent::process(ThreadContext
*tc
)
311 Linux::ThreadInfo
ti(tc
);
312 Addr task_descriptor
= tc
->readIntReg(2);
313 uint32_t pid
= ti
.curTaskPID(task_descriptor
);
314 uint32_t tgid
= ti
.curTaskTGID(task_descriptor
);
315 std::string next_task_str
= ti
.curTaskName(task_descriptor
);
317 // Streamline treats pid == -1 as the kernel process.
318 // Also pid == 0 implies idle process (except during Linux boot)
319 int32_t mm
= ti
.curTaskMm(task_descriptor
);
320 bool is_kernel
= (mm
== 0);
321 if (is_kernel
&& (pid
!= 0)) {
324 next_task_str
= "kernel";
327 LinuxArmSystem
* sys
= dynamic_cast<LinuxArmSystem
*>(tc
->getSystemPtr());
329 panic("System is not LinuxArmSystem while getting Linux process info!");
331 std::map
<uint32_t, uint32_t>& taskMap
= sys
->taskMap
;
333 // Create a new unique identifier for this pid
334 sys
->mapPid(tc
, pid
);
336 // Set cpu task id, output process info, and dump stats
337 tc
->getCpuPtr()->taskId(taskMap
[pid
]);
338 tc
->getCpuPtr()->setPid(pid
);
340 std::ostream
* taskFile
= sys
->taskFile
;
342 // Task file is read by cache occupancy plotting script or
343 // Streamline conversion script.
345 "tick=%lld %d cpu_id=%d next_pid=%d next_tgid=%d next_task=%s\n",
346 curTick(), taskMap
[pid
], tc
->cpuId(), (int) pid
, (int) tgid
,
350 // Dump and reset statistics
351 Stats::schedStatEvent(true, true, curTick(), 0);