2 * Copyright (c) 2001-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.
30 * Alpha Console Definition
37 #include "arch/alpha/ev5.hh"
38 #include "arch/alpha/system.hh"
39 #include "base/inifile.hh"
40 #include "base/str.hh"
41 #include "base/trace.hh"
42 #include "cpu/base.hh"
43 #include "cpu/exec_context.hh"
44 #include "dev/alpha_console.hh"
45 #include "dev/simconsole.hh"
46 #include "dev/simple_disk.hh"
47 #include "dev/tsunami_io.hh"
48 #include "mem/bus/bus.hh"
49 #include "mem/bus/pio_interface.hh"
50 #include "mem/bus/pio_interface_impl.hh"
51 #include "mem/functional/memory_control.hh"
52 #include "mem/functional/physical.hh"
53 #include "sim/builder.hh"
54 #include "sim/sim_object.hh"
57 using namespace AlphaISA
;
59 AlphaConsole::AlphaConsole(const string
&name
, SimConsole
*cons
, SimpleDisk
*d
,
60 AlphaSystem
*s
, BaseCPU
*c
, Platform
*p
,
61 MemoryController
*mmu
, Addr a
,
62 HierParams
*hier
, Bus
*pio_bus
)
63 : PioDevice(name
, p
), disk(d
), console(cons
), system(s
), cpu(c
), addr(a
)
65 mmu
->add_child(this, RangeSize(addr
, size
));
68 pioInterface
= newPioInterface(name
+ ".pio", hier
, pio_bus
, this,
69 &AlphaConsole::cacheAccess
);
70 pioInterface
->addAddrRange(RangeSize(addr
, size
));
73 alphaAccess
= new Access
;
74 alphaAccess
->last_offset
= size
- 1;
76 alphaAccess
->version
= ALPHA_ACCESS_VERSION
;
77 alphaAccess
->diskUnit
= 1;
79 alphaAccess
->diskCount
= 0;
80 alphaAccess
->diskPAddr
= 0;
81 alphaAccess
->diskBlock
= 0;
82 alphaAccess
->diskOperation
= 0;
83 alphaAccess
->outputChar
= 0;
84 alphaAccess
->inputChar
= 0;
85 bzero(alphaAccess
->cpuStack
, sizeof(alphaAccess
->cpuStack
));
87 system
->setAlphaAccess(addr
);
91 AlphaConsole::startup()
93 alphaAccess
->numCPUs
= system
->getNumCPUs();
94 alphaAccess
->kernStart
= system
->getKernelStart();
95 alphaAccess
->kernEnd
= system
->getKernelEnd();
96 alphaAccess
->entryPoint
= system
->getKernelEntry();
97 alphaAccess
->mem_size
= system
->physmem
->size();
98 alphaAccess
->cpuClock
= cpu
->frequency() / 1000000; // In MHz
99 alphaAccess
->intrClockFrequency
= platform
->intrFrequency();
103 AlphaConsole::read(MemReqPtr
&req
, uint8_t *data
)
105 memset(data
, 0, req
->size
);
107 Addr daddr
= req
->paddr
- (addr
& EV5::PAddrImplMask
);
111 case sizeof(uint32_t):
112 DPRINTF(AlphaConsole
, "read: offset=%#x val=%#x\n", daddr
,
116 case offsetof(AlphaAccess
, last_offset
):
117 *(uint32_t*)data
= alphaAccess
->last_offset
;
119 case offsetof(AlphaAccess
, version
):
120 *(uint32_t*)data
= alphaAccess
->version
;
122 case offsetof(AlphaAccess
, numCPUs
):
123 *(uint32_t*)data
= alphaAccess
->numCPUs
;
125 case offsetof(AlphaAccess
, intrClockFrequency
):
126 *(uint32_t*)data
= alphaAccess
->intrClockFrequency
;
129 // Old console code read in everyting as a 32bit int
130 *(uint32_t*)data
= *(uint32_t*)(consoleData
+ daddr
);
134 case sizeof(uint64_t):
135 DPRINTF(AlphaConsole
, "read: offset=%#x val=%#x\n", daddr
,
139 case offsetof(AlphaAccess
, inputChar
):
140 *(uint64_t*)data
= console
->console_in();
142 case offsetof(AlphaAccess
, cpuClock
):
143 *(uint64_t*)data
= alphaAccess
->cpuClock
;
145 case offsetof(AlphaAccess
, mem_size
):
146 *(uint64_t*)data
= alphaAccess
->mem_size
;
148 case offsetof(AlphaAccess
, kernStart
):
149 *(uint64_t*)data
= alphaAccess
->kernStart
;
151 case offsetof(AlphaAccess
, kernEnd
):
152 *(uint64_t*)data
= alphaAccess
->kernEnd
;
154 case offsetof(AlphaAccess
, entryPoint
):
155 *(uint64_t*)data
= alphaAccess
->entryPoint
;
157 case offsetof(AlphaAccess
, diskUnit
):
158 *(uint64_t*)data
= alphaAccess
->diskUnit
;
160 case offsetof(AlphaAccess
, diskCount
):
161 *(uint64_t*)data
= alphaAccess
->diskCount
;
163 case offsetof(AlphaAccess
, diskPAddr
):
164 *(uint64_t*)data
= alphaAccess
->diskPAddr
;
166 case offsetof(AlphaAccess
, diskBlock
):
167 *(uint64_t*)data
= alphaAccess
->diskBlock
;
169 case offsetof(AlphaAccess
, diskOperation
):
170 *(uint64_t*)data
= alphaAccess
->diskOperation
;
172 case offsetof(AlphaAccess
, outputChar
):
173 *(uint64_t*)data
= alphaAccess
->outputChar
;
176 int cpunum
= (daddr
- offsetof(AlphaAccess
, cpuStack
)) /
177 sizeof(alphaAccess
->cpuStack
[0]);
179 if (cpunum
>= 0 && cpunum
< 64)
180 *(uint64_t*)data
= alphaAccess
->cpuStack
[cpunum
];
182 panic("Unknown 64bit access, %#x\n", daddr
);
186 return genMachineCheckFault();
193 AlphaConsole::write(MemReqPtr
&req
, const uint8_t *data
)
198 case sizeof(uint32_t):
199 val
= *(uint32_t *)data
;
202 case sizeof(uint64_t):
203 val
= *(uint64_t *)data
;
206 return genMachineCheckFault();
209 Addr daddr
= req
->paddr
- (addr
& EV5::PAddrImplMask
);
210 ExecContext
*other_xc
;
213 case offsetof(AlphaAccess
, diskUnit
):
214 alphaAccess
->diskUnit
= val
;
217 case offsetof(AlphaAccess
, diskCount
):
218 alphaAccess
->diskCount
= val
;
221 case offsetof(AlphaAccess
, diskPAddr
):
222 alphaAccess
->diskPAddr
= val
;
225 case offsetof(AlphaAccess
, diskBlock
):
226 alphaAccess
->diskBlock
= val
;
229 case offsetof(AlphaAccess
, diskOperation
):
231 disk
->read(alphaAccess
->diskPAddr
, alphaAccess
->diskBlock
,
232 alphaAccess
->diskCount
);
234 panic("Invalid disk operation!");
238 case offsetof(AlphaAccess
, outputChar
):
239 console
->out((char)(val
& 0xff));
242 other_xc
->activate(); //Start the cpu
246 int cpunum
= (daddr
- offsetof(AlphaAccess
, cpuStack
)) /
247 sizeof(alphaAccess
->cpuStack
[0]);
248 warn("%d: Trying to launch CPU number %d!", curTick
, cpunum
);
249 assert(val
> 0 && "Must not access primary cpu");
250 if (cpunum
>= 0 && cpunum
< 64)
251 alphaAccess
->cpuStack
[cpunum
] = val
;
253 panic("Unknown 64bit access, %#x\n", daddr
);
260 AlphaConsole::cacheAccess(MemReqPtr
&req
)
262 return curTick
+ 1000;
266 AlphaConsole::Access::serialize(ostream
&os
)
268 SERIALIZE_SCALAR(last_offset
);
269 SERIALIZE_SCALAR(version
);
270 SERIALIZE_SCALAR(numCPUs
);
271 SERIALIZE_SCALAR(mem_size
);
272 SERIALIZE_SCALAR(cpuClock
);
273 SERIALIZE_SCALAR(intrClockFrequency
);
274 SERIALIZE_SCALAR(kernStart
);
275 SERIALIZE_SCALAR(kernEnd
);
276 SERIALIZE_SCALAR(entryPoint
);
277 SERIALIZE_SCALAR(diskUnit
);
278 SERIALIZE_SCALAR(diskCount
);
279 SERIALIZE_SCALAR(diskPAddr
);
280 SERIALIZE_SCALAR(diskBlock
);
281 SERIALIZE_SCALAR(diskOperation
);
282 SERIALIZE_SCALAR(outputChar
);
283 SERIALIZE_SCALAR(inputChar
);
284 SERIALIZE_ARRAY(cpuStack
,64);
288 AlphaConsole::Access::unserialize(Checkpoint
*cp
, const std::string
§ion
)
290 UNSERIALIZE_SCALAR(last_offset
);
291 UNSERIALIZE_SCALAR(version
);
292 UNSERIALIZE_SCALAR(numCPUs
);
293 UNSERIALIZE_SCALAR(mem_size
);
294 UNSERIALIZE_SCALAR(cpuClock
);
295 UNSERIALIZE_SCALAR(intrClockFrequency
);
296 UNSERIALIZE_SCALAR(kernStart
);
297 UNSERIALIZE_SCALAR(kernEnd
);
298 UNSERIALIZE_SCALAR(entryPoint
);
299 UNSERIALIZE_SCALAR(diskUnit
);
300 UNSERIALIZE_SCALAR(diskCount
);
301 UNSERIALIZE_SCALAR(diskPAddr
);
302 UNSERIALIZE_SCALAR(diskBlock
);
303 UNSERIALIZE_SCALAR(diskOperation
);
304 UNSERIALIZE_SCALAR(outputChar
);
305 UNSERIALIZE_SCALAR(inputChar
);
306 UNSERIALIZE_ARRAY(cpuStack
, 64);
310 AlphaConsole::serialize(ostream
&os
)
312 alphaAccess
->serialize(os
);
316 AlphaConsole::unserialize(Checkpoint
*cp
, const std::string
§ion
)
318 alphaAccess
->unserialize(cp
, section
);
321 BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole
)
323 SimObjectParam
<SimConsole
*> sim_console
;
324 SimObjectParam
<SimpleDisk
*> disk
;
325 SimObjectParam
<MemoryController
*> mmu
;
327 SimObjectParam
<AlphaSystem
*> system
;
328 SimObjectParam
<BaseCPU
*> cpu
;
329 SimObjectParam
<Platform
*> platform
;
330 SimObjectParam
<Bus
*> pio_bus
;
331 Param
<Tick
> pio_latency
;
332 SimObjectParam
<HierParams
*> hier
;
334 END_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole
)
336 BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaConsole
)
338 INIT_PARAM(sim_console
, "The Simulator Console"),
339 INIT_PARAM(disk
, "Simple Disk"),
340 INIT_PARAM(mmu
, "Memory Controller"),
341 INIT_PARAM(addr
, "Device Address"),
342 INIT_PARAM(system
, "system object"),
343 INIT_PARAM(cpu
, "Processor"),
344 INIT_PARAM(platform
, "platform"),
345 INIT_PARAM(pio_bus
, "The IO Bus to attach to"),
346 INIT_PARAM_DFLT(pio_latency
, "Programmed IO latency", 1000),
347 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
349 END_INIT_SIM_OBJECT_PARAMS(AlphaConsole
)
351 CREATE_SIM_OBJECT(AlphaConsole
)
353 return new AlphaConsole(getInstanceName(), sim_console
, disk
,
354 system
, cpu
, platform
, mmu
, addr
, hier
, pio_bus
);
357 REGISTER_SIM_OBJECT("AlphaConsole", AlphaConsole
)