Harbin Institute of Technology Operating System Experiment 1 (organization for personal use)

1. Experimental content

Print your own Logo at the system startup Logo, and the effect is as follows:

 2. Experimental environment setup (Ubuntu virtual machine environment)

Refer to this blog:

(64 messages) Linux 0.11 compile kernel under ubuntu - experimental environment construction

3. Prior knowledge

1. First look at a picture

 What is BIOS?

Basic Input Output System (Basic Input Output System), which is a set of programs that are solidified into the ROM (Read-Only Memory: read-only memory, a chip that does not require power supply and can keep data forever without loss) on the motherboard of the computer, BIOS It stores the most important basic input and output programs of the computer, system setting information, power-on self-test program and system startup self-test program.

It is the only area of ​​memory that has code at power-on.

What is the first instruction executed by the CPU?

When the computer system is powered on or the reset button on the chassis is pressed, the CPU will automatically set the code segment register CS to 0xFFFF, its segment base address to 0xFFFF0000, segment length to 64KB, and IP to 0xFFF0 .

At this time, the CPU code pointer points to 0xFFFFFFF0, which is the last 16 bytes of 64K in the 4G space, and here is a jump instruction.

Note that the addressing method in real mode when the PC is just turned on: CS:IP (CS*16+IP)

Why is CS set to 0xFFFF, but its segment base address is 0xFFFF0000?

Answer: It can be said that it is a hard rule. Because it enters the real mode after booting, it is the so-called CS*16+IP. However, the high 12 bits A31~A20 of the CS segment kept high by the internal circuit of the CPU, that is, 1. So F000H*16 = F0000H, F0000H+0000FFF0H = 000FFFF0H, the upper 12 bits are high level, so the final address is 0xFFFFFFF0.

(65 messages) ROM BIOS startup problems (transfer)_Linzimx's Blog-CSDN Blog

Why is the ROM BIOS at the last 64K of 4GB?

In 1981, the PC system only had 640KB of RAM main memory (memory for short). Because the adopted 8088/8086CPU has only 20 address lines, the memory addressing range is up to 1024KB (1MB).

Now, 1MB of memory is far from meeting the needs of the program. The current computers are equipped with 512MB or more physical memory capacity, and all use 32-bit CPUs, so the physical memory addressing range of the CPU has reached 4GB. However, in order to be compatible with the original PC in terms of software, the use and allocation of the physical memory below 1MB in the system is still basically the same as that of the original PC.

It’s just that the basic input and output program BIOS in the original system ROM has always been at the highest end of the memory addressable by the CPU, and the original location of the BIOS will be used as the shadow area of ​​the BIOS when the computer is turned on and initialized, that is, BIOS code will still be copied into this area.

 How does the ROM BIOS copy the code to the ROM BIOS mapping area?

It is said that the instruction pointed to by the PC for the first time is a jmp jump instruction, and this jump instruction will jump to a certain instruction (intra-segment jump) within the 64KB range of the BIOS code to start execution.

At present, most of the BIOS capacity in the PC is 1MB to 2MB, and it is stored in the flash ROM. Therefore, in order to execute or access other BIOS codes or data in the BIOS that exceed the 64KB range and are far from the 0~1M address space, the BIOS program will first Use a technology called 32-bit Big Mode (Big Mode) to set the access range of the data segment register to 4G, so that it can execute and operate data within the range of 0~4G.

Afterwards, after the BIOS performs a series of hardware detection and initialization operations, it will copy the original PC-compatible 64KB BIOS code and data to the 64K at the end of the low-end 1M of the memory, and then jump to this place and let the CPU enter the real The real address mode of the work.

Finally, the BIOS will load the operating system boot program from the disk 0 track 0 sector to the memory 0x7c00, and set cs = 0x07c0, ip = 0x0000, and the CPU starts to execute this 512-byte program.

Track 0 and sector 0 here is the boot sector , and the boot sector is the first sector on the hard disk, so the first sector on the hard disk stores the first program that we can control after booting.

The code of the boot sector is bootsect.s

Function description:

During the execution of this code block, it will move itself to the beginning of physical address 0x90000 and continue to execute. The following is the source code of bootsect.s, and some notes written by myself.

 The main function of this program is to first load the setup module (compiled by setup.s) of the 4 sectors starting from the second sector of the disk to the position behind the bootsect (0x90200) of the advanced memory, and then use the BIOS to interrupt 0x13 Get the parameters of the current boot disk in the disk parameter table.

 Then the "Loading system ..." string is displayed on the screen, here is the content of Experiment 1. Note that msg1 here is at the end of the bootsetc.s file. In fact, the whole experiment is completed by modifying these two places in this file. Of course, it needs to be compiled and finally run.

 Furthermore, load the system module behind the setup module on the disk to the place where the memory starts at 0x10000 and determine the device number.

 Finally, long jump to the setup module to start executing the setup program.

4. Experimental steps 

1. Open the ~/oslab/linux-0.11/boot/bootsect.s file on the Ubuntu virtual machine

2. Modify the code:

3. Where to modify the code:

4. Compile and run

  • cd ~/oslab/linux-0.11
  • make
  • At this point, the image file Image will be generated
  • cd ~/oslab
  • ./run

 Success interface:

Guess you like

Origin blog.csdn.net/qq_56919740/article/details/130873430