Page 1 of 2
Printing text
Posted: Sun Sep 23, 2007 2:31 pm
by deathkillspt
Ok please bear with me, I have been struggling with this for about 2 days now. All i want to do is just print a string on the screen, I have my bootloader all setup and it boots me into pmode i then execute my kernel and try to print the string with this function:
Code: Select all
unsigned int prints(char *string)
{
char *memptr = (char *) 0xb8000;
while(*string!='0')
{
*memptr = *string;
memptr++;
string++;
*memptr = 0x17;
memptr++;
};
return(0);
};
and i call it like this:
I originally got this from a tutorial and it didnt work so i kept changing things and trying to figure it out but, i'm stuck now i have tried everything i can think of.
Please help me out with this, Thanks in advance, Deathkillspt.
Posted: Sun Sep 23, 2007 2:47 pm
by Craze Frog
It would be helpful if you told us what happened when you boot your kernel.
If you're compiling with gcc and then linking as binary the string will probably end up before the code, which isn't a good idea. To fix this you use a linker script.
Posted: Sun Sep 23, 2007 3:00 pm
by deathkillspt
oh yea i forgot that part, it's very strange when i boot it up it does in fact print but it prints an "S" and thats it. i have a clearscreen function and that works fine. so i don't know why this isn't working. and i am using a linker script and also using the gcc option -fwritable-strings, here is my linker script if it is of any help:
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100000 : {
*(.text)
}
.data : {
*(.data)
}
.bss :
{
*(.bss)
}
}
as i have been saying i'm farely new to this whole scene so i might have done some things wrong but i am trying!
Posted: Sun Sep 23, 2007 3:03 pm
by piranha
Shouldn't your while loop be:
Thats what I find on a skim of your code...
-JL
Posted: Sun Sep 23, 2007 3:11 pm
by deathkillspt
i already tried that, it doesn't make a difference, but thanks anyway.
Reply
Posted: Sun Sep 23, 2007 3:21 pm
by matias_beretta
'0' is a char (48)
you should put 0, that means the end of a string...
good luck
mati
Posted: Sun Sep 23, 2007 3:28 pm
by OrOS
C does it automaticly. prints("Hello"); IS rints("Hello" + '\0');
Posted: Sun Sep 23, 2007 4:57 pm
by deathkillspt
well i tried all of the above but still nothing has worked.
Posted: Sun Sep 23, 2007 5:21 pm
by frank
Add these to your linker script somewhere.
I think one of those is the section for strings.
Posted: Sun Sep 23, 2007 5:30 pm
by deathkillspt
frank wrote:Add these to your linker script somewhere.
I think one of those is the section for strings.
nope that didn't work either
Posted: Sun Sep 23, 2007 5:41 pm
by frank
Try doing objdump -h on your object file and looking for any section names you don't have in your linker script. Excluding .comment of course.
Posted: Sun Sep 23, 2007 5:46 pm
by deathkillspt
Code: Select all
kernel.o: file format coff-go32
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000000b0 00000000 00000000 000000b4 2**4
CONTENTS, ALLOC, LOAD, RELOC, CODE
1 .data 00000010 000000b0 000000b0 00000164 2**4
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 000000c0 000000c0 00000000 2**2
ALLOC
3 .comment 00000010 000000c0 000000c0 00000174 2**2
CONTENTS, DEBUGGING
nope it looks like it's all there.
hold on you said do a dump of your object file, but this function is in a separate video header file, could that be the problem? do i have to do some special thing if i'm calling this from a header file?
Posted: Sun Sep 23, 2007 5:56 pm
by frank
Do you have bochs? Maybe you could try stepping though the function in the debugger mode and checking to see if everything looks ok. Also maybe try this:
Code: Select all
char string[] = {'h', 'e', 'l', 'l', 'o', 0};
prints( string );
hold on you said do a dump of your object file, but this function is in a separate video header file, could that be the problem? do i have to do some special thing if i'm calling this from a header file?
EDIT:
I was saying do a dump of the object file that had the call to prints in it.
Posted: Sun Sep 23, 2007 5:59 pm
by deathkillspt
frank wrote:Do you have bochs? Maybe you could try stepping though the function in the debugger mode and checking to see if everything looks ok. Also maybe try this:
Code: Select all
char string[] = {'h', 'e', 'l', 'l', 'o', 0};
prints( string );
I did have bochs but i could never get it to work right it would always say >>PANIC<< and then something about the rom and bios. As of now i am testing on an old laptop, but i guess i could give bochs another shot, and i will try that.
EDIT: yes that is a dump of the object file that had the call to prints in it
EDIT 2:well this does work:
Code: Select all
char string[] = {'h', 'e', 'l', 'l', 'o', 0};
prints( string );
but why does that work and the other doesn't?
Posted: Sun Sep 23, 2007 6:20 pm
by frank
Well the answer is that there is nothing wrong with your prints function. Somehow the linker messes up the address of the string "Hello" but it works just fine with the address of string. This normally means that you are missing the section for strings in your linker script but it doesn't seem to be the problem this time. Okay one last thing to try, add .rdata to your linker script.