X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Ftranslators%2FMSPack.java;h=a815801acb7ee2869dd2423ecb93793ab2c371ff;hb=7d832e12a5f66911b042885f8f07e37844501208;hp=00316de30f6d1cfa3dac99fc2171e06d79c4bd02;hpb=a071a56b6d9c9d38b85d23cc3eb287435322d0cc;p=org.ibex.core.git diff --git a/src/org/xwt/translators/MSPack.java b/src/org/xwt/translators/MSPack.java index 00316de..a815801 100644 --- a/src/org/xwt/translators/MSPack.java +++ b/src/org/xwt/translators/MSPack.java @@ -1,40 +1,91 @@ package org.xwt.translators; -import org.xwt.*; + +import org.xwt.Main; import org.xwt.util.*; +import org.xwt.mips.*; import java.io.*; -import java.util.zip.*; - -public class MSPack { - - MSPack() { } - private static org.xwt.mips.Interpreter vm = null; +import org.xwt.mips.Runtime; - public static synchronized void unpack(InputStream theCabFile) { - try { - if (vm == null) { - InputStream bis = Platform.getBuiltinInputStream(); - ZipInputStream zis = new ZipInputStream(bis); - for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("libmspack.mips"); ze = zis.getNextEntry()) { } - byte[] image = InputStreamToByteArray.convert(zis); - vm = new org.xwt.mips.Interpreter(image); - vm.start(new String[]{ "libmspack.mips" }); - vm.execute(); - } - - int CAB_RESERVED = 256*1024; - int baseAddr = vm.sbrk(CAB_RESERVED); +public class MSPack { + private static byte[] image; + + private String[] fileNames; + private int[] lengths; + private byte[][] data; + + public static class MSPackException extends IOException { public MSPackException(String s) { super(s); } } + + 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"); - byte[] cabstream = InputStreamToByteArray.convert(theCabFile); - vm.copyout(cabstream, baseAddr, cabstream.length); - vm.setUserInfo(0, baseAddr); - vm.setUserInfo(1, cabstream.length); + vm.copyout(cab,cabAddr,cab.length); + + vm.setUserInfo(0,cabAddr); + vm.setUserInfo(1,cab.length); + + int status = vm.run(new String[]{ "mspack"} ); + if(status != 0) throw new MSPackException("mspack.mips failed (" + status + ")"); - vm.execute(); - // FIXME: do more stuff here + /*static struct { + char *filename; + char *data; + int length; + } output_table[MAX_MEMBERS+1]; */ - } catch (Exception e) { - Log.log(MSPack.class, e); + int filesTable = vm.getUserInfo(2); + int count=0; + while(vm.memRead(filesTable+count*12) != 0) count++; + + fileNames = new String[count]; + data = new byte[count][]; + lengths = new int[count]; + + for(int i=0,addr=filesTable;i