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.
deathkillspt
Posts: 12
Joined: Sun Sep 23, 2007 2:22 pm
Location: Blairstown,NJ,USA

Post by deathkillspt »

I really don't know what to do, i've tried .rdata and it doesn't seem to be doing anything could you put an example of where to put that in please?

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text  0x100000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :
  { 					
    *(.bss)
  }
}
should i put it in it's own section or should i add it to one of the other one's? I am really sorry if i am being a pest, it's just that i have been trying so hard to figure out why it just won't work
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Your not a pest. I know how irritating something is when it doesn't work.

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text  0x100000 : {
    *(.text)
    *(.r*)
  }
  .data  : {
    *(.data)
  }
  .bss  :
  {                
    *(.bss)
  }
} 
try that one
deathkillspt
Posts: 12
Joined: Sun Sep 23, 2007 2:22 pm
Location: Blairstown,NJ,USA

Post by deathkillspt »

grr...It still just boots up and prints "S"
vhg119
Member
Member
Posts: 71
Joined: Fri Aug 24, 2007 5:56 pm
Location: CA, USA

Post by vhg119 »

deathkillspt wrote:grr...It still just boots up and prints "S"
The only problem I see is that your terminating condition is checking for the character '0' rather than '\0'.

I remember I had really strange printing problems also. It turned out that GCC's optimizations were messing everything up for whatever reason. Let us have a look at your cflags.

Vince
deathkillspt
Posts: 12
Joined: Sun Sep 23, 2007 2:22 pm
Location: Blairstown,NJ,USA

Post by deathkillspt »

How exactley would i get my "cflags"?
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

deathkillspt wrote:How exactley would i get my "cflags"?
Just tell us what you are passing to GCC and LD. cflags is the the makefile name for what options you pass to gcc.
deathkillspt
Posts: 12
Joined: Sun Sep 23, 2007 2:22 pm
Location: Blairstown,NJ,USA

Post by deathkillspt »

Code: Select all

gcc -c kernel.c -o kernel.o -fwritable-strings
ld -T link.ld -o kernel.bin stub.o kernel.o
iammisc
Member
Member
Posts: 269
Joined: Thu Nov 09, 2006 6:23 pm

Post by iammisc »

did you use -fwritable-strings with your gcc command?
deathkillspt
Posts: 12
Joined: Sun Sep 23, 2007 2:22 pm
Location: Blairstown,NJ,USA

Post by deathkillspt »

iammisc wrote:did you use -fwritable-strings with your gcc command?
Yes I did.
vhg119
Member
Member
Posts: 71
Joined: Fri Aug 24, 2007 5:56 pm
Location: CA, USA

Post by vhg119 »

deathkillspt wrote:

Code: Select all

gcc -c kernel.c -o kernel.o -fwritable-strings
ld -T link.ld -o kernel.bin stub.o kernel.o
This is mine... For some reason, the optimizations were screwing around with the loop that prints the strings.

Code: Select all

-Wall -O -floop-optimize2 -fno-builtin -nostdinc -I include -ffreestanding -c
I wish I knew exactly why I get the errors I get. But I don't. I do know that when I did an '-S' to see the assembly listing for gcc, things didn't look right.

Maybe that would be a good advice for you too. Add '-S' to your cflags and check out the assembly code it produces.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Code: Select all

gcc -c kernel.c -o kernel.o -fwritable-strings 
ld -T link.ld -o kernel.bin stub.o kernel.o
You must tell the compiler not to use it's standard library. If you don't, you'll end up with all sorts of crap in your executable and stuff that probably will make it die!

Add

Code: Select all

-nostdlib -nostdinc -fno-builtin -fno-stack-protector
To your gcc command. The last one is optional and doesn't work on some newer versions of gcc.
Mark139
Member
Member
Posts: 39
Joined: Mon Jan 15, 2007 2:32 pm

The loop

Post by Mark139 »

It does look like constant data is missing. Like the previous post I suspect the .rdata section.

Another point is the while is broken

Code: Select all

while(*string!='0')
Will loop until it sees the character zero, which has a value of 48 (if memory serves me correctly). You should have

Code: Select all

while(*string!= 0 )
or even

Code: Select all

while(*string)
Post Reply