Help with text in pmode

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
dhacker14
Posts: 3
Joined: Wed Sep 06, 2006 6:44 pm
Location: walker, LA
Contact:

Help with text in pmode

Post by dhacker14 »

OK i followed all instructions in the mega-tokyo.com osfaq and the osdever.net a simple c kernel, and it will not work on any of my computers it prints only 4 to 5 chars and on what i wanted my exact string, only one of the 5 of them, was "Pleaz wait booting....DONE!" it put the paragraph and pi simbly withe =. can anyone help me out. :?:
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Post by matthias »

Some code could help us help you ;)
The source of my problems is in the source.
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Post by hailstorm »

Well, at least you got something on screen! :D
But just like Matthias wrote, we need some more info to help you out.

Greetz.
dhacker14
Posts: 3
Joined: Wed Sep 06, 2006 6:44 pm
Location: walker, LA
Contact:

Post by dhacker14 »

here is my code:

Code: Select all


K_main()
{
	k_print(0x07, “Hello Booting....Done”);
	for(;;);
}
k_print(int colour, char *string)
{
       char *video=(char*)0xB8000;
       while(*string!=0)
       {
             *video=*string;
              string++;
              video++;
              *video=colour;
               video++;
        }
}
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Post by hailstorm »

I don't see any direct problems with your code... What does your datasegment descriptor look like?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Post by bubach »

whats up with the ” ? is that really a " ?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post by gaf »

You did include rodata in your linker-script ?

Code: Select all

SECTIONS 
{ 
    .text 0xDEADBEEF : 
    { 
        *(.text) 
        *(.rodata*) 
    } 

    .data : 
    { 
        *(.data) 
    } 

    .bss : 
    { 
        *(.bss*) 
        *(.comment*) 
    } 
}
cheers,
gaf
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Post by hailstorm »

@Buback: It probably compiles, so that can't be the problem (I think :) )
@Gaf:
What does that extra statement do exactly?

I shall try to explain why I ask this. Since I first compiled my kernel, I was always using the following compiler option: "-fwritable-strings", to make sure that all strings were included in the data section, instead of the code section. Cause, before I did this, I passed a string and only the offset was passed to the called function. The called function however, thought that this offset was related to the data segment and the only thing I got was garbage on screen, just like dhacker14 does.

If this is resolving that problem I had, I would sure like to know more about this .rodata section...

Sorry for this long and boring story... :wink:
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post by gaf »

The rodata section (read-only data) includes all constant global data that the executable uses. As string literals are constant by definition, they also get put into this section. If your linker-script doesn't include the rodata section, the linker can't add the strings to the binary and all strings pointers are invalid. The garbage that does get printed is just some data/code that happends to be at the wrong place at the wrong time..
If this is resolving that problem I had..
It solves 9 out of 10 problems related to string output. I actually already thought about putting it into my signature ;)

regards,
gaf
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Post by hailstorm »

Oke, so far I get it... But what about passing strings to other routines? Since strings get included in the text section, can I be sure that the subroutines I call also assume that const char * (is this allowed?) or char * can be found in the text section / code segment?

Thanks for your answer.
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post by gaf »

I actually assumed a flat memory model as virtually all modern operating systems use it. If you're planning to use segmention it might however indeeed by a good idea to put rodata in the regular data-section.

regards,
gaf
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Post by hailstorm »

Basically, I am not sure yet whether I use full segmentation or a flat memory model (paging only). But, since my kernel will use code segment and data segment, I need the strings to be in the data segment (just because pointers are always offsets to the dseg).

But thanks anyways, I can die happy now. :lol:
I wasn't beware of that option and you teached me.
Thnx dude! 8)
dhacker14
Posts: 3
Joined: Wed Sep 06, 2006 6:44 pm
Location: walker, LA
Contact:

didnt help

Post by dhacker14 »

I put in all the things i didnt have in the link.ld file, but the output was:

' }

any other ideas?
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Post by hailstorm »

Well, you could try the following:

- Look at your datasegment. If you are in protected mode, make sure that the datasegment you are writing to for screen output has base 0. In real mode your code should actualy work.
- Try to put .rodata in your data section. Memory operations are always executed on ds/es. If your string is included in code section (cs), than your string can never be found in ds...

Hope this helps...
Post Reply