Bootloader loaded at memory other than 0x7c00
Posted: Sat Dec 28, 2013 6:58 am
I made a simple boot loader that would just check for the first 'filled' memory location starting from 0x00 and show the next 512 bytes (which should be the 512 bytes of the bootloader).
Probably this first 'filled' memory should be the first byte of the bootloader where it is loaded. Traditionally a bootloader is loaded at 0x00007c00. But the program is outputting that the bootloader was loaded at 0x00.
How is this possible ? It gives the same result in a virtual machine (Virtual Box) as well as real machine. Please help. Also the program isn't executed if I use ORG 0x7C00 at line 2
Here is the bootloader :
Probably this first 'filled' memory should be the first byte of the bootloader where it is loaded. Traditionally a bootloader is loaded at 0x00007c00. But the program is outputting that the bootloader was loaded at 0x00.
How is this possible ? It gives the same result in a virtual machine (Virtual Box) as well as real machine. Please help. Also the program isn't executed if I use ORG 0x7C00 at line 2
Here is the bootloader :
Code: Select all
BITS 16
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax
mov si, text_string ; Put string position into SI
call print_string ; Call our string-printing routine
jmp find
jmp $ ; Jump here - infinite loop!
text_string db 'Ram contents from 0x7c0:0x0000 are : ', 0
ram_byte db 65
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
find:
mov cx,65535
mov edx,0
again:
mov al,[edx]
cmp al,0
jne print
inc edx
dec cx
cmp cx,0
jne again
hlt
print:
mov ah,0eh
mov cx,512
print_again: mov al,[edx]
int 10h
inc edx
dec cx
cmp cx,0
jne print_again
sub edx,512 ;Make edx equal to the loaction where it first found the non-zero byte
ror edx,24 ;
mov al,dl ;
int 10h ;
rol edx,8 ;
mov al,dl ;
int 10h ;
rol edx,8 ; Output the contentes of edx
mov al,dl ;
int 10h ;
rol edx,8 ;
mov al,dl ;
int 10h ;
jmp $ ; Jump here
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature