How the Master Boot Record works

Source: Internet
Author: User
The REM below is the DOS assembly part. Do not tamper with it.
; @ Echo off
; Goto end_batch
The following are some compilation settings. The tiny mode is used to compile COM files.
. Model tiny
. Code
Startupcode
The BIOS boot system moved me from the primary boot partition of the hard disk to the memory. my current location is 0000: 7c00.
I'm so happy: I can finally work. Let me set a new stack segment, data segment, and additional segment first!
M_0100:
CLI
XOR ax, ax
; SS: sp = 0000: 7c00, because 0000: 7c00 is my home, so of course my stack should be in front of me :)
MoV SS, ax
MoV sp, 7c00h
We will move the house soon, so we should first prepare the home location, DS: SI = 0000: 7c00, ES = 0000
MoV Si, SP
PUSH AX
Pop es
PUSH AX
Pop DS
STI
Move the new home to the location of 0000: 0600, because the location of 0000: 7c00 should be given to the DOS boot program :(
Note: The system boot virus will also be migrated, but it will be moved to 1 K at 9fc0: 0, the highest memory end.
In the memory, this not only makes room for DOS, but also protects itself from discovery, of course, the new home is very safe.
ClD
MoV Di, 0600 H
MoV CX, 0100 H
Repnz
Movsw
The new home has been moved. Hurry up and jump to the place at 0000: 061d. Do not skip the wrong step :)
DB 0eah, 1dh, 6,0, 0; JMP 0000: 061d
I finally jumped to my new home, and we can continue our work, but my current position is at 0000: 061d.
M_011d:
Set the start position of the partition table. We have to check it one by one.
MoV Si, 0600 H + PT-M_0100
; We want to read the information of 4 partitions, so BL = 4 and Bl are our counters. Do not count them incorrectly, or hit your pp :)
MoV BL, 04
M_0122:
CMP byte PTR [Si], 80 h
If we read the 80 h active partition Mark, go to m_0135 to continue working.
JZ m_0135
; 80 h indicates the active partition, 00 indicates the non-active partition, and other values are invalid. If it is another value,
You may be infected with a virus. No, if not, your hard disk is broken.
CMP byte PTR [Si], 00
; If there is no active partition and the partition is illegal, let's die :(
Jnz m_0148
; Continue to see if there are any legal partitions below. It is best to have active partitions. Thank God :(
Add Si, + 10 h
Dec BL
If you haven't finished it yet, go back and check it again. There are always opportunities. Don't be too discouraged. God bless :)
Jnz m_0122
Finally, I died. Although all the partitions I read are legal, they are not refreshing. None of them are active.
If you don't want to eat, come on strike. Haha, you can't do it. Go and play Rom basic. This is when Bill Gates just debuted.
Have you heard of it? It's basic, programming. If you don't want to compile the program, haha, cry, haha
Int 18 h
M_0135:
Fortunately, I read the active partition and saved the basic parameters first. I want to invite the DOS pilot program to play.
MoV dx, [Si]
MoV CX, [Si + 02]
First, store the location of the active partition in BP. It is useful.
MoV bp, Si
M_013c:
; Each partition table has a size of 10 h. Let's look at other partitions. If you want me to see illegal partitions, I will not let you live.
Add Si, + 10 h
Dec BL
If all the information about the four partitions is read, we should stop playing it. We need to move the DOS boot program to the memory.
Let it have fun, or the computer may have to go on strike. It's almost m_015d. Ask for DOS.
JZ m_015d
CMP byte PTR [Si], 00
If this partition is valid, check the next partition and kill one thousand by mistake.
JZ m_013c
M_0148:
Haha, finally let me hold on to an invalid partition. First, let's show you the string information of an invalid partition,
And killed you, huh, where 600 + 8B = 68B is the string location of the invalid partition.
MoV Si, 0600 H + IPT-M_0100
M_014b:
Start to show it. This sub-course is also used by others, but I will first, so I will first use it. Don't grab it with me, huh, huh
This is a subroutine used to display strings, but it does not return. Have you found the RET command?
Yes, because if it is executed, you will be killed, so there is no need to come back.
Lodsb
CMP Al, 00
If the string display is over, then you will die. Do you want to struggle? Go to m_015b and check it. No
The smell of death.
JZ m_015b
Display a character in tty telex mode at the current cursor position
Push Si
MoV X, 0007
MoV ah, 0eh
Int 10 h
Pop Si
; Continue to display the next character
JMP m_014b
M_015b:
The taste of hell is really bad, ...........
Nobody threw you out, because this is an endless loop, so let's play here, but it's quiet, I like it, huh, huh
JMP m_015b
M_015d:
My task has finally been completed. Next I want to allow DOS to take over. First, move the DOS boot program from the hard disk to the memory.
To the 7c00 location, do not move it wrong. I have five chances to move it. Di serves as the counter. If the number is good, do not make a mistake.
MoV Di, 0005
M_0160:
MoV BX, 7c00h
MoV ax, 0201 H
Push di
INT 13 H
Pop di
If the migration is successful, go to m_0178 for a health check. If the hacker is illegal, please be careful!
JNB m_0178
Alas, it's really uncomfortable. I can't move my house, but it's okay. I 've never had four chances. :) sort out my old house first.
XOR ax, ax
INT 13 H
; There will be another chance :(
Dec di
There are still opportunities. Go back and try again.
Jnz m_0160
Wow, I can't even move my house. Forget it. display an error message about loading the operating system. The hard disk may be broken, 555555
MoV Si, 0600 H + ELOS-M_0100
; Go to m_014b to display the string, but it will die when the display is complete.
JMP m_014b
M_0178:
Haha, although there is no health check, I will first prepare the location of the error prompt string, saving me the trouble of waiting for a while and then busy.
There are so many scammers, so be careful :)
MoV Si, 0600 H + MOS-M_0100
; Check to see if the two bytes in the 7c00h + vsig position are 55 AA
MoV Di, 7c00h + VSIG-M_0100
CMP word PTR [di], 0aa55h
If the DOS Boot Record we read does not contain the 55 AA mark, which would be sentenced to death?
M_014b: report to this location. This is a ghost gate, but the information should be shown as well. Hahaha
Jnz m_014b
After the health check, store the partition table in Si. DOS will use it to read the logic disk of the extended partition.
MoV Si, BP
If everything is normal, let the DOS boot program at 0000: 7c00 continue to play. I am about to retire.
It's really not easy. I have been connected to two levels, but I don't know whether there are any bad guys in the DOS boot program, but I don't care about it.
Oh, go and play, dos. It's better not to die.
DB 0eah, 0, 7ch, 0000; JMP: 7c00h
Below are some tips. You can see if you have seen them. Have you ever heard of them crying?
Delete them. Microsoft will not bother you, huh, huh
Org 18bh
IPT dB 'invalidpartition table', 0; the partition table is invalid.
Elos dB 'error loading Operating System', 0; Operating System loading error
Mos dB 'missing Operating System', 0; loss of Operating System
The following is an example of a partition table. Not every hard disk looks like this. People must be flexible and not rigid.
; No :)
Org 2beh
PT dB 80 h, 01,01, 0eh, 0feh, 81 h, 3eh, 0beh, 0ch, 0
DB 30 h DUP (0)
This is a sign of effective partitioning. Although it is useless, you will die if you don't have it. Wait and see your computer.
; Work :)
Vsig dB 55 h, 0aah
Alas, it's so easy to start the computer ...................
End
============== Below is the DOS batch processing section, do not tamper with it.
;: End_batch
; Tasm % 0.bat
; Tlink/X/T % 0, bootc
; Del % 0.obj
; Echo on
; REM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.