|
Cibyl
Describes cibyl
Cibyl is a programming environment and binary translator that allows compiled C programs to execute on J2ME-capable phones. Cibyl uses GCC to compile the C programs to MIPS binaries, and these are then recompiled into Java bytecode. Cibyl programs are regular compiled Java programs, and Cibyl therefore performs relatively well. Cibyl is an abbreviation of something, but only the C, meaning C has been fixed so far. With Cibyl, C programs can be ported to J2ME without switching language. It also allows C and Java code to be integrated in an easy and efficient way. The environment uses the GNU compiler tools (GCC and binutils) and should work in all environments which provide a GNU toolchain. There are three reasons why I want Cibyl. First, C is in my opinion a much better suited language for writing games than Java. Also, since I have a couple of old games written in C, I would like to port them to the J2ME environment without rewriting the entire games (which I have also done with Lessphun). The goal is to be able to get by without porting the game to ''another language''. Finally, I find it a nice intellectual past time which combines my favorite areas compilers, low-level programming and performance. TopicsThese pages contain information about how Cibyl works, how to build and run programs and reference usage of the tools. Simon's blog also contains journal entries about Cibyl internals.
Showcases
Short example program #include <javax/microedition/lcdui.h>
int main(int argc, char *argv[])
{
NOPH_GameCanvas_t canvas = NOPH_GameCanvas_get();
NOPH_Graphics_t graphics = NOPH_GameCanvas_getGraphics(canvas);
/* Select red pen, then draw a line */
NOPH_Graphics_setColor(graphics, 255,0,0);
NOPH_Graphics_drawLine(graphics, 10, 10, 50, 50);
NOPH_GameCanvas_flushGraphics(canvas);
return 0;
}Technology overviewCibyl is based on the beautiful MIPS1 instruction set and uses GCC for compiling C source. The MIPS instructions are not decoded and parsed during runtime, but instead recompiled into Java bytecode at build-time. The overhead should therefore be small and the goal is to achieve similar performance of code written in C to a native Java implementation. The API is called through special instruction encodings to get good efficiency. Cibyl also allows for semi-automatic generation of calls to native Java functionality. The technology used in Cibyl is very similar to that in NestedVM, which also recompiles MIPS binaries into Java .class-files although they are completely unrelated code-wise. '''Note''': I've seen somewhere on the web the statement that Cibyl ''predates'' NestedVM. This is ''not'' true, NestedVM came before Cibyl, but I was unaware of it until I had implemented quite a bit of Cibyl. The two projects are quite different, but I've tried to use good ideas from NestedVM whenever possible, and hope the same can be true in the other direction as well. Compiler technologyThe cibyl-mips2java compiler generates Java assembly for compilation with jasmin from the binary MIPS executable. Parts of the MIPS binary parser has been rewritten (into C++) from the Java MIPS emulator written for the topsy operating system. Some notes about the compilation:
Architectural modelThere are some simplifications of the MIPS instruction set employed in Cibyl. Only instructions accessible in userspace (i.e., no coprocessor updates etc) are allowed, and nop instructions generate no code. Cibyl stores the memory contents in an integer-vector and registers as local variables. The instructions are recompiled into Java bytecode which update the registers and memory contents directly.
System callsCibyl supports easy adaptation to different Cibyl APIs. Currently, subsets of the MIDP 2.0 and ANSI C APIs have been implemented. I will add functionality to the APIs as I go. The MIDP C API looks like typedef int NOPH_Sprite_t; ... NOPH_Sprite_t NOPH_Sprite_new_image(NOPH_Image_t image); NOPH_Sprite_t NOPH_Sprite_new_imageSize(NOPH_Image_t image, int width, int height); NOPH_Sprite_t NOPH_Sprite_new_sprite(NOPH_Sprite_t sprite); ... Integer handles are used to pass Java objects along. The cibyl-generate-c-header and cibyl-generate-java-wrappers tools goes through the syscall files and generates a C header and a Java class which defines the system calls and generates wrapper calls for the MIDP API. Help needed!Run the Cibyl test cases on your mobile phone: This is the easiest way of helping out - you don't even have to install Cibyl to do the tests! A partial list of things to be done in the development can be found below. ''Feel free to contribute these!''
DownloadCibyl is released under the GNU GPL and LGPL licenses. The tools (e.g., cibyl-mips2java) are released under GPL while the Java libraries are LGPL. Cibyl is managed on googlecode at http://cibyl.googlecode.com
ContactSimon KÃ¥gstöm is the author of Cibyl. Contact him at simon.kagstrom@gmail.com. He has a blog at http://simonkagstrom.livejournal.com, where he sometimes will post Cibyl stuff. |
Sign in to add a comment
I cant get the tests to work on my Motorola A1200i - my phone complains about permissions (and its a Linux phone!) I tried hacking the permissions but it didnt work either.
Also tried with a spare Nokia 2630 but it gave me a OutOfMemory? error... too bad. Cybil looks REAL cool.
Well, the test suite is really a kind of worst-case application - it's very big and tries to exercise pretty much all the APIs. You can always try a real application like Sarien (http://cibyl.googlecode.com/files/sarien-cibyl-3.jar), which might be easier to get running (although it wants pretty much memory)