Operating system guidance

Source: Internet
Author: User
Tags ultraedit

The first step to study the operating system is to implement guidance. Many articles on the Internet only refer to the implementation of floppy disks. Basically, a C program is used, write the boot code into the Boot Sector of the floppy disk.

However, if you can find a soft drive, you can try the optical drive. If you are interested, you can use the optical drive to guide the drive. Please remember to tell me the solution!

However, if none of these physical factors are available, you need to use the Virtual Machine-VMware. I am doing an experiment in windows, Win XP + VMware.

VMware can use the image file of a floppy disk, that is, the file suffixed with "IMG". You only need to create a new virtual machine and select the imgfile for the soft drive item at setting, the system starts to read the imgfile. (If you don't understand this, learn how to use VMware)

However, I don't understand the format of imgfile, and there seems to be no relevant tools on the Internet, so that you can directly write the code to the guidance part of the imgfile.

Since there is no tool, let's take a look at the imgfile format first. Because the Boot Sector is 512 bytes, The imgfile should have a certain relationship with it.

The following is the format of the boot sector:

The first sector of the hard disk is the primary Boot Sector, sometimes called MBR.

The primary Boot Sector is a data structure consisting of the following three parts:

1. 446-byte program code (the code here is preferred for virus rewriting );

2. 64-byte Partition Table;

3. 2 bytes of "magic number", or "guiding permit sign ".

The first 446 bytes are programs. All programs are standard, such as DoS/Windows boot programs, Linux boot programs,

Even if it breaks down, it doesn't matter. It's easy to get the code of these programs.

The 64-byte partition table is the worst! You must never change it (that is, destroy it). It stores your hard disk partition information. If it is broken, it will not be easy to recover.

The last two bytes cannot be changed. It is a flag that allows guidance. (0x55, 0xaa)

====================

Therefore, you only need to write 446 bytes. It is dangerous to write more! (Overwrite any part of the 64-byte partition table and it will be done !)

We recommend that you back up the partition table to a floppy disk or print it on paper before writing the disk, just in case.

It is useless to back up the data to the hard disk. Because the partition table on the hard disk is damaged, your operating system cannot enter.

====================

Writing a disk is too dangerous. If you are not absolutely sure, do not do it blindly.

 

Let's see the last two bytes in the 512 bytes, 0x55, 0xaa. Then we will use this clue to analyze the imgfile.

First, use ultraedit to open the imgfile. If there is no imgfile, use winimage or another tool to create one, and then directly search for "55 AA". The search result is as follows, on the top of h...

If you calculate it, you will know that 512 H is just, then you will be very clear,The first 512 bytes of the imgfile are the Boot Sector in the disk.Then, we only need to fill in the first 512 bytes of the written code in hexadecimal format (converted to binary as the machine code...

Next we write a piece of assembly code. This is the first piece of code executed after the pilot. Save this file as myos. ASM. The Code is as follows:

Assume Cs: Code

Data Segment

Data ends

Stack segment

Stack ends

Code segment
Start:
; A character 'a' is displayed in the first row and the first column'
MoV ax, 0b800h
MoV es, ax
MoV Al, 41 h
MoV ES: [0], Al
MoV Al, 2
MoV ES: [1], Al

Loop1:
JMP loop1; infinite loop

Code ends

End start

If you use MASM to compile this code successfully, an EXE file will be generated. However, this EXE file is not exactly the machine code, and MASM attaches a lot of information to it, people who know PE files should know.

Our goal is to know the hexadecimal format of the Code (convert to binary is the machine code), then we can use the debug program for disassembly and disassembly, you will immediately know the corresponding hexadecimal code. For example, what b800b8 on the left is the hexadecimal format corresponding to the Code:

 

 

Use ultraedit to open the myos.exe file and find the hexadecimal code, for example:

 

 

 

Copy the code found in this section to the beginning of the imgfile (note the number of bytes), for example:

 

 

 

 

 

Then save the imgfile, and our imgfile will be ready. Use VMware to load this imgfile and start the Virtual Machine. Then our system will be successfully guided, although nothing can be done. The figure is as follows:

 

 

 

 

The following is a record of system startup 8086:

 

 

Computer startup process details

Turning on the power to start the machine is almost a daily task for computer enthusiasts. We will not be unfamiliar with the screen startup screen,, what does the computer do when it displays these boot screens? I believe some of my friends are not very clear. This article will introduce what computers have done when the power is turned on to the appearance of windows blue sky and white clouds.

First, let's understand some basic concepts. First, we are very familiar with BIOS (Basic Input and Output Systems). BIOS is the underlying Code that deals directly with hardware. It provides the basic functions for the operating system to control hardware devices. BiOS includes the BIOS of the system BIOS (commonly referred to as the motherboard BIOS), the video card bios, and other devices (such as the IDE controller, scsicard, or Nic, the system BIOS is the main character of this article, because the Startup Process of a computer is under its control. The BIOS is generally stored in the ROM (read-only storage chip), and the Code will not disappear even after it is shut down or powers down.

The second basic concept is the memory address. Generally, 32 MB, 64 MB, or MB memory is installed on our machine. Each byte of memory is assigned an address, so that the CPU can access the memory. The 32 MB address range is expressed as 0 ~ in hexadecimal notation ~ 1 ffffffh, where 0 ~ Fffffh's low-end 1 MB memory is very special, because the first 8086 processor can access a maximum of 1 MB of memory, which is known as the basic memory at the low end of 1 MB 640kb, while a0000h ~ Bffffh must be retained for the display card. c0000h ~ Fffffh is reserved for the BIOS. The system BIOS usually occupies 64kb or more space ~ At c7fffh, the BIOS of the IDE controller is in c8000h ~ Cbfffh.

Now let's take a closer look at the computer startup process.

Step 1: When we press the power switch, the power supply starts to power the motherboard and other devices. The voltage is not stable yet, and the control chipset on the motherboard will send a reset to the CPU (reset) signal, so that the CPU is automatically restored to the initial state, but the CPU will not immediately execute the command at the moment. When the chipset detects that the power supply has begun to stabilize the power supply (of course, the process from unstable to stable is only a matter of an instant ), it removes the reset signal (if you manually press the reset button on the computer panel to restart the machine, the chipset removes the reset signal when the button is released ), the CPU immediately starts executing commands from the address ffff0h. From the previous introduction, we can see that this address is actually within the system BIOS address range, whether it is awardbios or amibios, here is just a jump command, jump to the real startup code in the system BIOS.

Step 2: The first thing to do for the startup code of the system BIOS is to perform post (power-onselftest, self-check after power-on ), the main task of post is to detect the existence and normal operation of some key devices in the system, such as memory and video card devices. Since post is the earliest detection process, the video card has not been initialized yet. If the system BIOS finds some fatal errors during the post process, for example, if the memory is not found or the memory is faulty (only KB of general memory will be checked at this time), the system BIOS will directly control the speaker voice to report the error, the length and number of sounds indicate the type of errors. Under normal circumstances, the post process is very fast and we can hardly feel its existence. After the post process is completed, other code will be called for more complete hardware detection.

Step 3: The system BIOS will look for the BIOS of the video card. As mentioned above, the starting address of the ROM chip storing the video card BIOS is usually located at c0000h, after the system BIOS finds the video card bios, it calls its initialization code. The video card BIOS initializes the video card. At this time, most video cards will display some initialization information on the screen, introduce the manufacturer, graphics chip type and other content, but this picture is almost a flash. The system BIOS then looks for the BIOS program of another device. After finding the program, you also need to call the initialization code in the BIOS to initialize the relevant device.

Step 4: After finding the BIOS of all other devices, the system BIOS displays its own boot screen, including the type, serial number, and version number of the system BIOS.

Step 5: Then, the system BIOS detects and displays the CPU type and operating frequency, starts testing all ram, and displays the Memory Test Progress on the screen, we can choose to use a simple and time-consuming or detailed testing method in the CMOS settings.

Step 6: After the memory test is passed, the system BIOS starts to detect some standard hardware devices installed in the system, including hard disks, CD-Rom, serial ports, parallel ports, and soft drives, in addition, the vast majority of newer versions of the system BIOS also need to automatically detect and set the memory timing parameters, hard disk parameters and access mode.

Step 7: After the standard device is detected, the plug-and-play code in the system BIOS starts to detect and configure the plug-and-play devices installed in the system. After each device is found, the system BIOS displays the device name, model, and other information on the screen, and allocates resources such as interrupts, DMA channels, and I/O ports to the device.

Step 8: By this step, all hardware has been tested and configured. Most system BIOS will be refreshed and a table is displayed above the screen, it roughly lists the various standard hardware devices installed in the system, the resources they use, and some related working parameters.

Step 9: The system BIOS will update escd (extendedsystemconfigurationdata, extended system configuration data ). The escd is a means for the system BIOS to exchange hardware configuration information with the operating system. The data is stored in CMOS (a small block of special ram, powered by a battery on the motherboard. Generally, the escd data is updated only after the system hardware configuration is changed. Therefore, we do not see "updateescd... Success ", however, some motherboard system BIOS uses a different data format than Windows 9x when saving escd data, therefore, during its own startup process, Windows 9x will change the escd data to its own format. However, even if the hardware configuration does not change during the next startup, the system BIOS will also change the escd data format back, so that the loop will cause the system BIOS to update the escd every time the machine is started, this is why some machines will display relevant information each time they are started.

Step 10: After the escd is updated, the startup code of the system BIOS performs the last task, that is, starting from a floppy disk, hard disk, or optical drive according to the boot sequence specified by the user. Take disk C as an example. The system BIOS will read and execute the Master Boot Record on the hard disk. The Master Boot Record will then find the first active partition from the partition table, then read and execute the Partition Boot Record of the active partition, And the Partition Boot Record reads and executes Io. sys, which is the most basic system file for DOS and Windows 9X. Io of Windows9x. sys first needs to initialize some important system data, and then shows the familiar blue sky and white clouds. In this picture, Windows will continue to perform dos and Gui (graphic user interface) partial boot and initialization work.

If a tool or software is installed in the system that directs multiple operating systems, the Master Boot Record is usually replaced with the boot code of the software, which allows you to select an operating system, then read and execute the basic Boot Code of the operating system (the Basic Boot Code of DOS and Windows is the Partition Boot Record ). The above describes the various initialization tasks that need to be completed by the computer when the power switch (or press the reset key) is enabled for cold start, if we press CTRL + ALT + DEL in DOS to perform Hot Start (or restart the computer from Windows), the post process will jump over and start directly from step 3, in addition, the CPU and memory test in step 5 will not be performed. We can see that both cold start and hot start, the system BIOS repeats these things that we do not pay too much attention to at ordinary times, however, it is these monotonous hardware detection steps that provide us with the Foundation for normal use of computers.

 

 

 

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.