gem5 v24.0.0.0
Loading...
Searching...
No Matches
keyboard.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/keyboard.hh"
42
43#include <cstdint>
44#include <list>
45
46#include "base/logging.hh"
47#include "base/trace.hh"
48#include "debug/PS2.hh"
49#include "dev/ps2/types.hh"
50#include "params/PS2Keyboard.hh"
51
52namespace gem5
53{
54
55namespace ps2
56{
57
58PS2Keyboard::PS2Keyboard(const PS2KeyboardParams &p)
59 : Device(p),
60 shiftDown(false),
61 enabled(false)
62{
63 if (p.vnc)
64 p.vnc->setKeyboard(this);
65}
66
67void
74
75void
82
83bool
85{
86 switch (data[0]) {
87 case ReadID:
88 DPRINTF(PS2, "Got keyboard read ID command.\n");
89 sendAck();
91 return true;
92 case Enable:
93 DPRINTF(PS2, "Enabling the keyboard.\n");
94 enabled = true;
95 sendAck();
96 return true;
97 case Disable:
98 DPRINTF(PS2, "Disabling the keyboard.\n");
99 enabled = false;
100 sendAck();
101 return true;
103 DPRINTF(PS2, "Disabling and resetting the keyboard.\n");
104 enabled = false;
105 sendAck();
106 return true;
107 case Reset:
108 DPRINTF(PS2, "Resetting keyboard.\n");
109 enabled = true;
110 sendAck();
112 return true;
113 case Resend:
114 panic("Keyboard resend unimplemented.\n");
115
117 if (data.size() == 1) {
118 DPRINTF(PS2, "Got LED write command.\n");
119 sendAck();
120 return false;
121 } else {
122 DPRINTF(PS2, "Setting LEDs: "
123 "caps lock %s, num lock %s, scroll lock %s\n",
124 bits(data[1], 2) ? "on" : "off",
125 bits(data[1], 1) ? "on" : "off",
126 bits(data[1], 0) ? "on" : "off");
127 sendAck();
128 return true;
129 }
132 return true;
134 if (data.size() == 1) {
135 DPRINTF(PS2, "Got scan code set command.\n");
136 sendAck();
137 return false;
138 } else {
139 sendAck();
140 uint8_t scan_code = data[1];
141 if (scan_code == 0) {
142 DPRINTF(PS2, "Sending hard coded current scan code set 2.\n");
143 send(0x2);
144 } else {
145 DPRINTF(PS2, "Setting scan code set to %d.\n", scan_code);
146 panic_if(scan_code != 0x2,
147 "PS/2 scan code set %d not supported.", scan_code);
148 }
149 }
150 return true;
152 if (data.size() == 1) {
153 DPRINTF(PS2, "Setting typematic info.\n");
154 sendAck();
155 return false;
156 } else {
157 DPRINTF(PS2, "Setting typematic info to %#02x.\n", data[1]);
158 sendAck();
159 return true;
160 }
162 panic("Setting all keys to typemantic unimplemented.\n");
164 panic("Setting all keys to make/release unimplemented.\n");
166 panic("Setting all keys to make unimplemented.\n");
168 panic("Setting all keys to "
169 "typematic/make/release unimplemented.\n");
171 panic("Setting a key to typematic unimplemented.\n");
173 panic("Setting a key to make/release unimplemented.\n");
175 panic("Setting key to make only unimplemented.\n");
176 default:
177 panic("Unknown keyboard command %#02x.\n", data[0]);
178 }
179}
180
181void
182PS2Keyboard::keyPress(uint32_t key, bool down)
183{
185
186 // convert the X11 keysym into ps2 codes and update the shift
187 // state (shiftDown)
189
190 // Drop key presses if the keyboard hasn't been enabled by the
191 // host. We do that after translating the key code to ensure that
192 // we keep track of the shift state.
193 if (!enabled)
194 return;
195
196 // Insert into our queue of characters
197 for (uint8_t c : keys)
198 send(c);
199}
200
201} // namespace ps2
202} // 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
PS2Keyboard(const PS2KeyboardParams &p)
Definition keyboard.cc:58
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition keyboard.cc:68
void keyPress(uint32_t key, bool down) override
Called when the vnc server receives a key press event from the client.
Definition keyboard.cc:182
bool enabled
Is the device enabled?
Definition keyboard.hh:62
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition keyboard.cc:84
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition keyboard.cc:76
bool shiftDown
is the shift key currently down
Definition keyboard.hh:59
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition bitfield.hh:79
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 0 > p
const std::vector< uint8_t > ID
Definition types.cc:51
@ AllKeysToTypematicMakeRelease
Definition types.hh:84
bool bool std::list< uint8_t > & keys
Definition types.hh:134
@ 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
bool down
Definition types.hh:133
void keySymToPs2(uint32_t key, bool down, bool &cur_shift, std::list< uint8_t > &keys)
Definition types.cc:87
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