bootloader does not seem to work
Posted: Sat Apr 30, 2016 11:06 pm
OSDEV POST:
I have been away from my project for about 3 months and started resuming on the bootloader.
Basically I have 3 file:
copyraw.exe - copies boot.bin to mbr (without overwriting p-table) and copies exp.exe below to sector 1 and so on.
boot.bin - bootloader that is less than 512 bytes.
exp.exe - actual executable that is loaded by bootloader.
Initially no concern regarding the FAT, it is all raw stuff.
To prove the bootloader is loaded successfully to 7c00h, i put small snippet to printed chars starting from 0 incrementing by 2 10 times (02468... ) to beginning of video buffer area b800h This part works.
After that boot loader should copy exp.exe file starting from sector 1 to 8000h and subsequent sectors to 8200h and so on.
The exp.exe starts with printing ABCD... 10h times to video buffer area b820h. This is where it does not seem to work anymore which I am still checking.
I have been away from my project for about 3 months and started resuming on the bootloader.
Basically I have 3 file:
copyraw.exe - copies boot.bin to mbr (without overwriting p-table) and copies exp.exe below to sector 1 and so on.
boot.bin - bootloader that is less than 512 bytes.
exp.exe - actual executable that is loaded by bootloader.
Initially no concern regarding the FAT, it is all raw stuff.
To prove the bootloader is loaded successfully to 7c00h, i put small snippet to printed chars starting from 0 incrementing by 2 10 times (02468... ) to beginning of video buffer area b800h This part works.
After that boot loader should copy exp.exe file starting from sector 1 to 8000h and subsequent sectors to 8200h and so on.
The exp.exe starts with printing ABCD... 10h times to video buffer area b820h. This is where it does not seem to work anymore which I am still checking.
Code: Select all
.
;boot.asm
686p
include macros.inc
; re-defined the part of disk.inc here so that no need to include
; disk.asm,
DAP_OFFSET_SIZE = 0
DAP_OFFSET_UNUSED = 1
DAP_OFFSET_NO_SECTORS = 2
DAP_OFFSET_BUFFER_PTR = 4
DAP_OFFSET_SECTOR_START = 8
sta segment para stack use16 'stack'
sta ends
data segment para public 'data'
data ends
code segment para public use16 'code'
assume cs:code, ds:data,ss:sta
M_EXTERNDEF
; code to be copied to 1st sector of HDD.
; this code will do a boot strap by copying main program into another
; program and will do a jmp.
; the size of this function must be less than 512 bytes in order to
; fit onto 1st sector.
main proc far
; Print a series of char into screen buffer, to verify this code has been reached
; and been executed by a processor.
mov si, 0b800h
mov ds, si
sub si, si ; (DS:SI) = video buffer.
mov cx, 10h ; display 80 times.
mov ax, 0e30h ; char to display byte1: color, byte2: char 0.
loop1:
mov ds:[si], al
inc al ; (AL) = next digit.
cmp al, 39h ; reset to 0 if 9
jb @f
mov al, 30h
@@:
add si, 2 ; (SI) = next char.
loop loop1
mov dl, 80h ; disk 0
mov si, 7e00h ;
mov ds, si
sub si, si ; (DS:SI) = 0000:7e00h = DAP area.
mov byte ptr ds:[si+DAP_OFFSET_SIZE], 10h
mov byte ptr ds:[si+DAP_OFFSET_UNUSED], 00h
mov word ptr ds:[si+DAP_OFFSET_NO_SECTORS], (400h * 64) ; copy 64k
mov word ptr ds:[si+DAP_OFFSET_BUFFER_PTR], 8000h
mov word ptr ds:[si+DAP_OFFSET_BUFFER_PTR+2], 00h
mov dword ptr ds:[si+DAP_OFFSET_SECTOR_START], eax
mov dword ptr ds:[si+DAP_OFFSET_SECTOR_START+4], 0h ; set starting sector No for upper 48 lba.
mov ah, 42h ; (AH) = fcn No. for extended disk read.
int 13h
sub si, si
mov ds, si
mov si, 8000h ; (DS:SI) = location, 0:8000h to jump to, pt of no ret.
jmp word ptr ds:[si]
; Should never reach here. Also up to this point should better not exceed 512 bytes.
fileEnd db 55h, 0aah
main endp
code ends
end main
;exp.asm
.686p
include macros.inc
include exp.inc
code segment para public use16 'code'
assume cs:code, ds:data,ss:sta
M_EXTERNDEF
main proc far
mov ax, DATA
mov ds, ax
mov si, 0b800h
add si, 20h ; Leave bootloader written area behind.
mov ds, si
sub si, si ; (DS:SI) = video buffer.
mov cx, 10h ; display 80 times.
mov ax, 'A' ; char to display byte1: color, byte2: char 0.
loop1:
mov ds:[si], al
inc al ; (AL) = next digit.
cmp al, 'E' ; reset to 0 if 9
jb @f
mov al, 'A'
@@:
add si, 2 ; (SI) = next char.
loop loop1