1 // 2 // Copyright (c) 2010-2022 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using Antmicro.Renode.Core; 8 using Antmicro.Renode.Logging; 9 using Antmicro.Renode.Peripherals.Bus; 10 11 namespace Antmicro.Renode.Peripherals.Miscellaneous 12 { 13 public class AmbiqApollo4_BootromLogger : IDoubleWordPeripheral, IKnownSize 14 { AmbiqApollo4_BootromLogger(long bootromBaseAddress)15 public AmbiqApollo4_BootromLogger(long bootromBaseAddress) 16 { 17 this.bootromBaseAddress = bootromBaseAddress; 18 } 19 ReadDoubleWord(long offset)20 public uint ReadDoubleWord(long offset) 21 { 22 this.LogUnhandledRead(offset); 23 return 0; 24 } 25 IPeripheral.Reset()26 void IPeripheral.Reset() 27 { 28 // Intentionally left blank. 29 } 30 WriteDoubleWord(long offset, uint value)31 public void WriteDoubleWord(long offset, uint value) 32 { 33 // In writes from the Bootrom, LR is the value so the first three bytes should match the bootrom's base address. 34 if((value & 0xFFFFFF00) == bootromBaseAddress) 35 { 36 // LR always points to the address following the 'bl[x]' instruction and might have bit0 set. 37 var callerAddress = (value & 0xFFFFFFFE) - 4; 38 var callerOffset = callerAddress - bootromBaseAddress; 39 40 this.Log(LogLevel.Error, "Unimplemented BOOTROM function called: {0} (0x{1:X8})", (BootromFunctionOffsets)callerOffset, callerAddress); 41 } 42 else 43 { 44 this.LogUnhandledWrite(offset, value); 45 } 46 } 47 48 public long Size => 0x4; 49 50 private readonly long bootromBaseAddress; 51 52 enum BootromFunctionOffsets 53 { 54 MassErase = 0x4C, 55 PageErase = 0x50, 56 ProgramMain = 0x54, 57 ProgramInfoArea = 0x58, 58 ProgramMain2 = 0x6C, 59 ReadWord = 0x74, 60 WriteWord = 0x78, 61 InfoErase = 0x80, 62 Recovery = 0x98, 63 Delay = 0x9C, 64 } 65 } 66 } 67