2 * Copyright (c) 2003 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 * System Console Definition
37 #include "base/inifile.hh"
38 #include "base/str.hh" // for to_number()
39 #include "base/trace.hh"
40 #include "cpu/base_cpu.hh"
41 #include "cpu/exec_context.hh"
42 #include "dev/alpha_console.hh"
43 #include "dev/console.hh"
44 #include "dev/simple_disk.hh"
45 #include "dev/tlaser_clock.hh"
46 #include "mem/bus/bus.hh"
47 #include "mem/bus/pio_interface.hh"
48 #include "mem/bus/pio_interface_impl.hh"
49 #include "mem/functional_mem/memory_control.hh"
50 #include "sim/builder.hh"
51 #include "sim/system.hh"
52 #include "dev/tsunami_io.hh"
53 #include "sim/sim_object.hh"
57 AlphaConsole::AlphaConsole(const string
&name
, SimConsole
*cons
, SimpleDisk
*d
,
58 System
*system
, BaseCPU
*cpu
, Platform
*platform
,
59 int num_cpus
, MemoryController
*mmu
, Addr a
,
60 HierParams
*hier
, Bus
*bus
)
61 : PioDevice(name
), disk(d
), console(cons
), addr(a
)
63 mmu
->add_child(this, Range
<Addr
>(addr
, addr
+ size
));
66 pioInterface
= newPioInterface(name
, hier
, bus
, this,
67 &AlphaConsole::cacheAccess
);
68 pioInterface
->addAddrRange(addr
, addr
+ size
);
71 consoleData
= new uint8_t[size
];
72 memset(consoleData
, 0, size
);
74 alphaAccess
->last_offset
= size
- 1;
75 alphaAccess
->kernStart
= system
->getKernelStart();
76 alphaAccess
->kernEnd
= system
->getKernelEnd();
77 alphaAccess
->entryPoint
= system
->getKernelEntry();
79 alphaAccess
->version
= ALPHA_ACCESS_VERSION
;
80 alphaAccess
->numCPUs
= num_cpus
;
81 alphaAccess
->mem_size
= system
->physmem
->size();
82 alphaAccess
->cpuClock
= cpu
->getFreq() / 1000000;
83 alphaAccess
->intrClockFrequency
= platform
->intrFrequency();
84 alphaAccess
->diskUnit
= 1;
88 AlphaConsole::read(MemReqPtr
&req
, uint8_t *data
)
90 memset(data
, 0, req
->size
);
93 Addr daddr
= req
->paddr
- (addr
& PA_IMPL_MASK
);
96 case offsetof(AlphaAccess
, inputChar
):
97 val
= console
->console_in();
101 val
= *(uint64_t *)(consoleData
+ daddr
);
105 DPRINTF(AlphaConsole
, "read: offset=%#x val=%#x\n", daddr
, val
);
108 case sizeof(uint32_t):
109 *(uint32_t *)data
= (uint32_t)val
;
112 case sizeof(uint64_t):
113 *(uint64_t *)data
= val
;
117 return Machine_Check_Fault
;
125 AlphaConsole::write(MemReqPtr
&req
, const uint8_t *data
)
130 case sizeof(uint32_t):
131 val
= *(uint32_t *)data
;
134 case sizeof(uint64_t):
135 val
= *(uint64_t *)data
;
138 return Machine_Check_Fault
;
141 Addr daddr
= req
->paddr
- (addr
& PA_IMPL_MASK
);
142 ExecContext
*other_xc
;
145 case offsetof(AlphaAccess
, diskUnit
):
146 alphaAccess
->diskUnit
= val
;
149 case offsetof(AlphaAccess
, diskCount
):
150 alphaAccess
->diskCount
= val
;
153 case offsetof(AlphaAccess
, diskPAddr
):
154 alphaAccess
->diskPAddr
= val
;
157 case offsetof(AlphaAccess
, diskBlock
):
158 alphaAccess
->diskBlock
= val
;
161 case offsetof(AlphaAccess
, diskOperation
):
163 disk
->read(alphaAccess
->diskPAddr
, alphaAccess
->diskBlock
,
164 alphaAccess
->diskCount
);
166 panic("Invalid disk operation!");
170 case offsetof(AlphaAccess
, outputChar
):
171 console
->out((char)(val
& 0xff), false);
174 case offsetof(AlphaAccess
, bootStrapImpure
):
175 alphaAccess
->bootStrapImpure
= val
;
178 case offsetof(AlphaAccess
, bootStrapCPU
):
179 warn("%d: Trying to launch another CPU!", curTick
);
180 assert(val
> 0 && "Must not access primary cpu");
182 other_xc
= req
->xc
->system
->execContexts
[val
];
183 other_xc
->regs
.intRegFile
[16] = val
;
184 other_xc
->regs
.ipr
[TheISA::IPR_PALtemp16
] = val
;
185 other_xc
->regs
.intRegFile
[0] = val
;
186 other_xc
->regs
.intRegFile
[30] = alphaAccess
->bootStrapImpure
;
187 other_xc
->activate(); //Start the cpu
191 return Machine_Check_Fault
;
198 AlphaConsole::cacheAccess(MemReqPtr
&req
)
200 return curTick
+ 1000;
204 AlphaAccess::serialize(ostream
&os
)
206 SERIALIZE_SCALAR(last_offset
);
207 SERIALIZE_SCALAR(version
);
208 SERIALIZE_SCALAR(numCPUs
);
209 SERIALIZE_SCALAR(mem_size
);
210 SERIALIZE_SCALAR(cpuClock
);
211 SERIALIZE_SCALAR(intrClockFrequency
);
212 SERIALIZE_SCALAR(kernStart
);
213 SERIALIZE_SCALAR(kernEnd
);
214 SERIALIZE_SCALAR(entryPoint
);
215 SERIALIZE_SCALAR(diskUnit
);
216 SERIALIZE_SCALAR(diskCount
);
217 SERIALIZE_SCALAR(diskPAddr
);
218 SERIALIZE_SCALAR(diskBlock
);
219 SERIALIZE_SCALAR(diskOperation
);
220 SERIALIZE_SCALAR(outputChar
);
221 SERIALIZE_SCALAR(inputChar
);
222 SERIALIZE_SCALAR(bootStrapImpure
);
223 SERIALIZE_SCALAR(bootStrapCPU
);
227 AlphaAccess::unserialize(Checkpoint
*cp
, const std::string
§ion
)
229 UNSERIALIZE_SCALAR(last_offset
);
230 UNSERIALIZE_SCALAR(version
);
231 UNSERIALIZE_SCALAR(numCPUs
);
232 UNSERIALIZE_SCALAR(mem_size
);
233 UNSERIALIZE_SCALAR(cpuClock
);
234 UNSERIALIZE_SCALAR(intrClockFrequency
);
235 UNSERIALIZE_SCALAR(kernStart
);
236 UNSERIALIZE_SCALAR(kernEnd
);
237 UNSERIALIZE_SCALAR(entryPoint
);
238 UNSERIALIZE_SCALAR(diskUnit
);
239 UNSERIALIZE_SCALAR(diskCount
);
240 UNSERIALIZE_SCALAR(diskPAddr
);
241 UNSERIALIZE_SCALAR(diskBlock
);
242 UNSERIALIZE_SCALAR(diskOperation
);
243 UNSERIALIZE_SCALAR(outputChar
);
244 UNSERIALIZE_SCALAR(inputChar
);
245 UNSERIALIZE_SCALAR(bootStrapImpure
);
246 UNSERIALIZE_SCALAR(bootStrapCPU
);
250 AlphaConsole::serialize(ostream
&os
)
252 alphaAccess
->serialize(os
);
256 AlphaConsole::unserialize(Checkpoint
*cp
, const std::string
§ion
)
258 alphaAccess
->unserialize(cp
, section
);
261 BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole
)
263 SimObjectParam
<SimConsole
*> sim_console
;
264 SimObjectParam
<SimpleDisk
*> disk
;
266 SimObjectParam
<MemoryController
*> mmu
;
268 SimObjectParam
<System
*> system
;
269 SimObjectParam
<BaseCPU
*> cpu
;
270 SimObjectParam
<Platform
*> platform
;
271 SimObjectParam
<Bus
*> io_bus
;
272 SimObjectParam
<HierParams
*> hier
;
274 END_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole
)
276 BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaConsole
)
278 INIT_PARAM(sim_console
, "The Simulator Console"),
279 INIT_PARAM(disk
, "Simple Disk"),
280 INIT_PARAM_DFLT(num_cpus
, "Number of CPU's", 1),
281 INIT_PARAM(mmu
, "Memory Controller"),
282 INIT_PARAM(addr
, "Device Address"),
283 INIT_PARAM(system
, "system object"),
284 INIT_PARAM(cpu
, "Processor"),
285 INIT_PARAM(platform
, "platform"),
286 INIT_PARAM_DFLT(io_bus
, "The IO Bus to attach to", NULL
),
287 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
289 END_INIT_SIM_OBJECT_PARAMS(AlphaConsole
)
291 CREATE_SIM_OBJECT(AlphaConsole
)
293 return new AlphaConsole(getInstanceName(), sim_console
, disk
,
294 system
, cpu
, platform
, num_cpus
, mmu
,
298 REGISTER_SIM_OBJECT("AlphaConsole", AlphaConsole
)