Page 1 of 1
printing text
Posted: Mon Jan 23, 2006 9:11 am
by oasix
hi there,
it just seems that i can't get a k-printf function to work.
i managed to display one character to the screen but when i go further and try to display a string well it just won't.
i would appretiate it if someone is willing to help or give me some kind of hint
.
kind regards oasix
Code: Select all
void k_printf(char *string, int colour)
{
char *video=(char*)0xB8000;
while(*string!=0)
{
*video=*string;
string++;
video++;
*video=colour;
video++;
}
}
in main:
void k_printf(char *string, int colour);
k_printf("hello, world!!", 0x07);
Re:printing text
Posted: Mon Jan 23, 2006 9:19 am
by Candy
This is a very common problem (stuff working, except when you use strings), usually caused by not including or linking .rodata (.gnuanything.rodata, .rdata or something like that) in the executable. Less common cases include setting wrong offsets or forgetting to load the bit of the executable that contains the actual string.
In some minor cases people have forgotten to map the memory they're writing to, have accidentally used a base segment or were expecting a 32-bit address to work normally in real-mode.
Since pretty much all of these common cases could apply and since we can't check many of then not knowing the rest of your environment, you might be able to check them yourselves.
We'd be interested in:
- Windows or other development platform (_-stuff)
- Compiler used (platform native, cygwin, djgpp, MSVC, Borland, crosscompiler)
- Build script (makefile)
- Link script (for this case especially this one)
Re:printing text
Posted: Mon Jan 23, 2006 10:24 am
by Pype.Clicker
This
troubleshooting page from the
FAQ might help you to guess what's wrong.
Re:printing text
Posted: Mon Jan 23, 2006 10:26 am
by oasix
hi,
thnx for your reply.
i'm developming my kernel in linux, and testing it with bochs.
here is mine link file.
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
as you can see i think that the problems lies in that there is no .rodata,
no i don't have a very good knowledge on linker scripts may there be some kind of article or tutorial on this?.
many thanks oasix
Re:printing text
Posted: Mon Jan 23, 2006 11:00 am
by oasix
hi there,
thanks a lot, i searched the web voor .rodata and i inserted it in my linker script and know it works. but i don't really understand the linker script.. if someone knows a good site that explains it would be great.
thanks a lot
greetings oasix
Re:printing text
Posted: Mon Jan 23, 2006 12:07 pm
by Candy
oasix wrote:
hi there,
thanks a lot, i searched the web voor .rodata and i inserted it in my linker script and know it works. but i don't really understand the linker script.. if someone knows a good site that explains it would be great.
thanks a lot
greetings oasix
You could start with the LD manpage and some example linker scripts plus loose descriptions of what they do. Lots of linker scripts have been posted to this forum in the past, with lots of criticism and comment on how they work, so you should be able to find them useful. Try searching for "linker".