aspose file tools*
The moose likes Java in General and the fly likes java OS? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java OS?" Watch "java OS?" New topic
Author

java OS?

Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204

Ok , I have been programming my own operating system from scratch with c and asm. Wrote my own bootloader.
changed my system from real mode to protected mode , setup interrupts , paging, TSS ,...etc etc
started writing kernel network nic drivers , VGA driver , ....etc

I can theoritically write an OS in pascal , or any other computer language that is compiled down to machine code.

What I am wondering is how you create an OS in java? I have seen these OS they exist.
Bascially I have to beable to compile the JVM into the kernel and pass it the java bytecode. ( I don't even know if this is the best way to go about it)

I don't know if their is any open source JVM that I can tweak so when I start my kernalMain function I can jump to some function of the JVM in memory passing it the bytecode.
Eitherway even if this is the way to go about it I don't know how I can convert the JVM to be a flat binary instead of dll ... I am just a little lost in what is the correct way to go about it.

Their are tools like gcj that compile java down to .exe file format but I would really need it to be a flat binary format....
something like nasm -f bin filename.asm would give me or something that a linker script FORMAT(BINARY) would do when passing it to ld.
With gcj I don't know if it allows linker scripts and compiling to bin. If their was a way to use gcj and compile/link to a bin then I could bypass the whole trying JVM issue above.

Thanks for any help
This is about as advanced as it gets so I don't except anybody to beable to answer it completely. But any help would be great.
Also If their is some way I can use the JNI as well since I need this to make calls to c and asm to do outb(0x60 or 0x64 ,...etc for the keyboard ,......and main other driver thing.
Things that asm or c can only do which is why I need the JNI as well.

I have used the JNI alot however I always had to create a dll or .so and load the library. My problem is can you use the JNI with out making a dll. The reason why I say that is I need a way from java to directly call a c function not be going thru a dll /loading a dll . .. my os is not that smart and and doesn't support dll, exe PE file format.
It only supports .com , a.out the simple exe file format nothing as complex as PE or ELF yet.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

Sam Doder wrote:What I am wondering is how you create an OS in java? I have seen these OS they exist.

Sun tried this: JavaOS but it looks like it's been abandoned. There's also an open source project JOS, but it looks like the project page hasn't been updated since 2007. There is also JNode.

Sam Doder wrote:I don't know if their is any open source JVM ...

Sun's Java is almost completely open source, see OpenJDK.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

gcj can cross-compile to just about anything.
Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
Ok well I found that with gcj I can just compile the java to elf .o file with this



this gives me MyJavaProg.o

In theory I should beable to create my linker script for my Os and add the MyJavaProg.o to the linker ld command
something like this should allow me to have a flat binary java based os in kernel mode

linker script example link.ld



Then just issue (as usual)


If that all works then I should beable to look at where the start method for a typical java exe file is and just call it from c or asm using extern "C" function to run the java code.
I can use objdump to look at what the mangled names is weather I have to call it with an _ or not ,...etc etc

QUESTION
I am curious now how the gcj command is actually compiling java to an exe file.
Is it compiling the JVM directly into the exe file and then passing the bytecodes to the compiled in JVM. (or compileing the java bytecodes somehow directly into the asm/c function equivalents)
Or is it just creating an exe which is just a program that calls the outside JVM passing the bytecodes to it (exactly like java.exe does to run a java .class file )
If it is the second case then gcj is no good because all it is really doing is renaming the java.exe file to something different and passing the bytecode internally.

Hopefully it is the first option above because that means I can use it for a java os. Because the first option would allow this exe to run on any machine even the ones that don't have a JVM installed.

Anybody that knows how gcj works please elaborate.
I believe it is the way I want it judging by the file size ...etc

Thanks for any help

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Did you consider looking at the gcj documentation? There's no JVM involved at all.
Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
So it must just convert the bytecodes into raw machine code. Basically it must do what the JVM does on the fly.

But now I am curious on how they actually convert the bytecodes into raw machine code.... I mean what is the equivalent...
Their must be a one to one corospondence between the bytecodes and a chunk of machine code for that bytecode...
(curious if their is some open source translation code or software that would allow me to see what the corresponding machine code for a bytecode instruction would be)

Well anyway I think it will all work out. And the ability to use java in an OS is pretty easy provided gcj doesn't have any quirks in it that I am not aware of.

I havn't went thru the documentation of gcj full yet....

I am just wondering now if they have the equivalent type of gcj command for different interpreted languages like python , ruby , perl so I can compile these into .exe files or elf o file as well?


Thanks
you guys have been a great help
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sam Doder wrote:(curious if their is some open source translation code or software that would allow me to see what the corresponding machine code for a bytecode instruction would be)

Well, there's gcj, OpenJDK (I don't know how much of the JIT is open), and Harmony, at the very least.
Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
I am also curious do they have a gcj that runs on windows.
I am currently on a linux machine but would like the ability to have the same gcj command on windows without having to install cwgin or some other emulated linux thing on windows.


As well it seems to work except I need some way to call c from java normally just use the JNI. But if I use this I have to create a dll,.so libarary. Is their anyway to call c function directly from java using no loadlibrary commands. Basically can native keyword be used exactly like extern in c. Because when I compile with gcj my java is really machine code but from the java code I need away to call back c/asm functions... If I use the JNI then that means I have depended libraries which for kernels / flat binary files is no good.

Wondering if their is away to copy or compile the JNI libraries / depend's into the kernel bin file.

This is my only problem dll,.so dependences.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java OS?
 
Similar Threads
Writing a JVM
creating dll
native keyword ?
JVM,JRE & PORTABILITY
debugging JNI application