[SOLVED] Why my Hello World don't boot?
Posted: Fri Sep 30, 2011 11:38 am
My Hello World don't boot (i use "qemu -kernel Kernel.bin")
Hi, excuse for italian comment but the code is simple:
Makefile
Loader.asm
Kernel.c
Kvideo.c
Kvideo.h
Link.ld
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)/*~
Code: Select all
global start
extern Kmain
start:
call Kmain ;Chiamata al main del kernel
cli
hlt
Code: Select all
#include "Kvideo.h"
void Kmain() //main del kernel
{
KvideoClean();
KvideoPrint("Hello World");
for(;;); //Ciclo infinito
}
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++;
}
}
Code: Select all
void KvideoClean();
void KvideoWrite(char);
void KvideoPrint(const char *);
Code: Select all
ENTRY (start)
SECTIONS
{
. = 0x00100000;
.text :
{
*(.text)
}
.rodata ALIGN (0x1000) :
{
*(.rodata)
}
.data ALIGN (0x1000) :
{
*(.data)
}
.bss :
{
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}