gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
speaker.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 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  * Authors: Gabe Black
29  */
30 
31 #include "dev/x86/speaker.hh"
32 
33 #include "base/bitunion.hh"
34 #include "base/trace.hh"
35 #include "debug/PcSpeaker.hh"
36 #include "dev/x86/i8254.hh"
37 #include "mem/packet.hh"
38 #include "mem/packet_access.hh"
39 
40 Tick
42 {
43  assert(pkt->getAddr() == pioAddr);
44  assert(pkt->getSize() == 1);
45  controlVal.timer = timer->outputHigh(2) ? 1 : 0;
46  DPRINTF(PcSpeaker,
47  "Reading from speaker device: gate %s, speaker %s, output %s.\n",
48  controlVal.gate ? "on" : "off",
49  controlVal.speaker ? "on" : "off",
50  controlVal.timer ? "on" : "off");
51  pkt->set((uint8_t)controlVal);
52  pkt->makeAtomicResponse();
53  return latency;
54 }
55 
56 Tick
58 {
59  assert(pkt->getAddr() == pioAddr);
60  assert(pkt->getSize() == 1);
61  SpeakerControl val = pkt->get<uint8_t>();
62  controlVal.gate = val.gate;
63  //Change the gate value in the timer.
64  if (!val.gate)
65  warn("The gate bit of the pc speaker isn't implemented and "
66  "is always on.\n");
67  //This would control whether the timer output is hooked up to a physical
68  //speaker. Since M5 can't make noise, it's value doesn't actually do
69  //anything.
70  controlVal.speaker = val.speaker;
71  DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n",
72  controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off");
73  pkt->makeAtomicResponse();
74  return latency;
75 }
76 
77 void
79 {
80  uint8_t controlValData = controlVal.__data;
81  SERIALIZE_SCALAR(controlValData);
82 }
83 
84 void
86 {
87  uint8_t controlValData;
88  UNSERIALIZE_SCALAR(controlValData);
89  controlVal.__data = controlValData;
90 }
91 
93 PcSpeakerParams::create()
94 {
95  return new X86ISA::Speaker(this);
96 }
#define DPRINTF(x,...)
Definition: trace.hh:212
void set(T v, ByteOrder endian)
Set the value in the data pointer to v using the specified endianness.
T get(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness.
Bitfield< 63 > val
Definition: misc.hh:770
#define warn(...)
Definition: misc.hh:219
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
void makeAtomicResponse()
Definition: packet.hh:857
uint64_t Tick
Tick count type.
Definition: types.hh:63
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: speaker.cc:41
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: speaker.cc:78
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
Declaration of the Packet class.
std::ostream CheckpointOut
Definition: serialize.hh:67
unsigned getSize() const
Definition: packet.hh:649
Bitfield< 5 > timer
Definition: speaker.hh:51
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:139
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: speaker.cc:85
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: speaker.cc:57
Addr getAddr() const
Definition: packet.hh:639

Generated on Fri Jun 9 2017 13:03:47 for gem5 by doxygen 1.8.6