Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions examples/fibonacci.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ __start:
li t0, 0
li t1, 1
# prints msg1
li a0, 4
la a1, msg1
li a7, 4
la a0, msg1
ecall
# reads an int and moves it to register t3
li a0, 5
li a7, 5
ecall
mv t3, a0
# prints a newline
li a0, 11
li a1, '\n'
li a7, 11
li a0, '\n'
ecall
# prints msg2
li a0, 4
la a1, msg2
li a7, 4
la a0, msg2
ecall
# prints the int value in t3
li a0, 1
mv a1, t3
li a7, 1
mv a0, t3
ecall
# fibonnaci program
fib:
Expand All @@ -44,13 +44,13 @@ fib:
j fib
finish:
# prints msg3
li a0, 4
la a1, msg3
li a7, 4
la a0, msg3
ecall
# prints the result in t0
li a0, 1
mv a1, t0
li a7, 1
mv a0, t0
ecall
# ends the program with status code 0
li a0, 10
li a7, 10
ecall
58 changes: 29 additions & 29 deletions src/main/java/jupiter/riscv/Syscall.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public final class Syscall {
*/
public static void handler(State state) throws SimulationException {
// match ecall code
switch (state.xregfile().getRegister("a0")) {
switch (state.xregfile().getRegister("a7")) {
case PRINT_INT:
printInt(state);
break;
Expand Down Expand Up @@ -173,7 +173,7 @@ public static void handler(State state) throws SimulationException {
randFloat(state);
break;
default:
throw new SimulationException("invalid ecall code: " + state.xregfile().getRegister("a0"));
throw new SimulationException("invalid ecall code: " + state.xregfile().getRegister("a7"));
}
}

Expand All @@ -184,7 +184,7 @@ public static void handler(State state) throws SimulationException {
*/
private static void printInt(State state) {
Globals.PRINT = true;
int num = state.xregfile().getRegister("a1");
int num = state.xregfile().getRegister("a0");
IO.stdout().print(Integer.toString(num));
}

Expand All @@ -206,7 +206,7 @@ private static void printFloat(State state) {
*/
private static void printString(State state) throws SimulationException {
Globals.PRINT = true;
int buffer = state.xregfile().getRegister("a1");
int buffer = state.xregfile().getRegister("a0");
// 65684
StringBuilder s = new StringBuilder(0);
char c;
Expand Down Expand Up @@ -249,8 +249,8 @@ private static void readFloat(State state) throws SimulationException {
* @param state program state
*/
private static void readString(State state) throws SimulationException {
int buffer = state.xregfile().getRegister("a1");
int length = Math.max(state.xregfile().getRegister("a2") - 1, 0);
int buffer = state.xregfile().getRegister("a0");
int length = Math.max(state.xregfile().getRegister("a1") - 1, 0);
String s = IO.readString(length);
int minLength = Math.min(length, s.length());
for (int i = 0; i < minLength; i++) {
Expand All @@ -266,7 +266,7 @@ private static void readString(State state) throws SimulationException {
* @param state program state
*/
private static void sbrk(State state) throws SimulationException {
int numBytes = state.xregfile().getRegister("a1");
int numBytes = state.xregfile().getRegister("a0");
if (numBytes >= 0) {
int address = state.memory().allocateBytesFromHeap(numBytes);
state.xregfile().setRegister("a0", address);
Expand All @@ -287,7 +287,7 @@ private static void exit() throws SimulationException {
*/
private static void printChar(State state) {
Globals.PRINT = true;
IO.stdout().print((char) state.xregfile().getRegister("a1") + "");
IO.stdout().print((char) state.xregfile().getRegister("a0") + "");
}

/**
Expand All @@ -305,8 +305,8 @@ private static void readChar(State state) {
* @param state program state
*/
private static void open(State state) throws SimulationException{
int buffer = state.xregfile().getRegister("a1");
int oflags = state.xregfile().getRegister("a2");
int buffer = state.xregfile().getRegister("a0");
int oflags = state.xregfile().getRegister("a1");
state.xregfile().setRegister("a0", VirtualFS.open(buffer, oflags, state));
}

Expand All @@ -316,9 +316,9 @@ private static void open(State state) throws SimulationException{
* @param state program state
*/
private static void read(State state) throws SimulationException {
int fd = state.xregfile().getRegister("a1");
int buffer = state.xregfile().getRegister("a2");
int nbytes = state.xregfile().getRegister("a3");
int fd = state.xregfile().getRegister("a0");
int buffer = state.xregfile().getRegister("a1");
int nbytes = state.xregfile().getRegister("a2");
if (nbytes > 0) {
state.xregfile().setRegister("a0", VirtualFS.read(fd, buffer, nbytes, state));
} else {
Expand All @@ -332,9 +332,9 @@ private static void read(State state) throws SimulationException {
* @param state program state
*/
private static void write(State state) throws SimulationException {
int fd = state.xregfile().getRegister("a1");
int buffer = state.xregfile().getRegister("a2");
int nbytes = state.xregfile().getRegister("a3");
int fd = state.xregfile().getRegister("a0");
int buffer = state.xregfile().getRegister("a1");
int nbytes = state.xregfile().getRegister("a2");
if (nbytes > 0) {
state.xregfile().setRegister("a0", VirtualFS.write(fd, buffer, nbytes, state));
} else {
Expand All @@ -348,9 +348,9 @@ private static void write(State state) throws SimulationException {
* @param state program state
*/
private static void lseek(State state) throws SimulationException {
int fd = state.xregfile().getRegister("a1");
int offset = state.xregfile().getRegister("a2");
int whence = state.xregfile().getRegister("a3");
int fd = state.xregfile().getRegister("a0");
int offset = state.xregfile().getRegister("a1");
int whence = state.xregfile().getRegister("a2");
state.xregfile().setRegister("a0", VirtualFS.lseek(fd, offset, whence));
}

Expand All @@ -360,7 +360,7 @@ private static void lseek(State state) throws SimulationException {
* @param state program state
*/
private static void close(State state) {
state.xregfile().setRegister("a0", VirtualFS.close(state.xregfile().getRegister("a1")));
state.xregfile().setRegister("a0", VirtualFS.close(state.xregfile().getRegister("a0")));
}

/**
Expand All @@ -369,7 +369,7 @@ private static void close(State state) {
* @param state program state
*/
private static void exit2(State state) throws SimulationException {
throw new HaltException(state.xregfile().getRegister("a1"));
throw new HaltException(state.xregfile().getRegister("a0"));
}

/**
Expand All @@ -378,7 +378,7 @@ private static void exit2(State state) throws SimulationException {
* @param state program state
*/
private static void sleep(State state) throws SimulationException {
int millis = state.xregfile().getRegister("a1");
int millis = state.xregfile().getRegister("a0");
if (millis >= 0) {
try {
Thread.sleep(millis);
Expand All @@ -395,7 +395,7 @@ private static void sleep(State state) throws SimulationException {
*/
private static void cwd(State state) throws SimulationException {
String path = System.getProperty("user.dir");
int buffer = state.xregfile().getRegister("a1");
int buffer = state.xregfile().getRegister("a0");
for (int i = 0; i < path.length(); i++) {
state.memory().storeByte(buffer++, (int) path.charAt(i));
}
Expand All @@ -420,7 +420,7 @@ private static void time(State state) {
*/
private static void printHex(State state) {
Globals.PRINT = true;
IO.stdout().print(String.format("0x%08x", state.xregfile().getRegister("a1")));
IO.stdout().print(String.format("0x%08x", state.xregfile().getRegister("a0")));
}

/**
Expand All @@ -430,7 +430,7 @@ private static void printHex(State state) {
*/
private static void printBin(State state) {
Globals.PRINT = true;
IO.stdout().print(String.format("0b%32s", Integer.toBinaryString(state.xregfile().getRegister("a1"))).replace(' ', '0'));
IO.stdout().print(String.format("0b%32s", Integer.toBinaryString(state.xregfile().getRegister("a0"))).replace(' ', '0'));
}

/**
Expand All @@ -440,7 +440,7 @@ private static void printBin(State state) {
*/
private static void printUsgn(State state) {
Globals.PRINT = true;
IO.stdout().print(Long.toString(Integer.toUnsignedLong(state.xregfile().getRegister("a1"))));
IO.stdout().print(Long.toString(Integer.toUnsignedLong(state.xregfile().getRegister("a0"))));
}

/**
Expand All @@ -449,7 +449,7 @@ private static void printUsgn(State state) {
* @param state program state
*/
private static void setSeed(State state) {
RNG.setSeed(state.xregfile().getRegister("a1"));
RNG.setSeed(state.xregfile().getRegister("a0"));
}

/**
Expand All @@ -467,8 +467,8 @@ private static void randInt(State state) {
* @param state program state
*/
private static void randIntRng(State state) {
int min = state.xregfile().getRegister("a1");
int max = state.xregfile().getRegister("a2");
int min = state.xregfile().getRegister("a0");
int max = state.xregfile().getRegister("a1");
state.xregfile().setRegister("a0", RNG.nextInt((max - min) + 1) + min);
}

Expand Down
3 changes: 1 addition & 2 deletions src/test/others/print.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.globl print

print:
mv a1, a0
li a0, 1
li a7, 1
ecall
ret
2 changes: 1 addition & 1 deletion src/test/others/test.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__start:
li a0, 0xbb
call print
li a0, 10
li a7, 10
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/add.s
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ test37:
bne x0, x29, fail

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/addi.s
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ test24:
bne x0, x29, fail

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/and.s
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ test26:
bne x0, x29, fail

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/andi.s
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ test13:
bne x0, x29, fail

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/auipc.s
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ label3_test01:
ret

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/beq.s
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ label1_test19:
bne x4, x5, label1_test19

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/bge.s
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ label1_test22:
bne x4, x5, label1_test22

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/bgeu.s
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ label1_test22:
bne x4, x5, label1_test22

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/blt.s
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ label1_test19:
bne x4, x5, label1_test19

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/bltu.s
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ label1_test19:
bne x4, x5, label1_test19

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
4 changes: 2 additions & 2 deletions src/test/riscv-tests/bne.s
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ label1_test19:
bne x4, x5, label1_test19

success:
li a0, 10
li a7, 10
ecall

fail:
li a0, 17
li a7, 17
ecall
Loading