Page 1 of 1

[SOLVED] Why my Hello World don't boot?

Posted: Fri Sep 30, 2011 11:38 am
by wsx
My Hello World don't boot (i use "qemu -kernel Kernel.bin")
Hi, excuse for italian comment but the code is simple:

Makefile

Code: Select all

SRC = src
INC = inc
BIN = bin
CC = gcc
LD = ld
NASM = nasm
INCLUDES = -I$(INC)
ARCHFLAGS = -m32
LDFLAGS = -melf_i386
NASMFLAGS = -f elf
CFLAGS = -Wall -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs

all: Kernel.o Loader.o Kvideo.o Kernel.bin

Loader.o: $(SRC)/Loader.asm
	$(NASM) $(NASMFLAGS) $(SRC)/Loader.asm -o $(BIN)/Loader.o

Kernel.o: $(SRC)/Kernel.c
	$(CC) -c $(SRC)/Kernel.c -o $(BIN)/Kernel.o $(CFLAGS) $(ARCHFLAGS) $(INCLUDES)

Kvideo.o: $(SRC)/Kvideo.c
	$(CC) -c $(SRC)/Kvideo.c -o $(BIN)/Kvideo.o $(CFLAGS) $(ARCHFLAGS) $(INCLUDES)

Kernel.bin: $(SRC)/Link.ld
	$(LD) $(LDFLAGS) -T $(SRC)/Link.ld -o $(BIN)/Kernel.bin $(BIN)/Loader.o $(BIN)/Kernel.o $(BIN)/Kvideo.o

clean: 
	rm -rf $(BIN)/*.o $(BIN)/*.bin $(SRC)/*~
Loader.asm

Code: Select all

global start
extern Kmain

start:
	call Kmain ;Chiamata al main del kernel
	cli
	hlt
Kernel.c

Code: Select all

#include "Kvideo.h"

void Kmain() //main del kernel
{
	KvideoClean();
	KvideoPrint("Hello World");
	for(;;); //Ciclo infinito
}
Kvideo.c

Code: Select all

#define VIDEO_POINTER 0xb8000 //Indirizzo della della memoria video (modalità testo colorato)
#define SCREEN_BYTE (80*25) //Byte totali della memoria video
#define COLOR 0x0700 //Grigio chiaro su sfondo nero

#include "Kvideo.h"

volatile unsigned int *videoMem = (volatile unsigned int *) VIDEO_POINTER;

void KvideoClean()
{
	unsigned int i = 0;
	//Ciclo che scrive spazi nella memoria video per cancellare tutto
	while(i < SCREEN_BYTE) 	{
		i++;
		videoMem[i] = COLOR | ' ';
	}
}

void KvideoWrite(char ch)
{
	//Scrive un carattere nella memoria video
	*videoMem = COLOR | ch;
}

void KvideoPrint(const char * string)
{
	//Itero la stringa e scrivo tutti i char nella memoria video
	while(*string != 0)
	{
		KvideoWrite(*string);
		string++;
	}
}
Kvideo.h

Code: Select all

void KvideoClean();
void KvideoWrite(char);
void KvideoPrint(const char *);
Link.ld

Code: Select all

ENTRY (start)

SECTIONS
{
	. = 0x00100000;

	.text :
	{
		*(.text)
	}

	.rodata ALIGN (0x1000) :
	{
		*(.rodata)
	}

	.data ALIGN (0x1000) :
	{
		*(.data)
	}

	.bss :
	{
		sbss = .;
		*(COMMON)
		*(.bss)
		ebss = .;
	}
}

Re: Why my Hello World don't boot?

Posted: Fri Sep 30, 2011 12:03 pm
by Karlosoft
You are assuming to be in protected mode, but have you already a bootloader? Otherwise you need to set up the protected mode from the real one ;)

Tu stai assumendo di essere in modalità protetta, ma hai già un bootloader? Altrimenti devi settare la modalità protetta da quella reale ;)

Re: Why my Hello World don't boot?

Posted: Fri Sep 30, 2011 3:04 pm
by Combuster
The -kernel option is intended for a linux kernel and generally does not do what you expect (which as far as forum history goes, includes not doing what the documentation says), so try to avoid it. And unless you want to stick with qemu forever, you'll have to learn to live without it at some point anyway.

Re: Why my Hello World don't boot?

Posted: Fri Sep 30, 2011 3:30 pm
by Velko
I do not see Multiboot header anywhere in your code.

Qemu's -kernel switch somewhat works with Multiboot compliant kernels, but it's not very reliable. Assuming you use recent enough Qemu, it should work with something this simple, however. But without Multiboot header it does $deity (and Qemu devs) knows what.

I'd suggest to switch to more stable bootloader, GRUB for example.

And when you'll finally get it to boot, it will print only single character 'd' in top-left corner of your screen. But I'll leave it up to you to figure out what's wrong with printing routines.

Re: Why my Hello World don't boot?

Posted: Sat Oct 01, 2011 8:47 am
by wsx
I wrote the multiboot header in Loader.asm and now go with qemu (-kernel option) or my grub (add this):

Code: Select all

title ZigzagOS
#home partition
root (hd0,1)
kernel wsx/ZigzagOS/Kernel/bin/Kernel.bin
Thanks to all ;)