求助呀 关于保护模式的
;关于操作系统的帖子,不知道发哪,就写到这了,请各位高手帮忙看一下哪里有错呀
;为什么我把它编译成.com文件放到DOS系统里面它不能运行呀,哪里出错了
;
;这是pm.inc文件
;定义一些常量和结构体等
Descriptor_Type_Data_R EQU 0
Descriptor_Type_Data_RA EQU 0x1
Descriptor_Type_Data_RW EQU 0x2
Descriptor_Type_Data_RWA EQU 0x3
Descriptor_Type_Data_RD EQU 0x4
Descriptor_Type_Data_RDA EQU 0x5
Descriptor_Type_Data_RDW EQU 0x6
Descriptor_Type_Data_RDWA EQU 0x7
Descriptor_Type_Code_E EQU 0x8
Descriptor_Type_Code_EA EQU 0x9
Descriptor_Type_Code_ER EQU 0xa
Descriptor_Type_Code_ERA EQU 0xb
Descriptor_Type_Code_EC EQU 0xc
Descriptor_Type_Code_ECA EQU 0xd
Descriptor_Type_Code_ECR EQU 0xe
Descriptor_Type_Code_ECRA EQU 0xa
Descriptor_System_Yes EQU 0
Descriptor_System_No EQU 0x10
Descriptor_DPL_0 EQU 0
Descriptor_DPL_1 EQU 0x20
Descriptor_DPL_2 EQU 0x40
Descriptor_DPL_3 EQU 0x60
Descriptor_Present_No EQU 0
Descriptor_Present_Yes EQU 0x80
Descriptor_L_32Mode EQU 0
Descriptor_L_64Mode EQU 0x2000
Descriptor_DB_16 EQU 0
Descriptor_DB_32 EQU 0x4000
Descriptor_G_Byte EQU 0
Descriptor_G_4KByte EQU 0x8000
%macro Descriptor 3
dw (%2)&0xffff
dw %1&0xffff
db (%1 >> 16) & 0xff
dw ((%2) >> 8) & 0xf00 | (%3)
db (%1 >> 24) & 0xff
%endmacro
;pm.inc文件结束
;下面是代码文件
%include "pm.inc"
org 0100h
jmp Code16Begin
;以下为描述符表,用宏实现,宏的定义在头文件pm.inc中
;第一个参数是段的地址,32位有效, 第二个参数是段的长度(参照intel文档些值为长度-1)20位有效,第三个参数是段的属性,具体定义也在头文件pm.inc中
;
GDT_FIRST_DESCRIPTOR Descriptor 0, 0, 0
GDT_CODE32_DESCRIPTOR Descriptor 0, Code32_Len-1, Descriptor_Type_Code_ER+Descriptor_System_No+Descriptor_Present_Yes+Descriptor_DB_32
GDT_VIDEO_DESCRIPTOR Descriptor 0b8000h, 0ffffh, Descriptor_Type_Data_RW+Descriptor_System_No+Descriptor_Present_Yes+Descriptor_DB_32
GDT_LEN: EQU $-GDT_FIRST_DESCRIPTOR
GDT_PTR: dw GDT_LEN-1
dd GDT_FIRST_DESCRIPTOR
GDT_SelectorCode32 EQU GDT_CODE32_DESCRIPTOR-GDT_FIRST_DESCRIPTOR
GDT_SelectorVideo EQU GDT_VIDEO_DESCRIPTOR-GDT_FIRST_DESCRIPTOR
[section .code16]
[bits 16]
Code16Begin:
mov ax, cx
mov es, ax
mov ds, ax
mov ss, ax
mov sp, 100h
xor eax, eax
mov ax, cs
shl eax, 4
add eax, Code32Begin
mov [GDT_CODE32_DESCRIPTOR+2], ax
shr ax, 10h
mov [GDT_CODE32_DESCRIPTOR+4], al
mov [GDT_CODE32_DESCRIPTOR+7], ah
lgdt [GDT_PTR]
cli
in al, 92h
or al, 0000010b
out 92h, al
mov eax, cr0
or eax, 1
mov cr0, eax
jmp dword GDT_SelectorCode32:0
[section .code32]
[bits 32]
Code32Begin:
mov ax, GDT_SelectorVideo
mov es, ax
mov edi, (80*0+0)*2 ;第0行第0列
mov ah, 0ch
mov al, 'W'
mov [es:edi], ax
jmp $
Code32_Len EQU $-Code32Begin