public MemoryLayout GetLayoutFromICF(string pFileNameICF, string pNameDev) { MemoryLayout layout = new MemoryLayout { DeviceName = pNameDev, Memories = new List <Memory>() }; int StartFlash = NO_DATA; int SizeFlash = NO_DATA; /*int StartRAM = NO_DATA; * int SizeRAM = NO_DATA; * int StartCCM = NO_DATA; * int SizeCCM = NO_DATA; */ foreach (var ln in File.ReadAllLines(pFileNameICF)) { var m = Regex.Match(ln, @"define symbol __ICFEDIT_region_([\w\d]+)_start__[ ]*=[ ]*([x0-9A-Faf]+)[ ]*;"); if (m.Success) { StartFlash = (int)ParseHex(m.Groups[2].Value); continue; } m = Regex.Match(ln, @"define symbol __ICFEDIT_region_([\w\d]+)_end__[ ]*=[ ]*([x0-9A-Faf]+)[ ]*;"); if (m.Success) { SizeFlash = (int)ParseHex(m.Groups[2].Value); MemoryType aTypeData = MemoryType.RAM; string aNameData = m.Groups[1].Value; if (m.Groups[1].Value.Contains("ROM")) { aTypeData = MemoryType.FLASH; } if (m.Groups[1].Value == "ROM") { aNameData = "FLASH"; } else if (m.Groups[1].Value == "RAM") { aNameData = "SRAM"; } if (StartFlash != NO_DATA && SizeFlash != NO_DATA) { SizeFlash -= StartFlash; if ((SizeFlash % 1024) != 0) { SizeFlash += 1; } layout.Memories.Add(new Memory { Name = aNameData, Access = MemoryAccess.Undefined,// Readable | MemoryAccess.Writable | MemoryAccess.Executable Type = aTypeData, Start = (uint)StartFlash, Size = (uint)SizeFlash }); } else { throw new Exception("Error ld size flash"); } StartFlash = NO_DATA; continue; } } return(layout); }
public override void GenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName) { foreach (var sd in SoftDevices) { if (!sd.IsCompatible(mcu.Name)) { continue; } if (sd.LinkerScriptWithMaximumReservedRAM == null) { //Due to the complexity of the Nordic SDK, we need to reuse the original linker scripts instead of generating them from scratch. throw new Exception("Could not locate the original linker script for this device."); } else { BuildLinkerScriptBasedOnOriginalNordicScripts(ldsDirectory, generalizedName, sd); } } mcu.LinkerScriptPath = $"$$SYS:BSP_ROOT$$/{familyFilePrefix}LinkerScripts/{generalizedName}_$${SoftdevicePropertyID}$$.lds"; }
public static void Main() { // The serial ports should have already been initialised MsgPort = Serial.COM2; NotifPort = Serial.COM3; // This looks silly, but the host debugger is actually waiting for this // to determine the OS has connected and is ready MsgPort.Write("Debug thread :D\n"); //MsgPort.Write("Enabling...\n"); // Everything is initialised and connected, so enable the debugger Enabled = true; //MsgPort.Write("Enabled.\n"); // Note: It doesn't actually matter if the host hasn't connected // because the debugger has near-zero effective cost to the rest of the system // unless it is sent a command (unlike the old debugger, which slowed everything // down to the point of being unusable). while (!Terminating) { // Read in a line from the host FOS_System.String line = ""; char c = (char)MsgPort.Read(); while (c != '\n' && c != '\r') { line += c; c = (char)MsgPort.Read(); } // Echo the command back to the host for verification MsgPort.Write("START OF COMMAND\n"); MsgPort.Write(line); MsgPort.Write("\n"); // Filter the line line = line.Trim().ToLower(); // Split it up into relevant parts List lineParts = line.Split(' '); if (lineParts.Count > 0) { FOS_System.String cmd = (FOS_System.String)lineParts[0]; if (cmd == "ping") { MsgPort.Write("pong\n"); } else if (cmd == "help") { #region Help MsgPort.Write("Available commands:\n"); MsgPort.Write(" - ping\n"); MsgPort.Write(" - threads\n"); MsgPort.Write(" - suspend (processId) (threadId | -1 for all threads)\n"); MsgPort.Write(" - resume (processId) (threadId | -1 for all threads)\n"); MsgPort.Write(" - step (processId) (threadId | -1 for all threads)\n"); MsgPort.Write(" - ss (processId) (threadId | -1 for all threads)\n"); MsgPort.Write(" - sta (processId) (threadId | -1 for all threads) (address)\n"); MsgPort.Write(" - bps (address:hex)\n"); MsgPort.Write(" - bpc (address:hex)\n"); MsgPort.Write(" - regs (processId) (threadId)\n"); MsgPort.Write(" - memory (processId) (address:hex) (length) (units:1,2,4)\n"); #endregion } else if (cmd == "threads") { #region Threads for (int i = 0; i < ProcessManager.Processes.Count; i++) { Process AProcess = (Process)ProcessManager.Processes[i]; MsgPort.Write(" - Process : "); MsgPort.Write((FOS_System.String)AProcess.Id); MsgPort.Write(" : "); MsgPort.Write(AProcess.Name); MsgPort.Write("\n"); for (int j = 0; j < AProcess.Threads.Count; j++) { Thread AThread = (Thread)AProcess.Threads[j]; MsgPort.Write(" - Thread : "); MsgPort.Write((FOS_System.String)AThread.Id); MsgPort.Write(" : "); if (AThread.Debug_Suspend) { MsgPort.Write("Suspended"); } else if (AThread.TimeToSleep == -1) { MsgPort.Write("Waiting "); } else if (AThread.TimeToSleep > 0) { MsgPort.Write("Sleeping "); } else { MsgPort.Write("Running "); } MsgPort.Write(" : "); MsgPort.Write(AThread.Name); MsgPort.Write("\n"); } } #endregion } else if (cmd == "suspend") { #region Suspend if (lineParts.Count == 3) { uint ProcessId = FOS_System.Int32.Parse_DecimalUnsigned((FOS_System.String)lineParts[1], 0); int ThreadId = FOS_System.Int32.Parse_DecimalSigned((FOS_System.String)lineParts[2]); Process TheProcess = ProcessManager.GetProcessById(ProcessId); if (TheProcess != null) { if (ThreadId == -1) { for (int i = 0; i < TheProcess.Threads.Count; i++) { Thread AThread = ((Thread)TheProcess.Threads[i]); if (AThread != MainThread) { UInt64 ProcessThreadId = (((UInt64)ProcessId) << 32) | AThread.Id; if (ThreadsToSuspend.IndexOf(ProcessThreadId) == -1) { ThreadsToSuspend.Add(ProcessThreadId); } AThread.Debug_Suspend = true; MsgPort.Write(" > Suspended "); MsgPort.Write(AThread.Name); MsgPort.Write(" thread\n"); } } } else { UInt64 ProcessThreadId = (((UInt64)ProcessId) << 32) | (uint)ThreadId; if (ThreadsToSuspend.IndexOf(ProcessThreadId) == -1) { ThreadsToSuspend.Add(ProcessThreadId); } Thread TheThread = ProcessManager.GetThreadById((uint)ThreadId, TheProcess); if (TheThread != null) { if (TheThread != MainThread) { TheThread.Debug_Suspend = true; MsgPort.Write(" > Suspended "); MsgPort.Write(TheThread.Name); MsgPort.Write(" thread\n"); } } else { MsgPort.Write("Thread not found.\n"); } } } else { MsgPort.Write("Process not found.\n"); } } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else if (cmd == "resume") { #region Resume if (lineParts.Count == 3) { uint ProcessId = FOS_System.Int32.Parse_DecimalUnsigned((FOS_System.String)lineParts[1], 0); int ThreadId = FOS_System.Int32.Parse_DecimalSigned((FOS_System.String)lineParts[2]); Process TheProcess = ProcessManager.GetProcessById(ProcessId); if (TheProcess != null) { if (ThreadId == -1) { for (int i = 0; i < TheProcess.Threads.Count; i++) { Thread AThread = ((Thread)TheProcess.Threads[i]); UInt64 ProcessThreadId = (((UInt64)ProcessId) << 32) | AThread.Id; ThreadsToSuspend.Remove(ProcessThreadId); AThread.Debug_Suspend = false; MsgPort.Write(" > Resumed "); MsgPort.Write(AThread.Name); MsgPort.Write(" thread\n"); } } else { UInt64 ProcessThreadId = (((UInt64)ProcessId) << 32) | (uint)ThreadId; ThreadsToSuspend.Remove(ProcessThreadId); Thread TheThread = ProcessManager.GetThreadById((uint)ThreadId, TheProcess); if (TheThread != null) { TheThread.Debug_Suspend = false; MsgPort.Write(" > Resumed "); MsgPort.Write(TheThread.Name); MsgPort.Write(" thread\n"); } else { MsgPort.Write("Thread not found.\n"); } } } else { MsgPort.Write("Process not found.\n"); } } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else if (cmd == "step") { #region Step if (lineParts.Count == 3) { uint ProcessId = FOS_System.Int32.Parse_DecimalUnsigned((FOS_System.String)lineParts[1], 0); int ThreadId = FOS_System.Int32.Parse_DecimalSigned((FOS_System.String)lineParts[2]); Process TheProcess = ProcessManager.GetProcessById(ProcessId); if (TheProcess != null) { if (ThreadId == -1) { for (int i = 0; i < TheProcess.Threads.Count; i++) { Thread AThread = ((Thread)TheProcess.Threads[i]); if (AThread.Debug_Suspend) { AThread.Debug_Suspend = false; MsgPort.Write(" > Stepping "); MsgPort.Write(AThread.Name); MsgPort.Write(" thread\n"); } else { MsgPort.Write("Thread must be suspended first.\n"); } } } else { Thread TheThread = ProcessManager.GetThreadById((uint)ThreadId, TheProcess); if (TheThread != null) { if (TheThread.Debug_Suspend) { TheThread.Debug_Suspend = false; MsgPort.Write(" > Stepping "); MsgPort.Write(TheThread.Name); MsgPort.Write(" thread\n"); } else { MsgPort.Write("Thread must be suspended first.\n"); } } else { MsgPort.Write("Thread not found.\n"); } } } else { MsgPort.Write("Process not found.\n"); } } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else if (cmd == "ss") { #region Single Step if (lineParts.Count == 3) { uint ProcessId = FOS_System.Int32.Parse_DecimalUnsigned((FOS_System.String)lineParts[1], 0); int ThreadId = FOS_System.Int32.Parse_DecimalSigned((FOS_System.String)lineParts[2]); Process TheProcess = ProcessManager.GetProcessById(ProcessId); if (TheProcess != null) { if (ThreadId == -1) { for (int i = 0; i < TheProcess.Threads.Count; i++) { Thread AThread = ((Thread)TheProcess.Threads[i]); if (AThread.Debug_Suspend) { // Set trap flag (int1) AThread.EFLAGSFromInterruptStack |= 0x0100; AThread.Debug_Suspend = false; MsgPort.Write(" > Single stepping "); MsgPort.Write(AThread.Name); MsgPort.Write(" thread\n"); } else { MsgPort.Write("Thread must be suspended first.\n"); } } } else { Thread TheThread = ProcessManager.GetThreadById((uint)ThreadId, TheProcess); if (TheThread != null) { if (TheThread.Debug_Suspend) { // Set trap flag (int1) TheThread.EFLAGSFromInterruptStack |= 0x0100; TheThread.Debug_Suspend = false; MsgPort.Write(" > Single stepping "); MsgPort.Write(TheThread.Name); MsgPort.Write(" thread\n"); } else { MsgPort.Write("Thread must be suspended first.\n"); } } else { MsgPort.Write("Thread not found.\n"); } } } else { MsgPort.Write("Process not found.\n"); } } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else if (cmd == "sta") { #region Step To Address if (lineParts.Count == 4) { uint ProcessId = FOS_System.Int32.Parse_DecimalUnsigned((FOS_System.String)lineParts[1], 0); int ThreadId = FOS_System.Int32.Parse_DecimalSigned((FOS_System.String)lineParts[2]); uint Address = FOS_System.Int32.Parse_HexadecimalUnsigned((FOS_System.String)lineParts[3], 0); Process TheProcess = ProcessManager.GetProcessById(ProcessId); if (TheProcess != null) { if (ThreadId == -1) { for (int i = 0; i < TheProcess.Threads.Count; i++) { Thread AThread = ((Thread)TheProcess.Threads[i]); if (AThread.Debug_Suspend) { // Set trap flag (int1) UInt64 ProcessThreadId = (((UInt64)ProcessId) << 32) | (uint)ThreadId; ThreadsToSuspendAtAddresses.Add(ProcessThreadId, Address); AThread.EFLAGSFromInterruptStack |= 0x0100; AThread.Debug_Suspend = false; MsgPort.Write(" > Single stepping "); MsgPort.Write(AThread.Name); MsgPort.Write(" thread to address "); MsgPort.Write(Address); MsgPort.Write("\n"); } else { MsgPort.Write("Thread must be suspended first.\n"); } } } else { Thread TheThread = ProcessManager.GetThreadById((uint)ThreadId, TheProcess); if (TheThread != null) { if (TheThread.Debug_Suspend) { // Set trap flag (int1) UInt64 ProcessThreadId = (((UInt64)ProcessId) << 32) | (uint)ThreadId; ThreadsToSuspendAtAddresses.Add(ProcessThreadId, Address); TheThread.EFLAGSFromInterruptStack |= 0x0100; TheThread.Debug_Suspend = false; MsgPort.Write(" > Single stepping "); MsgPort.Write(TheThread.Name); MsgPort.Write(" thread to address "); MsgPort.Write(Address); MsgPort.Write("\n"); } else { MsgPort.Write("Thread must be suspended first.\n"); } } else { MsgPort.Write("Thread not found.\n"); } } } else { MsgPort.Write("Process not found.\n"); } } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else if (cmd == "bps") { #region Set Breakpoint if (lineParts.Count == 2) { uint Address = FOS_System.Int32.Parse_HexadecimalUnsigned((FOS_System.String)lineParts[1], 0); MsgPort.Write(" > Breakpoint to be set at "); MsgPort.Write(Address); MsgPort.Write("\n"); *((byte *)Address) = 0xCC; } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else if (cmd == "bpc") { #region Clear Breakpoint if (lineParts.Count == 2) { uint Address = FOS_System.Int32.Parse_HexadecimalUnsigned((FOS_System.String)lineParts[1], 0); MsgPort.Write(" > Breakpoint to be cleared at "); MsgPort.Write(Address); MsgPort.Write("\n"); *((byte *)Address) = 0x90; } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else if (cmd == "regs") { #region Registers if (lineParts.Count == 3) { uint ProcessId = FOS_System.Int32.Parse_DecimalUnsigned((FOS_System.String)lineParts[1], 0); uint ThreadId = FOS_System.Int32.Parse_DecimalUnsigned((FOS_System.String)lineParts[2], 0); Process TheProcess = ProcessManager.GetProcessById(ProcessId); if (TheProcess != null) { Thread TheThread = ProcessManager.GetThreadById((uint)ThreadId, TheProcess); if (TheThread != null) { if (TheThread.Debug_Suspend) { MsgPort.Write("Registers of "); MsgPort.Write(TheThread.Name); MsgPort.Write(" : \n"); MsgPort.Write(" > EAX : "); MsgPort.Write((FOS_System.String)TheThread.EAXFromInterruptStack); MsgPort.Write("\n > EBX : "); MsgPort.Write((FOS_System.String)TheThread.EBXFromInterruptStack); MsgPort.Write("\n > ECX : "); MsgPort.Write((FOS_System.String)TheThread.ECXFromInterruptStack); MsgPort.Write("\n > EDX : "); MsgPort.Write((FOS_System.String)TheThread.EDXFromInterruptStack); MsgPort.Write("\n"); MsgPort.Write("\n > ESP : "); MsgPort.Write((FOS_System.String)TheThread.ESPFromInterruptStack); MsgPort.Write("\n > EBP : "); MsgPort.Write((FOS_System.String)TheThread.EBPFromInterruptStack); MsgPort.Write("\n > EIP : "); MsgPort.Write((FOS_System.String)TheThread.EIPFromInterruptStack); MsgPort.Write("\n"); } else { MsgPort.Write("Thread must be suspended first.\n"); } } else { MsgPort.Write("Thread not found.\n"); } } else { MsgPort.Write("Process not found.\n"); } } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else if (cmd == "mem") { #region Memory if (lineParts.Count == 5) { uint ProcessId = FOS_System.Int32.Parse_DecimalUnsigned((FOS_System.String)lineParts[1], 0); Process TheProcess = ProcessManager.GetProcessById(ProcessId); if (TheProcess != null) { // Need access to specified process' memory MemoryLayout OriginalMemoryLayout = SystemCallsHelpers.EnableAccessToMemoryOfProcess(TheProcess); uint Address = FOS_System.Int32.Parse_HexadecimalUnsigned((FOS_System.String)lineParts[2], 0); int length = FOS_System.Int32.Parse_DecimalSigned((FOS_System.String)lineParts[3]); int units = FOS_System.Int32.Parse_DecimalSigned((FOS_System.String)lineParts[4]); MsgPort.Write(" Memory from "); MsgPort.Write(Address); MsgPort.Write(" for "); MsgPort.Write(length); MsgPort.Write(" units with "); MsgPort.Write(units); MsgPort.Write(" bytes/unit:\n"); if (units == 1) { byte *AddrPtr = (byte *)Address; for (int i = 0; i < length; i++) { MsgPort.Write((FOS_System.String)AddrPtr[i]); MsgPort.Write(" "); } } else if (units == 2) { ushort *AddrPtr = (ushort *)Address; for (int i = 0; i < length; i++) { MsgPort.Write((FOS_System.String)AddrPtr[i]); MsgPort.Write(" "); } } else if (units == 4) { uint *AddrPtr = (uint *)Address; for (int i = 0; i < length; i++) { MsgPort.Write((FOS_System.String)AddrPtr[i]); MsgPort.Write(" "); } } MsgPort.Write("\n"); SystemCallsHelpers.DisableAccessToMemoryOfProcess(OriginalMemoryLayout); } else { MsgPort.Write("Process not found.\n"); } } else { MsgPort.Write("Incorrect arguments, see help.\n"); } #endregion } else { MsgPort.Write("Unrecognised command. (Note: Backspace not supported!)\n"); } } // Always issue end of command signal, even if something else went wrong // - Keeps the host in sync. MsgPort.Write("END OF COMMAND\n"); } }
public override void GenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName) { base.GenerateLinkerScriptsAndUpdateMCU(ldsDirectory, familyFilePrefix, mcu, layout, generalizedName); }
public static unsafe SystemCallResults HandleDeferredSystemCall( Process CallerProcess, Thread CallerThread, SystemCallNumbers syscallNumber, uint Param1, uint Param2, uint Param3, ref uint Return2, ref uint Return3, ref uint Return4) { SystemCallResults result = SystemCallResults.Unhandled; switch (syscallNumber) { case SystemCallNumbers.StartThread: //BasicConsole.WriteLine("DSC: Start Thread"); Return2 = CallerProcess.CreateThread((ThreadStartMethod)Utilities.ObjectUtilities.GetObject((void *)Param1), "[From sys call]").Id; //BasicConsole.WriteLine("DSC: Start Thread - done."); result = SystemCallResults.OK; break; case SystemCallNumbers.RegisterPipeOutpoint: { //BasicConsole.WriteLine("DSC: Register Pipe Outpoint"); Pipes.PipeOutpoint outpoint; bool registered = Pipes.PipeManager.RegisterPipeOutpoint(CallerProcess.Id, (Pipes.PipeClasses)Param1, (Pipes.PipeSubclasses)Param2, (int)Param3, out outpoint); if (registered) { result = SystemCallResults.OK; } else { result = SystemCallResults.Fail; } //BasicConsole.WriteLine("DSC: Register Pipe Outpoint - done."); } break; case SystemCallNumbers.GetNumPipeOutpoints: { //BasicConsole.WriteLine("DSC: Get Num Pipe Outpoints"); int numOutpoints; bool obtained = Pipes.PipeManager.GetNumPipeOutpoints((Pipes.PipeClasses)Param1, (Pipes.PipeSubclasses)Param2, out numOutpoints); if (obtained) { result = SystemCallResults.OK; Return2 = (uint)numOutpoints; } else { result = SystemCallResults.Fail; } //BasicConsole.WriteLine("DSC: Get Num Pipe Outpoints - done"); } break; case SystemCallNumbers.GetPipeOutpoints: { //BasicConsole.WriteLine("DSC: Get Pipe Outpoints"); bool obtained = Pipes.PipeManager.GetPipeOutpoints(CallerProcess, (Pipes.PipeClasses)Param1, (Pipes.PipeSubclasses)Param2, (Pipes.PipeOutpointsRequest *)Param3); if (obtained) { result = SystemCallResults.OK; } else { result = SystemCallResults.Fail; } //BasicConsole.WriteLine("DSC: Get Pipe Outpoints - done"); } break; case SystemCallNumbers.CreatePipe: { //BasicConsole.WriteLine("DSC: Create Pipe"); bool created = Pipes.PipeManager.CreatePipe(CallerProcess.Id, Param1, (Pipes.CreatePipeRequest *)Param2); if (created) { result = SystemCallResults.OK; } else { result = SystemCallResults.Fail; } //BasicConsole.WriteLine("DSC: Create Pipe - done"); } break; case SystemCallNumbers.WaitOnPipeCreate: { //BasicConsole.WriteLine("DSC: Wait On Pipe Create"); bool waiting = Pipes.PipeManager.WaitOnPipeCreate(CallerProcess.Id, CallerThread.Id, (Pipes.PipeClasses)Param1, (Pipes.PipeSubclasses)Param2); if (waiting) { result = SystemCallResults.Deferred; } else { result = SystemCallResults.Fail; } //BasicConsole.WriteLine("DSC: Wait On Pipe Create - done"); } break; case SystemCallNumbers.ReadPipe: { //BasicConsole.WriteLine("DSC: Read Pipe"); // Need access to calling process' memory to be able to set values in request structure(s) MemoryLayout OriginalMemoryLayout = SystemCallsHelpers.EnableAccessToMemoryOfProcess(CallerProcess); Pipes.ReadPipeRequest * RequestPtr = (Pipes.ReadPipeRequest *)Param1; Pipes.PipeManager.RWResults RWResult = Pipes.PipeManager.ReadPipe(RequestPtr->PipeId, RequestPtr->Blocking, CallerProcess, CallerThread); if (RWResult == Pipes.PipeManager.RWResults.Error) { result = SystemCallResults.Fail; } else { // Returning Deferred state from here will leave the caller thread // in whatever state ReadPipe decided it should be in. result = SystemCallResults.Deferred; } SystemCallsHelpers.DisableAccessToMemoryOfProcess(OriginalMemoryLayout); //BasicConsole.WriteLine("DSC: Read Pipe - done"); } break; case SystemCallNumbers.WritePipe: { //BasicConsole.WriteLine("DSC: Write Pipe"); // Need access to calling process' memory to be able to set values in request structure(s) MemoryLayout OriginalMemoryLayout = SystemCallsHelpers.EnableAccessToMemoryOfProcess(CallerProcess); Pipes.WritePipeRequest * RequestPtr = (Pipes.WritePipeRequest *)Param1; Pipes.PipeManager.RWResults RWResult = Pipes.PipeManager.WritePipe(RequestPtr->PipeId, RequestPtr->Blocking, CallerProcess, CallerThread); if (RWResult == Pipes.PipeManager.RWResults.Error) { result = SystemCallResults.Fail; } else { // Returning Deferred state from here will leave the caller thread // in whatever state WritePipe decided it should be in. result = SystemCallResults.Deferred; } SystemCallsHelpers.DisableAccessToMemoryOfProcess(OriginalMemoryLayout); //BasicConsole.WriteLine("DSC: Write Pipe - done"); } break; default: BasicConsole.WriteLine("DSC: Unrecognised call number."); BasicConsole.WriteLine((uint)syscallNumber); break; } return(result); }
public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family) { //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes. MemoryLayout layout = new MemoryLayout(); layout.Memories = new List <Memory>(); layout.DeviceName = mcu.Name; string shName = mcu.Name; string aDirSam; if (mcu.Name.StartsWith("AT")) { shName = mcu.Name.Substring(2, mcu.Name.Length - 2); } if (shName.StartsWith("SAMC") || shName.StartsWith("SAMD") || shName.StartsWith("SAMR") || shName.StartsWith("SAMB") || shName.StartsWith("SAML")) { aDirSam = "\\Sam0"; } else { aDirSam = "\\Sam"; } // EAK if (shName == "SAMD10D13A" || shName == "SAMD10D14A" || shName == "SAMD10D12A"|| shName == "SAMD11D14A") // EAK shName = shName + "S";//Different Device ID (DID) string aFileName = family.BSP.Directories.InputDir + aDirSam + "\\Utils\\Cmsis\\" + family.FamilyFilePrefix + "\\Include\\" + shName; if (family.FamilyFilePrefix.ToUpper().StartsWith("SAMG")) { aFileName = family.BSP.Directories.InputDir + "\\Sam\\Utils\\Cmsis\\samg\\" + family.FamilyFilePrefix + "\\Include\\" + shName; } if (family.Definition.Name.ToUpper() == "SAM4C" || family.Definition.Name.ToUpper() == "SAM4CM" || family.Definition.Name.ToUpper() == "SAM4CP" || family.Definition.Name.ToUpper() == "SAM4CM32") { aFileName = aFileName + "_0.h"; } else { aFileName = aFileName + ".h"; } int RAMStart = -1; int FLASHStart = -1; if (Regex.IsMatch(mcu.Name, "SAML21...B")) { aFileName = aFileName.Replace("\\Include\\S", "\\Include_b\\S"); } foreach (var ln in File.ReadAllLines(aFileName)) { // var m = Regex.Match(ln, @"(#define [IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+)+.*"); var m = Regex.Match(ln, @"(#define [ID]*[IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+[L]?)+.*"); if (m.Success) { RAMStart = Convert.ToInt32(m.Groups[2].Value, 16); } m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*"); if (!m.Success) { m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_CNC_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*"); } if (!m.Success) { m = Regex.Match(ln, @"(#define BOOTROM_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");//samb11 } if (m.Success) { FLASHStart = Convert.ToInt32(m.Groups[2].Value, 16); } if (FLASHStart > -1 && RAMStart > -1) { break; } } if (RAMStart == -1) { throw new Exception("no RAM Start"); } // Console.WriteLine("RAMBase mcu {0} NO file :{1} ", mcu.Name, aFileName); if (FLASHStart == -1) { throw new Exception("no FLASH Start"); } // Console.WriteLine("FLASHBase mcu {0} NO file :{1} ",mcu.Name , aFileName); layout.Memories.Insert(0, new Memory { Name = "FLASH", Access = MemoryAccess.Undefined, Type = MemoryType.FLASH, Start = (uint)FLASHStart, Size = (uint)mcu.FlashSize }); layout.Memories.Insert(0, new Memory { Name = "SRAM", Access = MemoryAccess.Undefined, Type = MemoryType.RAM, Start = (uint)RAMStart, Size = (uint)mcu.RAMSize }); return(layout); }
private void OnReadExternalFlashStarted(bool checkIfReadRequired, bool onlyReadRequiredSectors, bool shouldVerifyReadData, byte[] baseImage, MemoryLayout flashLayout, Operation.CompletedOperationDelegate operationCompletedDel) { var readImage = baseImage; if ((readImage == null) || (readImage.Length != flashLayout.Size)) { readImage = new byte[flashLayout.Size]; //fill the memory image with 0xFF because that is what blank data in the flash chip is for (int x = 0; x < readImage.Length; x++) { readImage[x] = 0xFF; } } var sectorImages = MemoryUtils.SplitMemoryImageIntoSectors(readImage, flashLayout); var KWP2000CommViewModel = App.CommInterfaceViewModel as KWP2000Interface_ViewModel; var settings = new ReadExternalFlashOperation.ReadExternalFlashSettings(); settings.CheckIfSectorReadRequired = checkIfReadRequired; settings.OnlyReadNonMatchingSectors = onlyReadRequiredSectors; settings.VerifyReadData = shouldVerifyReadData; settings.SecuritySettings.RequestSeed = KWP2000CommViewModel.SeedRequest; settings.SecuritySettings.SupportSpecialKey = KWP2000CommViewModel.ShouldSupportSpecialKey; settings.SecuritySettings.UseExtendedSeedRequest = KWP2000CommViewModel.ShouldUseExtendedSeedRequest; App.CurrentOperation = new ReadExternalFlashOperation(KWP2000CommViewModel.KWP2000CommInterface, KWP2000CommViewModel.DesiredBaudRates, settings, sectorImages); App.CurrentOperation.CompletedOperationEvent += operationCompletedDel; App.DisplayStatusMessage("Reading ECU flash memory.", StatusMessageType.USER); App.CurrentOperation.Start(); }
private CodeFrame Read(BinaryReader bw) { var frame = new CodeFrame(); frame.GlobalScope = new Scope(false, null); var v = bw.ReadInt32(); if (v != Version) { throw new ElaLinkerException(Strings.GetMessage("InvalidObjectFile", Version), null); } bw.ReadInt32(); //Version: Major bw.ReadInt32(); //Version: Minor bw.ReadInt32(); //Version: Build bw.ReadInt32(); //Version: Revision bw.ReadInt64(); //Version: Date stamp var c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var alias = bw.ReadString(); var modName = bw.ReadString(); var dllName = bw.ReadString(); dllName = dllName.Length == 0 ? null : dllName; var qual = bw.ReadBoolean(); var pl = bw.ReadInt32(); var list = new string[pl]; for (var j = 0; j < pl; j++) { list[j] = bw.ReadString(); } var lh = bw.ReadInt32(); frame.AddReference(alias, new ModuleReference(frame, modName, dllName, list, 0, 0, qual, lh)); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.GlobalScope.Locals.Add(bw.ReadString(), new ScopeVar((ElaVariableFlags)bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32())); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.LateBounds.Add(new LateBoundSymbol( bw.ReadString(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32())); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var l = new MemoryLayout(bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32()); frame.Layouts.Add(l); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.Strings.Add(bw.ReadString()); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var opCode = (Op)bw.ReadByte(); frame.Ops.Add(opCode); frame.OpData.Add(OpSizeHelper.OpSize[(Int32)opCode] > 1 ? bw.ReadInt32() : 0); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.InternalTypes.Add(bw.ReadString(), bw.ReadInt32()); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var k = bw.ReadString(); var cc = bw.ReadInt32(); var mbr = new ElaClassMember[cc]; for (var j = 0; j < cc; j++) { var m = new ElaClassMember(); m.Components = bw.ReadInt32(); m.Mask = bw.ReadInt32(); m.Name = bw.ReadString(); mbr[j] = m; } frame.InternalClasses.Add(k, new ClassData(mbr)); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.InternalInstances.Add(new InstanceData( bw.ReadString(), bw.ReadString(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32())); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var ct = new ConstructorData { Code = -1, Name = bw.ReadString(), TypeName = bw.ReadString(), TypeModuleId = bw.ReadInt32() }; var cc = bw.ReadInt32(); if (cc > 0) { ct.Parameters = new List <String>(); for (var j = 0; j < cc; j++) { ct.Parameters.Add(bw.ReadString()); } } frame.InternalConstructors.Add(ct); } var di = bw.ReadBoolean(); if (di) { var sym = new DebugInfo(); c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var ln = new LineSym(bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32()); sym.Lines.Add(ln); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var fn = new FunSym(bw.ReadString(), bw.ReadInt32(), bw.ReadInt32()); fn.Handle = bw.ReadInt32(); fn.EndOffset = bw.ReadInt32(); sym.Functions.Add(fn); } frame.Symbols = sym; } return(frame); }
void DoGenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName, string ldsSuffix) { using (var gen = new LdsFileGenerator(LDSTemplate, layout)) { using (var sw = new StreamWriter(Path.Combine(ldsDirectory, generalizedName + "_nosoftdev" + ldsSuffix + ".lds"))) gen.GenerateLdsFile(sw); } foreach (var sd in SoftDevices) { if (!sd.IsCompatible(mcu.Name)) { continue; } if (sd.LinkerScriptWithMaximumReservedRAM == null) { //IoT var softdevTemplate = LDSTemplate.ShallowCopy(); softdevTemplate.Sections = new List <Section>(softdevTemplate.Sections); softdevTemplate.Sections.Insert(0, new Section { Name = ".softdevice", TargetMemory = "FLASH_SOFTDEVICE", Inputs = new List <SectionReference> { new SectionReference { NamePattern = ".softdevice", Flags = SectionReferenceFlags.Keep } }, Fill = new FillInfo { Pattern = uint.MaxValue, TotalSize = (int)sd.FLASHSize }, Flags = SectionFlags.Unaligned }); softdevTemplate.Sections.Insert(1, new Section { Name = ".softdevice_sram", TargetMemory = "SRAM_SOFTDEVICE", Inputs = new List <SectionReference>(), Fill = new FillInfo { Pattern = 0, TotalSize = (int)sd.SRAMSize }, Flags = SectionFlags.Unaligned }); var layoutCopy = layout.Clone(); var flash = layoutCopy.Memories.First(m => m.Name == "FLASH"); var ram = layoutCopy.Memories.First(m => m.Name == "SRAM"); if (flash.Size < sd.FLASHSize || ram.Size < sd.SRAMSize) { throw new Exception("Device too small for " + sd.Name); } layoutCopy.Memories.Insert(layoutCopy.Memories.IndexOf(flash), new Memory { Name = "FLASH_SOFTDEVICE", Access = MemoryAccess.Readable | MemoryAccess.Executable, Start = flash.Start, Size = sd.FLASHSize }); layoutCopy.Memories.Insert(layoutCopy.Memories.IndexOf(ram), new Memory { Name = "SRAM_SOFTDEVICE", Access = MemoryAccess.Readable | MemoryAccess.Writable | MemoryAccess.Executable, Start = ram.Start, Size = sd.SRAMSize }); flash.Size -= sd.FLASHSize; flash.Start += sd.FLASHSize; ram.Size -= sd.SRAMSize; ram.Start += sd.SRAMSize; using (var gen = new LdsFileGenerator(softdevTemplate, layoutCopy)) { using (var sw = new StreamWriter(Path.Combine(ldsDirectory, generalizedName + "_" + sd.Name.ToLower() + ldsSuffix + ".lds"))) gen.GenerateLdsFile(sw, new string[] { "", "GROUP(" + sd.Name + "_softdevice.o)", "" }); } } else { BuildLinkerScriptBasedOnOriginalNordicScripts(ldsDirectory, generalizedName, ldsSuffix, sd); } } mcu.LinkerScriptPath = $"$$SYS:BSP_ROOT$$/{familyFilePrefix}LinkerScripts/{generalizedName}_$${SoftdevicePropertyID}$$.lds"; }