33 #include "debug/I8042.hh"
49 latency(
p->pio_latency),
50 dataPort(
p->data_port), commandPort(
p->command_port),
51 statusReg(0), commandByte(0), dataReg(0), lastCommand(NoCommand),
52 mouse(
p->mouse), keyboard(
p->keyboard)
54 fatal_if(!
mouse,
"The i8042 model requires a mouse instance");
65 for (
int i = 0;
i <
p->port_keyboard_int_pin_connection_count;
i++) {
69 for (
int i = 0;
i <
p->port_mouse_int_pin_connection_count;
i++) {
82 ranges.push_back(
RangeSize(commandPort, 1));
91 statusReg.outputFull = 1;
92 statusReg.mouseOutputFull = (mouse ? 1 : 0);
93 if (!mouse && commandByte.keyboardFullInt) {
95 for (
auto *wire: keyboardIntPin) {
100 }
else if (mouse && commandByte.mouseFullInt) {
102 for (
auto *wire: mouseIntPin) {
113 uint8_t
data = dataReg;
114 statusReg.outputFull = 0;
115 statusReg.mouseOutputFull = 0;
116 if (keyboard->hostDataAvailable()) {
117 writeData(keyboard->hostRead(),
false);
118 }
else if (mouse->hostDataAvailable()) {
119 writeData(mouse->hostRead(),
true);
129 if (
addr == dataPort) {
130 uint8_t
data = readDataOut();
133 }
else if (
addr == commandPort) {
135 pkt->
setLE<uint8_t>((uint8_t)statusReg);
137 panic(
"Read from unrecognized port %#x.\n",
addr);
149 if (
addr == dataPort) {
150 statusReg.commandLast = 0;
151 switch (lastCommand) {
153 keyboard->hostWrite(
data);
154 if (keyboard->hostDataAvailable())
155 writeData(keyboard->hostRead(),
false);
158 mouse->hostWrite(
data);
159 if (mouse->hostDataAvailable())
160 writeData(mouse->hostRead(),
true);
162 case WriteCommandByte:
165 "command byte\" command.\n",
data);
166 statusReg.passedSelfTest = (uint8_t)commandByte.passedSelfTest;
168 case WriteMouseOutputBuff:
170 "mouse output buffer\" command.\n",
data);
171 writeData(
data,
true);
173 case WriteKeyboardOutputBuff:
175 "keyboad output buffer\" command.\n",
data);
176 writeData(
data,
false);
178 case WriteOutputPort:
180 "output port\" command.\n",
data);
185 panic(
"Data written for unrecognized "
186 "command %#02x\n", lastCommand);
188 lastCommand = NoCommand;
189 }
else if (
addr == commandPort) {
191 statusReg.commandLast = 1;
194 if (
data > ReadControllerRamBase &&
196 panic(
"Attempted to use i8042 read controller RAM command to "
197 "get byte %d.\n",
data - ReadControllerRamBase);
198 }
else if (
data > WriteControllerRamBase &&
200 panic(
"Attempted to use i8042 read controller RAM command to "
201 "get byte %d.\n",
data - ReadControllerRamBase);
202 }
else if (
data >= PulseOutputBitBase &&
204 panic(
"Attempted to use i8042 pulse output bit command to "
205 "to pulse bit %d.\n",
data - PulseOutputBitBase);
210 writeData(commandByte);
212 case WriteCommandByte:
214 lastCommand = WriteCommandByte;
216 case CheckForPassword:
217 panic(
"i8042 \"Check for password\" command not implemented.\n");
219 panic(
"i8042 \"Load password\" command not implemented.\n");
221 panic(
"i8042 \"Check password\" command not implemented.\n");
224 commandByte.disableMouse = 1;
228 commandByte.disableMouse = 0;
231 panic(
"i8042 \"Test mouse\" command not implemented.\n");
233 panic(
"i8042 \"Self test\" command not implemented.\n");
235 panic(
"i8042 \"Interface test\" command not implemented.\n");
237 panic(
"i8042 \"Diagnostic dump\" command not implemented.\n");
238 case DisableKeyboard:
240 commandByte.disableKeyboard = 1;
244 commandByte.disableKeyboard = 0;
247 panic(
"i8042 \"Read input port\" command not implemented.\n");
248 case ContinuousPollLow:
249 panic(
"i8042 \"Continuous poll low\" command not implemented.\n");
250 case ContinuousPollHigh:
251 panic(
"i8042 \"Continuous poll high\" command not implemented.\n");
253 panic(
"i8042 \"Read output port\" command not implemented.\n");
254 case WriteOutputPort:
255 lastCommand = WriteOutputPort;
257 case WriteKeyboardOutputBuff:
258 lastCommand = WriteKeyboardOutputBuff;
260 case WriteMouseOutputBuff:
261 DPRINTF(
I8042,
"Got command to write to mouse output buffer.\n");
262 lastCommand = WriteMouseOutputBuff;
266 lastCommand = WriteToMouse;
269 panic(
"i8042 \"Disable A20\" command not implemented.\n");
271 panic(
"i8042 \"Enable A20\" command not implemented.\n");
273 panic(
"i8042 \"Read test inputs\" command not implemented.\n");
275 panic(
"i8042 \"System reset\" command not implemented.\n");
277 warn(
"Write to unknown i8042 "
278 "(keyboard controller) command port.\n");
281 panic(
"Write to unrecognized port %#x.\n",
addr);
310 I8042Params::create()