Page 1 of 1
printf doesn't work
Posted: Sun Oct 20, 2002 11:15 am
by Unexpected
Why this function doesn't work??
A loading kernel, but text doesn't printing...
Why?
unsigned int k_printf(char *message, unsigned int color, unsigned int line)
{
char *vidmem = ( char * ) 0xb8000;
unsigned int i = 0;
i = ( line * scrwidth * 2 );
while ( *message != 0 )
{
if ( *message == 0x2F )
{
*message++;
if ( *message == 0x6e )
{
line++;
i = ( line * scrwidth * 2 );
*message++;
if ( *message == 0 )
{
return( 1 );
};
};
*message--;
};
vidmem[ i ] = *message;
*message++;
i++;
vidmem[ i ]=color;
i++;
};
return(1);
}
Re:printf doesn't work
Posted: Sun Oct 20, 2002 12:26 pm
by Slasher
hi,
the problem could be in the way you linked your kernel and the selector base address in your data segments (es,ds)
if they base address in these registers are not zero based, then you have to subtract the base address from pointers to get to the right address.
eg
base address = 0x00000000 video pointer=0x000b8000 - 0x00000000
base address = 0x00004000 video pointer=0x000b8000 - 0x00004000
also in your linker script you need to specify the start address of your code in its full absolute adress form
ie
if you want to load your kernel at the 1mb mark you have to write (using gcc and ld)
eg
.text : .= 0x00100000 {
......
.......
.......
}
if you want to load your kernel at the 4000k mark you have to write (using gcc and ld)
eg
.text : .= 0x00004000 {
......
.......
.......
}
it would be a good idea for you to post your linker script
Re:printf doesn't work
Posted: Sun Oct 20, 2002 3:47 pm
by Unexpected
There is script:
ld -Ttext=0x1000 -o kernel kernel.o -e 0x0
I loading kernel to adress 0x1000:0x0000
So what I need to do?
Thnx very much!
Re:printf doesn't work
Posted: Sun Oct 20, 2002 3:55 pm
by Slasher
that's not a linker script, but command line settings
You have set the address for the code section but there isn't one for the data,bss etc sections. its best to use linker script.
read the gcc/ld info files and you will see an example linker script.
Re:printf doesn't work
Posted: Sun Oct 20, 2002 4:39 pm
by Unexpected
Is this good?
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x00100000 : {
*(.text)
}
.data : {
*(.data)
}
.bss :
{
*(.bss)
}
}
Which script is better?
What is the video pointer address?
Re:printf doesn't work
Posted: Tue Oct 22, 2002 6:24 am
by Unexpected
My printf still doesn't work
What can I do?
Re:printf doesn't work
Posted: Tue Oct 22, 2002 8:02 am
by Pype.Clicker
you're using *message++ to move forward in the string ? do you know what *message++ actually do is incrementing the character under *message (if i remember well from C operator precedence) ?
i guess what you want to do is message++, which increments the pointer !
Re:printf doesn't work
Posted: Tue Oct 22, 2002 8:04 am
by Pype.Clicker
maybe you could also give us feedback on what actually displays on screen ...
Re:printf doesn't work
Posted: Wed Oct 23, 2002 2:51 pm
by Ozguxxx
I think you are not remembering right Pype. Postfix operators (++, --) have the highest precedence so what *message++ will do is to return you value at address of unincremented pointer and then increment the pointer. Since you do not need a return value, only message++ will work but *message++ still works. (I think) If I am wrong I am sorry...
Re:printf doesn't work
Posted: Thu Oct 24, 2002 12:55 am
by Pype.Clicker
the video pointer address will depend on your code descriptor's base address. it should be
(void*)(0xb8000 - GDT[CODESEL].base)
(provided that base is baselo+65536*baseme+65536*256*basehi, of course