gem5 v24.0.0.0
Loading...
Searching...
No Matches
mouse.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017-2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2008 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#include "dev/ps2/mouse.hh"
42
43#include "base/logging.hh"
44#include "base/trace.hh"
45#include "debug/PS2.hh"
46#include "dev/ps2/types.hh"
47#include "params/PS2Mouse.hh"
48#include "sim/serialize.hh"
49
50namespace gem5
51{
52
53namespace ps2
54{
55
56PS2Mouse::PS2Mouse(const PS2MouseParams &p)
57 : Device(p),
58 status(0), resolution(4), sampleRate(100)
59{
60}
61
62bool
64{
65 switch (data[0]) {
66 case ReadID:
67 DPRINTF(PS2, "Mouse ID requested.\n");
68 sendAck();
70 return true;
71 case Disable:
72 DPRINTF(PS2, "Disabling data reporting.\n");
73 status.enabled = 0;
74 sendAck();
75 return true;
76 case Enable:
77 DPRINTF(PS2, "Enabling data reporting.\n");
78 status.enabled = 1;
79 sendAck();
80 return true;
81 case Resend:
82 panic("Mouse resend unimplemented.\n");
83 case Reset:
84 DPRINTF(PS2, "Resetting the mouse.\n");
85 sampleRate = 100;
86 resolution = 4;
87 status.twoToOne = 0;
88 status.enabled = 0;
89 sendAck();
92 return true;
93
95 DPRINTF(PS2, "Setting mouse scale to 1:1.\n");
96 status.twoToOne = 0;
97 sendAck();
98 return true;
100 DPRINTF(PS2, "Setting mouse scale to 2:1.\n");
101 status.twoToOne = 1;
102 sendAck();
103 return true;
105 if (data.size() == 1) {
106 DPRINTF(PS2, "Setting mouse resolution.\n");
107 sendAck();
108 return false;
109 } else {
110 DPRINTF(PS2, "Mouse resolution set to %d.\n", data[1]);
111 resolution = data[1];
112 sendAck();
113 return true;
114 }
115 case mouse::GetStatus:
116 DPRINTF(PS2, "Getting mouse status.\n");
117 sendAck();
118 send((uint8_t *)&(status), 1);
119 send(&resolution, sizeof(resolution));
120 send(&sampleRate, sizeof(sampleRate));
121 return true;
122 case mouse::ReadData:
123 panic("Reading mouse data unimplemented.\n");
125 DPRINTF(PS2, "Resetting Wrap Mode\n");
126 sendAck();
127 return true;
128 case mouse::WrapMode:
129 panic("Setting mouse wrap mode unimplemented.\n");
131 panic("Setting mouse remote mode unimplemented.\n");
133 if (data.size() == 1) {
134 DPRINTF(PS2, "Setting mouse sample rate.\n");
135 sendAck();
136 return false;
137 } else {
138 DPRINTF(PS2, "Mouse sample rate %d samples "
139 "per second.\n", data[1]);
140 sampleRate = data[1];
141 sendAck();
142 return true;
143 }
145 DPRINTF(PS2, "Disabling and resetting mouse.\n");
146 sampleRate = 100;
147 resolution = 4;
148 status.twoToOne = 0;
149 status.enabled = 0;
150 sendAck();
151 return true;
152 default:
153 warn("Unknown mouse command %#02x.\n", data[0]);
154 send(Resend);
155 return true;
156 }
157}
158
159void
168
169void
178
179} // namespace ps2
180} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
const char data[]
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition device.cc:65
void send(const uint8_t *data, size_t size)
Send data from a PS/2 device to a host.
Definition device.cc:113
void sendAck()
Send an ACK byte to the host.
Definition device.cc:128
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition device.cc:75
PS2Mouse(const PS2MouseParams &p)
Definition mouse.cc:56
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition mouse.cc:63
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition mouse.cc:160
uint8_t resolution
Definition mouse.hh:67
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition mouse.cc:170
uint8_t sampleRate
Definition mouse.hh:68
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define warn(...)
Definition logging.hh:256
Bitfield< 5, 0 > status
Bitfield< 0 > p
const std::vector< uint8_t > ID
Definition types.cc:52
@ Resend
Definition types.hh:68
@ DefaultsAndDisable
Definition types.hh:65
@ ReadID
Definition types.hh:62
@ Disable
Definition types.hh:64
@ Reset
Definition types.hh:69
@ Enable
Definition types.hh:63
@ SelfTestPass
Definition types.hh:61
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0