gem5  v20.1.0.0
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 "base/logging.hh"
44 #include "base/trace.hh"
45 #include "debug/PS2.hh"
46 #include "dev/ps2/types.hh"
47 #include "params/PS2Keyboard.hh"
48 
49 PS2Keyboard::PS2Keyboard(const PS2KeyboardParams *p)
50  : PS2Device(p),
51  shiftDown(false),
52  enabled(false)
53 {
54  if (p->vnc)
55  p->vnc->setKeyboard(this);
56 }
57 
58 void
60 {
64 }
65 
66 void
68 {
72 }
73 
74 bool
76 {
77  switch (data[0]) {
78  case Ps2::ReadID:
79  DPRINTF(PS2, "Got keyboard read ID command.\n");
80  sendAck();
82  return true;
83  case Ps2::Enable:
84  DPRINTF(PS2, "Enabling the keyboard.\n");
85  enabled = true;
86  sendAck();
87  return true;
88  case Ps2::Disable:
89  DPRINTF(PS2, "Disabling the keyboard.\n");
90  enabled = false;
91  sendAck();
92  return true;
94  DPRINTF(PS2, "Disabling and resetting the keyboard.\n");
95  enabled = false;
96  sendAck();
97  return true;
98  case Ps2::Reset:
99  DPRINTF(PS2, "Resetting keyboard.\n");
100  enabled = true;
101  sendAck();
103  return true;
104  case Ps2::Resend:
105  panic("Keyboard resend unimplemented.\n");
106 
108  if (data.size() == 1) {
109  DPRINTF(PS2, "Got LED write command.\n");
110  sendAck();
111  return false;
112  } else {
113  DPRINTF(PS2, "Setting LEDs: "
114  "caps lock %s, num lock %s, scroll lock %s\n",
115  bits(data[1], 2) ? "on" : "off",
116  bits(data[1], 1) ? "on" : "off",
117  bits(data[1], 0) ? "on" : "off");
118  sendAck();
119  return true;
120  }
122  panic("Keyboard diagnostic echo unimplemented.\n");
124  panic("Accessing alternate scan codes unimplemented.\n");
126  if (data.size() == 1) {
127  DPRINTF(PS2, "Setting typematic info.\n");
128  sendAck();
129  return false;
130  } else {
131  DPRINTF(PS2, "Setting typematic info to %#02x.\n", data[1]);
132  sendAck();
133  return true;
134  }
136  panic("Setting all keys to typemantic unimplemented.\n");
138  panic("Setting all keys to make/release unimplemented.\n");
140  panic("Setting all keys to make unimplemented.\n");
142  panic("Setting all keys to "
143  "typematic/make/release unimplemented.\n");
145  panic("Setting a key to typematic unimplemented.\n");
147  panic("Setting a key to make/release unimplemented.\n");
149  panic("Setting key to make only unimplemented.\n");
150  default:
151  panic("Unknown keyboard command %#02x.\n", data[0]);
152  }
153 }
154 
155 void
156 PS2Keyboard::keyPress(uint32_t key, bool down)
157 {
159 
160  // convert the X11 keysym into ps2 codes and update the shift
161  // state (shiftDown)
163 
164  // Drop key presses if the keyboard hasn't been enabled by the
165  // host. We do that after translating the key code to ensure that
166  // we keep track of the shift state.
167  if (!enabled)
168  return;
169 
170  // Insert into our queue of characters
171  for (uint8_t c : keys)
172  send(c);
173 }
174 
175 
176 PS2Keyboard *
177 PS2KeyboardParams::create()
178 {
179  return new PS2Keyboard(this);
180 }
Ps2::Keyboard::KeyToMakeRelease
@ KeyToMakeRelease
Definition: types.hh:78
PS2Device::send
void send(const uint8_t *data, size_t size)
Send data from a PS/2 device to a host.
Definition: device.cc:104
PS2Keyboard
Definition: keyboard.hh:49
types.hh
data
const char data[]
Definition: circlebuf.test.cc:42
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
Ps2::Keyboard::AlternateScanCodes
@ AlternateScanCodes
Definition: types.hh:71
Ps2::Keyboard::AllKeysToMakeRelease
@ AllKeysToMakeRelease
Definition: types.hh:74
PS2Keyboard::PS2Keyboard
PS2Keyboard(const PS2KeyboardParams *p)
Definition: keyboard.cc:49
Ps2::DefaultsAndDisable
@ DefaultsAndDisable
Definition: types.hh:59
Ps2::SelfTestPass
@ SelfTestPass
Definition: types.hh:55
Ps2::Enable
@ Enable
Definition: types.hh:57
PS2Device::sendAck
void sendAck()
Send an ACK byte to the host.
Definition: device.cc:119
Ps2::Keyboard::AllKeysToTypematic
@ AllKeysToTypematic
Definition: types.hh:73
std::vector< uint8_t >
PS2Keyboard::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: keyboard.cc:67
PS2Device
Definition: device.hh:51
Ps2::Resend
@ Resend
Definition: types.hh:62
Ps2::Keyboard::AllKeysToTypematicMakeRelease
@ AllKeysToTypematicMakeRelease
Definition: types.hh:76
Ps2::Keyboard::DiagnosticEcho
@ DiagnosticEcho
Definition: types.hh:70
cp
Definition: cprintf.cc:40
Stats::enabled
bool enabled()
Definition: statistics.cc:545
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Ps2::keySymToPs2
void keySymToPs2(uint32_t key, bool down, bool &cur_shift, std::list< uint8_t > &keys)
Definition: types.cc:83
Ps2::Keyboard::LEDWrite
@ LEDWrite
Definition: types.hh:69
Ps2::Keyboard::TypematicInfo
@ TypematicInfo
Definition: types.hh:72
PS2Keyboard::shiftDown
bool shiftDown
is the shift key currently down
Definition: keyboard.hh:53
Ps2::ReadID
@ ReadID
Definition: types.hh:56
Ps2::Disable
@ Disable
Definition: types.hh:58
Ps2::Keyboard::ID
const std::vector< uint8_t > ID
Definition: types.cc:45
Ps2::down
bool down
Definition: types.hh:123
keyboard.hh
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
Ps2::Keyboard::KeyToTypematic
@ KeyToTypematic
Definition: types.hh:77
Ps2::Keyboard::AllKeysToMake
@ AllKeysToMake
Definition: types.hh:75
PS2Device::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: device.cc:56
PS2Keyboard::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: keyboard.cc:59
logging.hh
PS2Keyboard::keyPress
void keyPress(uint32_t key, bool down) override
Called when the vnc server receives a key press event from the client.
Definition: keyboard.cc:156
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
trace.hh
Ps2::Keyboard::KeyToMakeOnly
@ KeyToMakeOnly
Definition: types.hh:79
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
std::list
STL list class.
Definition: stl.hh:51
PS2Keyboard::recv
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition: keyboard.cc:75
PS2Device::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: device.cc:66
CheckpointIn
Definition: serialize.hh:67
PS2Keyboard::enabled
bool enabled
Is the device enabled?
Definition: keyboard.hh:56
Ps2::Reset
@ Reset
Definition: types.hh:63
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
bits
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:75
Ps2::keys
bool bool std::list< uint8_t > & keys
Definition: types.hh:124

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17