2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
31 * This code loads the linux kernel, console, pal and patches certain
32 * functions. The symbol tables are loaded so that traces can show
33 * the executing function and we can skip functions. Various delay
34 * loops are skipped and their final values manually computed to speed
38 #include "base/loader/symtab.hh"
39 #include "cpu/exec_context.hh"
40 #include "cpu/base.hh"
41 #include "kern/linux/linux_system.hh"
42 #include "kern/linux/linux_threadinfo.hh"
43 #include "kern/linux/printk.hh"
44 #include "mem/functional/memory_control.hh"
45 #include "mem/functional/physical.hh"
46 #include "sim/builder.hh"
47 #include "dev/platform.hh"
48 #include "targetarch/arguments.hh"
49 #include "targetarch/vtophys.hh"
53 LinuxSystem::LinuxSystem(Params
*p
)
60 * The symbol swapper_pg_dir marks the beginning of the kernel and
61 * the location of bootloader passed arguments
63 if (!kernelSymtab
->findAddress("swapper_pg_dir", KernelStart
)) {
64 panic("Could not determine start location of kernel");
68 * Since we aren't using a bootloader, we have to copy the
69 * kernel arguments directly into the kernel's memory.
71 paddr
= vtophys(physmem
, CommandLine());
72 char *commandline
= (char *)physmem
->dma_addr(paddr
, sizeof(uint64_t));
74 strncpy(commandline
, params
->boot_osflags
.c_str(), CommandLineSize
);
77 * find the address of the est_cycle_freq variable and insert it
78 * so we don't through the lengthly process of trying to
79 * calculated it by using the PIT, RTC, etc.
81 if (kernelSymtab
->findAddress("est_cycle_freq", addr
)) {
82 paddr
= vtophys(physmem
, addr
);
83 uint8_t *est_cycle_frequency
=
84 physmem
->dma_addr(paddr
, sizeof(uint64_t));
86 if (est_cycle_frequency
)
87 *(uint64_t *)est_cycle_frequency
=
88 Clock::Frequency
/ p
->boot_cpu_frequency
;
93 * EV5 only supports 127 ASNs so we are going to tell the kernel that the
94 * paritiuclar EV6 we have only supports 127 asns.
95 * @todo At some point we should change ev5.hh and the palcode to support
98 if (kernelSymtab
->findAddress("dp264_mv", addr
)) {
99 paddr
= vtophys(physmem
, addr
);
100 char *dp264_mv
= (char *)physmem
->dma_addr(paddr
, sizeof(uint64_t));
103 *(uint32_t*)(dp264_mv
+0x18) = htog((uint32_t)127);
105 panic("could not translate dp264_mv addr\n");
108 panic("could not find dp264_mv\n");
111 kernelPanicEvent
= addKernelFuncEvent
<BreakPCEvent
>("panic");
112 if (!kernelPanicEvent
)
113 panic("could not find kernel symbol \'panic\'");
116 kernelDieEvent
= addKernelFuncEvent
<BreakPCEvent
>("die_if_kernel");
118 panic("could not find kernel symbol \'die_if_kernel\'");
124 * Any time ide_delay_50ms, calibarte_delay or
125 * determine_cpu_caches is called just skip the
126 * function. Currently determine_cpu_caches only is used put
127 * information in proc, however if that changes in the future we
128 * will have to fill in the cache size variables appropriately.
131 skipIdeDelay50msEvent
=
132 addKernelFuncEvent
<SkipFuncEvent
>("ide_delay_50ms");
134 addKernelFuncEvent
<SkipDelayLoopEvent
>("calibrate_delay");
135 skipCacheProbeEvent
=
136 addKernelFuncEvent
<SkipFuncEvent
>("determine_cpu_caches");
137 debugPrintkEvent
= addKernelFuncEvent
<DebugPrintkEvent
>("dprintk");
138 idleStartEvent
= addKernelFuncEvent
<IdleStartEvent
>("cpu_idle");
140 if (kernelSymtab
->findAddress("alpha_switch_to", addr
) && DTRACE(Thread
)) {
141 printThreadEvent
= new PrintThreadInfo(&pcEventQueue
, "threadinfo",
142 addr
+ sizeof(MachInst
) * 6);
144 printThreadEvent
= NULL
;
147 if (params
->bin_int
) {
148 intStartEvent
= addPalFuncEvent
<InterruptStartEvent
>("sys_int_21");
150 panic("could not find symbol: sys_int_21\n");
152 intEndEvent
= addPalFuncEvent
<InterruptEndEvent
>("rti_to_kern");
154 panic("could not find symbol: rti_to_kern\n");
156 intEndEvent2
= addPalFuncEvent
<InterruptEndEvent
>("rti_to_user");
158 panic("could not find symbol: rti_to_user\n");
160 intEndEvent3
= addKernelFuncEvent
<InterruptEndEvent
>("do_softirq");
162 panic("could not find symbol: do_softirq\n");
166 LinuxSystem::~LinuxSystem()
169 delete kernelPanicEvent
;
171 delete skipIdeDelay50msEvent
;
172 delete skipDelayLoopEvent
;
173 delete skipCacheProbeEvent
;
174 delete debugPrintkEvent
;
175 delete idleStartEvent
;
176 delete printThreadEvent
;
177 delete intStartEvent
;
184 LinuxSystem::setDelayLoop(ExecContext
*xc
)
187 if (kernelSymtab
->findAddress("loops_per_jiffy", addr
)) {
188 Addr paddr
= vtophys(physmem
, addr
);
190 uint8_t *loops_per_jiffy
=
191 physmem
->dma_addr(paddr
, sizeof(uint32_t));
193 Tick cpuFreq
= xc
->cpu
->frequency();
194 Tick intrFreq
= platform
->intrFrequency();
195 *(uint32_t *)loops_per_jiffy
=
196 (uint32_t)((cpuFreq
/ intrFreq
) * 0.9988);
201 LinuxSystem::SkipDelayLoopEvent::process(ExecContext
*xc
)
203 SkipFuncEvent::process(xc
);
204 // calculate and set loops_per_jiffy
205 ((LinuxSystem
*)xc
->system
)->setDelayLoop(xc
);
209 LinuxSystem::DebugPrintkEvent::process(ExecContext
*xc
)
211 if (DTRACE(DebugPrintf
)) {
213 StringWrap
name(xc
->system
->name() + ".dprintk");
217 AlphaArguments
args(xc
);
219 SkipFuncEvent::process(xc
);
224 LinuxSystem::PrintThreadInfo::process(ExecContext
*xc
)
226 Linux::ThreadInfo
ti(xc
);
228 DPRINTF(Thread
, "Currently Executing Thread %s, pid %d, started at: %d\n",
229 ti
.curTaskName(), ti
.curTaskPID(), ti
.curTaskStart());
233 BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem
)
235 Param
<Tick
> boot_cpu_frequency
;
236 SimObjectParam
<MemoryController
*> memctrl
;
237 SimObjectParam
<PhysicalMemory
*> physmem
;
239 Param
<string
> kernel
;
240 Param
<string
> console
;
243 Param
<string
> boot_osflags
;
244 Param
<string
> readfile
;
245 Param
<unsigned int> init_param
;
247 Param
<uint64_t> system_type
;
248 Param
<uint64_t> system_rev
;
251 VectorParam
<string
> binned_fns
;
254 END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem
)
256 BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem
)
258 INIT_PARAM(boot_cpu_frequency
, "Frequency of the boot CPU"),
259 INIT_PARAM(memctrl
, "memory controller"),
260 INIT_PARAM(physmem
, "phsyical memory"),
261 INIT_PARAM(kernel
, "file that contains the kernel code"),
262 INIT_PARAM(console
, "file that contains the console code"),
263 INIT_PARAM(pal
, "file that contains palcode"),
264 INIT_PARAM_DFLT(boot_osflags
, "flags to pass to the kernel during boot",
266 INIT_PARAM_DFLT(readfile
, "file to read startup script from", ""),
267 INIT_PARAM_DFLT(init_param
, "numerical value to pass into simulator", 0),
268 INIT_PARAM_DFLT(system_type
, "Type of system we are emulating", 34),
269 INIT_PARAM_DFLT(system_rev
, "Revision of system we are emulating", 1<<10),
270 INIT_PARAM_DFLT(bin
, "is this system to be binned", false),
271 INIT_PARAM(binned_fns
, "functions to be broken down and binned"),
272 INIT_PARAM_DFLT(bin_int
, "is interrupt code binned seperately?", true)
274 END_INIT_SIM_OBJECT_PARAMS(LinuxSystem
)
276 CREATE_SIM_OBJECT(LinuxSystem
)
278 System::Params
*p
= new System::Params
;
279 p
->name
= getInstanceName();
280 p
->boot_cpu_frequency
= boot_cpu_frequency
;
281 p
->memctrl
= memctrl
;
282 p
->physmem
= physmem
;
283 p
->kernel_path
= kernel
;
284 p
->console_path
= console
;
286 p
->boot_osflags
= boot_osflags
;
287 p
->init_param
= init_param
;
288 p
->readfile
= readfile
;
289 p
->system_type
= system_type
;
290 p
->system_rev
= system_rev
;
292 p
->binned_fns
= binned_fns
;
293 p
->bin_int
= bin_int
;
294 return new LinuxSystem(p
);
297 REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem
)