Page 1 of 1

java OS continued?

Posted: Fri Jun 04, 2010 10:48 am
by Sam111
from this thread http://forum.osdev.org/viewtopic.php?f=1&t=22084

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 from time to time (i.e for device driver stuff , outportb ,...etc etc)... If I use the JNI then that means I have depended libraries which for kernels / flat binary files is no good.

I can go from c functions to java functions by using extern and using objdump to see what the java function name is to call
that gcj compiled to. But once I am in java code I need a way to call back c/asm code?

If their is no other way then creating a dll,.so and using the JNI interface then is their away to compile in all the dependenc's that JNI would bring so it is a standalone kernel.bin file that allows me to call c/asm from java?

This question is more general.
Is their away to compile in all the depence's lib's ,...etc into a single .exe or bin file so that it will run without having to load anything other then itself.... ???

If so then you could use the same method to compile in the whole c run time libraries ,...math , stdio ,...etc
I am aware that it will get huge very quickly but then you won't have to keep rewritting things like malloc ,...etc etc in your os

Could be as easy as specifying the library in the path to gcc right after --nolib's or nostandardincludes statement.
Always wondered if the kernel.bin would work if you add libraries to it.
I am always using the statement

Code: Select all

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c
to compile the code into object files

then I link with

Code: Select all

ld -T mylinkerscript.ld  code1.o code2.o ,...etc 
in the linker script I have it set to FORMAT binary so it ether has to compile/link everything in or fail to link all the libararies in...
does anybody know?

This is my only problem dll,.so dependences.

Re: java OS continued?

Posted: Fri Jun 04, 2010 12:47 pm
by fronty
Don't know about C. I checked GCJ's manual, it has nice chapter about calling C++ from Java code and vice versa with system somewhat similar to JNI (don't know how different it feels in use, I haven't ever used Java).

Re: java OS continued?

Posted: Fri Jun 04, 2010 1:40 pm
by Sam111
Ok can you provide a link to the specific things you are looking at/reading
Maybe their is some example of doing it thru gcj like you are speaking of with system....

However the method cann't rely on dll , or .so files.... I need to compile to .bin binary files.

If their is depenence's like libraries then that gets back to my question about compiling a dll into a binary file or exe ...
so it can be a standalone program and not depend one anything.

I get this is probably going to make my binary file large but I don't care.
The only thing I care about is it working and being standalone.

So what I post previously be the way to compile a dll into a binary.
I have always used the nonlibs switch when making my kernel but I am wondering if I included a library... being set to a binary in the linker script would that be enough to inform the linker it must physically copy into my kernel.bin any dependence functions in the .dll or .so files?

Thanks