1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
7 import org.ibex.nestedvm.Runtime;
11 public class CallTest {
12 public static void main(String[] args) throws Exception {
13 int a1 = args.length > 0 ? Integer.parseInt(args[0]) : 0;
14 int a2 = args.length > 1 ? Integer.parseInt(args[1]) : 0;
15 int a3 = args.length > 2 ? Integer.parseInt(args[2]) : 0;
16 int a4 = args.length > 3 ? Integer.parseInt(args[3]) : 0;
17 int a5 = args.length > 4 ? Integer.parseInt(args[4]) : 0;
18 int a6 = args.length > 5 ? Integer.parseInt(args[5]) : 0;
20 System.out.println("Version is: " + System.getProperty("os.version"));
22 if(a1 == 99) // yeah.. this is ugly
23 rt = new org.ibex.nestedvm.Interpreter("build/tests/Test.mips");
25 rt = (Runtime) Class.forName("tests.Test").newInstance();
27 rt.setCallJavaCB(new Runtime.CallJavaCB() {
28 public int call(int a, int b, int c, int d) {
30 case 1: return rt.strdup("OS: " + System.getProperty("os.name"));
31 case 2: return rt.strdup(System.getProperty("os.version"));
32 case 3: return rt.strdup(new Date().toString());
33 case 4: return rt.addFD(new Runtime.InputOutputStreamFD(null,new CustomOS()));
35 System.out.println("In callJava() in Java");
36 try { rt.call("backinmips"); } catch(Runtime.CallException e) { }
37 System.out.println("Back in callJava() in Java");
43 System.out.println("Runtime: " + rt);
45 rt.start(new String[]{"Test","calltest"});
48 System.out.println("== Start of CallTest ==");
49 System.out.println("Back in java... calling callme()");
50 int ret = rt.call("callme",new int[]{a1,a2,a3,a4,a5,a6});
51 System.out.println("callme returned: " + ret);
53 int addr = rt.strdup("Hello, World from java");
54 rt.call("echo",addr,4);
56 rt.call("echo",new Object[]{"Hello, World, from the Object[] call method",new Integer(2)});
57 System.out.println("== End of CallTest ==");
60 System.exit(rt.exitStatus());
63 private static class CustomOS extends OutputStream {
65 public void write(int b) { byte[] a = new byte[1]; a[0] = (byte)(b&0xff); write(a,0,1); }
66 public void write(byte[] b, int off, int len) {
68 while(b[len2-1]=='\n') len2--;
69 System.out.println("This just in from MIPS: " + new String(b,off,len2));