String 16 bit os - character array not working

I am creating a 16-bit operating system. But the character array doesn't 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) ) ; } 

He prints:

 A 

means putchar function is working fine, but

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

does not work.

I compile it:

 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?

+4
source share
1 answer

Your data segment is probably not loaded on target. What do you do after linking with your new kernel.bin file, which is actually an elf file?

+1
source

Source: https://habr.com/ru/post/1308142/


All Articles