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

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
wsx
Posts: 2
Joined: Fri Sep 30, 2011 11:29 am

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

Post 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 = .;
	}
}
Attachments
Kernel.tar.gz
(2.63 KiB) Downloaded 88 times
Last edited by wsx on Sat Oct 01, 2011 10:00 am, edited 2 times in total.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Why my Hello World don't boot?

Post 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 ;)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Why my Hello World don't boot?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: Why my Hello World don't boot?

Post 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.
If something looks overcomplicated, most likely it is.
wsx
Posts: 2
Joined: Fri Sep 30, 2011 11:29 am

Re: Why my Hello World don't boot?

Post 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 ;)
Post Reply