Linux Kernel Series-Advantages of protected mode for operating system development

Source: Internet
Author: User

In the previous article, although we successfully entered the protection mode, but did not experience the protection model to bring us the convenience. In fact, in the protection mode of the address space can reach 4GB, real mode 1MB addressing ability is too far away. So below, let's change the program slightly to experience its ability to access more than 1MB of memory.

Let's try to read and write large address memory. On the basis of the previous program, create a new segment, this segment with 5MB as the base, far beyond the real mode 1MB limit. We read the beginning of the 8-byte content, then write a string and read out 8 bytes from it, as shown here:

Calltestreadcalltestwritecalltestread

If read-write succeeds, the content of two reads should be different, and the second read out should be the string we write in. The string is stored in the data segment and is also newly added. The two added segments are as follows:

Label_desc_data:   descriptor    0,      DataLen-1, DA_DRW    ; Datalabel_desc_test:   descriptor 0500000h,     0FFFFH, Da_drwselectordataequlabel_desc_data-label_ Gdtselectortestequlabel_desc_test-label_gdt[section. Data1]; Data segment Align32[bits32]label_data:bootmessage:db "Joey, I ' m in protected mode!" Offsetpmmessageequbootmessage-$$; represents the offset of the string bootmessage relative to the beginning (label_data) of this section strtest:db "abcdefghijklmnopqrstuvwxyz ", 0OffsetStrTestequStrTest-$ $DataLenequ $-label_data; END of [section. Data1]

Segment [section. S32] The beginning of this paragraph initializes the DS, ES, and GS, which points to the new data segment, ES points to the new segment of the 5MB memory, and GS points to the video. As shown below:

Label_seg_code32:movax, SELECTORDATAMOVDS, ax; Data Segment Selector Sub Movax, selectortestmoves, ax; Test Segment Selector Sub Movax, Selectorvideomovgs, ax; Video Segment Selector (purpose)

The base of the data segment is the physical address of the label_data. So offsetstrtest is both the offset of the string relative to the label_data and its offset in the data segment. It is this offset that we need to use in protected mode, not the address in real mode. A bit of the magic of section refers to the $$ here.

; Initialize data segment descriptor Xoreax, Eaxmovax, Dsshleax, 4addeax, Label_datamovword [Label_desc_data + 2], axshreax, 16movbyte [label_desc_ DATA + 4], Almovbyte [Label_desc_data + 7], ah

Run as follows:

The first time you execute call testread , 8 null characters are displayed, and ABCDEFGH is displayed the second time you execute call testread . Because Testread's segment registers point to the contents of the 5MB memory address, there is no data at the beginning.

Testread:xoresi, ESIMOVECX, 8.loop:moval, [Es:esi]calldispalincesiloop.loopret

The 190th line then writes 8 bytes of data to the 5MB memory address.

" source code and floppy Image "

Linux Kernel Series-Advantages of protected mode for operating system development

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.