Modify pmtest1.asm to start and enter the protection mode as bootloader.

Source: Internet
Author: User

; ========================================================== =

; Pmtest1.asm

; Compilation Method: NASM pmtest1.asm-O pmtest1.com

The segment definition is removed to determine that the 55aa mark is added to the 512 byte

; ========================================================== =

 

% Include "PM. Inc"; constants, macros, and descriptions

 

Org07c00h

Jmplabel_begin

 

; Gdt

; Segment Base Address, segment boundaries, attributes

Label_gdt: descriptor 0, 0, 0; empty Descriptor

Label_desc_code32: descriptor 0, segcode32len-1, da_c + da_32; inconsistent code segment, 32

Label_desc_video: descriptor 0b8000h, 0 ffffh, da_drw; first video address

; Gdt ended

 

Gdtlenequ $-label_gdt; gdt Length

Gdtptrdwgdtlen-1; gdt Boundary

Dd0; gdt base address

 

; Gdt Select Sub-

Selectorcode32equlabel_desc_code32-label_gdt

Selectorvideoequlabel_desc_video-label_gdt

 

 

[Bits16]

Label_begin:

Movax, CS

Movds, ax

Moves, ax

Movss, ax

Movsp, 0100 H

 

; Initialize 32-bit code segment descriptor

Xoreax, eax

Movax, CS

Shleax, 4

Addeax, label_seg_code32

Movword [label_desc_code32 + 2], ax

Shreax, 16

Movbyte [label_desc_code32 + 4], Al

Movbyte [label_desc_code32 + 7], ah

 

Prepare for loading GDTR

Xoreax, eax

Movax, DS

Shleax, 4

Addeax, label_gdt; eax <-gdt base address

Movdword [gdtptr + 2], eax; [gdtptr + 2] <-gdt base address

 

; Load GDTR

Lgdt [gdtptr]

 

; Guanzhong disconnection

CLI

 

; Open address line A20

Inal, 92 h

Oral, 00000010b

Out92h, Al

 

; Prepare to switch to protection mode

Moveax, Cr0

Oreax, 1

Movcr0, eax

 

To enter the protection mode, modify the code here and try the redirection with an offset.

Jmpword selectorcode32: offset_32; execute this statement to load selectorcode32 into CS and jump to code32selector: 0

 

 

[Bits32]

 

Label_seg_code32:

 

Times 100 db 0; add meaningless code to test redirection with a low cost

Label_start:

Offset_32equlabel_start-label_seg_code32

Movax, selectorvideo

Movgs, ax; video segment Selection Sub-(Purpose)

 

Movedi, (80*10 + 0) * 2; screen 10th rows, 0th columns.

Movah, 0ch; 0000: Black Bottom 1100: Red Letter

Moval, 'P'

MoV [GS: EDI], ax

 

; Stop now

JMP $

 

Segcode32lenequ $-label_seg_code32

 

Times 510-($-$) db0; fill in the remaining space to make the generated binary code exactly 210 bytes

DW 0xaa55; End mark

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.