Alioth Code Coverage

fw_dbg.rs0.00%

1// Copyright 2026 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use parking_lot::Mutex;
16
17use crate::device::{MmioDev, Pause, Result};
18use crate::mem;
19use crate::mem::emulated::{Action, Mmio};
20
21#[derive(Debug, Default)]
22pub struct FwDbg {
23 buffer: Mutex<Vec<u8>>,
24}
25
26impl FwDbg {
27 pub fn new() -> Self {
28 FwDbg::default()
29 }
30}
31
32impl Mmio for FwDbg {
33 fn size(&self) -> u64 {
34 1
35 }
36
37 fn read(&self, _offset: u64, _size: u8) -> mem::Result<u64> {
38 Ok(0xe9)
39 }
40
41 fn write(&self, _offset: u64, _size: u8, val: u64) -> mem::Result<Action> {
42 let mut buffer = self.buffer.lock();
43 if val as u8 == b'\n' {
44 log::debug!("{}", String::from_utf8_lossy(&buffer));
45 buffer.clear();
46 } else {
47 buffer.push(val as u8);
48 }
49 Ok(Action::None)
50 }
51}
52
53impl Pause for FwDbg {
54 fn pause(&self) -> Result<()> {
55 Ok(())
56 }
57
58 fn resume(&self) -> Result<()> {
59 Ok(())
60 }
61}
62
63impl MmioDev for FwDbg {}
64