mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-11 12:59: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(1, BSDStyleFunctions0.__exit);
|
||||||
config.FuncCalls.Add(4, BSDStyleFunctions0.__write);
|
config.FuncCalls.Add(4, BSDStyleFunctions0.__write);
|
||||||
|
config.FuncCalls.Add(5, BSDStyleFunctions0.__open);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class BSDFcntl
|
public static class BSDFcntl
|
||||||
@@ -69,7 +70,7 @@ namespace SVM.Advanced.BSDStyleVM
|
|||||||
var size = machine.registers.GetData<ulong>(11);
|
var size = machine.registers.GetData<ulong>(11);
|
||||||
var flag = machine.registers.GetData<int>(12);
|
var flag = machine.registers.GetData<int>(12);
|
||||||
var fn = Encoding.UTF8.GetString((byte*)machine.GetPointer(ptr), (int)size);
|
var fn = Encoding.UTF8.GetString((byte*)machine.GetPointer(ptr), (int)size);
|
||||||
FileMode fm = default;
|
FileMode fm = FileMode.Create;
|
||||||
FileAccess fa = default;
|
FileAccess fa = default;
|
||||||
if ((flag & BSDFcntl.O_WRONLY) == BSDFcntl.O_WRONLY)
|
if ((flag & BSDFcntl.O_WRONLY) == BSDFcntl.O_WRONLY)
|
||||||
{
|
{
|
||||||
@@ -80,6 +81,7 @@ namespace SVM.Advanced.BSDStyleVM
|
|||||||
var stream = File.Open(fn, fm, fa);
|
var stream = File.Open(fn, fm, fa);
|
||||||
FileDescripter fd = new FileDescripter(stream);
|
FileDescripter fd = new FileDescripter(stream);
|
||||||
w.FDs.Add(fdID, fd);
|
w.FDs.Add(fdID, fd);
|
||||||
|
machine.registers.SetDataInRegister<int>(10,fdID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -95,7 +97,9 @@ namespace SVM.Advanced.BSDStyleVM
|
|||||||
var size = machine.registers.GetData<ulong>(12);
|
var size = machine.registers.GetData<ulong>(12);
|
||||||
if (w.FDs.TryGetValue(fd, out var descripter))
|
if (w.FDs.TryGetValue(fd, out var descripter))
|
||||||
{
|
{
|
||||||
|
Console.OpenStandardOutput().WriteData(machine.GetPointer(ptr), size);
|
||||||
descripter.stream.WriteData(machine.GetPointer(ptr), size);
|
descripter.stream.WriteData(machine.GetPointer(ptr), size);
|
||||||
|
descripter.stream.Flush();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Console.WriteLine($"FD:{fd} does not exist.");
|
Console.WriteLine($"FD:{fd} does not exist.");
|
||||||
|
|||||||
@@ -69,6 +69,32 @@ namespace SVM.Assembler.Core
|
|||||||
registerID = byte.MaxValue;
|
registerID = byte.MaxValue;
|
||||||
return false;
|
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)
|
public static bool TryParseInt32(string input, LinkingContext context, out int value)
|
||||||
{
|
{
|
||||||
if (int.TryParse(input, out 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);
|
WriteData(instruction, paraDef.ExpectdValue.Type, paraDef.ExpectdValue.Pos, (byte*)®isterID);
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,5 +111,34 @@
|
|||||||
</InstructionParameter>
|
</InstructionParameter>
|
||||||
</Parameters>
|
</Parameters>
|
||||||
</InstructionDefinition>
|
</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>
|
</Definitions>
|
||||||
</ISARoot>
|
</ISARoot>
|
||||||
@@ -44,6 +44,12 @@ namespace SVM.Core
|
|||||||
if (offset * sizeof(ulong) + sizeof(T) > Size) return;
|
if (offset * sizeof(ulong) + sizeof(T) > Size) return;
|
||||||
((T*)((byte*)Data + offset * sizeof(ulong)))[0] = d;
|
((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
|
public unsafe void SetDataOffsetInBytes<T>(int offset, T d) where T : unmanaged
|
||||||
{
|
{
|
||||||
if (offset == 0) return;
|
if (offset == 0) return;
|
||||||
|
|||||||
@@ -171,6 +171,15 @@ namespace SVM.Core
|
|||||||
case PrimaryInstruction.JALF:
|
case PrimaryInstruction.JALF:
|
||||||
break;
|
break;
|
||||||
case PrimaryInstruction.Load:
|
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;
|
break;
|
||||||
case PrimaryInstruction.Save:
|
case PrimaryInstruction.Save:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user