Kernel don't show anything.

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.
Post Reply
Mikroe
Posts: 3
Joined: Sat Jun 15, 2013 6:36 am

Kernel don't show anything.

Post 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?
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Kernel don't show anything.

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Kernel don't show anything.

Post 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
Mikroe
Posts: 3
Joined: Sat Jun 15, 2013 6:36 am

Re: Kernel don't show anything.

Post by Mikroe »

Ok, I've rebuilt kernel with barebones(old are only kernel.c) but now Qemu is freezing on Booting from ROM...
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Kernel don't show anything.

Post 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?
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
Mikroe
Posts: 3
Joined: Sat Jun 15, 2013 6:36 am

Re: Kernel don't show anything.

Post by Mikroe »

Something was wrong with my kernel.c
I've rewrote this and now works.

Thanks all.
Post Reply