Better pool job handling
[gem5.git] / kern / linux / linux_system.cc
1 /*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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
29 /**
30 * @file
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
35 * up boot time.
36 */
37
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"
50
51 using namespace std;
52
53 LinuxSystem::LinuxSystem(Params *p)
54 : System(p)
55 {
56 Addr addr = 0;
57 Addr paddr = 0;
58
59 /**
60 * The symbol swapper_pg_dir marks the beginning of the kernel and
61 * the location of bootloader passed arguments
62 */
63 if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) {
64 panic("Could not determine start location of kernel");
65 }
66
67 /**
68 * Since we aren't using a bootloader, we have to copy the
69 * kernel arguments directly into the kernel's memory.
70 */
71 paddr = vtophys(physmem, CommandLine());
72 char *commandline = (char *)physmem->dma_addr(paddr, sizeof(uint64_t));
73 if (commandline)
74 strncpy(commandline, params->boot_osflags.c_str(), CommandLineSize);
75
76 /**
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.
80 */
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));
85
86 if (est_cycle_frequency)
87 *(uint64_t *)est_cycle_frequency =
88 Clock::Frequency / p->boot_cpu_frequency;
89 }
90
91
92 /**
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
96 * 255 ASNs.
97 */
98 if (kernelSymtab->findAddress("dp264_mv", addr)) {
99 paddr = vtophys(physmem, addr);
100 char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t));
101
102 if (dp264_mv) {
103 *(uint32_t*)(dp264_mv+0x18) = htog((uint32_t)127);
104 } else
105 panic("could not translate dp264_mv addr\n");
106
107 } else
108 panic("could not find dp264_mv\n");
109
110 #ifndef NDEBUG
111 kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic");
112 if (!kernelPanicEvent)
113 panic("could not find kernel symbol \'panic\'");
114
115 #if 0
116 kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel");
117 if (!kernelDieEvent)
118 panic("could not find kernel symbol \'die_if_kernel\'");
119 #endif
120
121 #endif
122
123 /**
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.
129 */
130
131 skipIdeDelay50msEvent =
132 addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms");
133 skipDelayLoopEvent =
134 addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay");
135 skipCacheProbeEvent =
136 addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches");
137 debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk");
138 idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle");
139
140 if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) {
141 printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo",
142 addr + sizeof(MachInst) * 6);
143 } else {
144 printThreadEvent = NULL;
145 }
146
147 if (params->bin_int) {
148 intStartEvent = addPalFuncEvent<InterruptStartEvent>("sys_int_21");
149 if (!intStartEvent)
150 panic("could not find symbol: sys_int_21\n");
151
152 intEndEvent = addPalFuncEvent<InterruptEndEvent>("rti_to_kern");
153 if (!intEndEvent)
154 panic("could not find symbol: rti_to_kern\n");
155
156 intEndEvent2 = addPalFuncEvent<InterruptEndEvent>("rti_to_user");
157 if (!intEndEvent2)
158 panic("could not find symbol: rti_to_user\n");
159
160 intEndEvent3 = addKernelFuncEvent<InterruptEndEvent>("do_softirq");
161 if (!intEndEvent3)
162 panic("could not find symbol: do_softirq\n");
163 }
164 }
165
166 LinuxSystem::~LinuxSystem()
167 {
168 #ifndef NDEBUG
169 delete kernelPanicEvent;
170 #endif
171 delete skipIdeDelay50msEvent;
172 delete skipDelayLoopEvent;
173 delete skipCacheProbeEvent;
174 delete debugPrintkEvent;
175 delete idleStartEvent;
176 delete printThreadEvent;
177 delete intStartEvent;
178 delete intEndEvent;
179 delete intEndEvent2;
180 }
181
182
183 void
184 LinuxSystem::setDelayLoop(ExecContext *xc)
185 {
186 Addr addr = 0;
187 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) {
188 Addr paddr = vtophys(physmem, addr);
189
190 uint8_t *loops_per_jiffy =
191 physmem->dma_addr(paddr, sizeof(uint32_t));
192
193 Tick cpuFreq = xc->cpu->frequency();
194 Tick intrFreq = platform->intrFrequency();
195 *(uint32_t *)loops_per_jiffy =
196 (uint32_t)((cpuFreq / intrFreq) * 0.9988);
197 }
198 }
199
200 void
201 LinuxSystem::SkipDelayLoopEvent::process(ExecContext *xc)
202 {
203 SkipFuncEvent::process(xc);
204 // calculate and set loops_per_jiffy
205 ((LinuxSystem *)xc->system)->setDelayLoop(xc);
206 }
207
208 void
209 LinuxSystem::DebugPrintkEvent::process(ExecContext *xc)
210 {
211 if (DTRACE(DebugPrintf)) {
212 if (!raw) {
213 StringWrap name(xc->system->name() + ".dprintk");
214 DPRINTFN("");
215 }
216
217 AlphaArguments args(xc);
218 Printk(args);
219 SkipFuncEvent::process(xc);
220 }
221 }
222
223 void
224 LinuxSystem::PrintThreadInfo::process(ExecContext *xc)
225 {
226 Linux::ThreadInfo ti(xc);
227
228 DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n",
229 ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart());
230 }
231
232
233 BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem)
234
235 Param<Tick> boot_cpu_frequency;
236 SimObjectParam<MemoryController *> memctrl;
237 SimObjectParam<PhysicalMemory *> physmem;
238
239 Param<string> kernel;
240 Param<string> console;
241 Param<string> pal;
242
243 Param<string> boot_osflags;
244 Param<string> readfile;
245 Param<unsigned int> init_param;
246
247 Param<uint64_t> system_type;
248 Param<uint64_t> system_rev;
249
250 Param<bool> bin;
251 VectorParam<string> binned_fns;
252 Param<bool> bin_int;
253
254 END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem)
255
256 BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem)
257
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",
265 "a"),
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)
273
274 END_INIT_SIM_OBJECT_PARAMS(LinuxSystem)
275
276 CREATE_SIM_OBJECT(LinuxSystem)
277 {
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;
285 p->palcode = pal;
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;
291 p->bin = bin;
292 p->binned_fns = binned_fns;
293 p->bin_int = bin_int;
294 return new LinuxSystem(p);
295 }
296
297 REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem)
298