# Special treatment:
#
-builtin_src := $(find src/org/xwt/builtin)
-build/res/resources.jar: $(builtin_src:src/%=build/res/%) build/res/freetype.mips
+builtin_src := $(shell find src/org/xwt/builtin -name '*.*')
+build/res/builtin.jar: $(builtin_src:src/%=build/res/%) build/res/freetype.mips
@echo -e "\n\033[1mzipping res/* -> .jar: builtin.jar\033[0m"
cd build/res; $(jar) cf builtin.jar $(^:build/res/%=%)
# having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
gcj: .vendor .install_gcc-3.3_$(target) $(target_bin)
-build/JVM/xwt.jar: $(java_sources:build/java/%.java=build/class/%.class)
+build/JVM/xwt.jar: $(java_sources:build/java/%.java=build/class/%.class) build/res/builtin.jar
@echo -e "\n\033[1marchiving .class -> .jar: build/JVM/xwt.jar\033[0m"
mkdir -p build/JVM
echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
- cd build/class; $(jar) cfm ../JVM/xwt.jar ../JVM/.manifest `find .`;
+ cd build/class/org/xwt; ln -sf ../../../res/builtin.jar
+ cd build/class; $(jar) cfm ../JVM/xwt.jar ../JVM/.manifest `find . \! -type d`;
build/res/freetype.mips: build/mips/org/xwt/translators/Freetype.c.o build/mips/org/xwt/mips/crt0.c.o build/mips/org/xwt/mips/syscalls.c.o
make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
@echo -e "\n\033[1mlinking .o -> .mips: $@\033[0m"
- mkdir -p build/mips
+ mkdir -p build/mips build/res
upstream/install/bin/mips-unknown-elf-gcc \
-nostdlib \
--static \
/** returns an InputStream to the builtin xwar */
protected InputStream _getBuiltinInputStream() {
- try {
- return new FileInputStream("builtin.xwar");
- } catch (Exception e) {
- Log.log(this, e);
- return null;
- }
- //return this.getClass().getClassLoader().getResourceAsStream("org/xwt/builtin.xwar");
- }
-
- /** returns an InputStream to the builtin xwar */
- protected InputStream _getFreetypeInputStream() {
- try {
- return new FileInputStream("freetype.mips");
- } catch (Exception e) {
- Log.log(this, e);
- return null;
- }
- //return this.getClass().getClassLoader().getResourceAsStream("org/xwt/freetype.mips");
+ return this.getClass().getClassLoader().getResourceAsStream("org/xwt/builtin.jar");
}
/** returns the value of the environment variable key, or null if no such key exists */
/** returns an InputStream to the builtin xwar */
public static InputStream getBuiltinInputStream() { return platform._getBuiltinInputStream(); }
- /** returns an InputStream to the freetype mips binary */
- public static InputStream getFreetypeInputStream() { return platform._getFreetypeInputStream(); }
-
/** creates and returns a picture */
public static Picture createPicture(ImageDecoder i) { return platform._createPicture(i.getData(), i.getWidth(), i.getHeight()); }
public final InputStream getInputStream() throws IOException { return getInputStream(""); }
public Res graft(Object newResource) { throw new JS.Exn("cannot graft onto this resource"); }
- public Object get(Object key) { return new Ref(this, key); }
+
+ private Hash refCache = null;
+ public Object get(Object key) {
+ Object ret = refCache == null ? null : refCache.get(key);
+ if (ret != null) return ret;
+ ret = new Ref(this, key);
+ if (refCache == null) refCache = new Hash();
+ refCache.put(key, ret);
+ return ret;
+ }
+
public void put(Object key, Object val) { throw new JS.Exn("cannot put to a resource"); }
public Object[] keys() { throw new JS.Exn("cannot enumerate a resource"); }
import java.io.*;
class ELF {
- private MyRandomAccessFile fd;
+
+ private DataInput fd;
+ private Object image;
+ private void seek(long l) throws IOException {
+ if (image instanceof RandomAccessFile) {
+ ((RandomAccessFile)image).seek(l);
+ } else if (image instanceof byte[]) {
+ ByteArrayInputStream bais = new ByteArrayInputStream((byte[])image);
+ bais.skip(l);
+ fd = new DataInputStream(bais);
+ }
+ }
public ELFHeader header;
public PHeader[] pheaders;
private boolean sectionReaderActive;
+ private static void skipFully(DataInput fd, int n) throws IOException {
+ while(n>0) n -= fd.skipBytes(n);
+ }
+
public class ELFHeader {
byte klass;
byte data;
if(fd.readInt() != ELF_MAGIC) throw new ELFException("Bad Magic (is: " );
klass = fd.readByte();
data = fd.readByte();
- fd.skipFully(1); // version
+ skipFully(fd, 1); // version
osabi = fd.readByte();
abiversion = fd.readByte();
- fd.skipFully(7);
+ skipFully(fd, 7);
type = fd.readShort();
machine = fd.readShort();
version = fd.readInt();
}
}
- public ELF(String file) throws IOException, ELFException {
- fd = new MyRandomAccessFile(file,"r");
+ public ELF(Object img) throws IOException, ELFException {
+ image = img;
+ seek(0);
header = new ELFHeader();
pheaders = new PHeader[header.phnum];
for(int i=0;i<header.phnum;i++) {
- fd.seek(header.phoff+i*header.phentsize);
+ seek(header.phoff+i*header.phentsize);
pheaders[i] = new PHeader();
}
sheaders = new SHeader[header.shnum];
for(int i=0;i<header.shnum;i++) {
- fd.seek(header.shoff+i*header.shentsize);
+ seek(header.shoff+i*header.shentsize);
sheaders[i] = new SHeader();
}
if(header.shstrndx < 0 || header.shstrndx >= header.shnum) throw new ELFException("Bad shstrndx");
- fd.seek(sheaders[header.shstrndx].offset);
+ seek(sheaders[header.shstrndx].offset);
byte[] a = new byte[sheaders[header.shstrndx].size];
fd.readFully(a);
for(int i=0;i<header.shnum;i++) {
public class ELFException extends IOException { ELFException(String s) { super(s); } }
- private class MyRandomAccessFile extends RandomAccessFile {
- MyRandomAccessFile(String f,String m) throws IOException { super(f,m); }
- public void skipFully(int n) throws IOException {
- while(n>0) n-= skipBytes(n);
- }
- }
-
private class SectionInputStream extends InputStream {
private int pos;
private int maxpos;
throw new IOException("Section reader already active");
sectionReaderActive = true;
pos = start;
- fd.seek(pos);
+ seek(pos);
maxpos = end;
}
private int bytesLeft() { return maxpos - pos; }
- public int read() throws IOException { if(bytesLeft()==0) return -1; int b = fd.read(); if(b >= 0) pos++; return b; }
+ public int read() throws IOException {
+ if(bytesLeft()==0) return -1;
+ try {
+ byte b = fd.readByte();
+ pos++;
+ return b;
+ } catch (EOFException e) {
+ return -1;
+ }
+ }
public int read(byte[] b, int off, int len) throws IOException {
- int n = fd.read(b,off,Math.min(len,bytesLeft())); if(n > 0) pos += n; return n;
+ fd.readFully(b, off, len);
+ return len;
}
public void close() { sectionReaderActive = false; }
}
private int nextPC;
// The filename if the binary we're running
- private String image;
+ private Object image;
// Register Operations
private final void setFC(boolean b) { fcsr = (fcsr&~0x800000) | (b ? 0x800000 : 0x000000); }
}
// Image loading function
- void loadImage(String file) throws IOException {
- ELF elf = new ELF(file);
+ void loadImage(Object file) throws IOException {
+ ELF elf = null;
+ if (file instanceof String) elf = new ELF(new RandomAccessFile((String)file,"r"));
+ else if (file instanceof byte[]) elf = new ELF((byte[])file);
if(elf.header.type != ELF.ELFHeader.ET_EXEC)
throw new IOException("Binary is not an executable");
if(elf.header.machine != ELF.ELFHeader.EM_MIPS)
}
public Interpreter() { }
public Interpreter(String image) throws IOException { loadImage(image); }
+ public Interpreter(byte[] image) throws IOException { loadImage(image); }
// Debug functions
// NOTE: This probably requires a jdk > 1.1, however, it is only used for debugging
String line;
if(image==null) return null;
try {
- Process p = Runtime.getRuntime().exec(new String[]{addr2line,"-e",image,toHex(pc)});
+ Process p = Runtime.getRuntime().exec(new String[]{addr2line,"-e",image.toString(),toHex(pc)});
line = new BufferedReader(new InputStreamReader(p.getInputStream())).readLine();
if(line == null) return null;
while(line.startsWith("../")) line = line.substring(3);
#include <org/xwt/util/Semaphore.h>
#include <stdlib.h>
+#include <objc/objc.h>
#include "DarwinCarbonHeaders.h"
rect.top = 0; rect.left = 0; rect.bottom = 10; rect.right=10;
r = CreateNewWindow(wc,attr,&rect,&window);
checkStatus(r,"CreateNewWindow");
+
+ id NSWindowClass = objc_getClass("NSWindow");
+ printf("nswindowclass is %x\n", NSWindowClass);
+ SEL selector = sel_registerName("initWithWindowRef");
+ printf("selector is %s\n", selector);
+ objc_method method = class_getClassMethod(NSWindowClass, selector);
+ printf("method is %x\n", method);
+ id windowInstance = objc_msgSend(NSWindowClass, selector, window);
+ printf("instance is %x\n", windowInstance);
GCJ$Retainer::retain(this); // Need to account for the EventHandlers pointer to us
EventHandlerUPP upp = NewEventHandlerUPP(our_windowEventHandler);
// builtin.xwar /////////////////////////////////////////////////////////
-extern unsigned char builtin_xwar[];
-extern int builtin_xwar_length;
+extern unsigned char builtin_bytes[];
+extern int builtin_length;
java::io::InputStream* org::xwt::plat::GCJ::_getBuiltinInputStream() {
- jbyteArray ret = JvNewByteArray(builtin_xwar_length);
- memcpy(elements(ret), builtin_xwar, builtin_xwar_length);
+ jbyteArray ret = JvNewByteArray(builtin_length);
+ memcpy(elements(ret), builtin_bytes, builtin_length);
return new java::io::ByteArrayInputStream(ret);
}
-
-
-// freetype.mips /////////////////////////////////////////////////////////
-
-extern unsigned char freetype_mips[];
-extern int freetype_mips_length;
-
-java::io::InputStream* org::xwt::plat::GCJ::_getFreetypeInputStream() {
- jbyteArray ret = JvNewByteArray(freetype_mips_length);
- memcpy(elements(ret), freetype_mips, freetype_mips_length);
- return new java::io::ByteArrayInputStream(ret);
-}
-
protected org.xwt.Weak _getWeak(Object o) { return new Java2Weak(o); }
protected native InputStream _getBuiltinInputStream();
- protected native InputStream _getFreetypeInputStream();
private static class Java2Weak extends java.lang.ref.WeakReference implements org.xwt.Weak {
public Java2Weak(Object o) { super(o); }
import org.xwt.*;
import org.xwt.util.*;
import java.io.*;
+import java.util.zip.*;
// FEATURE: use streams, not memoryfont's
// FEATURE: kerning pairs
public static synchronized void renderGlyphs(Res res, int pointsize, int firstGlyph, int lastGlyph, Cache glyphCache) {
try {
+
if (vm == null) {
- vm = new org.xwt.mips.Interpreter("freetype.mips");
- vm.start(new String[]{ "freetype.mips"});
+
+ InputStream bis = Platform.getBuiltinInputStream();
+ ZipInputStream zis = new ZipInputStream(bis);
+ for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry());
+ byte[] image = Resources.isToByteArray(zis);
+ vm = new org.xwt.mips.Interpreter(image);
+ vm.start(new String[]{ "freetype.mips" });
vm.execute();
}