当前位置: 技术问答>linux和unix
自动收手写操作系统第三章第2小节内容求教
来源: 互联网 发布时间:2017-02-13
本文导语: %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,Da...
%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
;
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
;
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!