Printing to screen in C kernel

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
TheUnbeliever

Printing to screen in C kernel

Post by TheUnbeliever »

I have four declarations: colour attributes, text memory pointer and cursor x and y co-ords at the start of my scrn.c (following this tutorial: http://osdever.net/bkerndev/index.php?the_id=90, with some very minor changes). The pointer is just a declaration, it's set to point to 0xB8000 in a function called VidInit which is called from the main kernel. This does:

Code: Select all

txtptr = (unsigned short *)0xB8000;
clear();
/* Clear, unsurprisingly, clears the screen
The main then calls the putstr() function to write a little welcome string to the screen.

Unfortunately, in bochs and on real hardware, it runs fine without crashing, but nothing changes on the screen. I'm not entirely certain what's happening...

Sorry for the fountain of questions. :(
Ushma

Re:Printing to screen in C kernel

Post by Ushma »

might we see the code to some of these functions?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Printing to screen in C kernel

Post by Pype.Clicker »

does The FAQ help ?
Farmer

Re:Printing to screen in C kernel

Post by Farmer »

This might help:
Make sure that "-fwriteable-strings" is included in your gcc compiler line in your makefile or whatever.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Printing to screen in C kernel

Post by Solar »

Missed this before: As of GCC 4.x, -fwriteable-strings is no longer supported. You might want to add the (.rodata) to your linker script...
Every good solution is obvious once you've found it.
proxy

Re:Printing to screen in C kernel

Post by proxy »

since this is a frequent poor solution many new people try to use, perhaps the wiki shoudl be updated to give the better more proper solution of adding the rodata section instead of -fwritable-strings?

proxy
mystran

Re:Printing to screen in C kernel

Post by mystran »

-fwritable-strings is evil indeed, and should not be used as a workaround for bad linker script. Just include both .text and .rodata in your .text segment and that's it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Printing to screen in C kernel

Post by Pype.Clicker »

well, -fwritable-strings is hardly evil in kernel environment! it's useful in user-level since your OS enforces .text is not writable, but who around here has disabled write access to .text and .rodata within the kernel ?

btw, imho, GCC 4.x still has to proove it can be used without a box of aspirin aside of it (damn'. they changed everything again ??)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Printing to screen in C kernel

Post by Solar »

Unfortunately, there are those tools who don't have to prove anything to be "accepted" by the general public. If Emacs and vi hadn't been around for ages already, no-one would touch them at arm's length. Same with GCC. They released it, it will be used, 3.x will become unsupported some day, people have to cope. It's a bit like Microsoft. ;)
Every good solution is obvious once you've found it.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Printing to screen in C kernel

Post by distantvoices »

Gonna see how the gcc 4.0 line compiles. Just to take care: *hands a biiig box of aspirin to Pype*

btw, Solar: doesn't one use "which" if refering to things and "who" if refering to persons? I'm just not sure for my english lessons are sooooo long ago *chuckle*
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Printing to screen in C kernel

Post by Solar »

Jeez, ain't I allowed one little mistake? 8) You are right, of course.
Every good solution is obvious once you've found it.
TheUnbeliever

Re:Printing to screen in C kernel

Post by TheUnbeliever »

Thanks guys for all the help. What should an example .rodata section look like in my linker script? Sorry for so many questions, I've barely ever used GCC, LD etc. (Yes, okay, I'm a Windows guy in experience.) ;D
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Printing to screen in C kernel

Post by Pype.Clicker »

You should find that on BareBones, on the FAQ.
TheUnbeliever

Re:Printing to screen in C kernel

Post by TheUnbeliever »

Thanks, I've now got:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    . = ALIGN(4096);
  }
  .data : AT(phys + (rodata - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}


as my linker script, and for the sake of attempting to keep things tidy, my code is all as shown on the site.

If I use the above linker script, I get the multiboot kludge header as I should, then the screen clears and I get a (non-flashing) cursor in the top left of the screen. So that's two steps in the right direction - the third would be nice - printing the hello world message.

If I switch the .data section to a .rodata section, I get the multiboot kludge header then the clear screen, but no cursor, flashing or otherwise. That's just the one step in that direction.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Printing to screen in C kernel

Post by Pype.Clicker »

i suggest you check the script has done what you wish with "objdump -h <final elf file>" ... i'm unsure about the use of 'phys' for binary files either...

keep in mind that there may be more than ".rodata" (gcc 3.x splits strings between .rodata and .rodata-32 or something) which is the purpose of "(.rodata*)" in scripts...
Post Reply