printf doesn't work
printf doesn't work
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);
}
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
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
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
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!
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
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.
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
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?
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x00100000 : {
*(.text)
}
.data : {
*(.data)
}
.bss :
{
*(.bss)
}
}
Which script is better?
What is the video pointer address?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:printf doesn't work
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 !
i guess what you want to do is message++, which increments the pointer !
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:printf doesn't work
maybe you could also give us feedback on what actually displays on screen ...
Re:printf doesn't work
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...
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:printf doesn't work
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
(void*)(0xb8000 - GDT[CODESEL].base)
(provided that base is baselo+65536*baseme+65536*256*basehi, of course