1 // 2 // Copyright (c) 2010-2024 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 using System; 9 using Antmicro.Renode.Core; 10 using Antmicro.Renode.Logging; 11 using Antmicro.Renode.Utilities; 12 13 namespace Antmicro.Renode.Peripherals.Bus.Wrappers 14 { 15 public class ReadLoggingWrapper<T> : ReadHookWrapper<T> 16 { ReadLoggingWrapper(IBusPeripheral peripheral, Func<long, T> originalMethod)17 public ReadLoggingWrapper(IBusPeripheral peripheral, Func<long, T> originalMethod) : 18 base(peripheral, originalMethod) 19 { 20 mapper = new RegisterMapper(peripheral.GetType()); 21 machine = peripheral.GetMachine(); 22 } 23 Read(long offset)24 public override T Read(long offset) 25 { 26 var value = OriginalMethod(offset); 27 Peripheral.Log(LogLevel.Info, machine.SystemBus.DecorateWithCPUNameAndPC($"Read{Name} from 0x{offset:X}{(mapper.ToString(offset, " ({0})"))}, returned 0x{value:X}.")); 28 return value; 29 } 30 31 private readonly IMachine machine; 32 private readonly RegisterMapper mapper; 33 } 34 } 35