home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n02 / emulate.asc < prev    next >
Encoding:
Text File  |  1991-12-17  |  4.2 KB  |  202 lines

  1. _PROTECTED-MODE DEBUGGING USING IN-CIRCUIT EMULATORS_
  2. by Tovey Barron
  3.  
  4. Example 1
  5.          
  6.  
  7.     lgdt  pword ptr gdt_reg_values
  8.                          ; Load global descriptor table register
  9.     mov   eax,cr0        ; Set Protection Enabled bit to go into protected
  10.     or    eax,1          ;  mode
  11.     mov   cr0,eax
  12.     jmp   next           ; Flush prefetch queue to get rid of instructions
  13.                          ;  decoded in real mode 
  14. next: 
  15.     xor   bx,d_seg_selector; Initialize data selectors with appropriate
  16.     mov   ds,bx          ;  values - here, we see FLAT model
  17.     mov   es,bx          ;  initialization
  18.     mov   fs,bx 
  19.     mov   gs,bx 
  20.     mov   ss,bx 
  21. pejump: 
  22.     jmp    full_prot_code ; FAR jump, loads CS register with protected mode 
  23.                           ;  value and branches to full protected mode code
  24.          
  25.  
  26.  
  27.  
  28. Example 2
  29.  
  30. (a)
  31.  
  32. hlt> gdtbas    /* Display the base field of the GDT register  */
  33. 11000
  34. hlt>
  35. hlt> gdtlim    /* Display the limit field of the GDT register */
  36. 77
  37.  
  38. (b)
  39.          
  40. hlt> &gdt_reg_values    /* Display address of variable.          */
  41. some-address-here   /* The address would be displayed in     */
  42.                         /* virtual format, i.e. seg:offset or    */
  43.                         /* ldt:seg:offset, depending on whether  */
  44.                         /* code is in real or protected mode     */
  45.  
  46. (c)
  47.  
  48. hlt> byte &gdt_reg_values L length 6
  49. 0ffff0168L  77 00 00 10 01 00 
  50.  
  51.  
  52.  
  53. Example 3
  54.          
  55. hlt> d_seg_selector
  56. 003B
  57.  
  58.  
  59.  
  60. Example 4
  61.  
  62. (a)
  63.  
  64. hlt> dt(3BH)
  65. GDT(7T)   0040F30116C0017B
  66.           DSEG    BASE=000116C0 LIMIT=0017B DPL=3 P=1 G=0 V=0 B=1 E=0 W=1 A=1
  67.  
  68.  
  69. (b)
  70.  
  71. hlt> dt(38).limit = 27B
  72.  
  73. (c)
  74.  
  75. hlt> dt(38).limit = dt(38).limit + 100
  76.  
  77.  
  78.  
  79. Example 5
  80.  
  81. hlt> asm full_prot_code length 5
  82. ;  :TASK_1.PROC_A.full_prot_code
  83. 0098:0014:00000000H 1E           PUSH   DS
  84. 0098:0014:00000000H 66B9F900     MOV    CX,0F9H
  85. 0098:0014:00000000H 8ED9         MOV    DS,CX
  86. 0098:0014:00000000H 8EC1         MOV    EX,CX
  87. 0098:0014:00000000H 55           PUSH   EBP
  88.  
  89.  
  90.  
  91. Example 6
  92.  
  93. hlt> gdt          /* Display the contents of the GDT  */
  94. GDT(1T)   00009201100000FF
  95.           DSEG    BASE=00011000 LIMIT=000FF DPL=0 P=1 G=0 V=0 B=0 E=0 W=1 A=0 
  96. GDT(17T)  00409A01146C0055
  97.           ESEG    BASE=0001146C LIMIT=00055 DPL=0 P=1 G=0 V=0 D=1 C=0 R=1 A=0
  98. GDT(19T)  0000820112000027
  99.           DTABL   BASE=00011200 LIMIT=00027 DPL=0 P=1 G=0 V=0 
  100. GDT(26T)  0000EC0000150000
  101.           CALLG3  SSEL=0015  SOFF=00000000   DPL=3  P=1  WCO=00
  102.  
  103.  
  104.  
  105. Example 7
  106.          
  107. hlt> idt
  108.  
  109. IDT(0T)    FFFF8E00001803A4
  110.            INTG3   SSEL=0018 SOFF=FFFF03A4   DPL=0 P=1 
  111. IDT(1T)    FFFF8E00001803A8
  112.            INTG3   SSEL=0018 SOFF=FFFF03A8   DPL=0 P=1 
  113. IDT(2T)    FFFF8E00001803AC
  114.            INTG3   SSEL=0018 SOFF=FFFF03AC   DPL=0 P=1 
  115.  
  116.  
  117.  
  118. Example 8
  119.  
  120. (a)
  121.          
  122. hlt> gdt(19t)
  123. GDT(19T)  0000820112000027
  124.           DTABL   BASE=00011200 LIMIT=00027 DPL=0 P=1 G=0 V=0 
  125.  
  126.  
  127. (b)
  128.  
  129. gdt(7).ldt(3).limit = 12345H
  130.  
  131.  
  132.  
  133. Example 9
  134.  
  135. (a)
  136.  
  137. hlt> tss
  138. 386 TSS
  139.  
  140. SS0= 00f0      ESP0= 00000101  SS1= 001d       ESP1= 00000101
  141. SS2= 0000      ESP2= 00000000
  142. EAX= 00000000  EBX= 00000000   ECX= 00000000   EDX= 00000000 
  143. DS=  00fb      ES=  00fb       FS=  00fb       GS=  00fb
  144. ESI= 00000000  EDI= 00000000
  145. SS=  001d      CS=  0025       
  146. ESP= 00000101  EIP= 00000000
  147. EBP= 00000101  LDTR=00b0
  148. LINK= 0068     EFLAGS= 00000000   CR3= 00000000
  149.  
  150.  
  151. (b)
  152.  
  153. hlt> tss(50)
  154.  
  155.  
  156. (c)
  157.  
  158. hlt> tss(50).esp2
  159.  
  160.  
  161.  
  162. (d)
  163.  
  164. hlt> tss(50).ldtr
  165. 0068
  166.  
  167.  
  168. (e)
  169.  
  170. hlt> dt(68)
  171. GDT(13T)   0000820112000027
  172.            DTABL    BASE=00011200 LIMIT=00027 DPL=0 P=1 G=0 V=0
  173.  
  174.  
  175. (f)
  176.  
  177. hlt> gdt(13t).ldt  /* For brevity, the LDT will not be shown */
  178.  
  179.  
  180.  
  181. Example 10
  182.  
  183. hlt> ldtbas       /* Display base field of the current LDT  */
  184. 00011200H
  185.  
  186. hlt> idtlim       /* Display limit field of current IDT     */ 
  187. 00ffH
  188.  
  189. hlt> tr           /* Display selector field of current TR   */
  190. 0080H
  191.          
  192. hlt> dslim = dslim + 35H  /* Change limit of current data segment   */ 
  193.  
  194. hlt> cs           /* Display selector in CS register        */
  195. 0025H
  196.          
  197. hlt> csar         /* Display the access rights bits as they */
  198. 0bbH              /* appear in the current CS register       */
  199.  
  200.  
  201.  
  202.