The Enhanced MBR
Posted: Sat May 31, 2003 3:08 pm
do you think this code will do the work i want to:
-------------------------------------------------------------
[bits 16]
[org 0x7C00]
cli
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti
read:
mov ah,02h
mov al,01h
mov ch,00h
mov cl,01h
mov dh,00h
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x0600
int 13h
copy_pt:
mov ax,0x0000
mov es,ax
mov ds,ax
mov si,0x07be
mov di,0x7dbe
mov cx,40h
repz movsb
mov ax,0x0000
mov es,ax
mov di,0x7dbe
mov cx,04h
active_check:
mov ax,word [es:di]
add word [di],0010h
cmp ax,80h
jnz active_check
jz load_boot
repz
load_boot:
mov si,0
mov di,0200h
mov cx,0200h
repz movsb
jmp read_boot + 200h
read_boot:
mov ah,02h
mov al,01h
mov ch,byte [es:di+02h]
mov cl,byte [es:di+03h]
mov dh,byte [es:di+01h]
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x7c00
int 13h
write_mbr:
mov ah,03h
mov al,01h
mov ch,00h
mov cl,01h
mov dh,00h
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x7c00
int 13h
jmp 0x0000:0x7C00
times 510-($-$$) db 0
dw 0AA55h
-------------------------------------------------------------
i wrote it yesterday and compiled it with nasm - it doesn't return any errors, but i don't dare to try it. it is supposed to do the following:
1. reads the hdd mbr at 0x0600
2. copy partition table of loaded hdd mbr to the right place in the current boot sector [loaded at 0x7c00]
3. checks for an active partition
4. finds the first sector of this partition
5. moves itself [the bootsector loaded from the floppy at address 0x7c00] to another location, so
6. it can load the bootsector from step 4 at this address [0x7c00]
7. and finally execute it with jmp 0x0000:0x7c00
-------------------------------------------------------------
if i'm not right and not doing it the right way please tell me. if someone dares to test - ok. i'll be very interested in the results, or if you think the code is making the things i pointed out above in the right way and does not wipes the partition table or something i'll be the first to try it. the source can be downloaded at: http://manchev.data.bg/bs.asm and the bin file is here: http://manchev.data.bg/bs.bin
thanks for the patience!
:manchev
-------------------------------------------------------------
[bits 16]
[org 0x7C00]
cli
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti
read:
mov ah,02h
mov al,01h
mov ch,00h
mov cl,01h
mov dh,00h
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x0600
int 13h
copy_pt:
mov ax,0x0000
mov es,ax
mov ds,ax
mov si,0x07be
mov di,0x7dbe
mov cx,40h
repz movsb
mov ax,0x0000
mov es,ax
mov di,0x7dbe
mov cx,04h
active_check:
mov ax,word [es:di]
add word [di],0010h
cmp ax,80h
jnz active_check
jz load_boot
repz
load_boot:
mov si,0
mov di,0200h
mov cx,0200h
repz movsb
jmp read_boot + 200h
read_boot:
mov ah,02h
mov al,01h
mov ch,byte [es:di+02h]
mov cl,byte [es:di+03h]
mov dh,byte [es:di+01h]
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x7c00
int 13h
write_mbr:
mov ah,03h
mov al,01h
mov ch,00h
mov cl,01h
mov dh,00h
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x7c00
int 13h
jmp 0x0000:0x7C00
times 510-($-$$) db 0
dw 0AA55h
-------------------------------------------------------------
i wrote it yesterday and compiled it with nasm - it doesn't return any errors, but i don't dare to try it. it is supposed to do the following:
1. reads the hdd mbr at 0x0600
2. copy partition table of loaded hdd mbr to the right place in the current boot sector [loaded at 0x7c00]
3. checks for an active partition
4. finds the first sector of this partition
5. moves itself [the bootsector loaded from the floppy at address 0x7c00] to another location, so
6. it can load the bootsector from step 4 at this address [0x7c00]
7. and finally execute it with jmp 0x0000:0x7c00
-------------------------------------------------------------
if i'm not right and not doing it the right way please tell me. if someone dares to test - ok. i'll be very interested in the results, or if you think the code is making the things i pointed out above in the right way and does not wipes the partition table or something i'll be the first to try it. the source can be downloaded at: http://manchev.data.bg/bs.asm and the bin file is here: http://manchev.data.bg/bs.bin
thanks for the patience!
:manchev