; ========================================================== =
; 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