gem5  v21.2.0.0
types.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 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  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "dev/ps2/types.hh"
39 
40 #include <list>
41 
42 #include "base/logging.hh"
43 #include "x11keysym/keysym.h"
44 
45 namespace gem5
46 {
47 
49 namespace ps2
50 {
51 
54 
62 static const uint16_t keySymToPs2Byte[128] = {
63 // 0 / 8 1 / 9 2 / A 3 / B 4 / C 5 / D 6 / E 7 / F
64  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00-0x07
65  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x08-0x0f
66  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x10-0x17
67  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x18-0x1f
68  0x0029, 0x0116, 0x0152, 0x0126, 0x0125, 0x012e, 0x013d, 0x0052, // 0x20-0x27
69  0x0146, 0x0145, 0x013e, 0x0155, 0x0041, 0x004e, 0x0049, 0x004a, // 0x28-0x2f
70  0x0045, 0x0016, 0x001e, 0x0026, 0x0025, 0x002e, 0x0036, 0x003d, // 0x30-0x37
71  0x003e, 0x0046, 0x014c, 0x004c, 0x0141, 0x0055, 0x0149, 0x014a, // 0x38-0x3f
72  0x011e, 0x011c, 0x0132, 0x0121, 0x0123, 0x0124, 0x012b, 0x0134, // 0x40-0x47
73  0x0133, 0x0143, 0x013b, 0x0142, 0x014b, 0x013a, 0x0131, 0x0144, // 0x48-0x4f
74  0x014d, 0x0115, 0x012d, 0x011b, 0x012c, 0x013c, 0x012a, 0x011d, // 0x50-0x57
75  0x0122, 0x0135, 0x011a, 0x0054, 0x005d, 0x005b, 0x0136, 0x014e, // 0x58-0x5f
76  0x000e, 0x001c, 0x0032, 0x0021, 0x0023, 0x0024, 0x002b, 0x0034, // 0x60-0x67
77  0x0033, 0x0043, 0x003b, 0x0042, 0x004b, 0x003a, 0x0031, 0x0044, // 0x68-0x6f
78  0x004d, 0x0015, 0x002d, 0x001b, 0x002c, 0x003c, 0x002a, 0x001d, // 0x70-0x77
79  0x0022, 0x0035, 0x001a, 0x0154, 0x015d, 0x015b, 0x010e, 0x0000 // 0x78-0x7f
80 };
81 
82 const uint8_t ShiftKey = 0x12;
83 const uint8_t BreakKey = 0xf0;
84 const uint8_t ExtendedKey = 0xe0;
85 const uint32_t UpperKeys = 0xff00;
86 
87 void
88 keySymToPs2(uint32_t key, bool down, bool &cur_shift,
90 {
91  if (key <= XK_asciitilde) {
92  uint16_t tmp = keySymToPs2Byte[key];
93  uint8_t code = tmp & 0xff;
94  bool shift = tmp >> 8;
95 
96  if (down) {
97  if (!cur_shift && shift) {
98  keys.push_back(ShiftKey);
99  cur_shift = true;
100  }
101  keys.push_back(code);
102  } else {
103  if (cur_shift && !shift) {
104  keys.push_back(BreakKey);
105  keys.push_back(ShiftKey);
106  cur_shift = false;
107  }
108  keys.push_back(BreakKey);
109  keys.push_back(code);
110  }
111  } else {
112  if ((key & UpperKeys) == UpperKeys) {
113  bool extended = false;
114  switch (key) {
115  case XK_BackSpace:
116  keys.push_back(0x66);
117  break;
118  case XK_Tab:
119  keys.push_back(0x0d);
120  break;
121  case XK_Return:
122  keys.push_back(0x5a);
123  break;
124  case XK_Escape:
125  keys.push_back(0x76);
126  break;
127  case XK_Delete:
128  extended = true;
129  keys.push_back(0x71);
130  break;
131  case XK_Home:
132  extended = true;
133  keys.push_back(0x6c);
134  break;
135  case XK_Left:
136  extended = true;
137  keys.push_back(0x6b);
138  break;
139  case XK_Right:
140  extended = true;
141  keys.push_back(0x74);
142  break;
143  case XK_Down:
144  extended = true;
145  keys.push_back(0x72);
146  break;
147  case XK_Up:
148  extended = true;
149  keys.push_back(0x75);
150  break;
151  case XK_Page_Up:
152  extended = true;
153  keys.push_back(0x7d);
154  break;
155  case XK_Page_Down:
156  extended = true;
157  keys.push_back(0x7a);
158  break;
159  case XK_End:
160  extended = true;
161  keys.push_back(0x69);
162  break;
163  case XK_Shift_L:
164  keys.push_back(0x12);
165  if (down)
166  cur_shift = true;
167  else
168  cur_shift = false;
169  break;
170  case XK_Shift_R:
171  keys.push_back(0x59);
172  if (down)
173  cur_shift = true;
174  else
175  cur_shift = false;
176  break;
177  case XK_Control_L:
178  keys.push_back(0x14);
179  break;
180  case XK_Control_R:
181  extended = true;
182  keys.push_back(0x14);
183  break;
184  case XK_Alt_L:
185  keys.push_back(0x11);
186  break;
187  case XK_Alt_R:
188  extended = true;
189  keys.push_back(0x11);
190  break;
191  default:
192  warn("Unknown extended key %#x\n", key);
193  return;
194  }
195 
196  if (extended) {
197  if (down) {
198  keys.push_front(ExtendedKey);
199  } else {
200  keys.push_front(BreakKey);
201  keys.push_front(ExtendedKey);
202  }
203  } else {
204  if (!down)
205  keys.push_front(BreakKey);
206  }
207  } // upper keys
208  } // extended keys
209  return;
210 }
211 
212 } // namespace ps2
213 } // namespace gem5
warn
#define warn(...)
Definition: logging.hh:246
types.hh
gem5::ps2::keySymToPs2
void keySymToPs2(uint32_t key, bool down, bool &cur_shift, std::list< uint8_t > &keys)
Definition: types.cc:88
gem5::ps2::mouse::ID
const std::vector< uint8_t > ID
Definition: types.cc:53
std::vector< uint8_t >
gem5::ps2::keySymToPs2Byte
static const uint16_t keySymToPs2Byte[128]
Table to convert simple key symbols (0x00XX) into ps2 bytes.
Definition: types.cc:62
gem5::ArmISA::shift
Bitfield< 6, 5 > shift
Definition: types.hh:117
gem5::ps2::UpperKeys
const uint32_t UpperKeys
Definition: types.cc:85
gem5::ps2::ShiftKey
const uint8_t ShiftKey
Definition: types.cc:82
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::ps2::keys
bool bool std::list< uint8_t > & keys
Definition: types.hh:137
gem5::ps2::BreakKey
const uint8_t BreakKey
Definition: types.cc:83
logging.hh
gem5::ps2::cur_shift
bool bool & cur_shift
Definition: types.hh:136
std::list
STL list class.
Definition: stl.hh:51
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::ps2::down
bool down
Definition: types.hh:136
gem5::ps2::ExtendedKey
const uint8_t ExtendedKey
Definition: types.cc:84
gem5::ps2::keyboard::ID
const std::vector< uint8_t > ID
Definition: types.cc:52

Generated on Tue Dec 21 2021 11:34:23 for gem5 by doxygen 1.8.17