After pressing the power button on the host computer, the first running software is BIOS. The full name of BIOS is Base Input & Output System, which is the basic input and output system.
(1MB memory for 8086)
The address 0~0x9FFFF is DRAM, the top 0xF0000~0xFFFFF, the 64KB memory is ROM.
BIOS itself is a program. To execute the program, there must be an entry address. The entry address is 0xFFFF0.
The main job of BIOS is to detect and initialize hardware, how to initialize? The hardware itself provides some initialization function calls, and the BIOS can call them directly. The BIOS has also done a great thing, establishing an interrupt vector table, so that related hardware calls can be realized through the "int interrupt number". Of course, these functions established by the BIOS are IO operations on the hardware. This is what the BIOS calls The reason for the basic input output system.
(1) Who loaded it.
(2) Where it is loaded.
(3) Who changed its cs:ip.
At the moment of power on, that is, the moment of power connection, the cs: ip register of the CPU is forcibly initialized to 0xF000: 0xFFF0.
Since there is only 16 bytes of space here, this only means that the real code of the BIOS is not here, so the code here can only be a jump
instruction jmp far f000:e05b, that is, it jumps to 0xfe05b, which is the BIOS code where it really begins.
Next, the BIOS checks the memory, graphics card and other peripheral information non-stop. When the test is passed and the hardware is initialized, it starts
to build data structures at 0x000~0x3FF in the memory, interrupt vector table IVT and fill in interrupt routines.
The last job of BIOS is to verify the contents of sector 0, track 0, and sector 1 of the boot disk. The two bytes at the end of this sector are the magic number 0x55 and 0xaa, and the BIOS considers this program to be the master boot record MBR. It is loaded to physical address 0x7c00.
Why 0x7c00
According to the minimum memory required by DOS 1.0 of 32KB, MBR hopes to reserve as much space as possible for it, which is also a
way to protect itself, so as not to be overwritten prematurely. So MBR can only be placed at the end of 32KB.
MBR itself is also a program, and the program needs to use the stack, and the stack is also in memory. Although MBR itself is only 512 bytes, it needs to allocate some space for the stack
it uses, so the actual memory space it uses is greater than 512 bytes. Bytes, it is estimated that 1KB of memory is enough.
Combining the above three points, it is most appropriate to choose the last 1KB in 32KB,
so what is the address? 32KB converted to hexadecimal is 0x8000, minus 1KB (0x400), it is equal to 0x7c00. This is the origin of the questioned 0x7c00, now it is clear. It can be seen that the location of loading MBR depends on the memory size and memory layout of the operating system itself.
The size of MBR must be 512 bytes, and mbr runs in 8086 real mode, which is learned in detail in microcomputer principles, and will not be repeated here.
The "real" of the real mode is reflected in: the addresses used in the program are all real physical addresses, and the logical address generated by "segment base address: segment offset" is the physical address. Before the 8086, the program was loaded to a fixed location, that is, what the programmer saw was completely real memory. Developers can't wait any longer, so they simply change the address in the program to something else. After recompiling, it is found that a certain address is still occupied, and it still cannot run on the CPU. What should I do? Change the address again...
;mbr.S
;主引导程序
;
;LOADER_BASE_ADDR equ 0xA000
;LOADER_START_SECTOR equ 0x2
;------------------------------------------------------------
SECTION MBR vstart=0x7c00
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov sp,0x7c00
mov ax,0xb800
mov gs,ax
; 清屏
;利用0x06号功能,上卷全部行,则可清屏。
; -----------------------------------------------------------
;INT 0x10 功能号:0x06 功能描述:上卷窗口
;------------------------------------------------------
;输入:
;AH 功能号= 0x06
;AL = 上卷的行数(如果为0,表示全部)
;BH = 上卷行属性
;(CL,CH) = 窗口左上角的(X,Y)位置
;(DL,DH) = 窗口右下角的(X,Y)位置
;无返回值:
mov ax, 0600h
mov bx, 0700h
mov cx, 0 ; 左上角: (0, 0)
mov dx, 184fh ; 右下角: (80,25),
; 因为VGA文本模式中,一行只能容纳80个字符,共25行。
; 下标从0开始,所以0x18=24,0x4f=79
int 10h ; int 10h
; 输出背景色绿色,前景色红色,并且跳动的字符串"1 MBR"
mov byte [gs:0x00],'1'
mov byte [gs:0x01],0xA4 ; A表示绿色背景闪烁,4表示前景色为红色
mov byte [gs:0x02],' '
mov byte [gs:0x03],0xA4
mov byte [gs:0x04],'M'
mov byte [gs:0x05],0xA4
mov byte [gs:0x06],'B'
mov byte [gs:0x07],0xA4
mov byte [gs:0x08],'R'
mov byte [gs:0x09],0xA4
jmp $ ; 通过死循环使程序悬停在此
times 510-($-$$) db 0
db 0x55,0xaa
operation result:
: study notes, sort out the operating system and restore the truth