I went through this link
http://dc0d32.blogspot.in/2010/06/real- ... iting.html . To create a bootloader in C . The code works just fine . But when I try to load this bootloader code itself with my custom loader , the loading function is mentioned below .( by the linker script given in the link already, I get nothing , plain nothing man ). I just modified the addresses in the link to make the starting address of the linked C code as 0x2000 , so that it works, but it doesn't . I just cannot load anything which was initially written in C through the my bootloader , no matter what format they are in and how I link them. But i can load everything in assembly with the help of my bootloader. Also , I want to make the jump to C world in real mode only . So , no Pmode yet.
Can anybody please give me some link. Some sequence of commands to load a C file at memory location (0x2000) as a flat binary. So that , it would just run . I am writing the relevant code
Code: Select all
repeat_read:
;Code to load the second sector on the disk into memory location 0x2000:0x0000
mov bx, 0x2000 ; Segment location to read into (remember can't load direct to segment register)
mov es, bx
mov bx, 0 ; Offset to read into
mov ah, 02 ; BIOS read sector function
mov al, 01 ; read one sector
mov ch, 0 ; Track to read
mov cl, 02 ; Sector to read
mov dh, 0 ; Head to read
mov dl, 00 ; Drive to read
int 0x13 ; Make the BIOS call (int 13h contains mainly BIOS drive functions)
;Set up the data segment
jnc repeat_read_success
mov si , error_message
call print_string
ret
repeat_read_success:
mov si , kernel_loading_success
call print_string
;Set the data segment
mov ax , 0x2000
mov ds , ax
jmp 0x2000:0x0 ; Load at address 0x20000
Code: Select all
nasm -f bin -o main.bin main.asm (main.asm , just a dummy code which can print a string)
dd if=boot.bin of=floppy.img seek=1 count=1 bs=512 conv=notrunc (just load this binary at the second sector)
Code: Select all
SECTIONS
{
. = 0x20000;
.text : AT(0x20000)
{
_text = .;
*(.text);
_text_end = .;
}
.data :
{
_data = .;
*(.bss);
*(.bss*);
*(.data);
*(.rodata*);
*(COMMON)
_data_end = .;
}
/*
.sig : AT(0x2)
{
SHORT(0xaa55);
}
*/
/DISCARD/ :
{
*(.note*);
*(.iplt*);
*(.igot*);
*(.rel*);
*(.comment);
/* add any unwanted sections spewed out by your version of gcc and flags here */
}
}
I hope that the link script is correct. Please , tell me where i am correct. I cannot find the solution out. Woke up till late night , but still nothing makes sense.