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 System.Collections.Generic; 10 11 namespace Antmicro.Renode.Peripherals.Memory 12 { 13 public class ArrayMemoryWithReadonlys : ArrayMemory 14 { ArrayMemoryWithReadonlys(ulong size)15 public ArrayMemoryWithReadonlys(ulong size):base(size) 16 { 17 } ArrayMemoryWithReadonlys(byte[] source)18 public ArrayMemoryWithReadonlys(byte[] source):base(source) 19 { 20 } 21 SetReadOnlyDoubleWord(long offset, uint value)22 public void SetReadOnlyDoubleWord(long offset, uint value) 23 { 24 WriteDoubleWord(offset, value); 25 ignoreWrites.Add(offset); 26 } 27 SetReadOnlyWord(long offset, ushort value)28 public void SetReadOnlyWord(long offset, ushort value) 29 { 30 WriteWord(offset, value); 31 ignoreWrites.Add(offset); 32 } 33 SetReadOnlyByte(long offset, byte value)34 public void SetReadOnlyByte(long offset, byte value) 35 { 36 WriteByte(offset, value); 37 ignoreWrites.Add(offset); 38 } 39 WriteDoubleWord(long offset, uint value)40 public override void WriteDoubleWord(long offset, uint value) 41 { 42 if(!ignoreWrites.Contains(offset)) 43 { 44 var bytes = BitConverter.GetBytes(value); 45 bytes.CopyTo(array, offset); 46 } 47 } WriteWord(long offset, ushort value)48 public override void WriteWord(long offset, ushort value) 49 { 50 if(!ignoreWrites.Contains(offset)) 51 { 52 var bytes = BitConverter.GetBytes(value); 53 bytes.CopyTo(array, offset); 54 } 55 } WriteByte(long offset, byte value)56 public override void WriteByte(long offset, byte value) 57 { 58 if(!ignoreWrites.Contains(offset)) 59 { 60 var intOffset = (int)offset; 61 array[intOffset] = value; 62 } 63 } 64 65 private HashSet<long> ignoreWrites = new HashSet<long>(); 66 } 67 } 68 69