Page 1 of 1

Printing text with C is showing weird screen.

Posted: Fri Aug 25, 2017 2:44 pm
by Gigaboy
I'm trying to print text to the screen in C and whenever I run my OS with Qemu I get this image. I'm following this Github user and this PDF file for a tutorial. When I downloaded his files from github and ran his OS in Qemu I get the same result. The clear_screen() function works, I commented out the print functions and the screen is cleared. These are my files if you'll please check them out for me.
Image

EDIT: I've been messing with the code and I think it has something to do with getting and setting the offset.

Re: Printing text with C is showing weird screen.

Posted: Fri Aug 25, 2017 5:31 pm
by simeonz
If you are using 64 bit host to build, you need to pass -m32 to compiler, -m elf_i386 to the linker, -f elf32 to the assembler. After those fixes it works on my end.

Re: Printing text with C is showing weird screen.

Posted: Fri Aug 25, 2017 5:42 pm
by Gigaboy
simeonz wrote:If you are using 64 bit host to build, you need to pass -m32 to compiler, -m elf_i386 to the linker, -f elf32 to the assembler. After those fixes it works on my end.
Thanks that worked for me too.

Re: Printing text with C is showing weird screen.

Posted: Fri Aug 25, 2017 7:06 pm
by BrightLight
simeonz wrote:If you are using 64 bit host to build, you need to pass -m32 to compiler, -m elf_i386 to the linker, -f elf32 to the assembler. After those fixes it works on my end.
Actually, you (and the OP) should use a cross-compiler.

Re: Printing text with C is showing weird screen.

Posted: Fri Aug 25, 2017 8:13 pm
by simeonz
omarrx024 wrote:
simeonz wrote:If you are using 64 bit host to build, you need to pass -m32 to compiler, -m elf_i386 to the linker, -f elf32 to the assembler. After those fixes it works on my end.
Actually, you (and the OP) should use a cross-compiler.
You mean in order to get proper libgcc, or there are differences in the code generator? The object files that provide arithmetic functions in libgcc do not call into the platform. And the code generator I imagine should be agnostic. Or you mean as a principle, because any other use is unsupported officially?

Also, if a person decides to use C++ in the kernel, there is little chance to get correct platform agnostic i386 support for exceptions, because they need thread local storage to operate (i.e. to track the current exception during unwinding.) Which means you will have to get dirty with rewriting at least a small amount of internal functions.

P.S. I have a cross-compiler lying around. :)