Technical Experiment: System Startup Process

Source: Internet
Author: User
Software and environment used:

1. Intel CPU

2. Windows XP

3. NSAM-2.09RC1

4. VMWare 6.5

Startup Process Overview:

When the computer starts, it first runs the solid code in the BIOS, such as power-on self-check. If this part of the code is correct, the BIOS will find the boot device (floppy disk, hard disk, and optical drive). The device search sequence is defined by the user in the BIOS. This is a small problem. How can I determine whether a device is a Startup Device? When installing the system, we put the system disk into the optical drive for boot, but not every CD can boot the system. The BIOS determines whether a device has a boot function based on the following: The last two bytes of the device's 1st Sector are 0xAA55; if the above conditions are met, the BIOS will load the data (512 K) in the first Sector to the memory 0x7C00, and then start execution from this location. Note: This is still in the 16-bit real-world mode.

After the computer powers on, the order of control is: BIOS-> 0x7C00 code.

The BIOS defined above is a mechanism that I did not look for specific reasons. If you are interested, you can Google the reasons.

 

Hello Word:

After learning about the above process, we will write a small assembler (floppy. asm ):

[BITS 16]; indicates the positioning mode [ORG 0x7C00]; specifies the starting address for loading; defines a string MsgString db 'Hello World! ', 13, 10, 0; unconditionally jump to JMP _ start_start:; clear ax xor ax, AX; clear DS. SI is used below. The base address of SI addressing is dsmov ds, AX; load the starting address of the string to SI to facilitate subsequent loop output of mov si, MsgStringCALL next_characterJMP $; call BIOS interrupt for character output, interrupt is equivalent to Windows API, the parameters are stored in the registers. For more information about interrupt calls, see the relevant documents. BIOS interrupt number: 0x10PrintCharacter: mov ah, 0x0EMOV BH, 0x00MOV BL, 0x07INT 0x10RETPrintString: next_character :; SI is similar to a pointer in C. [SI] is similar to * simov al, [SI] inc si; or, which affects the 0 flag bit, or the result of the operation is false: both operands are 0, which is used to determine whether the string ends or al, ALJZ exit_functionCALL PrintCharacterJMP next_characterexit_function: RET; fill other spaces, $ represents the offset of the current position $ represents the offset of the start position of the program, 510 + 0xAA + 0x55 = 512 TIMES 510-($-$) db 0DW 0xAA55

Then compile the above program with NASM:

Nasm floppy. asm-f bin-o floppy. img

PS:

To facilitate the use of NASM, I set it as follows:

Create a batch file to start NASM:

d:cd D:/nasm-2.09rc1PATH=PATH;D:/nasm-2.09rc1cls


Start it in the following way:

Create a shortcut with the target: C:/WINDOWS/system32/cmd.exe/E: ON/k d:/nasm-2.09rc1/setup. bat, starting at: D:/nasm-2.09rc1

 

Programs used in VMWare:

Create a dos vm:

1. Start the VM creation Wizard:

2. Do not install the system temporarily:

3. select another system:

4. Set the name and select the storage location:

5. Change the hard disk size to the minimum:

 

6. Click Configure hardware on this interface:

7. Uninstall the optical drive:

8. Attach a soft drive (specify to load from the image file and select floppy. img generated above ):

9. unmount the network:

10. Uninstall the sound card:

11. VM configuration results:

12. Start the Bootstrap program execution result:

Further:

If you want to perform further experiments, try to use BIOS interruption, write the boot program to the hard disk, and then use the hard disk to start and output "Hello World !"

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.