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/functional_mem/memory_control.hh"
47 #include "sim/builder.hh"
48 #include "sim/system.hh"
49 #include "dev/tsunami_io.hh"
53 AlphaConsole::AlphaConsole(const string
&name
, SimConsole
*cons
,
54 SimpleDisk
*d
, int size
, System
*system
,
55 BaseCPU
*cpu
, TsunamiIO
*clock
, int num_cpus
,
56 Addr addr
, Addr mask
, MemoryController
*mmu
)
57 : MmapDevice(name
, addr
, mask
, mmu
), disk(d
), console(cons
)
59 consoleData
= new uint8_t[size
];
60 memset(consoleData
, 0, size
);
62 alphaAccess
->last_offset
= size
- 1;
63 alphaAccess
->kernStart
= system
->getKernelStart();
64 alphaAccess
->kernEnd
= system
->getKernelEnd();
65 alphaAccess
->entryPoint
= system
->getKernelEntry();
67 alphaAccess
->version
= ALPHA_ACCESS_VERSION
;
68 alphaAccess
->numCPUs
= num_cpus
;
69 alphaAccess
->mem_size
= system
->physmem
->getSize();
70 alphaAccess
->cpuClock
= cpu
->getFreq() / 1000000;
71 alphaAccess
->intrClockFrequency
= clock
->frequency();
73 alphaAccess
->diskUnit
= 1;
77 AlphaConsole::read(MemReqPtr
&req
, uint8_t *data
)
79 memset(data
, 0, req
->size
);
82 Addr daddr
= req
->paddr
& addr_mask
;
84 case offsetof(AlphaAccess
, inputChar
):
85 val
= console
->console_in();
89 val
= *(uint64_t *)(consoleData
+ daddr
);
93 DPRINTF(AlphaConsole
, "read: offset=%#x val=%#x\n", daddr
, val
);
96 case sizeof(uint32_t):
97 *(uint32_t *)data
= (uint32_t)val
;
100 case sizeof(uint64_t):
101 *(uint64_t *)data
= val
;
105 return Machine_Check_Fault
;
113 AlphaConsole::write(MemReqPtr
&req
, const uint8_t *data
)
118 case sizeof(uint32_t):
119 val
= *(uint32_t *)data
;
122 case sizeof(uint64_t):
123 val
= *(uint64_t *)data
;
126 return Machine_Check_Fault
;
129 Addr daddr
= req
->paddr
& addr_mask
;
130 ExecContext
*other_xc
;
133 case offsetof(AlphaAccess
, diskUnit
):
134 alphaAccess
->diskUnit
= val
;
137 case offsetof(AlphaAccess
, diskCount
):
138 alphaAccess
->diskCount
= val
;
141 case offsetof(AlphaAccess
, diskPAddr
):
142 alphaAccess
->diskPAddr
= val
;
145 case offsetof(AlphaAccess
, diskBlock
):
146 alphaAccess
->diskBlock
= val
;
149 case offsetof(AlphaAccess
, diskOperation
):
151 disk
->read(alphaAccess
->diskPAddr
, alphaAccess
->diskBlock
,
152 alphaAccess
->diskCount
);
154 panic("Invalid disk operation!");
158 case offsetof(AlphaAccess
, outputChar
):
159 console
->out((char)(val
& 0xff), false);
162 case offsetof(AlphaAccess
, bootStrapImpure
):
163 alphaAccess
->bootStrapImpure
= val
;
166 case offsetof(AlphaAccess
, bootStrapCPU
):
167 warn("%d: Trying to launch another CPU!", curTick
);
168 assert(val
> 0 && "Must not access primary cpu");
170 other_xc
= req
->xc
->system
->execContexts
[val
];
171 other_xc
->regs
.intRegFile
[16] = val
;
172 other_xc
->regs
.ipr
[TheISA::IPR_PALtemp16
] = val
;
173 other_xc
->regs
.intRegFile
[0] = val
;
174 other_xc
->regs
.intRegFile
[30] = alphaAccess
->bootStrapImpure
;
175 other_xc
->activate(); //Start the cpu
179 return Machine_Check_Fault
;
186 AlphaAccess::serialize(ostream
&os
)
188 SERIALIZE_SCALAR(last_offset
);
189 SERIALIZE_SCALAR(version
);
190 SERIALIZE_SCALAR(numCPUs
);
191 SERIALIZE_SCALAR(mem_size
);
192 SERIALIZE_SCALAR(cpuClock
);
193 SERIALIZE_SCALAR(intrClockFrequency
);
194 SERIALIZE_SCALAR(kernStart
);
195 SERIALIZE_SCALAR(kernEnd
);
196 SERIALIZE_SCALAR(entryPoint
);
197 SERIALIZE_SCALAR(diskUnit
);
198 SERIALIZE_SCALAR(diskCount
);
199 SERIALIZE_SCALAR(diskPAddr
);
200 SERIALIZE_SCALAR(diskBlock
);
201 SERIALIZE_SCALAR(diskOperation
);
202 SERIALIZE_SCALAR(outputChar
);
203 SERIALIZE_SCALAR(inputChar
);
204 SERIALIZE_SCALAR(bootStrapImpure
);
205 SERIALIZE_SCALAR(bootStrapCPU
);
209 AlphaAccess::unserialize(Checkpoint
*cp
, const std::string
§ion
)
211 UNSERIALIZE_SCALAR(last_offset
);
212 UNSERIALIZE_SCALAR(version
);
213 UNSERIALIZE_SCALAR(numCPUs
);
214 UNSERIALIZE_SCALAR(mem_size
);
215 UNSERIALIZE_SCALAR(cpuClock
);
216 UNSERIALIZE_SCALAR(intrClockFrequency
);
217 UNSERIALIZE_SCALAR(kernStart
);
218 UNSERIALIZE_SCALAR(kernEnd
);
219 UNSERIALIZE_SCALAR(entryPoint
);
220 UNSERIALIZE_SCALAR(diskUnit
);
221 UNSERIALIZE_SCALAR(diskCount
);
222 UNSERIALIZE_SCALAR(diskPAddr
);
223 UNSERIALIZE_SCALAR(diskBlock
);
224 UNSERIALIZE_SCALAR(diskOperation
);
225 UNSERIALIZE_SCALAR(outputChar
);
226 UNSERIALIZE_SCALAR(inputChar
);
227 UNSERIALIZE_SCALAR(bootStrapImpure
);
228 UNSERIALIZE_SCALAR(bootStrapCPU
);
232 AlphaConsole::serialize(ostream
&os
)
234 alphaAccess
->serialize(os
);
238 AlphaConsole::unserialize(Checkpoint
*cp
, const std::string
§ion
)
240 alphaAccess
->unserialize(cp
, section
);
243 BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole
)
245 SimObjectParam
<SimConsole
*> sim_console
;
246 SimObjectParam
<SimpleDisk
*> disk
;
249 SimObjectParam
<MemoryController
*> mmu
;
252 SimObjectParam
<System
*> system
;
253 SimObjectParam
<BaseCPU
*> cpu
;
254 SimObjectParam
<TsunamiIO
*> clock
;
256 END_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole
)
258 BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaConsole
)
260 INIT_PARAM(sim_console
, "The Simulator Console"),
261 INIT_PARAM(disk
, "Simple Disk"),
262 INIT_PARAM_DFLT(size
, "AlphaConsole size", sizeof(AlphaAccess
)),
263 INIT_PARAM_DFLT(num_cpus
, "Number of CPU's", 1),
264 INIT_PARAM(mmu
, "Memory Controller"),
265 INIT_PARAM(addr
, "Device Address"),
266 INIT_PARAM(mask
, "Address Mask"),
267 INIT_PARAM(system
, "system object"),
268 INIT_PARAM(cpu
, "Processor"),
269 INIT_PARAM(clock
, "Turbolaser Clock")
271 END_INIT_SIM_OBJECT_PARAMS(AlphaConsole
)
273 CREATE_SIM_OBJECT(AlphaConsole
)
275 return new AlphaConsole(getInstanceName(), sim_console
,
277 cpu
, clock
, num_cpus
,
281 REGISTER_SIM_OBJECT("AlphaConsole", AlphaConsole
)