Deleted Added
sdiff udiff text old ( 12514:09556145b380 ) new ( 12653:4f6b6c1a8e2f )
full compact
1/*
2 * Copyright (c) 2008 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 29 unchanged lines hidden (view full) ---

38/**
39 * Note: For details on the implementation see
40 * https://wiki.osdev.org/%228042%22_PS/2_Controller
41 */
42
43// The 8042 has a whopping 32 bytes of internal RAM.
44const uint8_t RamSize = 32;
45const uint8_t NumOutputBits = 14;
46
47
48X86ISA::I8042::I8042(Params *p)
49 : BasicPioDevice(p, 0), // pioSize arg is dummy value... not used
50 latency(p->pio_latency),
51 dataPort(p->data_port), commandPort(p->command_port),
52 statusReg(0), commandByte(0), dataReg(0), lastCommand(NoCommand),
53 mouseIntPin(p->mouse_int_pin), keyboardIntPin(p->keyboard_int_pin),
54 mouse(p->mouse), keyboard(p->keyboard)
55{
56 fatal_if(!mouse, "The i8042 model requires a mouse instance");
57 fatal_if(!keyboard, "The i8042 model requires a keyboard instance");
58
59 statusReg.passedSelfTest = 1;
60 statusReg.commandLast = 1;
61 statusReg.keyboardUnlocked = 1;
62
63 commandByte.convertScanCodes = 1;
64 commandByte.passedSelfTest = 1;
65 commandByte.keyboardFullInt = 1;
66}

--- 24 unchanged lines hidden (view full) ---

91 } else if (mouse && commandByte.mouseFullInt) {
92 DPRINTF(I8042, "Sending mouse interrupt.\n");
93 mouseIntPin->raise();
94 //This is a hack
95 mouseIntPin->lower();
96 }
97}
98
99uint8_t
100X86ISA::I8042::readDataOut()
101{
102 uint8_t data = dataReg;
103 statusReg.outputFull = 0;
104 statusReg.mouseOutputFull = 0;
105 if (keyboard->hostDataAvailable()) {
106 writeData(keyboard->hostRead(), false);
107 } else if (mouse->hostDataAvailable()) {
108 writeData(mouse->hostRead(), true);
109 }
110 return data;
111}
112
113Tick
114X86ISA::I8042::read(PacketPtr pkt)
115{
116 assert(pkt->getSize() == 1);
117 Addr addr = pkt->getAddr();
118 if (addr == dataPort) {
119 uint8_t data = readDataOut();
120 //DPRINTF(I8042, "Read from data port got %#02x.\n", data);

--- 13 unchanged lines hidden (view full) ---

134{
135 assert(pkt->getSize() == 1);
136 Addr addr = pkt->getAddr();
137 uint8_t data = pkt->get<uint8_t>();
138 if (addr == dataPort) {
139 statusReg.commandLast = 0;
140 switch (lastCommand) {
141 case NoCommand:
142 keyboard->hostWrite(data);
143 if (keyboard->hostDataAvailable())
144 writeData(keyboard->hostRead(), false);
145 break;
146 case WriteToMouse:
147 mouse->hostWrite(data);
148 if (mouse->hostDataAvailable())
149 writeData(mouse->hostRead(), true);
150 break;
151 case WriteCommandByte:
152 commandByte = data;
153 DPRINTF(I8042, "Got data %#02x for \"Write "
154 "command byte\" command.\n", data);
155 statusReg.passedSelfTest = (uint8_t)commandByte.passedSelfTest;
156 break;
157 case WriteMouseOutputBuff:

--- 119 unchanged lines hidden (view full) ---

277X86ISA::I8042::serialize(CheckpointOut &cp) const
278{
279 SERIALIZE_SCALAR(dataPort);
280 SERIALIZE_SCALAR(commandPort);
281 SERIALIZE_SCALAR(statusReg);
282 SERIALIZE_SCALAR(commandByte);
283 SERIALIZE_SCALAR(dataReg);
284 SERIALIZE_SCALAR(lastCommand);
285}
286
287void
288X86ISA::I8042::unserialize(CheckpointIn &cp)
289{
290 UNSERIALIZE_SCALAR(dataPort);
291 UNSERIALIZE_SCALAR(commandPort);
292 UNSERIALIZE_SCALAR(statusReg);
293 UNSERIALIZE_SCALAR(commandByte);
294 UNSERIALIZE_SCALAR(dataReg);
295 UNSERIALIZE_SCALAR(lastCommand);
296}
297
298X86ISA::I8042 *
299I8042Params::create()
300{
301 return new X86ISA::I8042(this);
302}