2003/12/28 09:45:29
[org.ibex.core.git] / src / org / xwt / translators / MSPack.java
index 3275bb9..c15aff4 100644 (file)
@@ -5,6 +5,8 @@ import org.xwt.util.*;
 import org.xwt.mips.*;
 import java.io.*;
 
+import org.xwt.mips.Runtime;
+
 public class MSPack {
     private static byte[] image;
     
@@ -13,27 +15,20 @@ public class MSPack {
     private byte[][] data;
         
     public static class MSPackException extends IOException { public MSPackException(String s) { super(s); } }
-    
-    private static synchronized byte[] getImage() throws IOException {
-        if (image == null)
-            image = InputStreamToByteArray.convert(Main.builtin.getInputStream("libmspack.mips"));
-        return image;
-    }
-    
-    public MSPack(InputStream cabIS) throws IOException {
-        byte[] cab = InputStreamToByteArray.convert(cabIS);
-        Interpreter vm = new Interpreter(getImage());
-        
-        int cabAddr = vm.sbrk(cab.length);
-        if(cabAddr < 0) throw new MSPackException("sbrk failed");
         
+    public MSPack(InputStream cabIS) throws IOException {
         try {
+            Runtime vm = new MIPSApps();
+            byte[] cab = InputStreamToByteArray.convert(cabIS);
+            int cabAddr = vm.sbrk(cab.length);
+            if(cabAddr < 0) throw new MSPackException("sbrk failed");
+            
             vm.copyout(cab,cabAddr,cab.length);
         
             vm.setUserInfo(0,cabAddr);
             vm.setUserInfo(1,cab.length);
         
-            int status = vm.run(new String[]{ "mspack.mips"} );
+            int status = vm.run(new String[]{ "mspack"} );
             if(status != 0) throw new MSPackException("mspack.mips failed (" + status + ")");
             
             /*static struct {
@@ -58,7 +53,7 @@ public class MSPack {
                 System.out.println("" + fileNames[i]);
                 vm.copyin(vm.memRead(addr+4),data[i],length);
             }
-        } catch(Exception e) {
+        } catch(Runtime.ExecutionException e) {
             e.printStackTrace();
             throw new MSPackException("mspack.mips crashed");
         }