[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2110
  • Last Modified:

dos boot loading MBR

when i boot from a DOS bootable diskette, is it possible to load the MBR sector of the hard and run it, just as if the computer was booted from hard disk ?
i've found many code examples showing how to load the MBR in memory but i don't find a way to run this code and boot the system.

thank you for your help.
0
psadac
Asked:
psadac
  • 6
  • 6
  • 5
  • +3
4 Solutions
 
dimitryCommented:
Take a look here:
http://home.no.net/tkos/info/hd.html

So what is the problem ? You do not know how to compile the code of bootloader ?
You do not now how to insert bootloader into diskette ?
You do not know how to change diskette bootloader to boot from HD ?

What is your main task ? You can simply return from diskete bootloader and BIOS shpuld continue to boot from HD.
0
 
manish_regmiCommented:
hi,
 If i understand your problem correctly, You want to load a bootsector from within dos and jump to it.
It can be done.
1. Read the sector of the disk. Bootsector is sector 0, U can use int 13.
2. Store the read buffer to the segment 07c0:0. (I am using this address because bios use this address to boot the computer. Just overwriting it. )
3. make a jump to that address.

you are done.

regards manish.
0
 
manish_regmiCommented:
here is an example how to do it, Some people might say it is risky. But i dont thinkm so. Loadlin does the same.


mov ah, 0x02 /* function 2 */
mov al, 0x1  /* no of sectors */
mov dl, 0x80 /* disk no. 0x80 = 1st hard disk, 0= first floppy */
lea bx, buff  /* this can be any buffer or any address */
int 0x13

/* now the boot sector is loaded at the specified address  */
/* make a jump */

regards manish


0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
BrianGEFF719Commented:
to add on to manish's code...I've done this too, your best bet is NASM.


using int 13h, 02h, load it to memory address like 5000:5000 or something. Then just do a simple JMP 5000:5000.

Above manish posted the complete code to read the MBR.
Using his code you might want to do...

jmp [buff]


-Brian
0
 
psadacAuthor Commented:
thank you for all your suggestions. I've tried with any kind of jump instruction and various tricks with ret, but i get always the same result : it begins to boot and it hangs up without launching the OS. here is the code :

Present segment Para 'code'
            assume CS:Present, DS:Present, ES:Present, SS:MyStack
            
main PROC far

      org 200h

      mov ax,07C0h
      mov ds, ax
      
      mov dx, 07C0h      
      mov es, dx
      mov bx, 00h
                mov dl, 80h
      mov dh,0h      
      xor ch, ch
      mov cl, 1h
      mov ax, 0201h
      int 13h
           
        mov ax,07C0h
        push ax            ; cs : 07C0h
       
        xor ax,ax
        push ax            ; ip : 0
       
        ret      
            
main ENDP

Present ENDS

MyStack segment para STACK 'STACK'
      byte 200h dup (?)
MyStack ENDS

END main


is there something wrong ?

0
 
dimitryCommented:
Try 'retf' instead of 'ret'.

How are you putting it into floppy bootsector ?
0
 
manish_regmiCommented:
hi,
 Flags are not the problem.
 The main problem is that si must be pointing to the partition table. The table entry starts at offset 0xbe.

just add a line
mov si, 0xbe

regards manish
0
 
manish_regmiCommented:
no, no,
 sorry about by last post. it is also not the case.
 Si i points to partition table, in the code of MBR.

I have the disassembly if you would like to see.

try using a far jump
jmp far seg:off

regards


0
 
psadacAuthor Commented:
let me clarify the process :
-i compile a dos executable file
-i boot from a dos bootable diskette (a win98 boot diskette)
-i run the executable previously compiled
-i've tried it on many computers, on a dual boot system with lilo (linux boot loader) it begins to launch lilo then it hangs.
-i've tried your suggestions (retf, far jump) but i get the same result.

so i thnk the jump is not the problem, there must be something else to do before the jump
0
 
dimitryCommented:
You want to have a bootloader but what are you doing is not the same at all.
You need to insert it into the bootsector of the floppy and you need to take ORG 200h out.
And you need to reboot your computer and give the BIOS opportunity to boot with the help of your bootloader.
And you can copy your 512 bytes bootloader to floppy with the help of diskeditor or any other utility that
allows you sector copy.
In Linux you can use 'dd':
% dd if=mybootldr.bin of=/dev/fd0 bs=512 count=512
0
 
psadacAuthor Commented:
dimitry, i already know you can use dd on linux to read or write boot sector, but that's not what i want.
basically i have a dos boot diskette, and on a given condition i want to boot from the hard drive. i thought it was possible to download the boot sector of the hard drive, make a jump to the boot code, but maybe it's not possible.
0
 
dimitryCommented:
No, my point is that DOS executable is not the same as Bootloader you are trying to run.
Run your code as Bootloader and not as DOS Executable.
0
 
DancieCommented:
Why not just execute INT 19h. This is the dos restart interrupt.

From Ralph Brown's interrupt list

This interrupt reboots the system without clearing memory or restoring
        interrupt vectors.  Because interrupt vectors are preserved, this
        interrupt usually causes a system hang if any TSRs have hooked
        vectors from 00h through 1Ch, particularly INT 08.
Notes:      Usually, the BIOS will try to read sector 1, head 0, track 0 from drive
        A: to 0000h:7C00h.  If this fails, and a hard disk is installed, the
        BIOS will read sector 1, head 0, track 0 of the first hard disk.
        This sector should contain a master bootstrap loader and a partition
        table (see #00650).  After loading the master boot sector at
        0000h:7C00h, the master bootstrap loader is given control
        (see #00653).      It will scan the partition table for an active
        partition, and will then load the operating system's bootstrap
        loader (contained in the first sector of the active partition) and
        give it control.
      true IBM PCs and most clones issue an INT 18 if neither floppy nor hard
        disk have a valid boot sector
      to accomplish a warm boot equivalent to Ctrl-Alt-Del, store 1234h in
        0040h:0072h and jump to FFFFh:0000h.      For a cold boot equivalent to
        a reset, store 0000h at 0040h:0072h before jumping.
      VDISK.SYS hooks this interrupt to allow applications to find out how
        much extended memory has been used by VDISKs (see #00649).  DOS 3.3+
        PRINT hooks INT 19 but does not set up a correct VDISK header block
        at the beginning of its INT 19 handler segment, thus causing some
        programs to overwrite extended memory which is already in use.
      the default handler is at F000h:E6F2h for 100% compatible BIOSes
      MS-DOS 3.2+ hangs on booting (even from floppy) if the hard disk
        contains extended partitions which point at each other in a loop,
        since it will never find the end of the linked list of extended
        partitions
      under Windows Real and Enhanced modes, calling INT 19 will hang the
        system in the same was as under bare DOS; under Windows Standard
        mode, INT 19 will successfully perform a cold reboot as it appears
        to have been redirected to a MOV AL,0FEh/OUT 64h,AL sequence
BUG:      when loading the remainder of the DOS system files fails, various
        versions of IBMBIO.COM/IO.SYS incorrectly restore INT 1E before
        calling INT 19, assuming that the boot sector had stored the
        contents of INT 1E at DS:SI instead of on the stack as it actually
        does
SeeAlso: INT 14/AH=17h,INT 18"BOOT HOOK",INT 49"Tandy 2000",INT 5B"PC Cluster"
SeeAlso: MEM 0040h:0067h,MEM F000h:FFF0h,CMOS 0Fh
0
 
manish_regmiCommented:
yes,
 If that algorithm is not a constraint, you can use int 0x19.
Just a single instruction will do the job.
But i was wondering why the first method is not working.

regards
0
 
psadacAuthor Commented:
sorry, but i can't use int 0x19 : i boot from a dos diskette and i want to run the hard disk boot loader, but i don't want to eject the diskette (it's an automated job). i've tried on many computers, it loads correctly the boot loader like lilo or grub, but it hangs as soon as i choose a system. i think the problem is related to the interrupt vector table, is there a way to reset the interrupt table vectors to their values after bios execution ?
0
 
DancieCommented:
I have done this by first booting from the hard disk with no extra drivers.
By pressing F5. then run debug with these commands

C:\>debug <enter>
ndos.dat   <enter>     ;give a name to write to a file ie. dos.dat
rcs        <enter>       ;set cs register -- gives basis for a data segment
0          <enter>        ; to the first segment
rcx       <enter>        ;set cx to 400h to give the length of the file in bytes
400    <emter>       ;and saves all vectors
w0      <enter>         ;write form the 0 data position
q         <enter>         ;quit

Now you have a data file that can be loaded at 0:0 -- over the interrupt vector table.


0
 
manish_regmiCommented:
hi psadac,
 I checked the code, It also hangs in my computer. There is some problem,  but i am not figuring out where. hmm,
see this link if it can help,
http://www.geocities.com/thestarman3/asm/mbr/STDMBR.htm

regards.
0
 
psadacAuthor Commented:
ok, it's time to close, i don't have a solution to the problem but thank you for your help.
0
 
dimitryCommented:
Hi psadac,

Sorry for delay. I found several small points we didn't mention to you and the code below is booting from floppy from HD.
I used TASM, so my directives are different.
1) MBR is copied to [0:7C00h] and not to [7C0h:0]. It is same physical address, but not the same segment register value.
2) Your bootloader from floppy is copied to the same address, so you need to move it before MBR read.
3) The code below was loaded from floppy and boot MBR from HD.
4) First jump and last 55AA was added to tell to BIOS that floppy has valid boot sector.

MODEL TINY
.186
.CODE

start:
  org 0h
  jmp loadmbr
loadmbr:

; Self Copy to [0:7A00]
  cli
  xor  ax, ax
  mov  ds, ax
  mov  es, ax
  mov  si, 7C00h + offset startload
  mov  cx, offset endload - startload
  mov  di, 7A00h
  cld
  rep movsb
; Far jump to loader code in system RAM for execution
  push es
  push 7A00h
  retf
startload:
  xor ax, ax
  mov es, ax
  mov bx, 7C00h
  mov dl, 80h
  mov dh, 0h
  mov cx, 1h
  mov ax, 0201h
  int 13h

  push 0           ; cs : 0h
  push 7C00h       ; ip : 7C00h
  retf
endload:
  org 510
  DB  55h, 0AAh
END start
END
0
 
dimitryCommented:
Hi psadac,
Do you need additional help ?
0
 
RobertoDeAlbaCommented:
I wonder if someone finally could make and exe file, that succesfully loads MBR from hards disk, being on DOS without removing the flopply?
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 6
  • 6
  • 5
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now