gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Gabe Black
41  * Andreas Sandberg
42  */
43 
44 #include "dev/ps2/keyboard.hh"
45 
46 #include "base/logging.hh"
47 #include "debug/PS2.hh"
48 #include "dev/ps2/types.hh"
49 #include "params/PS2Keyboard.hh"
50 
51 PS2Keyboard::PS2Keyboard(const PS2KeyboardParams *p)
52  : PS2Device(p),
53  shiftDown(false),
54  enabled(false)
55 {
56  if (p->vnc)
57  p->vnc->setKeyboard(this);
58 }
59 
60 void
62 {
66 }
67 
68 void
70 {
74 }
75 
76 bool
78 {
79  switch (data[0]) {
80  case Ps2::ReadID:
81  DPRINTF(PS2, "Got keyboard read ID command.\n");
82  sendAck();
84  return true;
85  case Ps2::Enable:
86  DPRINTF(PS2, "Enabling the keyboard.\n");
87  enabled = true;
88  sendAck();
89  return true;
90  case Ps2::Disable:
91  DPRINTF(PS2, "Disabling the keyboard.\n");
92  enabled = false;
93  sendAck();
94  return true;
96  DPRINTF(PS2, "Disabling and resetting the keyboard.\n");
97  enabled = false;
98  sendAck();
99  return true;
100  case Ps2::Reset:
101  DPRINTF(PS2, "Resetting keyboard.\n");
102  enabled = true;
103  sendAck();
105  return true;
106  case Ps2::Resend:
107  panic("Keyboard resend unimplemented.\n");
108 
110  if (data.size() == 1) {
111  DPRINTF(PS2, "Got LED write command.\n");
112  sendAck();
113  return false;
114  } else {
115  DPRINTF(PS2, "Setting LEDs: "
116  "caps lock %s, num lock %s, scroll lock %s\n",
117  bits(data[1], 2) ? "on" : "off",
118  bits(data[1], 1) ? "on" : "off",
119  bits(data[1], 0) ? "on" : "off");
120  sendAck();
121  return true;
122  }
124  panic("Keyboard diagnostic echo unimplemented.\n");
126  panic("Accessing alternate scan codes unimplemented.\n");
128  if (data.size() == 1) {
129  DPRINTF(PS2, "Setting typematic info.\n");
130  sendAck();
131  return false;
132  } else {
133  DPRINTF(PS2, "Setting typematic info to %#02x.\n", data[1]);
134  sendAck();
135  return true;
136  }
138  panic("Setting all keys to typemantic unimplemented.\n");
140  panic("Setting all keys to make/release unimplemented.\n");
142  panic("Setting all keys to make unimplemented.\n");
144  panic("Setting all keys to "
145  "typematic/make/release unimplemented.\n");
147  panic("Setting a key to typematic unimplemented.\n");
149  panic("Setting a key to make/release unimplemented.\n");
151  panic("Setting key to make only unimplemented.\n");
152  default:
153  panic("Unknown keyboard command %#02x.\n", data[0]);
154  }
155 }
156 
157 void
158 PS2Keyboard::keyPress(uint32_t key, bool down)
159 {
161 
162  // convert the X11 keysym into ps2 codes and update the shift
163  // state (shiftDown)
164  Ps2::keySymToPs2(key, down, shiftDown, keys);
165 
166  // Drop key presses if the keyboard hasn't been enabled by the
167  // host. We do that after translating the key code to ensure that
168  // we keep track of the shift state.
169  if (!enabled)
170  return;
171 
172  // Insert into our queue of characters
173  for (uint8_t c : keys)
174  send(c);
175 }
176 
177 
178 PS2Keyboard *
179 PS2KeyboardParams::create()
180 {
181  return new PS2Keyboard(this);
182 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
#define DPRINTF(x,...)
Definition: trace.hh:229
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition: keyboard.cc:77
PS2Keyboard(const PS2KeyboardParams *p)
Definition: keyboard.cc:51
void sendAck()
Send an ACK byte to the host.
Definition: device.cc:121
bool down
Definition: types.hh:125
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: keyboard.cc:69
Definition: cprintf.cc:42
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:645
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: device.cc:58
STL list class.
Definition: stl.hh:54
bool enabled()
Definition: statistics.cc:546
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:643
bool shiftDown
is the shift key currently down
Definition: keyboard.hh:56
const std::vector< uint8_t > ID
Definition: types.cc:47
void send(const uint8_t *data, size_t size)
Send data from a PS/2 device to a host.
Definition: device.cc:106
Bitfield< 29 > c
std::ostream CheckpointOut
Definition: serialize.hh: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:158
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: device.cc:68
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: keyboard.cc:61
bool bool std::list< uint8_t > & keys
Definition: types.hh:125
bool enabled
Is the device enabled?
Definition: keyboard.hh:59
void keySymToPs2(uint32_t key, bool down, bool &cur_shift, std::list< uint8_t > &keys)
Definition: types.cc:85
T bits(T val, int first, int last)
Extract the bitfield from position &#39;first&#39; to &#39;last&#39; (inclusive) from &#39;val&#39; and right justify it...
Definition: bitfield.hh:72
Bitfield< 0 > p
const char data[]

Generated on Fri Feb 28 2020 16:27:01 for gem5 by doxygen 1.8.13