X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Ftranslators%2FMSPack.java;h=a815801acb7ee2869dd2423ecb93793ab2c371ff;hb=16ad8b9430571d806f2aeb18ec472a277ff69423;hp=c9482eb9d27bcd92b526e769cc4fc8b8c6d6feba;hpb=bbfe17b34980e100bcf26ec0c0b1b3fde1992793;p=org.ibex.core.git diff --git a/src/org/xwt/translators/MSPack.java b/src/org/xwt/translators/MSPack.java index c9482eb..a815801 100644 --- a/src/org/xwt/translators/MSPack.java +++ b/src/org/xwt/translators/MSPack.java @@ -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 = (Runtime)Class.forName("org.xwt.translators.MIPSApps").newInstance(); + 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,15 +53,19 @@ public class MSPack { System.out.println("" + fileNames[i]); vm.copyin(vm.memRead(addr+4),data[i],length); } - } catch(VM.EmulationException e) { + } catch(Runtime.ExecutionException e) { e.printStackTrace(); throw new MSPackException("mspack.mips crashed"); + } catch(Exception e) { + throw new MSPackException(e.toString()); } } public String[] getFileNames() { return fileNames; } public int[] getLengths() { return lengths; } - public InputStream getInputStream(int index) { return new ByteArrayInputStream(data[index]); } + public InputStream getInputStream(int index) { + return new KnownLength.KnownLengthInputStream(new ByteArrayInputStream(data[index]), data[index].length); + } public InputStream getInputStream(String fileName) { for(int i=0;i