Unable to find error in small boot loader program

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
avinashse
Posts: 2
Joined: Sat Sep 03, 2011 4:20 am

Unable to find error in small boot loader program

Post 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.. :(
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Unable to find error in small boot loader program

Post 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.
If a trainstation is where trains stop, what is a workstation ?
avinashse
Posts: 2
Joined: Sat Sep 03, 2011 4:20 am

Re: Unable to find error in small boot loader program

Post 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...
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: Unable to find error in small boot loader program

Post by chibicitiberiu »

Tibi,
Currently working on the Lux Operating System
Post Reply