mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-10 20:39:54 +00:00
Working on __open.
Working op `load` instruction.
This commit is contained in:
@@ -45,6 +45,7 @@ namespace SVM.Advanced.BSDStyleVM
|
||||
{
|
||||
config.FuncCalls.Add(1, BSDStyleFunctions0.__exit);
|
||||
config.FuncCalls.Add(4, BSDStyleFunctions0.__write);
|
||||
config.FuncCalls.Add(5, BSDStyleFunctions0.__open);
|
||||
}
|
||||
}
|
||||
public static class BSDFcntl
|
||||
@@ -69,7 +70,7 @@ namespace SVM.Advanced.BSDStyleVM
|
||||
var size = machine.registers.GetData<ulong>(11);
|
||||
var flag = machine.registers.GetData<int>(12);
|
||||
var fn = Encoding.UTF8.GetString((byte*)machine.GetPointer(ptr), (int)size);
|
||||
FileMode fm = default;
|
||||
FileMode fm = FileMode.Create;
|
||||
FileAccess fa = default;
|
||||
if ((flag & BSDFcntl.O_WRONLY) == BSDFcntl.O_WRONLY)
|
||||
{
|
||||
@@ -80,6 +81,7 @@ namespace SVM.Advanced.BSDStyleVM
|
||||
var stream = File.Open(fn, fm, fa);
|
||||
FileDescripter fd = new FileDescripter(stream);
|
||||
w.FDs.Add(fdID, fd);
|
||||
machine.registers.SetDataInRegister<int>(10,fdID);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -95,7 +97,9 @@ namespace SVM.Advanced.BSDStyleVM
|
||||
var size = machine.registers.GetData<ulong>(12);
|
||||
if (w.FDs.TryGetValue(fd, out var descripter))
|
||||
{
|
||||
Console.OpenStandardOutput().WriteData(machine.GetPointer(ptr), size);
|
||||
descripter.stream.WriteData(machine.GetPointer(ptr), size);
|
||||
descripter.stream.Flush();
|
||||
}
|
||||
else
|
||||
Console.WriteLine($"FD:{fd} does not exist.");
|
||||
|
||||
@@ -69,6 +69,32 @@ namespace SVM.Assembler.Core
|
||||
registerID = byte.MaxValue;
|
||||
return false;
|
||||
}
|
||||
public static bool TryParseUInt8(string input, LinkingContext context, out byte value)
|
||||
{
|
||||
if (byte.TryParse(input, out value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (context.IntermediateObject.TryGetConst(input, out var realStr))
|
||||
{
|
||||
return TryParseUInt8(realStr, context, out value);
|
||||
}
|
||||
if (context.TryFindLabel(input, out var lblV))
|
||||
{
|
||||
value = (byte)lblV;
|
||||
return true;
|
||||
}
|
||||
if (context.TryFindData(input, out var dataV))
|
||||
{
|
||||
value = (byte)dataV;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
value = byte.MaxValue;
|
||||
return false;
|
||||
}
|
||||
public static bool TryParseInt32(string input, LinkingContext context, out int value)
|
||||
{
|
||||
if (int.TryParse(input, out value))
|
||||
@@ -361,6 +387,27 @@ namespace SVM.Assembler.Core
|
||||
WriteData(instruction, paraDef.ExpectdValue.Type, paraDef.ExpectdValue.Pos, (byte*)®isterID);
|
||||
}
|
||||
break;
|
||||
case "Integer64":
|
||||
{
|
||||
if (!TryParseInt64(para.Content, context, out var registerID))
|
||||
{
|
||||
result.AddError(new ErrorWMsg($"{para.Content} cannot be parsed to Integer64!", para));
|
||||
return result;
|
||||
}
|
||||
WriteData(instruction, paraDef.ExpectdValue.Type, paraDef.ExpectdValue.Pos, (byte*)®isterID);
|
||||
}
|
||||
break;
|
||||
case "UnsignedInteger8":
|
||||
case "UInt8":
|
||||
{
|
||||
if (!TryParseUInt8(para.Content, context, out var registerID))
|
||||
{
|
||||
result.AddError(new ErrorWMsg($"{para.Content} cannot be parsed to Unsigned Integer8!", para));
|
||||
return result;
|
||||
}
|
||||
WriteData(instruction, paraDef.ExpectdValue.Type, paraDef.ExpectdValue.Pos, (byte*)®isterID);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -111,5 +111,34 @@
|
||||
</InstructionParameter>
|
||||
</Parameters>
|
||||
</InstructionDefinition>
|
||||
<InstructionDefinition Id="load" PrimaryInstruction="Load" InstructionCount="1">
|
||||
<Aliases>
|
||||
<Alias Name="load"/>
|
||||
<Alias Name="ld"/>
|
||||
</Aliases>
|
||||
<Parameters>
|
||||
<InstructionParameter>
|
||||
<MatchingItems>
|
||||
<Item Id="Register"/>
|
||||
<Item Id="Word"/>
|
||||
</MatchingItems>
|
||||
<ExpectedValue Type="UInt8" Pos="1" Converter="Register" />
|
||||
</InstructionParameter>
|
||||
<InstructionParameter>
|
||||
<MatchingItems>
|
||||
<Item Id="Number"/>
|
||||
<Item Id="Word"/>
|
||||
</MatchingItems>
|
||||
<ExpectedValue Type="UInt8" Pos="2" Converter="UInt8" />
|
||||
</InstructionParameter>
|
||||
<InstructionParameter>
|
||||
<MatchingItems>
|
||||
<Item Id="Register"/>
|
||||
<Item Id="Word"/>
|
||||
</MatchingItems>
|
||||
<ExpectedValue Type="UInt8" Pos="3" Converter="Register" />
|
||||
</InstructionParameter>
|
||||
</Parameters>
|
||||
</InstructionDefinition>
|
||||
</Definitions>
|
||||
</ISARoot>
|
||||
@@ -44,6 +44,12 @@ namespace SVM.Core
|
||||
if (offset * sizeof(ulong) + sizeof(T) > Size) return;
|
||||
((T*)((byte*)Data + offset * sizeof(ulong)))[0] = d;
|
||||
}
|
||||
public unsafe void SetDataInRegister(int offset, IntPtr ptr, int size)
|
||||
{
|
||||
if (offset == 0) return;
|
||||
if (offset * sizeof(ulong) + size > Size) return;
|
||||
Buffer.MemoryCopy((byte*)ptr, (byte*)Data + offset * sizeof(ulong), size, size);
|
||||
}
|
||||
public unsafe void SetDataOffsetInBytes<T>(int offset, T d) where T : unmanaged
|
||||
{
|
||||
if (offset == 0) return;
|
||||
|
||||
@@ -171,6 +171,15 @@ namespace SVM.Core
|
||||
case PrimaryInstruction.JALF:
|
||||
break;
|
||||
case PrimaryInstruction.Load:
|
||||
{
|
||||
var Reg = Instruction.GetData<byte>(1);
|
||||
var Length = Instruction.GetData<byte>(2);
|
||||
var Target = Instruction.GetData<byte>(3);
|
||||
var source = registers.GetData<SVMPointer>(Reg);
|
||||
var srcPtr = GetPointer(source);
|
||||
registers.SetDataInRegister(Target, srcPtr, Length);
|
||||
}
|
||||
|
||||
break;
|
||||
case PrimaryInstruction.Save:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user