What books need to be read if you want to understand the following code?

xiaoxiao2021-04-10  527

The following is a code that transforms from the real model to the protection mode. What books do you need to learn?

; ===========================================; pm.inc;

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

% Macro Descriptor 3 DW% 2 & 0FFFFH; Segment Direction 1 (2 bytes) DW% 1 & 0FFFFH; Segment Biclings 1 (2 bytes) DB (% 1 >> 16) & 0FFH; Segment Tissing 2 (1 Byte) DW (% 2 >> 8) & 0F00H) | (% 3 & 0F0FFH); attribute 1 segment limit 2 attribute 2 (2 bytes) DB (% 1 >> 24) & 0FFH; Address 3 (1 byte)% endmacro; total 8 bytes

% Macro Gate 4 DW (% 2 & 0FFFH); Offset 1 (2 bytes) DW% 1; Selecton (2 bytes) DW (% 3 & 1FH) | (% 4 << 8) & 0FF00H) ; Property (2 bytes) DW (% 2 >> 16) & 0FFFFH); Offset 2 (2 bytes)% endmacro; total 8 bytes

; ===================================================; PMTEST1.ASM; compilation method : NASM PMTEST1.ASM -O Pmtest1.com; ======================================== ===

% include "pm.inc"; constant, macro, and some instructions

ORG 0100H JMP Label_Begin

[Section .GDT]; GDT; segment base, segment boundary, attribute label_gdt: descriptor 0, 0, 0; empty descriptor label_desc_code32: descriptor 0, segcode32len - 1, da_c da_32; non-uniform code segment, 32LABEL_DESC_VIDEO: Descriptor 0B8000H 0FFFH, DA_DRW; display the first address; GDT end GDTLEN EQU $ - label_gdt; GDT length gdtptr dw gdtlen; GDT limit DD 0; GDT base address

GDT Select Subsence SelectorCode32 Equ Label_Desc_code32 - Label_GdtSelectorVideo EQU Label_Desc_Video - Label_Gdt; End of [Section .GDT]

[Section .s16] [BITS 16] Label_Begin: MOV AX, CS MOV DS, AX MOV ES, AX MOV SS, AX MOV SP, 0100H

; 32-bit initialization code segment xor eax, eax mov ax, cs shl eax, 4 add eax, LABEL_SEG_CODE32 mov word [LABEL_DESC_CODE32 2], ax shr eax, 16 mov byte [LABEL_DESC_CODE32 4], al mov byte [LABEL_DESC_CODE32 7], AH

To load GDTR, prepare XOR EAX, EAX MOV AX, DS SHL EAX, 4 Add Eax, Label_GDT; EAX <- GDT base address MOV DWORD [GDTPTR 2], EAX; [GDTPTR 2] <- GDT base address

Load GDTR LGDT [GDTPTR]

; Off Interrupt CLI

Open the address line A20 in Al, 92h or Al, 00000010B OUT 92H, Al

Prepare to switch to protect mode MOV Eax, Cr0 or Eax, 1 MOV CR0, EAX

; Really entered the protection mode JMP DWORD selectorcode32: 0; executing this sentence will put the SelectorCode32 into CS and jump to the code32selector: 0; end of [section .s16]

[Section .s32]; 32-bit code segment. Jump in the real mode. [BITS 32]

Label_seg_code32: MOV AX, SelectorVideo Mov GS, AX; video selection sub (purpose)

MOV EDI, (80 * 10 0) * 2; screen 10 line, 0 column. MOV AH, 0CH; 0000: Black bottom 1100: Red word MOV Al, 'P' MOV [GS: EDI], AX

; Here to stop JMP $

Segcode32len EQU $ - Label_SEG_CODE32; End of [Section .s32]

转载请注明原文地址:https://www.9cbs.com/read-133255.html

New Post(0)