I cant print to screen :'(

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.
Lord_Coder

I cant print to screen :'(

Post 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 .
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re:I cant print to screen :'(

Post 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
Lord_Coder

Re:I cant print to screen :'(

Post 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 ?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:I cant print to screen :'(

Post 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)
Every good solution is obvious once you've found it.
Lord_Coder

Re:I cant print to screen :'(

Post 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
Lord_Coder

Re:I cant print to screen :'(

Post by Lord_Coder »

Could anyone help me ?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:I cant print to screen :'(

Post 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?
Every good solution is obvious once you've found it.
Lord_Coder

Re:I cant print to screen :'(

Post 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 .
Lord_Coder

Re:I cant print to screen :'(

Post by Lord_Coder »

Is there any binary package for cygwin ?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:I cant print to screen :'(

Post 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. ;)
Every good solution is obvious once you've found it.
Lord_Coder

Re:I cant print to screen :'(

Post by Lord_Coder »

K , thanks for your help !
Lord_Coder

Re:I cant print to screen :'(

Post 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
Lord_Coder

Re:I cant print to screen :'(

Post by Lord_Coder »

I ill try make install ( instead of make all install ) .
Lord_Coder

Re:I cant print to screen :'(

Post by Lord_Coder »

i tried make and make install , but nothing works , could anyone help me ?
Lord_Coder

Re:I cant print to screen :'(

Post by Lord_Coder »

Oops , i was using the 2.9 version instead of the 2.16.1 :P
Post Reply