Page 1 of 1

The Enhanced MBR

Posted: Sat May 31, 2003 3:08 pm
by manchev
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

Re:The Enhanced MBR

Posted: Sat May 31, 2003 3:46 pm
by Pype.Clicker
Hmm ... i wouldn't take the responsibility of telling whether it will work or not. The best way to test it is probably to make it run in bochs first, or to make it write the result in a sector of the floppy rather than on the MBR so that you can check what would be written is correct.

However, i don't think it's a wise idea to put both the modifier and the future MBR code on a single sector. I would rather organize it this way:
1. initialize the bootsector (from floppy) that has been loaded, make sure *all* registers have known value (you still miss a jmp 0000:7C00, imho, aswell as a CLD)

2. load from another place of the floppy (say sector#2) the future mbr code, which will look like

Code: Select all

[bits 16]
[org 7C00]
jmp 0000:start
start:
<code to move the MBR at 0x7e00>
jmp $+200
<the code for partition selection goes here>
<the code to load the first sector of this partition goes here>
jmp 0000:7C00
times 466 - ($-$$) db 0
partition table:
times 64 db 0
db 0x55,0xaa
3. read the actual MBR and perform the merging with the "template" sector

4. write back the result.
5. display a success message and halt.

Re:The Enhanced MBR

Posted: Tue Jun 03, 2003 4:01 pm
by manchev
thanks for the ideas, pype.clicker. i highly appreciate your help! any other ideas?


:manchev