386-5.txt
上传用户:gb3576
上传日期:2007-01-03
资源大小:24k
文件大小:37k
源码类别:

Shell编程

开发平台:

DOS

  1.                                                     ┌┐┌┐∞
  2. 【 80386 保护模式简介五 】                     ┘└┘└┘
  3. ==========================================================================
  4. 前言:
  5.     底下是进入保护模式、进入 V86 的精简范例 ,执行前请确定 CPU 是处在真实模
  6. 式 ,程式码因为用到 386 指令 ,请用 TASM 3.1 来编译。
  7. --------------------------------------------------------------------------
  8. ┌──────┐
  9. │进入保护模式│
  10. └──────┘
  11.     进入保护模式的程式范例 ,其目地是进入保护模式 ,并在保护模式下用绝对记忆
  12. 体读写的方式 ,直接将 'Protection Mode !' 字串写入 Video Ram (B800:0000) ,
  13. 本程式以最精简的方式撰写 ,没有任何错误处理 ,因此请确定电脑现在处在真实模式
  14. 下才可执行本程式。(禁挂 EMM 系保护模式软体)
  15.     程式流程如下:(底下所指记忆体位址皆为 32bit 绝对位址)
  16.         1. 设定 GDTtab 表所在的记忆体位址填入 GDTadds
  17.         2. 设定 Selector 0008 的记忆体起始位址就是现在 CS 的记忆体位址
  18.            设定 Selector 0010 的记忆体起始位址就是现在 CS 的记忆体位址
  19.                 Selector 0018 的记忆体起始位址就是 000B8000 = (B800:0000)
  20.         3. 执行 LGDT FWORD PTR CS:GDTadds 告诉 CPU 一但进入保护模式 ,各
  21.                 区段的记忆体起始位址、长度
  22.         4. 设定 CR0 的 Bit0 = '1' ,并透过 JMP 指令进入保护模式
  23.              ※ 进入保护模式後 ,DS.ES.SS.CS.GS.FS 等等暂存器定址方式不再
  24.                 是 Segment ,而变成 Selector
  25.         5. 秀字 将 0010:MSG_1 搬到 0018:0000
  26.                 意即将 'Protection Mode !' 字串搬到 Video Ram 去
  27.         6. 设定 CR0 的 Bit0 = '0' ,并透过 JMP 指令回到真实模式
  28.              ※ 回到真实模式後 ,DS.ES.SS.CS.GS.FS 等等暂存器定址方式不再
  29.                 是 Selector ,而变成 Segment
  30.         5. 秀字 将 CS:MSG_2 搬到 B800:00A0
  31.                 意即将 'Return Real Mode !' 字串搬到 Video Ram 去
  32.         6. 结束程式
  33. -----------------------------  P.ASM  ------------------------------------
  34. code    segment
  35.         assume  cs:code,ds:code
  36. .386p
  37. start   proc    near
  38.         jmp     next
  39. gdtadds dw      001fh,0000h,0000h
  40. gdttab  db      000h,000h,00h,00h,00h,00h,00h,00h ;00 Null
  41.         db      0ffh,0ffh,00h,00h,00h,9bh,00h,00h ;08 PRG Seg
  42.         db      0ffh,0ffh,00h,00h,00h,93h,00h,00h ;10 PRG Seg
  43.         db      0ffh,0ffh,00h,80h,0bh,93h,00h,00h ;18 B8000
  44. msg_1   db      'Protection Mode !'
  45. msg_2   db      'Return Real Mode !'
  46. next :
  47.         xor     eax,eax                 ;
  48.         xor     ebx,ebx                 ;
  49.         mov     ax,cs                   ;设定 GDTadds
  50.         shl     eax,04h                 ;
  51.         mov     bx,offset gdttab        ;
  52.         add     eax,ebx                 ;
  53.         mov     di,offset gdtadds+02h   ;
  54.         mov     cs:[di],eax             ;
  55.         NOP
  56.         xor     eax,eax                 ;
  57.         xor     ebx,ebx                 ;
  58.         mov     ax,cs                   ;
  59.         shl     eax,04h                 ;
  60.         mov     di,offset gdttab+08h    ;设定 GDTtab 内的
  61.         mov     si,offset gdttab+10h    ;Selector 0008 及 0010
  62.         mov     cs:[di+02h],ax          ;两个段落的记忆体起始位址
  63.         mov     cs:[si+02h],ax          ;
  64.         shr     eax,10h                 ;
  65.         mov     cs:[di+04h],al          ;
  66.         mov     cs:[si+04h],al          ;
  67.         mov     cs:[di+07h],ah          ;
  68.         mov     cs:[si+07h],ah          ;
  69.         NOP
  70.         cli
  71.         lgdt    fword ptr cs:gdtadds    ;载入 GDT 表格
  72.         mov     eax,cr0             ;
  73.         or      al,01h              ;
  74.         mov     cr0,eax             ;
  75.         jmp     protection_mode     ;进入保护模式
  76. protection_mode :                   ;
  77.         mov     ax,0010h                ;
  78.         mov     ds,ax                   ;
  79.         mov     si,offset msg_1         ;
  80.         mov     ax,0018h                ;将 0010:MSG_1 搬到 0018:0000
  81.         mov     es,ax                   ;
  82.         mov     di,0000h                ;
  83.         mov     ah,70h                  ;
  84.         mov     cx,0011h                ;
  85.         cld                             ;
  86. L1 :                                    ;
  87.         lodsb                           ;
  88.         stosw                           ;
  89.         loop    L1                      ;
  90.         NOP
  91.         mov     eax,cr0             ;
  92.         and     al,0feh             ;
  93.         mov     cr0,eax             ;回到真实模式
  94.         jmp     return_real_mode    ;
  95. return_real_mode :                  ;
  96.         sti
  97.         mov     ax,cs                   ;
  98.         mov     ds,ax                   ;
  99.         mov     si,offset msg_2         ;
  100.         mov     ax,0b800h               ;
  101.         mov     es,ax                   ;将 CS:MSG_2 搬到 B800:00A0
  102.         mov     di,00a0h                ;
  103.         mov     ah,70h                  ;
  104.         mov     cx,0012h                ;
  105.         cld                             ;
  106. L2 :                                    ;
  107.         lodsb                           ;
  108.         stosw                           ;
  109.         loop    L2                      ;
  110.         mov     ax,4cffh
  111.         int     21h
  112. start   endp
  113. code    ends
  114.         end     start
  115. --------------------------------------------------------------------------
  116.     因为保护模式下不能呼叫真实模式下的中断 ,所以笔者以直接填写显示卡记忆体
  117. 的方式秀字。这是一个简单、尚未使用中断向量表的范例。
  118. 注: 所谓一山不容二虎 ,如果已载入其它保护模式的程式 ,那本程式将會与它打架 ,
  119.     造成电脑当机。
  120. ┌────────┐
  121. │进入虚拟 86 模式│            为求精简 ,本程式毫无错误处理能力
  122. └────────┘
  123. ------------------------  V86.ASM  ---------------------------------------
  124. code    segment
  125.         assume  cs:code,ds:code
  126. .386p
  127. start   proc    near
  128.         jmp     next
  129. gdtadds dw      002fh,0000h,0000h
  130. gdttab  db      000h,000h,000h,000h,000h,000h,000h,000h ;00 Null
  131.         db      0ffh,0ffh,000h,000h,000h,09bh,000h,000h ;08 PRG Seg
  132.         db      0ffh,0ffh,000h,000h,000h,093h,08fh,000h ;10 Dos=Page
  133.         db      0ffh,0ffh,000h,000h,000h,089h,000h,000h ;18 TSSltr
  134.         db      0ffh,0ffh,000h,000h,000h,089h,000h,000h ;20 TSSjmp
  135.         db      0ffh,003h,000h,000h,000h,093h,000h,000h ;28 Stack (1K)
  136. tssltr  dd      00000000h
  137.         dd      000003ffh       ;ESP
  138.         dw      0028h,0000h     ;SS.0
  139.         dd      0,0,0,0,0
  140.         dw      offset enter_v86,0000h      ;EIP
  141.         dd      00000200h       ;EFlag
  142.         dd      0,0,0,0
  143.         dd      000003ffh       ;ESP
  144.         dd      0,0,0
  145.         dw      0010h,0000h     ;ES.0
  146.         dw      0008h,0000h     ;CS.0
  147.         dw      0028h,0000h     ;SS.0
  148.         dw      0010h,0000h     ;DS,0
  149.         dw      0010h,0000h     ;FS.0
  150.         dw      0010h,0000h     ;GS.0
  151.         dw      0000h,0000h     ;LDT.0
  152.         dw      0000h,0068h     ;0.IOMAP
  153.         dw      0ffffh
  154. tssjmp  dd      00000000h
  155.         dd      000003ffh       ;ESP
  156.         dw      0028h,0000h     ;SS.0
  157.         dd      0,0,0,0,0
  158.         dw      offset enter_v86,0000h      ;EIP
  159.         dd      00000000h       ;EFlag
  160.         dd      0,0,0,0
  161.         dd      000003ffh       ;ESP
  162.         dd      0,0,0
  163.         dw      0010h,0000h     ;ES.0
  164.         dw      0008h,0000h     ;CS.0
  165.         dw      0028h,0000h     ;SS.0
  166.         dw      0010h,0000h     ;DS,0
  167.         dw      0010h,0000h     ;FS.0
  168.         dw      0010h,0000h     ;GS.0
  169.         dw      0000h,0000h     ;LDT.0
  170.         dw      0000h,0068h     ;0.IOMAP
  171. iomap   db      1000h dup (0)
  172.         dw      0ffffh
  173. buffer1 db      0400h dup (0)           ;Stack
  174. idtadds dw      07ffh,0000h,0000h
  175. idttab  dw      offset new_00,0008h,0ee00h,0000h,offset new_01,0008h,0ee00h,0000h
  176.         dw      offset new_02,0008h,0ee00h,0000h,offset new_03,0008h,0ee00h,0000h
  177.         dw      offset new_04,0008h,0ee00h,0000h,offset new_05,0008h,0ee00h,0000h
  178.         dw      offset new_06,0008h,0ee00h,0000h,offset new_07,0008h,0ee00h,0000h
  179.         dw      offset new_08,0008h,0ee00h,0000h,offset new_09,0008h,0ee00h,0000h
  180.         dw      offset new_0a,0008h,0ee00h,0000h,offset new_0b,0008h,0ee00h,0000h
  181.         dw      offset new_0c,0008h,0ee00h,0000h,offset new_0d,0008h,0ee00h,0000h
  182.         dw      offset new_0e,0008h,0ee00h,0000h,offset new_0f,0008h,0ee00h,0000h
  183.         dw      offset new_10,0008h,0ee00h,0000h,offset new_11,0008h,0ee00h,0000h
  184.         dw      offset new_12,0008h,0ee00h,0000h,offset new_13,0008h,0ee00h,0000h
  185.         dw      offset new_14,0008h,0ee00h,0000h,offset new_15,0008h,0ee00h,0000h
  186.         dw      offset new_16,0008h,0ee00h,0000h,offset new_17,0008h,0ee00h,0000h
  187.         dw      offset new_18,0008h,0ee00h,0000h,offset new_19,0008h,0ee00h,0000h
  188.         dw      offset new_1a,0008h,0ee00h,0000h,offset new_1b,0008h,0ee00h,0000h
  189.         dw      offset new_1c,0008h,0ee00h,0000h,offset new_1d,0008h,0ee00h,0000h
  190.         dw      offset new_1e,0008h,0ee00h,0000h,offset new_1f,0008h,0ee00h,0000h
  191.         dw      offset new_20,0008h,0ee00h,0000h,offset new_21,0008h,0ee00h,0000h
  192.         dw      offset new_22,0008h,0ee00h,0000h,offset new_23,0008h,0ee00h,0000h
  193.         dw      offset new_24,0008h,0ee00h,0000h,offset new_25,0008h,0ee00h,0000h
  194.         dw      offset new_26,0008h,0ee00h,0000h,offset new_27,0008h,0ee00h,0000h
  195.         dw      offset new_28,0008h,0ee00h,0000h,offset new_29,0008h,0ee00h,0000h
  196.         dw      offset new_2a,0008h,0ee00h,0000h,offset new_2b,0008h,0ee00h,0000h
  197.         dw      offset new_2c,0008h,0ee00h,0000h,offset new_2d,0008h,0ee00h,0000h
  198.         dw      offset new_2e,0008h,0ee00h,0000h,offset new_2f,0008h,0ee00h,0000h
  199.         dw      offset new_30,0008h,0ee00h,0000h,offset new_31,0008h,0ee00h,0000h
  200.         dw      offset new_32,0008h,0ee00h,0000h,offset new_33,0008h,0ee00h,0000h
  201.         dw      offset new_34,0008h,0ee00h,0000h,offset new_35,0008h,0ee00h,0000h
  202.         dw      offset new_36,0008h,0ee00h,0000h,offset new_37,0008h,0ee00h,0000h
  203.         dw      offset new_38,0008h,0ee00h,0000h,offset new_39,0008h,0ee00h,0000h
  204.         dw      offset new_3a,0008h,0ee00h,0000h,offset new_3b,0008h,0ee00h,0000h
  205.         dw      offset new_3c,0008h,0ee00h,0000h,offset new_3d,0008h,0ee00h,0000h
  206.         dw      offset new_3e,0008h,0ee00h,0000h,offset new_3f,0008h,0ee00h,0000h
  207.         dw      offset new_40,0008h,0ee00h,0000h,offset new_41,0008h,0ee00h,0000h
  208.         dw      offset new_42,0008h,0ee00h,0000h,offset new_43,0008h,0ee00h,0000h
  209.         dw      offset new_44,0008h,0ee00h,0000h,offset new_45,0008h,0ee00h,0000h
  210.         dw      offset new_46,0008h,0ee00h,0000h,offset new_47,0008h,0ee00h,0000h
  211.         dw      offset new_48,0008h,0ee00h,0000h,offset new_49,0008h,0ee00h,0000h
  212.         dw      offset new_4a,0008h,0ee00h,0000h,offset new_4b,0008h,0ee00h,0000h
  213.         dw      offset new_4c,0008h,0ee00h,0000h,offset new_4d,0008h,0ee00h,0000h
  214.         dw      offset new_4e,0008h,0ee00h,0000h,offset new_4f,0008h,0ee00h,0000h
  215.         dw      offset new_50,0008h,0ee00h,0000h,offset new_51,0008h,0ee00h,0000h
  216.         dw      offset new_52,0008h,0ee00h,0000h,offset new_53,0008h,0ee00h,0000h
  217.         dw      offset new_54,0008h,0ee00h,0000h,offset new_55,0008h,0ee00h,0000h
  218.         dw      offset new_56,0008h,0ee00h,0000h,offset new_57,0008h,0ee00h,0000h
  219.         dw      offset new_58,0008h,0ee00h,0000h,offset new_59,0008h,0ee00h,0000h
  220.         dw      offset new_5a,0008h,0ee00h,0000h,offset new_5b,0008h,0ee00h,0000h
  221.         dw      offset new_5c,0008h,0ee00h,0000h,offset new_5d,0008h,0ee00h,0000h
  222.         dw      offset new_5e,0008h,0ee00h,0000h,offset new_5f,0008h,0ee00h,0000h
  223.         dw      offset new_60,0008h,0ee00h,0000h,offset new_61,0008h,0ee00h,0000h
  224.         dw      offset new_62,0008h,0ee00h,0000h,offset new_63,0008h,0ee00h,0000h
  225.         dw      offset new_64,0008h,0ee00h,0000h,offset new_65,0008h,0ee00h,0000h
  226.         dw      offset new_66,0008h,0ee00h,0000h,offset new_67,0008h,0ee00h,0000h
  227.         dw      offset new_68,0008h,0ee00h,0000h,offset new_69,0008h,0ee00h,0000h
  228.         dw      offset new_6a,0008h,0ee00h,0000h,offset new_6b,0008h,0ee00h,0000h
  229.         dw      offset new_6c,0008h,0ee00h,0000h,offset new_6d,0008h,0ee00h,0000h
  230.         dw      offset new_6e,0008h,0ee00h,0000h,offset new_6f,0008h,0ee00h,0000h
  231.         dw      offset new_70,0008h,0ee00h,0000h,offset new_71,0008h,0ee00h,0000h
  232.         dw      offset new_72,0008h,0ee00h,0000h,offset new_73,0008h,0ee00h,0000h
  233.         dw      offset new_74,0008h,0ee00h,0000h,offset new_75,0008h,0ee00h,0000h
  234.         dw      offset new_76,0008h,0ee00h,0000h,offset new_77,0008h,0ee00h,0000h
  235.         dw      offset new_78,0008h,0ee00h,0000h,offset new_79,0008h,0ee00h,0000h
  236.         dw      offset new_7a,0008h,0ee00h,0000h,offset new_7b,0008h,0ee00h,0000h
  237.         dw      offset new_7c,0008h,0ee00h,0000h,offset new_7d,0008h,0ee00h,0000h
  238.         dw      offset new_7e,0008h,0ee00h,0000h,offset new_7f,0008h,0ee00h,0000h
  239.         dw      offset new_80,0008h,0ee00h,0000h,offset new_81,0008h,0ee00h,0000h
  240.         dw      offset new_82,0008h,0ee00h,0000h,offset new_83,0008h,0ee00h,0000h
  241.         dw      offset new_84,0008h,0ee00h,0000h,offset new_85,0008h,0ee00h,0000h
  242.         dw      offset new_86,0008h,0ee00h,0000h,offset new_87,0008h,0ee00h,0000h
  243.         dw      offset new_88,0008h,0ee00h,0000h,offset new_89,0008h,0ee00h,0000h
  244.         dw      offset new_8a,0008h,0ee00h,0000h,offset new_8b,0008h,0ee00h,0000h
  245.         dw      offset new_8c,0008h,0ee00h,0000h,offset new_8d,0008h,0ee00h,0000h
  246.         dw      offset new_8e,0008h,0ee00h,0000h,offset new_8f,0008h,0ee00h,0000h
  247.         dw      offset new_90,0008h,0ee00h,0000h,offset new_91,0008h,0ee00h,0000h
  248.         dw      offset new_92,0008h,0ee00h,0000h,offset new_93,0008h,0ee00h,0000h
  249.         dw      offset new_94,0008h,0ee00h,0000h,offset new_95,0008h,0ee00h,0000h
  250.         dw      offset new_96,0008h,0ee00h,0000h,offset new_97,0008h,0ee00h,0000h
  251.         dw      offset new_98,0008h,0ee00h,0000h,offset new_99,0008h,0ee00h,0000h
  252.         dw      offset new_9a,0008h,0ee00h,0000h,offset new_9b,0008h,0ee00h,0000h
  253.         dw      offset new_9c,0008h,0ee00h,0000h,offset new_9d,0008h,0ee00h,0000h
  254.         dw      offset new_9e,0008h,0ee00h,0000h,offset new_9f,0008h,0ee00h,0000h
  255.         dw      offset new_a0,0008h,0ee00h,0000h,offset new_a1,0008h,0ee00h,0000h
  256.         dw      offset new_a2,0008h,0ee00h,0000h,offset new_a3,0008h,0ee00h,0000h
  257.         dw      offset new_a4,0008h,0ee00h,0000h,offset new_a5,0008h,0ee00h,0000h
  258.         dw      offset new_a6,0008h,0ee00h,0000h,offset new_a7,0008h,0ee00h,0000h
  259.         dw      offset new_a8,0008h,0ee00h,0000h,offset new_a9,0008h,0ee00h,0000h
  260.         dw      offset new_aa,0008h,0ee00h,0000h,offset new_ab,0008h,0ee00h,0000h
  261.         dw      offset new_ac,0008h,0ee00h,0000h,offset new_ad,0008h,0ee00h,0000h
  262.         dw      offset new_ae,0008h,0ee00h,0000h,offset new_af,0008h,0ee00h,0000h
  263.         dw      offset new_b0,0008h,0ee00h,0000h,offset new_b1,0008h,0ee00h,0000h
  264.         dw      offset new_b2,0008h,0ee00h,0000h,offset new_b3,0008h,0ee00h,0000h
  265.         dw      offset new_b4,0008h,0ee00h,0000h,offset new_b5,0008h,0ee00h,0000h
  266.         dw      offset new_b6,0008h,0ee00h,0000h,offset new_b7,0008h,0ee00h,0000h
  267.         dw      offset new_b8,0008h,0ee00h,0000h,offset new_b9,0008h,0ee00h,0000h
  268.         dw      offset new_ba,0008h,0ee00h,0000h,offset new_bb,0008h,0ee00h,0000h
  269.         dw      offset new_bc,0008h,0ee00h,0000h,offset new_bd,0008h,0ee00h,0000h
  270.         dw      offset new_be,0008h,0ee00h,0000h,offset new_bf,0008h,0ee00h,0000h
  271.         dw      offset new_c0,0008h,0ee00h,0000h,offset new_c1,0008h,0ee00h,0000h
  272.         dw      offset new_c2,0008h,0ee00h,0000h,offset new_c3,0008h,0ee00h,0000h
  273.         dw      offset new_c4,0008h,0ee00h,0000h,offset new_c5,0008h,0ee00h,0000h
  274.         dw      offset new_c6,0008h,0ee00h,0000h,offset new_c7,0008h,0ee00h,0000h
  275.         dw      offset new_c8,0008h,0ee00h,0000h,offset new_c9,0008h,0ee00h,0000h
  276.         dw      offset new_ca,0008h,0ee00h,0000h,offset new_cb,0008h,0ee00h,0000h
  277.         dw      offset new_cc,0008h,0ee00h,0000h,offset new_cd,0008h,0ee00h,0000h
  278.         dw      offset new_ce,0008h,0ee00h,0000h,offset new_cf,0008h,0ee00h,0000h
  279.         dw      offset new_d0,0008h,0ee00h,0000h,offset new_d1,0008h,0ee00h,0000h
  280.         dw      offset new_d2,0008h,0ee00h,0000h,offset new_d3,0008h,0ee00h,0000h
  281.         dw      offset new_d4,0008h,0ee00h,0000h,offset new_d5,0008h,0ee00h,0000h
  282.         dw      offset new_d6,0008h,0ee00h,0000h,offset new_d7,0008h,0ee00h,0000h
  283.         dw      offset new_d8,0008h,0ee00h,0000h,offset new_d9,0008h,0ee00h,0000h
  284.         dw      offset new_da,0008h,0ee00h,0000h,offset new_db,0008h,0ee00h,0000h
  285.         dw      offset new_dc,0008h,0ee00h,0000h,offset new_dd,0008h,0ee00h,0000h
  286.         dw      offset new_de,0008h,0ee00h,0000h,offset new_df,0008h,0ee00h,0000h
  287.         dw      offset new_e0,0008h,0ee00h,0000h,offset new_e1,0008h,0ee00h,0000h
  288.         dw      offset new_e2,0008h,0ee00h,0000h,offset new_e3,0008h,0ee00h,0000h
  289.         dw      offset new_e4,0008h,0ee00h,0000h,offset new_e5,0008h,0ee00h,0000h
  290.         dw      offset new_e6,0008h,0ee00h,0000h,offset new_e7,0008h,0ee00h,0000h
  291.         dw      offset new_e8,0008h,0ee00h,0000h,offset new_e9,0008h,0ee00h,0000h
  292.         dw      offset new_ea,0008h,0ee00h,0000h,offset new_eb,0008h,0ee00h,0000h
  293.         dw      offset new_ec,0008h,0ee00h,0000h,offset new_ed,0008h,0ee00h,0000h
  294.         dw      offset new_ee,0008h,0ee00h,0000h,offset new_ef,0008h,0ee00h,0000h
  295.         dw      offset new_f0,0008h,0ee00h,0000h,offset new_f1,0008h,0ee00h,0000h
  296.         dw      offset new_f2,0008h,0ee00h,0000h,offset new_f3,0008h,0ee00h,0000h
  297.         dw      offset new_f4,0008h,0ee00h,0000h,offset new_f5,0008h,0ee00h,0000h
  298.         dw      offset new_f6,0008h,0ee00h,0000h,offset new_f7,0008h,0ee00h,0000h
  299.         dw      offset new_f8,0008h,0ee00h,0000h,offset new_f9,0008h,0ee00h,0000h
  300.         dw      offset new_fa,0008h,0ee00h,0000h,offset new_fb,0008h,0ee00h,0000h
  301.         dw      offset new_fc,0008h,0ee00h,0000h,offset new_fd,0008h,0ee00h,0000h
  302.         dw      offset new_fe,0008h,0ee00h,0000h,offset new_ff,0008h,0ee00h,0000h
  303. new_00 :
  304.         push    0000h
  305.         jmp     int_emu
  306. new_01 :
  307.         push    0001h
  308.         jmp     int_emu
  309. new_02 :
  310.         push    0002h
  311.         jmp     int_emu
  312. new_03 :
  313.         push    0003h
  314.         jmp     int_emu
  315. new_04 :
  316.         push    0004h
  317.         jmp     int_emu
  318. new_05 :
  319.         push    0005h
  320.         jmp     int_emu
  321. new_06 :
  322.         push    0006h
  323.         jmp     int_emu
  324. new_07 :
  325.         push    0007h
  326.         jmp     int_emu
  327. new_08 :
  328.         push    0008h
  329.         jmp     int_emu
  330. new_09 :
  331.         push    0009h
  332.         jmp     int_emu
  333. new_0a :
  334.         push    000ah
  335.         jmp     int_emu
  336. new_0b :
  337.         push    000bh
  338.         jmp     int_emu
  339. new_0c :
  340.         push    000ch
  341.         jmp     int_emu
  342. new_0d :
  343.         push    000dh
  344.         jmp     int_emu
  345. new_0e :
  346.         push    000eh
  347.         jmp     int_emu
  348. new_0f :
  349.         push    000fh
  350.         jmp     int_emu
  351. new_10 :
  352.         push    0010h
  353.         jmp     int_emu
  354. new_11 :
  355.         push    0011h
  356.         jmp     int_emu
  357. new_12 :
  358.         push    0012h
  359.         jmp     int_emu
  360. new_13 :
  361.         push    0013h
  362.         jmp     int_emu
  363. new_14 :
  364.         push    0014h
  365.         jmp     int_emu
  366. new_15 :
  367.         cmp     ah,87h
  368.         jnz     L3
  369.         push    bp
  370.         mov     bp,sp
  371.         add     bp,02h
  372.         push    eax
  373.         push    ebx
  374.         push    ecx
  375.         push    edx
  376.         push    edi
  377.         push    esi
  378.         mov     ebx,ss:[bp+14h]
  379.         shl     ebx,04h
  380.         and     esi,0000ffffh
  381.         add     ebx,esi
  382.         mov     ax,0010h
  383.         mov     ds,ax
  384.         mov     es,ax
  385.         mov     esi,ds:[ebx+12h]
  386.         mov     edi,ds:[ebx+1ah]
  387.         and     esi,00ffffffh
  388.         and     edi,00ffffffh
  389.         or      cx,cx
  390.         jz      L2
  391. L1 :
  392.         mov     ax,ds:[esi]
  393.         mov     es:[edi],ax
  394.         add     esi,02h
  395.         add     edi,02h
  396.         loop    L1
  397. L2 :
  398.         pop     esi
  399.         pop     edi
  400.         pop     edx
  401.         pop     ecx
  402.         pop     ebx
  403.         pop     eax
  404.         pop     bp
  405.         iretd
  406. L3 :
  407.         push    0015h
  408.         jmp     int_emu
  409. new_16 :
  410.         push    0016h
  411.         jmp     int_emu
  412. new_17 :
  413.         push    0017h
  414.         jmp     int_emu
  415. new_18 :
  416.         push    0018h
  417.         jmp     int_emu
  418. new_19 :
  419.         push    0019h
  420.         jmp     int_emu
  421. new_1a :
  422.         push    001ah
  423.         jmp     int_emu
  424. new_1b :
  425.         push    001bh
  426.         jmp     int_emu
  427. new_1c :
  428.         push    001ch
  429.         jmp     int_emu
  430. new_1d :
  431.         push    001dh
  432.         jmp     int_emu
  433. new_1e :
  434.         push    001eh
  435.         jmp     int_emu
  436. new_1f :
  437.         push    001fh
  438.         jmp     int_emu
  439. new_20 :
  440.         push    0020h
  441.         jmp     int_emu
  442. new_21 :
  443.         push    0021h
  444.         jmp     int_emu
  445. new_22 :
  446.         push    0022h
  447.         jmp     int_emu
  448. new_23 :
  449.         push    0023h
  450.         jmp     int_emu
  451. new_24 :
  452.         push    0024h
  453.         jmp     int_emu
  454. new_25 :
  455.         push    0025h
  456.         jmp     int_emu
  457. new_26 :
  458.         push    0026h
  459.         jmp     int_emu
  460. new_27 :
  461.         push    0027h
  462.         jmp     int_emu
  463. new_28 :
  464.         push    0028h
  465.         jmp     int_emu
  466. new_29 :
  467.         push    0029h
  468.         jmp     int_emu
  469. new_2a :
  470.         push    002ah
  471.         jmp     int_emu
  472. new_2b :
  473.         push    002bh
  474.         jmp     int_emu
  475. new_2c :
  476.         push    002ch
  477.         jmp     int_emu
  478. new_2d :
  479.         push    002dh
  480.         jmp     int_emu
  481. new_2e :
  482.         push    002eh
  483.         jmp     int_emu
  484. new_2f :
  485.         push    002fh
  486.         jmp     int_emu
  487. new_30 :
  488.         push    0030h
  489.         jmp     int_emu
  490. new_31 :
  491.         push    0031h
  492.         jmp     int_emu
  493. new_32 :
  494.         push    0032h
  495.         jmp     int_emu
  496. new_33 :
  497.         push    0033h
  498.         jmp     int_emu
  499. new_34 :
  500.         push    0034h
  501.         jmp     int_emu
  502. new_35 :
  503.         push    0035h
  504.         jmp     int_emu
  505. new_36 :
  506.         push    0036h
  507.         jmp     int_emu
  508. new_37 :
  509.         push    0037h
  510.         jmp     int_emu
  511. new_38 :
  512.         push    0038h
  513.         jmp     int_emu
  514. new_39 :
  515.         push    0039h
  516.         jmp     int_emu
  517. new_3a :
  518.         push    003ah
  519.         jmp     int_emu
  520. new_3b :
  521.         push    003bh
  522.         jmp     int_emu
  523. new_3c :
  524.         push    003ch
  525.         jmp     int_emu
  526. new_3d :
  527.         push    003dh
  528.         jmp     int_emu
  529. new_3e :
  530.         push    003eh
  531.         jmp     int_emu
  532. new_3f :
  533.         push    003fh
  534.         jmp     int_emu
  535. new_40 :
  536.         push    0040h
  537.         jmp     int_emu
  538. new_41 :
  539.         push    0041h
  540.         jmp     int_emu
  541. new_42 :
  542.         push    0042h
  543.         jmp     int_emu
  544. new_43 :
  545.         push    0043h
  546.         jmp     int_emu
  547. new_44 :
  548.         push    0044h
  549.         jmp     int_emu
  550. new_45 :
  551.         push    0045h
  552.         jmp     int_emu
  553. new_46 :
  554.         push    0046h
  555.         jmp     int_emu
  556. new_47 :
  557.         push    0047h
  558.         jmp     int_emu
  559. new_48 :
  560.         push    0048h
  561.         jmp     int_emu
  562. new_49 :
  563.         push    0049h
  564.         jmp     int_emu
  565. new_4a :
  566.         push    004ah
  567.         jmp     int_emu
  568. new_4b :
  569.         push    004bh
  570.         jmp     int_emu
  571. new_4c :
  572.         push    004ch
  573.         jmp     int_emu
  574. new_4d :
  575.         push    004dh
  576.         jmp     int_emu
  577. new_4e :
  578.         push    004eh
  579.         jmp     int_emu
  580. new_4f :
  581.         push    004fh
  582.         jmp     int_emu
  583. new_50 :
  584.         push    0050h
  585.         jmp     int_emu
  586. new_51 :
  587.         push    0051h
  588.         jmp     int_emu
  589. new_52 :
  590.         push    0052h
  591.         jmp     int_emu
  592. new_53 :
  593.         push    0053h
  594.         jmp     int_emu
  595. new_54 :
  596.         push    0054h
  597.         jmp     int_emu
  598. new_55 :
  599.         push    0055h
  600.         jmp     int_emu
  601. new_56 :
  602.         push    0056h
  603.         jmp     int_emu
  604. new_57 :
  605.         push    0057h
  606.         jmp     int_emu
  607. new_58 :
  608.         push    0058h
  609.         jmp     int_emu
  610. new_59 :
  611.         push    0059h
  612.         jmp     int_emu
  613. new_5a :
  614.         push    005ah
  615.         jmp     int_emu
  616. new_5b :
  617.         push    005bh
  618.         jmp     int_emu
  619. new_5c :
  620.         push    005ch
  621.         jmp     int_emu
  622. new_5d :
  623.         push    005dh
  624.         jmp     int_emu
  625. new_5e :
  626.         push    005eh
  627.         jmp     int_emu
  628. new_5f :
  629.         push    005fh
  630.         jmp     int_emu
  631. new_60 :
  632.         push    0060h
  633.         jmp     int_emu
  634. new_61 :
  635.         push    0061h
  636.         jmp     int_emu
  637. new_62 :
  638.         push    0062h
  639.         jmp     int_emu
  640. new_63 :
  641.         push    0063h
  642.         jmp     int_emu
  643. new_64 :
  644.         push    0064h
  645.         jmp     int_emu
  646. new_65 :
  647.         push    0065h
  648.         jmp     int_emu
  649. new_66 :
  650.         push    0066h
  651.         jmp     int_emu
  652. new_67 :
  653.         push    0067h
  654.         jmp     int_emu
  655. new_68 :
  656.         push    0068h
  657.         jmp     int_emu
  658. new_69 :
  659.         push    0069h
  660.         jmp     int_emu
  661. new_6a :
  662.         push    006ah
  663.         jmp     int_emu
  664. new_6b :
  665.         push    006bh
  666.         jmp     int_emu
  667. new_6c :
  668.         push    006ch
  669.         jmp     int_emu
  670. new_6d :
  671.         push    006dh
  672.         jmp     int_emu
  673. new_6e :
  674.         push    006eh
  675.         jmp     int_emu
  676. new_6f :
  677.         push    006fh
  678.         jmp     int_emu
  679. new_70 :
  680.         push    0070h
  681.         jmp     int_emu
  682. new_71 :
  683.         push    0071h
  684.         jmp     int_emu
  685. new_72 :
  686.         push    0072h
  687.         jmp     int_emu
  688. new_73 :
  689.         push    0073h
  690.         jmp     int_emu
  691. new_74 :
  692.         push    0074h
  693.         jmp     int_emu
  694. new_75 :
  695.         push    0075h
  696.         jmp     int_emu
  697. new_76 :
  698.         push    0076h
  699.         jmp     int_emu
  700. new_77 :
  701.         push    0077h
  702.         jmp     int_emu
  703. new_78 :
  704.         push    0078h
  705.         jmp     int_emu
  706. new_79 :
  707.         push    0079h
  708.         jmp     int_emu
  709. new_7a :
  710.         push    007ah
  711.         jmp     int_emu
  712. new_7b :
  713.         push    007bh
  714.         jmp     int_emu
  715. new_7c :
  716.         push    007ch
  717.         jmp     int_emu
  718. new_7d :
  719.         push    007dh
  720.         jmp     int_emu
  721. new_7e :
  722.         push    007eh
  723.         jmp     int_emu
  724. new_7f :
  725.         push    007fh
  726.         jmp     int_emu
  727. new_80 :
  728.         push    0080h
  729.         jmp     int_emu
  730. new_81 :
  731.         push    0081h
  732.         jmp     int_emu
  733. new_82 :
  734.         push    0082h
  735.         jmp     int_emu
  736. new_83 :
  737.         push    0083h
  738.         jmp     int_emu
  739. new_84 :
  740.         push    0084h
  741.         jmp     int_emu
  742. new_85 :
  743.         push    0085h
  744.         jmp     int_emu
  745. new_86 :
  746.         push    0086h
  747.         jmp     int_emu
  748. new_87 :
  749.         push    0087h
  750.         jmp     int_emu
  751. new_88 :
  752.         push    0088h
  753.         jmp     int_emu
  754. new_89 :
  755.         push    0089h
  756.         jmp     int_emu
  757. new_8a :
  758.         push    008ah
  759.         jmp     int_emu
  760. new_8b :
  761.         push    008bh
  762.         jmp     int_emu
  763. new_8c :
  764.         push    008ch
  765.         jmp     int_emu
  766. new_8d :
  767.         push    008dh
  768.         jmp     int_emu
  769. new_8e :
  770.         push    008eh
  771.         jmp     int_emu
  772. new_8f :
  773.         push    008fh
  774.         jmp     int_emu
  775. new_90 :
  776.         push    0090h
  777.         jmp     int_emu
  778. new_91 :
  779.         push    0091h
  780.         jmp     int_emu
  781. new_92 :
  782.         push    0092h
  783.         jmp     int_emu
  784. new_93 :
  785.         push    0093h
  786.         jmp     int_emu
  787. new_94 :
  788.         push    0094h
  789.         jmp     int_emu
  790. new_95 :
  791.         push    0095h
  792.         jmp     int_emu
  793. new_96 :
  794.         push    0096h
  795.         jmp     int_emu
  796. new_97 :
  797.         push    0097h
  798.         jmp     int_emu
  799. new_98 :
  800.         push    0098h
  801.         jmp     int_emu
  802. new_99 :
  803.         push    0099h
  804.         jmp     int_emu
  805. new_9a :
  806.         push    009ah
  807.         jmp     int_emu
  808. new_9b :
  809.         push    009bh
  810.         jmp     int_emu
  811. new_9c :
  812.         push    009ch
  813.         jmp     int_emu
  814. new_9d :
  815.         push    009dh
  816.         jmp     int_emu
  817. new_9e :
  818.         push    009eh
  819.         jmp     int_emu
  820. new_9f :
  821.         push    009fh
  822.         jmp     int_emu
  823. new_a0 :
  824.         push    00a0h
  825.         jmp     int_emu
  826. new_a1 :
  827.         push    00a1h
  828.         jmp     int_emu
  829. new_a2 :
  830.         push    00a2h
  831.         jmp     int_emu
  832. new_a3 :
  833.         push    00a3h
  834.         jmp     int_emu
  835. new_a4 :
  836.         push    00a4h
  837.         jmp     int_emu
  838. new_a5 :
  839.         push    00a5h
  840.         jmp     int_emu
  841. new_a6 :
  842.         push    00a6h
  843.         jmp     int_emu
  844. new_a7 :
  845.         push    00a7h
  846.         jmp     int_emu
  847. new_a8 :
  848.         push    00a8h
  849.         jmp     int_emu
  850. new_a9 :
  851.         push    00a9h
  852.         jmp     int_emu
  853. new_aa :
  854.         push    00aah
  855.         jmp     int_emu
  856. new_ab :
  857.         push    00abh
  858.         jmp     int_emu
  859. new_ac :
  860.         push    00ach
  861.         jmp     int_emu
  862. new_ad :
  863.         push    00adh
  864.         jmp     int_emu
  865. new_ae :
  866.         push    00aeh
  867.         jmp     int_emu
  868. new_af :
  869.         push    00afh
  870.         jmp     int_emu
  871. new_b0 :
  872.         push    00b0h
  873.         jmp     int_emu
  874. new_b1 :
  875.         push    00b1h
  876.         jmp     int_emu
  877. new_b2 :
  878.         push    00b2h
  879.         jmp     int_emu
  880. new_b3 :
  881.         push    00b3h
  882.         jmp     int_emu
  883. new_b4 :
  884.         push    00b4h
  885.         jmp     int_emu
  886. new_b5 :
  887.         push    00b5h
  888.         jmp     int_emu
  889. new_b6 :
  890.         push    00b6h
  891.         jmp     int_emu
  892. new_b7 :
  893.         push    00b7h
  894.         jmp     int_emu
  895. new_b8 :
  896.         push    00b8h
  897.         jmp     int_emu
  898. new_b9 :
  899.         push    00b9h
  900.         jmp     int_emu
  901. new_ba :
  902.         push    00bah
  903.         jmp     int_emu
  904. new_bb :
  905.         push    00bbh
  906.         jmp     int_emu
  907. new_bc :
  908.         push    00bch
  909.         jmp     int_emu
  910. new_bd :
  911.         push    00bdh
  912.         jmp     int_emu
  913. new_be :
  914.         push    00beh
  915.         jmp     int_emu
  916. new_bf :
  917.         push    00bfh
  918.         jmp     int_emu
  919. new_c0 :
  920.         push    00c0h
  921.         jmp     int_emu
  922. new_c1 :
  923.         push    00c1h
  924.         jmp     int_emu
  925. new_c2 :
  926.         push    00c2h
  927.         jmp     int_emu
  928. new_c3 :
  929.         push    00c3h
  930.         jmp     int_emu
  931. new_c4 :
  932.         push    00c4h
  933.         jmp     int_emu
  934. new_c5 :
  935.         push    00c5h
  936.         jmp     int_emu
  937. new_c6 :
  938.         push    00c6h
  939.         jmp     int_emu
  940. new_c7 :
  941.         push    00c7h
  942.         jmp     int_emu
  943. new_c8 :
  944.         push    00c8h
  945.         jmp     int_emu
  946. new_c9 :
  947.         push    00c9h
  948.         jmp     int_emu
  949. new_ca :
  950.         push    00cah
  951.         jmp     int_emu
  952. new_cb :
  953.         push    00cbh
  954.         jmp     int_emu
  955. new_cc :
  956.         push    00cch
  957.         jmp     int_emu
  958. new_cd :
  959.         push    00cdh
  960.         jmp     int_emu
  961. new_ce :
  962.         push    00ceh
  963.         jmp     int_emu
  964. new_cf :
  965.         push    00cfh
  966.         jmp     int_emu
  967. new_d0 :
  968.         push    00d0h
  969.         jmp     int_emu
  970. new_d1 :
  971.         push    00d1h
  972.         jmp     int_emu
  973. new_d2 :
  974.         push    00d2h
  975.         jmp     int_emu
  976. new_d3 :
  977.         push    00d3h
  978.         jmp     int_emu
  979. new_d4 :
  980.         push    00d4h
  981.         jmp     int_emu
  982. new_d5 :
  983.         push    00d5h
  984.         jmp     int_emu
  985. new_d6 :
  986.         push    00d6h
  987.         jmp     int_emu
  988. new_d7 :
  989.         push    00d7h
  990.         jmp     int_emu
  991. new_d8 :
  992.         push    00d8h
  993.         jmp     int_emu
  994. new_d9 :
  995.         push    00d9h
  996.         jmp     int_emu
  997. new_da :
  998.         push    00dah
  999.         jmp     int_emu
  1000. new_db :
  1001.         push    00dbh
  1002.         jmp     int_emu
  1003. new_dc :
  1004.         push    00dch
  1005.         jmp     int_emu
  1006. new_dd :
  1007.         push    00ddh
  1008.         jmp     int_emu
  1009. new_de :
  1010.         push    00deh
  1011.         jmp     int_emu
  1012. new_df :
  1013.         push    00dfh
  1014.         jmp     int_emu
  1015. new_e0 :
  1016.         push    00e0h
  1017.         jmp     int_emu
  1018. new_e1 :
  1019.         push    00e1h
  1020.         jmp     int_emu
  1021. new_e2 :
  1022.         push    00e2h
  1023.         jmp     int_emu
  1024. new_e3 :
  1025.         push    00e3h
  1026.         jmp     int_emu
  1027. new_e4 :
  1028.         push    00e4h
  1029.         jmp     int_emu
  1030. new_e5 :
  1031.         push    00e5h
  1032.         jmp     int_emu
  1033. new_e6 :
  1034.         push    00e6h
  1035.         jmp     int_emu
  1036. new_e7 :
  1037.         push    00e7h
  1038.         jmp     int_emu
  1039. new_e8 :
  1040.         push    00e8h
  1041.         jmp     int_emu
  1042. new_e9 :
  1043.         push    00e9h
  1044.         jmp     int_emu
  1045. new_ea :
  1046.         push    00eah
  1047.         jmp     int_emu
  1048. new_eb :
  1049.         push    00ebh
  1050.         jmp     int_emu
  1051. new_ec :
  1052.         push    00ech
  1053.         jmp     int_emu
  1054. new_ed :
  1055.         push    00edh
  1056.         jmp     int_emu
  1057. new_ee :
  1058.         push    00eeh
  1059.         jmp     int_emu
  1060. new_ef :
  1061.         push    00efh
  1062.         jmp     int_emu
  1063. new_f0 :
  1064.         push    00f0h
  1065.         jmp     int_emu
  1066. new_f1 :
  1067.         push    00f1h
  1068.         jmp     int_emu
  1069. new_f2 :
  1070.         push    00f2h
  1071.         jmp     int_emu
  1072. new_f3 :
  1073.         push    00f3h
  1074.         jmp     int_emu
  1075. new_f4 :
  1076.         push    00f4h
  1077.         jmp     int_emu
  1078. new_f5 :
  1079.         push    00f5h
  1080.         jmp     int_emu
  1081. new_f6 :
  1082.         push    00f6h
  1083.         jmp     int_emu
  1084. new_f7 :
  1085.         push    00f7h
  1086.         jmp     int_emu
  1087. new_f8 :
  1088.         push    00f8h
  1089.         jmp     int_emu
  1090. new_f9 :
  1091.         push    00f9h
  1092.         jmp     int_emu
  1093. new_fa :
  1094.         push    00fah
  1095.         jmp     int_emu
  1096. new_fb :
  1097.         push    00fbh
  1098.         jmp     int_emu
  1099. new_fc :
  1100.         push    00fch
  1101.         jmp     int_emu
  1102. new_fd :
  1103.         push    00fdh
  1104.         jmp     int_emu
  1105. new_fe :
  1106.         push    00feh
  1107.         jmp     int_emu
  1108. new_ff :
  1109.         push    00ffh
  1110.         jmp     int_emu
  1111. int_emu :
  1112.         push    bp
  1113.         mov     bp,sp
  1114.         add     bp,04h
  1115.         push    eax
  1116.         push    ebx
  1117.        mov     ax,0010h                 ;
  1118.        mov     ds,ax                    ;
  1119.         mov     ax,ss:[bp+0ch]          ;
  1120.         sub     ax,06h                  ;
  1121.         mov     ss:[bp+0ch],ax          ;
  1122.         xor     eax,eax                 ;
  1123.         xor     ebx,ebx                 ;
  1124.         mov     ax,ss:[bp+10h]          ;V86 下 IRET 要返回的位址
  1125.         shl     eax,04h                 ;
  1126.         mov     bx,ss:[bp+0ch]          ;
  1127.         add     ebx,eax                 ;
  1128.         mov     ax,ss:[bp+00h]          ;
  1129.         mov     ds:[ebx],ax             ;
  1130.         mov     ax,ss:[bp+04h]          ;
  1131.         mov     ds:[ebx+02h],ax         ;
  1132.         mov     ax,ss:[bp+08h]          ;
  1133.         mov     ds:[ebx+04h],ax         ;
  1134.         nop
  1135.         xor     ebx,ebx                 ;
  1136.         mov     bx,ss:[bp-02h]          ;
  1137.         shl     ebx,02h                 ;
  1138.         mov     ax,ds:[ebx]             ;IRETD後跳到何处执行
  1139.         mov     ss:[bp+00h],ax          ;(查 0000:0000 的中断表)
  1140.         mov     ax,ds:[ebx+02h]         ;
  1141.         mov     ss:[bp+04h],ax          ;
  1142.         mov     eax,ss:[bp+08h]
  1143.         or      eax,00032000h
  1144.         and     eax,0fffffeffh
  1145.         mov     ss:[bp+08h],eax
  1146.         pop     ebx
  1147.         pop     eax
  1148.         pop     bp
  1149.         add     sp,02h
  1150.         iretd
  1151. set_base :
  1152.         mov     cs:[di+02h],ax
  1153.         shr     eax,0010h
  1154.         mov     cs:[di+04h],al
  1155.         mov     cs:[di+07h],ah
  1156.         ret
  1157. next :
  1158.         xor     eax,eax
  1159.         xor     ebx,ebx
  1160.         mov     ax,cs
  1161.         shl     eax,04h
  1162.         mov     bx,offset gdttab
  1163.         add     eax,ebx
  1164.         mov     di,offset gdtadds+02h
  1165.         mov     cs:[di],eax                     ;设定 gdtadds
  1166.         NOP
  1167.         xor     eax,eax
  1168.         xor     ebx,ebx
  1169.         mov     ax,cs
  1170.         shl     eax,04h
  1171.         mov     di,offset gdttab+08h
  1172.         call    set_base                        ;设定 PRG Seg 的 Base
  1173.         NOP
  1174.         xor     eax,eax
  1175.         xor     ebx,ebx
  1176.         mov     ax,cs
  1177.         shl     eax,04h
  1178.         mov     bx,offset tssltr
  1179.         add     eax,ebx
  1180.         mov     di,offset gdttab+18h
  1181.         call    set_base
  1182.         NOP                                     ;设定 TSSltr 的 Base
  1183.         xor     eax,eax
  1184.         xor     ebx,ebx
  1185.         mov     ax,cs
  1186.         shl     eax,04h
  1187.         mov     bx,offset tssjmp
  1188.         add     eax,ebx
  1189.         mov     di,offset gdttab+20h
  1190.         call    set_base
  1191.         NOP                                     ;设定 TSSjmp 的 Base
  1192.         xor     eax,eax
  1193.         xor     ebx,ebx
  1194.         mov     ax,cs
  1195.         shl     eax,04h
  1196.         mov     bx,offset buffer1
  1197.         add     eax,ebx
  1198.         mov     di,offset gdttab+28h
  1199.         call    set_base
  1200.         NOP                                     ;设定 Stack 的 Base
  1201.         xor     eax,eax
  1202.         xor     ebx,ebx
  1203.         mov     ax,cs
  1204.         shl     eax,04h
  1205.         mov     bx,offset idttab
  1206.         add     eax,ebx
  1207.         mov     di,offset idtadds+02h
  1208.         mov     cs:[di],eax                     ;设定 idtadds
  1209.         NOP
  1210.         cli
  1211.         lgdt    fword ptr cs:gdtadds
  1212.         lidt    fword ptr cs:idtadds
  1213.         mov     eax,cr0
  1214.         or      al,01h
  1215.         mov     cr0,eax
  1216.         mov     bx,0018h
  1217.         ltr     bx
  1218.         db      0eah,00h,00h,20h,00h            ;根據TSS表可知跳到enter_v86
  1219. enter_v86 :
  1220.         mov     ax,0028h
  1221.         mov     es,ax
  1222.         xor     eax,eax
  1223.         mov     ax,code
  1224.         push    eax             ;GS
  1225.         push    eax             ;FS
  1226.         push    eax             ;DS
  1227.         push    eax             ;ES
  1228.         push    eax             ;SS
  1229.         mov     ax,0f000h
  1230.         push    eax             ;ESP
  1231.         mov     eax,00023000h   ;设定VM=1    等级=3
  1232.         push    eax             ;Eflag
  1233.         xor     eax,eax
  1234.         mov     ax,code
  1235.         push    eax             ;CS
  1236.         mov     ax,offset return_dos
  1237.         push    eax             ;EIP
  1238.         clts                    ;将 387 切换成 32 位元模式
  1239.         iretd                   ;回到 V86 (共弹出24h BYTE)
  1240. ;-------------------------------------------------------------------------
  1241. ;  下面的程式便是回到 V86 继续执行的程式
  1242. ;-------------------------------------------------------------------------
  1243. return_dos :
  1244.         sti
  1245.         mov     ax,cs
  1246.         mov     ds,ax
  1247.         mov     dx,offset next
  1248.         add     dx,0200h
  1249.         int     27h
  1250. start   endp
  1251. code    ends
  1252.         end     start
  1253. ;-------------------------------------------------------------------------
  1254.     如何侦测现在是在真实模式下或保护模式呢 ,重点就在於 CR0 暂存器的 Bit0
  1255. 是否为 '1' ,若为 '1' 则表示现在在保护模式 ,反之则为真实模式 ,不过如果要
  1256. 执行 MOV EAX,CR0 这个指令必需要在特权等级才能执行 ,所以您要侦测这个位元的
  1257. 话 ,可以使用 SMSW AX ,来读取 CR0 的低位元部份。
  1258. ┌───────────────────────────────────┐
  1259. │  Soft Bugger 软体蛀虫 90:90/2                    软体新技术的实行者  │
  1260. │  BBS:02-5955461 24HR          ID:Werong Ho               -- 软蛀 --  │
  1261. └───────────────────────────────────┘