Page 1 of 1

Kernel don't show anything.

Posted: Sat Jun 15, 2013 7:52 am
by Mikroe
I'm trying to run my simple kernel, but qemu doesn't show anything.

kernel.c

Code: Select all

int kmain(void){
    unsigned char *vidmem = (char*) 0xB8000;
    vidmem[0] = 65; // 'A' 
    vidmem[1] = 0x07; //whie text on black screen
}
boot.asm

Code: Select all

[global start]

start:
    extern kmain // _kmain caused error
    call kmain
    cli
    hlt

link.ld

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text  0x100000 : {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(4096);
  }
  .data  : {
    data = .; _data = .; __data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss  :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .; _end = .; __end = .;
}
Makefile

Code: Select all

all:
	gcc -c kernel.c -o kernel.o
	nasm -f aout boot.asm -o boot.o
	ld -T link.ld -o kernel.bin boot.o kernel.o
	qemu -kernel kernel.bin
But qemu don't show anything.

Any ideas?

Re: Kernel don't show anything.

Posted: Sat Jun 15, 2013 8:10 am
by xenos
This is a well-known problem with QEMU. When you use cli; hlt, the QEMU display freezes and is not updated anymore, and even things you wrote to the screen just before are not being shown. Try an endless loop instead of the cli; hlt.

Re: Kernel don't show anything.

Posted: Sat Jun 15, 2013 8:27 am
by sortie
You are making a huge number of mistakes. For instance, you don't set the stack before calling C code, you don't provide enough flags to gcc to tell it is building freestanding, you are not using a cross-compiler, you are casting to char* when you meant unsignd char*, and more.

I recommend you follow the osdev standard kernel tutorial: http://wiki.osdev.org/Bare_Bones

Re: Kernel don't show anything.

Posted: Sat Jun 15, 2013 1:16 pm
by Mikroe
Ok, I've rebuilt kernel with barebones(old are only kernel.c) but now Qemu is freezing on Booting from ROM...

Re: Kernel don't show anything.

Posted: Sat Jun 15, 2013 9:59 pm
by Mikemk
Why do you automatically assume that the bootloader is loading the image correctly? Also, are you using your system gcc or a cross gcc?

Re: Kernel don't show anything.

Posted: Sun Jun 16, 2013 12:46 am
by Mikroe
Something was wrong with my kernel.c
I've rewrote this and now works.

Thanks all.