Page 1 of 1
Printing to screen in C kernel
Posted: Fri Apr 22, 2005 2:47 pm
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.
Re:Printing to screen in C kernel
Posted: Fri Apr 22, 2005 4:50 pm
by Ushma
might we see the code to some of these functions?
Re:Printing to screen in C kernel
Posted: Sat Apr 23, 2005 7:31 am
by Pype.Clicker
Re:Printing to screen in C kernel
Posted: Fri Apr 29, 2005 5:43 am
by Farmer
This might help:
Make sure that "-fwriteable-strings" is included in your gcc compiler line in your makefile or whatever.
Re:Printing to screen in C kernel
Posted: Wed May 04, 2005 7:35 am
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...
Re:Printing to screen in C kernel
Posted: Wed May 04, 2005 9:36 pm
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
Re:Printing to screen in C kernel
Posted: Thu May 05, 2005 7:49 am
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.
Re:Printing to screen in C kernel
Posted: Thu May 05, 2005 2:18 pm
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 ??)
Re:Printing to screen in C kernel
Posted: Mon May 09, 2005 1:00 am
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.
Re:Printing to screen in C kernel
Posted: Mon May 09, 2005 1:18 am
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*
Re:Printing to screen in C kernel
Posted: Mon May 09, 2005 6:10 am
by Solar
Jeez, ain't I allowed
one little mistake?
You are right, of course.
Re:Printing to screen in C kernel
Posted: Tue May 10, 2005 9:22 am
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
Re:Printing to screen in C kernel
Posted: Tue May 10, 2005 10:52 am
by Pype.Clicker
You should find that on BareBones, on the FAQ.
Re:Printing to screen in C kernel
Posted: Tue May 10, 2005 2:03 pm
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.
Re:Printing to screen in C kernel
Posted: Wed May 11, 2005 4:58 am
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...