自动收手写操作系统第三章第2小节内容求教
%include "pm.inc"
org 07c00h
jmp LABEL_BEGIN
[SECTION .gdt]
LABEL_GDT:Descriptor 0,0,0
LABEL_DESC_CODE32:Descriptor 0,SegCode32Len-1,DA_C+DA_32
LABEL_DESC_VIDEO:Descriptor 0B8000h,0ffffh,DA_DRW
LABEL_DESC_TEST:Descriptor 05000000h,0ffffh,DA_DRW
LABEL_DESC_DATA:Descriptor 0,DataLen-1,DA_DRW
LABEL_DESC_CODE16:Descriptor 0,0ffffh,DA_C
LABEL_DESC_NORMAL:Descriptor 0,0ffffh,DA_DRW
LABEL_DESC_LDT:Descriptor 0,0ffffh,DA_LDT
LABEL_DESC_XCESHI:Descriptor 0,0ffffh,DA_C
GdtLen equ $-LABEL_GDT
GdtPtr:dw GdtLen-1
dd 0
;GDT选择子
SelectorCode32 equ LABEL_DESC_CODE32-LABEL_GDT
SelectorVideo equ LABEL_DESC_VIDEO-LABEL_GDT
SelectorData equ LABEL_DESC_DATA-LABEL_GDT
SelectorTest equ LABEL_DESC_TEST-LABEL_GDT
SelectorNormal equ LABEL_DESC_NORMAL-LABEL_GDT
SelectorCode16 equ LABEL_DESC_CODE16-LABEL_GDT
SelectorLdt equ LABEL_DESC_LDT-LABEL_GDT
SelectorXCESHI equ LABEL_DESC_XCESHI-LABEL_GDT
[SECTION .data]
ALIGN 32
[BITS 32]
LABEL_DATA:
BMSpRealValue: dw 0
OffsetMessage:
dd 'hello great',0
DataLen equ $-LABEL_DATA
[SECTION .s16]
[BITS 16]
LABEL_BEGIN:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0100h
;存储SP值
mov [BMSpRealValue],sp
mov [LABEL_GO_BACK_REAL_MODE+3],ax
;初始化测试段描述符
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_SEG_CESHICODE
mov [LABEL_DESC_XCESHI+2],ax
shr eax,16
mov [LABEL_DESC_XCESHI+4],al
mov [LABEL_DESC_XCESHI+7],ah
;初始化LDT
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_SEG_LDT
mov [LABEL_DESC_LDT+2],ax
shr eax,16
mov [LABEL_DESC_LDT+4],al
mov [LABEL_DESC_LDT+7],ah
;初始化LDT
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_LA
mov [LABEL_LDT_CODE+2],ax
shr eax,16
mov [LABEL_LDT_CODE+4],al
mov [LABEL_LDT_CODE+7],ah
;初始化16位代码段描述符
mov ax,cs
movzx eax,ax;这个为什么不一样些,而且不能用xor。为什么?
shl eax,4
add eax,LABEL_SEG_CODE16
mov [LABEL_DESC_CODE16+2],ax
shr eax,16
mov [LABEL_DESC_CODE16+4],al
mov [LABEL_DESC_CODE16+7],ah
;初始化32位代码段描述符
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_SEG_CODE32
mov [LABEL_DESC_CODE32+2],ax
shr eax,16
mov [LABEL_DESC_CODE32+4],al
mov [LABEL_DESC_CODE32+7],ah
;初始化32位数据段描述符
xor eax,eax
mov ax,ds
shl ax,4
add eax,LABEL_DATA
mov [LABEL_DATA+2],ax
shr eax,16
mov [LABEL_DATA+4],al
mov [LABEL_DATA+7],ah
;准备加载GDT
xor eax,eax
mov ax,ds
shl eax,4
add eax,LABEL_GDT
mov [GdtPtr+2],eax
;加载GDT
lgdt [GdtPtr]
;关中断
cli
;打开地址总线
in al,92h
or al,00000010B
out 92h,al
;打开CR0
mov eax,cr0
or eax,1
mov cr0,eax
;真正进入保护模式
jmp dword SelectorCode32:0
;<<<<<<<<<<<<<<<<<<<回到实模式<<<<<<<<<<<<<<
LABEL_REAL_ENTRY:
mov ax,cs
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
;恢复实模式SP
mov sp,[BMSpRealValue]
;关闭a20地址线
in al,92h
and al,11111101B
out 92h,al
;开中断
sti
;返回dos
mov ax,4c00h
int 21h
[SECTION .s32]
[BITS 32]
LABEL_SEG_CODE32:
mov ax,SelectorVideo
mov gs,ax
mov ax,SelectorData
mov ds,ax
mov ax,SelectorTest
mov es,ax
mov al,'a'
mov [es:0],al
mov edi,(80*10+11)*2
mov al,[es:0]
mov ah,0ch
mov [gs:edi],ax
;开始返回16位
;call SelectorXCESHI:0;这个没有就能正常打印a,有这行就不行了。。为什么啊??
mov ax,SelectorLdt
lldt ax
jmp SelectorLdtCode:0
SegCode32Len equ $-LABEL_SEG_CODE32
[SECTION .s16code]
ALIGN 32
[BITS 16]
LABEL_SEG_CODE16:
mov ax,SelectorNormal
mov