printing text

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
oasix

printing text

Post 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);
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:printing text

Post 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)
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 text

Post by Pype.Clicker »

This troubleshooting page from the FAQ might help you to guess what's wrong.
oasix

Re:printing text

Post 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
oasix

Re:printing text

Post 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:printing text

Post 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".
Post Reply