Page 1 of 1

Unable to find error in small boot loader program

Posted: Sat Sep 03, 2011 4:45 am
by avinashse
Hello Sir, I am using DELL laptop and with the help of QEMU, NASM and GCC i am trying to compile a simple code which is not executing properly. I am using UBUNTU 10.04.

here is the loader.asm assembly file.

Code: Select all

global 	loader
extern 	dmain
MODULEALIGN		equ 1<<0
MEMINFO 			equ 1<<1
FLAGS equ 	MODULEALIGN | MEMINFO
MAGIC  equ		0x1BADB002
CHECKSUM 	equ  -(MAGIC + FLAGS)
section .text
align 	4
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM


STACKSIZE 	equ 0x4000
loader:
mov 	esp, stack+STACKSIZE
push 	eax
push 	ebx


call dmain
cli


hang:
hlt
jmp hang


section .bss

align 	4

stack :

resb STACKSIZE
$nasm -f elf loader.o loader.asm

my c program kernel.c

Code: Select all

void dmain(void* mbd ,unsigned int magic)
{
	if(magic !=0x1BADB002)
	{
		clr();
		print("Error:Invalid Number",0xAF);
		
	}
	else
	{
		clr();
		print("Hello World",0xAF);
		
	}
}


void print(char* msg,int color)
{
	char* mem=(char*) 0xB8000;
	while(*msg !=0)
	{
		*mem=   *msg;
		mem++;
		msg++;
		*mem=(char*)  color;
		mem++;
	}
}

void clr(void)
{
	char* mem=(char*) 0xB8000;
	while(*mem !=0)
	{
		*mem = 0;
		mem++;
	}
}
$gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs

linker prorgram linker.ld

Code: Select all

ENTRY(loader)
SECTIONS{
	. =0x00100000 ;
	.text :{
		*(.text)
	}
	.rodata ALIGN (0x1000) :{
		*(.data)
	}
	.bss : {
		sbss =  .;
		*(COMMON)
		*(.bss)
		ebss = .;
	}
}
$ld -T linker.ld -o kernel.bin loader.o kernel.o

$qemu -kernel -kernel.bin

in the output part of QEMU , nothing is displayed. I tried to find error but i am not getting it, Its also not like that its not addressing video memory as in my output clr() is working and clearing the screen but print() is not working it should give output:- Error:Invalid Number.
I am not getting the error, Please help me out.. :(

Re: Unable to find error in small boot loader program

Posted: Sat Sep 03, 2011 5:00 am
by gerryg400

Code: Select all

cli


hang:
hlt
jmp hang
Don't do this. It does't work in QEMU. Change the CLI to STI.

Re: Unable to find error in small boot loader program

Posted: Sat Sep 03, 2011 11:53 am
by avinashse
berkus
You also didn't put .rodata/.rdata into your .rodata segment in linker script, chances are your text strings are not even output to the file.
sory sir, i am very new to this assembly language programming, I searched a lot in net to make this code , I am unable to understand what you are trying to say, please help me with the code and explanation.
waiting eagerly for the reply...

Re: Unable to find error in small boot loader program

Posted: Sat Sep 03, 2011 12:27 pm
by chibicitiberiu