00316de30f6d1cfa3dac99fc2171e06d79c4bd02
[org.ibex.core.git] / src / org / xwt / translators / MSPack.java
1 package org.xwt.translators;
2 import org.xwt.*;
3 import org.xwt.util.*;
4 import java.io.*;
5 import java.util.zip.*;
6
7 public class MSPack {
8
9     MSPack() { }
10
11     private static org.xwt.mips.Interpreter vm = null;
12
13     public static synchronized void unpack(InputStream theCabFile) {
14         try {           
15             if (vm == null) {
16                 InputStream bis = Platform.getBuiltinInputStream();
17                 ZipInputStream zis = new ZipInputStream(bis);
18                 for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("libmspack.mips"); ze = zis.getNextEntry()) { }
19                 byte[] image = InputStreamToByteArray.convert(zis);
20                 vm = new org.xwt.mips.Interpreter(image);
21                 vm.start(new String[]{ "libmspack.mips" });
22                 vm.execute();
23             }
24
25             int CAB_RESERVED = 256*1024;
26             int baseAddr = vm.sbrk(CAB_RESERVED);
27             
28             byte[] cabstream = InputStreamToByteArray.convert(theCabFile);
29             vm.copyout(cabstream, baseAddr, cabstream.length);
30             vm.setUserInfo(0, baseAddr);
31             vm.setUserInfo(1, cabstream.length);
32             
33             vm.execute();
34             // FIXME: do more stuff here
35
36         } catch (Exception e) {
37             Log.log(MSPack.class, e);
38         }
39     }
40 }