home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / DOS32V3B / EXAMPLES / EG10.ASM < prev    next >
Assembly Source File  |  1995-02-09  |  5KB  |  220 lines

  1. ;****************************************************************************
  2. ;       DOS32  DOS   EXTENDER                   By Adam Seychell
  3. ;
  4. ;    Example program demonstrating the Debugger.
  5. ;
  6. ;
  7. ;  Don't forget to link in DEBUG.OBJ
  8. ;
  9. ;****************************************************************************
  10. .386p
  11. .model flat
  12. .stack 65*1024                                   ; Define a 65Kb stack
  13.  
  14. assume gs:_TEXT,fs:_TEXT                         ; For some reson the
  15.                                                  ; assembler needs this line
  16.  
  17.  
  18. EXTRN   Debug   :Near                           ; Define external symbol
  19.  
  20.  
  21. .DATA
  22. My_Array                DD 8000h dup (?)
  23.  
  24.  
  25. .CODE
  26.  
  27. _48bit_pointer  df   00
  28.  
  29. Program_base    dd   ?
  30. My_varible      db   0
  31.  
  32. g1 db '11111111111111$'
  33. g2 db '11111111111111$'
  34.  
  35. Intro_mesg   db    'Press any key to start the debugger ',10,13,36
  36.  
  37. Start32:                                        ; Start of program
  38.  
  39.  
  40. ;
  41. ;  Print intro message
  42. ;
  43.         mov     edx,offset Intro_mesg
  44.         mov     ah,9
  45.         int     21h
  46.  
  47.         mov      ah,0
  48.         int      16h
  49.  
  50.  
  51. ;
  52. ;  Must start the debugger with a call.
  53. ;
  54.  
  55.         call    Debug
  56.  
  57.  
  58.         mov     ax,0EE02h
  59.         int     31h
  60.         mov     Program_base,ebx
  61.         cbw
  62.         cwd
  63.         cwde
  64.         cdq
  65.  
  66.         push    ds
  67.         pop     ds
  68.  
  69.         mov   edx,offset  g1
  70.         mov   ah,9
  71.         int   21h
  72.         mov   edx,offset  g2
  73.         int   21h
  74.  
  75.  
  76. ;
  77. ;       Some instrucions just to show off the debugger.
  78. ;
  79.  
  80.  
  81.         xor     eax,eax
  82.         mov     edi,Offset My_Array
  83.         xor     eax,eax
  84.         mov     ecx,30
  85.         cld
  86.  
  87.         rep     stosd
  88.  
  89.  
  90.         mov     eax,1
  91.         mov     ebp,2
  92.         mov     ecx,3
  93.         mov     edx,4
  94.         mov     edi,5
  95.         mov     esi,6
  96.         mov     ebp,7
  97.  
  98.         pushad
  99.  
  100.         mov     ecx,10
  101.         loop $
  102.  
  103.         push    00000000h
  104.         push    11111111h
  105.         push    22222222h
  106.         push    33333333h
  107.  
  108.         mov     eax,ds:[1]
  109.      ;   int     3                        ; put in a breakpoint
  110.         mov     eax,ds:[2]
  111.  
  112.         call    test_proc
  113.  
  114.         sub     edx,edx                 ; Load NUL selectors in FS and ES
  115.         mov     fs,dx
  116.         mov     es,dx
  117.         stc
  118.         std
  119.         clc
  120.         sti
  121.         nop
  122.         mov     edx,-1
  123.         mov     ebp,1
  124.         movzx   eax,word ptr gs:[edx+2*ebp+00000004ah]
  125.         mov     edx,eax
  126.  
  127.         lea     eax,fs:[edx+ebp*8+333]
  128.       ;  mov     ax,word ptr [bx+di]
  129.         imul    eax,ebx,12345678h
  130.  
  131.         mov     dword ptr _48bit_pointer,offset  far_jump
  132.         mov     word ptr _48bit_pointer+4,cs
  133.  
  134.  
  135.         jmp     fword ptr cs:[_48bit_pointer]
  136.  
  137.  
  138.  
  139. test_proc       proc
  140.         stc
  141.         std
  142.         clc
  143.         sti
  144.         nop
  145.         smsw  dx
  146.         ret
  147. test_proc       endp
  148.  
  149.  
  150.  
  151.  
  152.  
  153. far_jump:
  154.  
  155.  
  156.  
  157.  
  158.  
  159. ;
  160. ;  Load in the debug registers and set breakpoint registers 0 and 2.
  161. ;
  162.  
  163.  
  164.     ;
  165.     ;  Load DR0 with breakpoint address
  166.     ;
  167.         mov     eax,offset My_varible  ; first get offset and add the
  168.         add     eax,Program_base       ; segment base to give linear address.
  169.         mov     DR0,eax               ; Load 32bit Linear address
  170.  
  171.    ;
  172.    ;  Load DR2 with breakpoint address
  173.    ;
  174.  
  175.         mov     eax,offset  brkpt2    ; first get offset and add the
  176.         add     eax,Program_base      ; segment base to give linear address
  177.         mov     DR2,eax               ; Load 32bit Linear address
  178.  
  179.  
  180.     ;
  181.     ; Load   DR7      (See Intel docs for register description)
  182.     ;
  183.  
  184. ;                W0 = 1                W2 = 0
  185. ;                R0 = 1                R2 = 0
  186. ;                LEN0 = 0              LEN2 = 0
  187. ;                G0 = 1                G2 = 1
  188. ;                GE = 1
  189. ;                all other fields are zero
  190.  
  191.         mov     eax,000030222h
  192.         mov     DR7,eax
  193.  
  194.  
  195.  
  196. ;
  197. ;  Do some instrucions that should invoke the breakpoint registers.
  198. ;
  199.  
  200.         mov     ebp,2
  201.         mov     ecx,3
  202.         mov     edx,4
  203.         mov     edi,5
  204. brkpt2: mov     ebp,0          ;<- this instrucion will cause breakpoint 2
  205.         mov     ecx,3
  206.         mov     edx,4
  207.         mov     edi,5
  208.         mov     al,[My_varible]   ;<- this data read will cause breakpoint 0
  209.         mov     esi,6
  210.         mov     ebp,7
  211.  
  212.  
  213.         mov     ah,4ch          ; Terminate  Program
  214.         int     21h
  215.  
  216.  
  217.  
  218.  
  219. END Start32
  220.