实模式和保护模式的切换
在实模式下输出一个B,在保护模式下输出一个A
ea20       macro
                push    ax
                in      al,92h
                or      al,00000010b
                out     92h,al
                pop     ax
                endm
;----------------------------------------------------------------------------
;关闭A20地址线
;----------------------------------------------------------------------------
da20      macro
                push    ax
                in      al,92h
                and     al,11111101b
                out     92h,al
pop     ax               
       endm               ;A20详见 
http://www.xemean.net/data/article.asp?id=8
jump       macro     selector,offsetv
       db    0EAh
       dw   offsetv
       dw   selector
       endm               
 ;--------------------
descriptor       struc                          ;描述符的结构
limitl       dw   0
basel       dw   0
basem     db    0
attributes dw   0
baseh      db    0
descriptor       ends
;--------------------
pdesc      struc
limit dw   0
base dd    0
pdesc      ends
;
atdw=92h                                                 ; 存在可读写数据段类型
atce=98h                                                  ; 存在只执行代码段类型
atcer=9ah                                                        ; 存在可执行可读写的代码段类型
                                                        .386P
dseg    segment   use16  
;----------------------------------------
gdt   label byte                                                         ;全局描述符表
dummy   descriptor       <>
code    descriptor      <0FFFFh,,,atce,>                    ;代码段描述符      
code_sel=code-gdt                                                  ;选择子   
data    descriptor      <0FFFFh,,,atdw,>              ;数据段描述符
data_sel=data-gdt                                                    ;对应的选择子      
;注意:代码段又代码段的属性,数据段又数据段的属性.不要混淆否则无法正常运行
vcode   descriptor      <0FFFFh,,,atce,>              ;显示字符A的代码段描述符
vcode_sel=vcode-gdt                                               ;对应选择子
vbuf   descriptor      <0FFFFh,8000h,0bh,atdw,>
vbuf_sel=vbuf-gdt
normal  descriptor      <0FFFFh,,,atdw,>             ;描述符
normal_sel=normal-gdt                                            ;选择子
;-----------------------------------------
gdtlen=$-gdt
;
vgdtr       pdesc             <gdtlen-1,>     
dseg ends
;----------------------------------------
;代码段
vcseg   segment use16    'vcode'
        assume  cs:vcseg
vstart: mov     ax,0B800h                                                   ;直接写屏,输出A
        mov     ds,ax                    
        mov     bx,0
        mov     al,'A'
        mov     ah,07h
        mov     ,ax
        jump    <code_sel>,<offset toreal>
vcseg   ends
        end     vstart
  
cseg    segment use16    'code'                                         ;实模式
       assume    cs:cseg,ds:dseg                    
start:   
    mov     ax,dseg
       mov ds,ax
       mov bx,16                                                       ;*16转化成32位
       mul  bx
       add  ax,offset  gdt
       adc  dx,0
       mov word       ptr   vgdtr.base,ax
    mov     word    ptr     vgdtr.base+2,dx
       ;
       mov ax,cseg
       mul  bx
        mov     word    ptr     code.basel,ax
        mov     byte    ptr     code.basem,dl
        mov     byte    ptr     code.baseh,dh
       ;
       mov ax,dseg
       mul  bx
        mov     word    ptr     data.basel,ax
        mov     byte    ptr     data.basem,dl
        mov     byte    ptr     data.baseh,dh
       ;
        mov     ax,vcseg
        mul     bx
        mov     word    ptr     vcode.basel,ax
        mov     byte    ptr     vcode.basem,dl
        mov     byte    ptr     vcode.baseh,dh
       ;
              lgdt  qword     ptr   vgdtr              ;将伪描述符导入到GDTR,很重要的一步  
       cli
    ea20                             ;打开A20是能够寻址4G的空间.
       mov eax,cr0                                                     ;设置CR0,进入保护模式
       or    eax,1                                                        ;将CR0设置为1进入保护模式
       mov cr0,eax
    jump    <vcode_sel>,<offset vstart>     ;跳转到显示字符A的代码段
toreal:
    mov     ax,normal_sel
       mov ds,ax
       mov eax,cr0                                                     ;设置CR0,进入保护实模式  
       and  eax,0FFFFFFFEH                                     ;将CR0设置为0,返回到实模式
       mov cr0,eax
jump    <seg real>,<offset real>
real: 
       da20
    sti
    mov  ax,dseg                                           ;显示字符B
    mov ds,ax
    mov  dl,'B'
    mov  ah,2
    int  21h
    mov  ah,4Ch
    int    21h
cseg ends
       end  start
问:::   gdt   label byte         ;全局描述符表
这是什么意思???
问::::code_sel=code-gdt               ;选择子  
这里是地址吗???