mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-11 20:56:12 +00:00
I have been running into Debug-printed error messages too often and needing to look up in the source code each level of nested errors to find out from the comment on the error variant what the short name of the variant means in human terms. Worse, many errors (like the one shown below) already had error strings written but were being printed from the calling code in the less helpful Debug representation anyway. Before: [ERROR:src/main.rs:705] The architecture failed to build the vm: NoVarEmpty After: [ERROR:src/main.rs:705] The architecture failed to build the vm: /var/empty doesn't exist, can't jail devices. TEST=cargo check --all-features TEST=FEATURES=test emerge-amd64-generic crosvm Change-Id: I77122c7d6861b2d610de2fff718896918ab21e10 Reviewed-on: https://chromium-review.googlesource.com/1469225 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
use sys_util::EventFd;
|
|
|
|
use BusDevice;
|
|
|
|
/// A i8042 PS/2 controller that emulates just enough to shutdown the machine.
|
|
pub struct I8042Device {
|
|
reset_evt: EventFd,
|
|
}
|
|
|
|
impl I8042Device {
|
|
/// Constructs a i8042 device that will signal the given event when the guest requests it.
|
|
pub fn new(reset_evt: EventFd) -> I8042Device {
|
|
I8042Device { reset_evt }
|
|
}
|
|
}
|
|
|
|
// i8042 device is mapped I/O address 0x61. We partially implement two 8-bit
|
|
// registers: port 0x61 (I8042_PORT_B_REG, offset 0 from base of 0x61), and
|
|
// port 0x64 (I8042_COMMAND_REG, offset 3 from base of 0x61).
|
|
impl BusDevice for I8042Device {
|
|
fn debug_label(&self) -> String {
|
|
"i8042".to_owned()
|
|
}
|
|
|
|
fn read(&mut self, offset: u64, data: &mut [u8]) {
|
|
if data.len() == 1 && offset == 3 {
|
|
data[0] = 0x0;
|
|
} else if data.len() == 1 && offset == 0 {
|
|
// Like kvmtool, we return bit 5 set in I8042_PORT_B_REG to
|
|
// avoid hang in pit_calibrate_tsc() in Linux kernel.
|
|
data[0] = 0x20;
|
|
}
|
|
}
|
|
|
|
fn write(&mut self, offset: u64, data: &[u8]) {
|
|
if data.len() == 1 && data[0] == 0xfe && offset == 3 {
|
|
if let Err(e) = self.reset_evt.write(1) {
|
|
error!("failed to trigger i8042 reset event: {}", e);
|
|
}
|
|
}
|
|
}
|
|
}
|