diff --git a/src/SVM.Core/SimpleVirtualMachine.cs b/src/SVM.Core/SimpleVirtualMachine.cs index f3ada2c..a357985 100644 --- a/src/SVM.Core/SimpleVirtualMachine.cs +++ b/src/SVM.Core/SimpleVirtualMachine.cs @@ -27,6 +27,7 @@ namespace SVM.Core public static uint InitGPMemorySize = 696320; public Object? AdditionalData = null; public ErrorIDs ErrorIDs = new ErrorIDs(); + public DebugSymbol? symbols; public void Init(uint StackSize = 1024 * 1024, uint RegisterSize = 512, uint GPMemory = uint.MaxValue) { registers.Init(RegisterSize); @@ -51,9 +52,31 @@ namespace SVM.Core block.Init(GPMemory); SetMemory(1, block); registers.SetData((int)CFOffset, new SVMPointer() { index = 1, offset = 0 }); + + var cfPtr = GetPointer(ReadCallFrameRegisterAsPtr()); + cfPtr.SetData(ulong.MaxValue - 4); registers.SetData((int)SPOffset, new SVMPointer() { index = 1, offset = StackSize }); } } + public void Invoke(ulong PC) + { + while (true) + { + var ptr = ReadCallFrameRegisterAsPtr(); + if (ptr.offset == 0) return; + Step(); + } + } + public void Invoke(string funcName) + { + if (symbols != null) + { + if (symbols.Functions.TryGetValue(funcName, out var func)) + { + Invoke(func); + } + } + } public bool isReachBinaryEnd() { uint PCOffset = 1; @@ -233,6 +256,7 @@ namespace SVM.Core var cfPtr = GetPointer(ReadCallFrameRegisterAsPtr()); PC = cfPtr.GetData(); PC -= 1; + WriteCallFrameRegister(ReadCallFrameRegister() - 1); } break; case PrimaryInstruction.System: