Linux kernel series -12.b. Operating system development from loader into protected mode

Source: Internet
Author: User

Now that the kernel has been loaded into memory by us, it's time to jump into protected mode.

The first is the GDT and the corresponding selector, we define only three descriptors, one 0~4GB executable segment, one 0~4GB read-write segment, and one point to the memory start address:

; GDT;                            Segment base     segment bounds, attribute LABEL_GDT:    descriptor 0,            0, 0              ; NULL descriptor Label_desc_flat_c:  descriptor 0,      0FFFFFH, Da_ cr|da_32|da_limit_4k; 0-4glabel_desc_flat_rw:descriptor 0,      0fffffh, da_drw|da_32|da_limit_4k;0-4glabel_desc_ Video:   descriptor 0b8000h, 0FFFFH, DA_DRW|DA_DPL3; memory first address gdtlenequ$-label_gdtgdtptrdwgdtlen-1; Segment boundary ddbaseofloaderphyaddr + LABEL_GDT; Base site; GDT Selector Sub Selectorflatcequlabel_desc_flat_c-label_gdtselectorflatrwequlabel_desc_flat_rw-label_ GDTSELECTORVIDEOEQULABEL_DESC_VIDEO-LABEL_GDT + SA_RPL3

In the previous study of protection mode, most of the segment base of the descriptor is run-time calculation after filling in the corresponding location, because our program is loaded by the BIOS or DOS, we do not know the segment address, so we do not know the program runtime in memory location.

Now, loader is loaded by ourselves, the segment address has been identified as Baseofloader, so the physical address of the label (variable) appearing in loader can be represented by the following formula:

The physical address of the designator (variable) =baseofloader*10h+ The offset of the label (variable)

We put it and the corresponding statement in the Load.inc.

Baseofloader    equ 09000h; LOADER. BIN is loaded into the location----  segment address Offsetofloader    equ  0100h; LOADER. The BIN is loaded into the location----offset address baseofloaderphyaddr equbaseofloader*10h; LOADER. The BIN is loaded into the location----Physical Address baseofkernelfile    equ 08000h; KERNEL. BIN is loaded into the location----  segment address Offsetofkernelfile  equ     0h; KERNEL. The location where the BIN is loaded----offset address

We define a macro baseofloaderphyaddr to replace the baseofloader*10h, which is used once in the loader.asm to calculate the base address of the GDT.

The results of the operation are as follows:

" Source "

Linux kernel series -12.b. Operating system development from loader into protected mode

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.