Chinaunix

标题: 在进行调用门切换的时候出现问题了 [打印本页]

作者: pang68599    时间: 2012-04-26 14:51
标题: 在进行调用门切换的时候出现问题了

labelcallgatecode32:
descriptor        labelcallgatelen - 1, 0000h,00h, ACER | AC_D ,00h
不能访问
是不是我的cpl和rpl设置出错了?

特权0时的cpu状态:

特权3时候的cpu:



  1. [section .s321]
  2. [BITS 32]
  3. pt:
  4.         jmp $
  5.         nop
  6.         nop
  7.         mov ax , gdt_ss_sel
  8.         mov ss , ax
  9.         mov esp , 512

  10.         mov ax , data32_sel
  11.         mov es , ax
  12.         mov si ,  (80 * 5 + 10) * 2
  13.         mov byte [es:si] , 'W'
  14.         inc si
  15.         mov byte [es:si] , 01101100b


  16.         mov si ,  (80 * 7 + 18) * 2
  17.         mov byte [es:si] , 'L'
  18.         inc si
  19.         mov byte [es:si] , 01101100b


  20.         ;load ldt
  21.         mov ax , ldt_sel
  22.         lldt ax


  23.         mov si ,  (80 * 7 + 19) * 2
  24.         mov byte [es:si] , 'L'
  25.         inc si
  26.         mov byte [es:si] , 01101100b


  27.         mov ax , tss_sel
  28.         ltr ax
  29.        

  30.         ;jmp ldtcode32_sel:0
  31.         ;
  32.         ;修改特权级为3
  33.         jmp $
  34.         nop
  35.         nop

  36.         mov eax , 512
  37.         push stack2_sel
  38.         push eax
  39.         push ldtcode32_sel2
  40.         push 0
  41.         retf

  42. JMPREAL:
  43.         jmp dword code16_sel:0
  44.         ptlen equ $ - pt
  45. ;end of [section .s321]

  46. ;use ldt jump ldtpt
  47. ;特权级别为3
  48. [section .s322]
  49. [BITS 32]
  50. ldtpt:
  51.        

  52.         mov ax , 01234h
  53.        
  54.         push ax
  55.         pop ax
  56.         call call_gate32_sel:0
  57.         ;这里设置成了直接调用而 不是间接调用门去访问       
  58.         ;call labelcallgatecode32_sel:0
  59.         mov ax , 3456h
  60.         call call_gatecode32tocode16_sel:0

  61.         ldtptlen equ $ - ldtpt
  62. ;end of [section .s322]

  63. [section .callgate32]
  64. [BITS 32]
  65. ;0级权限,但是通过gate能被ldtpt这个3级权限的code segment调用
  66. labelcallgate:

  67.         mov ax , data32_ldt_sel
  68.         mov es , ax
  69.        
  70.         mov si ,  (80 * 8 + 1) * 2
  71.         mov byte [es:si] , 'C'
  72.         inc si
  73.         mov byte [es:si] , 01101100b

  74.         ;retf
  75.         call call_gatecode32tocode16_sel:0

  76.         labelcallgatelen equ $ - labelcallgate
  77. ;end of [section .callgate32]



  78. [section .s162]

  79. ;----------------------------- ldt --------------------------------------
  80. [section .ldt]
  81. [BITS 16]
  82. LABEL_LDT:
  83.        

  84.         ;这里为什么DPL要于RPL一样呢?
  85.         ldtcode32:
  86.                 descriptor        ldtptlen - 1,0000h,00h,ACER | AC_D  + DA_DPL2 ,00h
  87.                 ldtcode32_sel3        equ         ldtcode32 - LABEL_LDT  + SA_TIL + RA_RPL3
  88.                 ldtcode32_sel2        equ         ldtcode32 - LABEL_LDT  + SA_TIL + RA_RPL2
  89.                 ldtcode32_sel0        equ         ldtcode32 - LABEL_LDT  + SA_TIL

  90.         ;调用门目标段代码
  91.         labelcallgatecode32:
  92.                 descriptor        labelcallgatelen - 1, 0000h,00h, ACER | AC_D   ,00h
  93.                 labelcallgatecode32_sel0        equ        labelcallgatecode32 - LABEL_LDT + SA_TIL
  94.                 labelcallgatecode32_sel3        equ        labelcallgatecode32 - LABEL_LDT + SA_TIL + RA_RPL3



  95.         data32_ldt:
  96.                 descriptor        0ffffh,0000h,00h,ADRW  ,00h
  97.                 data32_ldt_sel        equ        data32_ldt - LABEL_LDT + SA_TIL
  98.                 data32_ldt_sel3        equ        data32_ldt - LABEL_LDT + SA_TIL + RA_RPL3

  99.         call_gate32:
  100.                 gate                        0000h , labelcallgatecode32_sel0 , 00h , GA_386CALL + DA_DPL3 ,0000h
  101.                 call_gate32_sel                equ        call_gate32 - LABEL_LDT + SA_TIL
  102.        
  103.         ;call_gatecode32tocode16:
  104.         ;        gate                        0000h , code16_sel , 00h , GA_386CALL ,00h
  105.         ;        call_gatecode32tocode16_sel                equ        call_gatecode32tocode16 - LABEL_LDT + SA_TIL
  106.        
  107.         call_gatecode32tocode16:
  108.                 gate                        0000h ,backcode32_sel , 00h , GA_386CALL  ,0000h
  109.                 call_gatecode32tocode16_sel                equ        call_gatecode32tocode16 - LABEL_LDT + SA_TIL
  110.        
  111.         backcode32:
  112.                 descriptor        0ffffh,0000h,00h,ACER | AC_D,00h
  113.                 backcode32_sel        EQU        backcode32 - LABEL_LDT + SA_TIL
  114.         LDTLEN                equ        $ - LABEL_LDT
  115.         ldtlen equ $ - LABEL_LDT
  116. ;end of [section .ldt]
复制代码



作者: pang68599    时间: 2012-04-26 15:17
有谁可以帮我解决下啊。。。。
作者: pang68599    时间: 2012-04-26 19:14
木有人回答。。。。各位大侠在哪里




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2