3 import org.ibex.nestedvm.Runtime;
7 public class CallTest {
8 public static void main(String[] args) throws Exception {
9 int a1 = args.length > 0 ? Integer.parseInt(args[0]) : 0;
10 int a2 = args.length > 1 ? Integer.parseInt(args[1]) : 0;
11 int a3 = args.length > 2 ? Integer.parseInt(args[2]) : 0;
12 int a4 = args.length > 3 ? Integer.parseInt(args[3]) : 0;
13 int a5 = args.length > 4 ? Integer.parseInt(args[4]) : 0;
14 int a6 = args.length > 5 ? Integer.parseInt(args[5]) : 0;
16 System.out.println("Version is: " + System.getProperty("os.version"));
18 if(a1 == 99) // yeah.. this is ugly
19 rt = new org.ibex.nestedvm.Interpreter("build/tests/Test.mips");
21 rt = (Runtime) Class.forName("tests.Test").newInstance();
23 rt.setCallJavaCB(new Runtime.CallJavaCB() {
24 public int call(int a, int b, int c, int d) {
26 case 1: return rt.strdup("OS: " + System.getProperty("os.name"));
27 case 2: return rt.strdup(System.getProperty("os.version"));
28 case 3: return rt.strdup(new Date().toString());
29 case 4: return rt.addFD(new Runtime.InputOutputStreamFD(null,new CustomOS()));
31 System.out.println("In callJava() in Java");
32 try { rt.call("backinmips"); } catch(Runtime.CallException e) { }
33 System.out.println("Back in callJava() in Java");
39 System.out.println("Runtime: " + rt);
41 rt.start(new String[]{"Test","calltest"});
44 System.out.println("== Start of CallTest ==");
45 System.out.println("Back in java... calling callme()");
46 int ret = rt.call("callme",new int[]{a1,a2,a3,a4,a5,a6});
47 System.out.println("callme returned: " + ret);
49 int addr = rt.strdup("Hello, World from java");
50 rt.call("echo",addr,4);
52 rt.call("echo",new Object[]{"Hello, World, from the Object[] call method",new Integer(2)});
53 System.out.println("== End of CallTest ==");
56 System.exit(rt.exitStatus());
59 private static class CustomOS extends OutputStream {
61 public void write(int b) { byte[] a = new byte[1]; a[0] = (byte)(b&0xff); write(a,0,1); }
62 public void write(byte[] b, int off, int len) {
64 while(b[len2-1]=='\n') len2--;
65 System.out.println("This just in from MIPS: " + new String(b,off,len2));