4

I am building a 16 bit operating system. But character array does not seem to work.

Here is my example kernel code:

asm(".code16gcc\n");
void putchar(char);

int main()
{
char *str = "hello";

putchar('A');
if(str[0]== 'h')
    putchar('h');

return 0;
}


void putchar(char val)
{

   asm("movb %0, %%al\n"  
       "movb $0x0E, %%ah\n" 
       "int $0x10\n"
      :
      :"m"(val)
     ) ;
}

It prints:

A

that means putchar function is working properly but

 if(str[0]== 'h')
        putchar('h');

is not working.

I am compiling it by:

gcc -fno-toplevel-reorder -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c
ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0

What should I do?

  • 2
    How in particular is it failing? What output or errors are you seeing? – Michael Ekstrand Apr 27 '10 at 14:52
  • It is giving output the character 'A'. That is the putchar('A') is working. But the putchar('h') is not working that means the condition in if statement fails. But I initialized str = "hello"; Then what is wrong? – brainbarshan Apr 27 '10 at 15:37
  • Could you try to print what is there, do a `putchar(str[0])` to see what you find. I did not look closely but you want to make sure that the initialization you think you did really worked right. Then we can diagnose the problems from what we see. – Ukko Apr 27 '10 at 17:14
  • putchar(str[0]) prints an arrow sign. Its a garbage value I think. – brainbarshan Apr 27 '10 at 18:06
  • Totally unrelated to your question, but in your environment I think you have to use -ffreestanding option for GCC. – Laurynas Biveinis Feb 04 '11 at 05:37

1 Answers1

1

Your data segment is probably not loaded in to the target. What are you doing after the link with your brand new kernel.bin file, which is in fact an elf file ?

Laurent G
  • 2,994
  • 1
  • 18
  • 10