Skip to content

Commit

Permalink
Add: Support for ECALL and EBREAK
Browse files Browse the repository at this point in the history
  • Loading branch information
rizwan3d committed Oct 23, 2023
1 parent 0a6246e commit 9635ac8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Example/helloworld.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Risc-V Assembler program to print "Hello World!"
# to stdout.
#
# a0-a2 - parameters to linux function services
# a7 - linux function number
#

# Setup the parameters to print hello world
# and then call Linux to do it.
.text
_start:
addi a0, x0, 1 # 1 = StdOut
la a1, helloworld # load address of helloworld
addi a2, x0, 13 # length of our string
addi a7, x0, 64 # linux write system call
ecall # Call linux to output the string

# Setup the parameters to exit the program
# and then call Linux to do it.

addi a0, x0, 0 # Use 0 return code
addi a7, x0, 93 # Service command code 93 terminates
ecall # Call linux to terminate the program

.data
helloworld: .string "Hello World!\n"
1 change: 1 addition & 0 deletions SharpRISCV.Core/MachineCode/MachineCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static int GetLoPart(string imm)

public static int ProcessSource(string Immediate)
{
if(Immediate == null) { return 0; }

if (Immediate.StartsWith("%"))
{
Expand Down
13 changes: 13 additions & 0 deletions SharpRISCV.Core/Parser/Instruction/I_Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public RiscVInstruction Parse(string instruction)
InstructionType = InstructionType.I,
};
}

if(instruction == "ecall" || instruction == "ebreak")
{
return new RiscVInstruction
{
Instruction = instruction,
Opcode = instruction,
Rd = string.Empty,
Rs1 = string.Empty,
InstructionType = InstructionType.I,
};
}

return null;
}
}
1 change: 1 addition & 0 deletions SharpRISCV.Core/Registers/Register.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static Register()
FromABI.Add("x29", 29);
FromABI.Add("x30", 30);
FromABI.Add("x31", 31);
FromABI.Add(string.Empty, 0);
}
}
}
2 changes: 2 additions & 0 deletions SharpRISCV.Core/RiscVAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ public static InstructionType IdentifyInstructionType(string instruction)
return InstructionType.U;
case (OpCode)0b0010011:
return InstructionType.I;
case (OpCode)0b1110011:
return InstructionType.I;
case (OpCode)0b1100011:
return InstructionType.B;
case (OpCode)0b0000011:
Expand Down
5 changes: 3 additions & 2 deletions SharpRISCV.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Example", "Example", "{2730FC94-0E0E-4CD7-870B-27E1D55C9B27}"
ProjectSection(SolutionItems) = preProject
Example\example.s = Example\example.s
helloworld.s = helloworld.s
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebRISCV", "WebRISCV\WebRISCV.csproj", "{E4C78F51-2521-41A5-BBC2-8ABCE9B9975B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebRISCV", "WebRISCV\WebRISCV.csproj", "{E4C78F51-2521-41A5-BBC2-8ABCE9B9975B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpRISCV.Core", "SharpRISCV.Core\SharpRISCV.Core.csproj", "{4532AF82-E17D-4B81-B311-58C78096900A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpRISCV.Core", "SharpRISCV.Core\SharpRISCV.Core.csproj", "{4532AF82-E17D-4B81-B311-58C78096900A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit 9635ac8

Please sign in to comment.