Printing text with C is showing weird screen.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Gigaboy
Posts: 20
Joined: Wed Aug 23, 2017 1:09 pm
Libera.chat IRC: #gigaboy
Contact:

Printing text with C is showing weird screen.

Post 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.
Gigaboy
simeonz
Member
Member
Posts: 360
Joined: Fri Aug 19, 2016 10:28 pm

Re: Printing text with C is showing weird screen.

Post 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.
User avatar
Gigaboy
Posts: 20
Joined: Wed Aug 23, 2017 1:09 pm
Libera.chat IRC: #gigaboy
Contact:

Re: Printing text with C is showing weird screen.

Post 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.
Gigaboy
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Printing text with C is showing weird screen.

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
simeonz
Member
Member
Posts: 360
Joined: Fri Aug 19, 2016 10:28 pm

Re: Printing text with C is showing weird screen.

Post 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. :)
Post Reply