Page 1 of 2

I cant print to screen :'(

Posted: Thu Aug 03, 2006 3:06 pm
by Lord_Coder
Hi all ,

i tried to create a simple minimalist kernel that works on protected mode , and i've created a function that should display string on screen by accessing the 0xb8000 adresse but it doesnt work , i tried all clues on the faq , but the problem is persisting .
Here's the C code of the mini kernel :

Code: Select all

#define VIDEOMEM 0xB8000

void print(char*);

int kernel_main(void)
{
   print("HELLO");
   while(1);
   return(0);
}

void print(char* string)
{
   unsigned char* fb = (unsigned char*) VIDEOMEM;
   char* ptr;
   ptr=string;
   while(*ptr!='\0'){
                *(fb++)=*(ptr++);
            *(fb++)=0x57;
   }
}
Its print S on the top of BOCHS's screen and not HELLO .
But *((int*)0xb8000)=0x07690748; works perfectly , i dont know why my function doesnt work !!!

Thanks .

PS : sorry , probably bad english :P .

Re:I cant print to screen :'(

Posted: Thu Aug 03, 2006 3:19 pm
by gaf
Hello,
chances are that you didn't include the rodata (read-only) section in your linker-script. As string literals are always constant, they get stored in this section:

Code: Select all

SECTIONS 
{ 
  .text : 
  { 
    *(.text) 
    *(.rodata*) 
  } 
  ... 
}
regards,
gaf

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 1:59 am
by Lord_Coder
gaf wrote: Hello,
chances are that you didn't include the rodata (read-only) section in your linker-script. As string literals are always constant, they get stored in this section:

Code: Select all

SECTIONS 
{ 
  .text : 
  { 
    *(.text) 
    *(.rodata*) 
  } 
  ... 
}
regards,
gaf
Thanks !
Its very interesting , but i cant use linker scripts , could you give me a tutorial ?

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 2:07 am
by Solar
Click on the "Mega-Tokyo.com" banner at the top to find the FAQ, and look for the BareBones tutorial.

You, too, are found guilty of not having honored the sticky thread "Quick Links - Read this before you post". 8)

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 2:29 am
by Lord_Coder
Sorry , the linker script on the Barebones tutorial doesnt work under Windows ( Mingw ) .
To compile my kernel , i use this :

Code: Select all

gcc -c -ffreestanding -nostdinc -mno-stack-arg-probe kernel.c
ld -i -e _kernel_main -Ttext 1000 -o tmp.o kernel.o
objcopy -R .note -R .comment -S -O binary tmp.o kernel.bin

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 3:02 am
by Lord_Coder
Could anyone help me ?

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 3:04 am
by Solar
Lord_Coder wrote: Sorry , the linker script on the Barebones tutorial doesnt work under Windows ( Mingw ) .
That is because, at the point of linking, you are still working on object files in PE format, not ELF. We recommend, especially for users working under Windows, to use a GCC cross-compiler for various reasons.

As for PE linker scripts, I have no experience with them. Any takers?

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 3:08 am
by Lord_Coder
So if i download a GCC Cross Compiler , it should be easy and i can simply use osfaq's compiling commands ?
I ill try to install with cygwin .

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 3:17 am
by Lord_Coder
Is there any binary package for cygwin ?

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 3:24 am
by Solar
For a cross-compiler? No. But if you look closely at the beginning of the BareBones tutorial, you'll find this line:

(It is assumed that you use a GCC Cross-Compiler for this.)

That's a tutorial for building a cross-compiler under Cygwin (or any other installation, for that matter). It's not as bad as it sounds. ;)

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 3:34 am
by Lord_Coder
K , thanks for your help !

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 4:36 am
by Lord_Coder
I followed the instructions to compile the binutils source package , the configure script works , but make failed !
Here's the error message :

Code: Select all

make[1]: *** [dummy.o] Error 1
make[1]: Leaving directory `/usr/src/build-binutils/libiberty'
make: *** [all-libiberty] Error 2

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 4:44 am
by Lord_Coder
I ill try make install ( instead of make all install ) .

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 4:48 am
by Lord_Coder
i tried make and make install , but nothing works , could anyone help me ?

Re:I cant print to screen :'(

Posted: Fri Aug 04, 2006 5:30 am
by Lord_Coder
Oops , i was using the 2.9 version instead of the 2.16.1 :P