home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tools / profiler / prf / prf.asm < prev    next >
Assembly Source File  |  1988-11-23  |  9KB  |  318 lines

  1. ; 80286 ASSEMBLER
  2.  
  3.         PAGE        42, 132
  4.         TITLE        prf.asm
  5.         .286c
  6.  
  7.  
  8. VERSION    EQU 0001
  9. REVISION EQU 0000
  10. MODIFICATION EQU 0000    
  11. PRINT EQU 0000
  12.  
  13. ;
  14. ; File:
  15. ;        prf.asm    - PROFILING TOOL
  16. ;
  17.  
  18. ;*******************************************************************************
  19. ;*                             INCLUDE FILES                                   *
  20. ;*******************************************************************************
  21.         INCLUDE    prf.h
  22.  
  23. ;*******************************************************************************
  24. ;*                               CONSTANTS                                     *
  25. ;*******************************************************************************
  26. PRFInterrupt    equ    88H
  27. PROFILE_DWORDS  equ    8192 
  28.  
  29. ;*******************************************************************************
  30. ;*                             PUBLIC SYMBOLS                                  *
  31. ;*******************************************************************************
  32.  
  33.         PUBLIC  FirstByte        ;used for TSR code
  34.         PUBLIC  LastByte        ;           "
  35.         PUBLIC  TimerISR        ;timer interrupt routine
  36.         PUBLIC    _PRF_SWEntry        ;prf software entry point
  37.                  
  38. ;*******************************************************************************
  39. ;*                                                                             *
  40. ;*                                                                             *
  41. ;*                                                                             *
  42. ;*                        DATA    STRUCTURES                                   *
  43. ;*                                                                             *
  44. ;*                                                                             *
  45. ;*                                                                             *
  46. ;*******************************************************************************
  47.     
  48. ;*******************************************************************************
  49. ;*                             SEGMENT STUFF                                   *
  50. ;*******************************************************************************
  51.  
  52. ; Code and data segment (SAME)
  53. CODE        SEGMENT PARA PUBLIC
  54.         assume cs:CODE
  55.  
  56. ;*******************************************************************************
  57. ;*                                                                             *
  58. ;*       ALL DATA BETWEEN  FirstByte:  AND  LastByte: REMAIN RESIDENT          *
  59. ;*                                                                             *
  60. ;*******************************************************************************
  61. FirstByte:              
  62.  
  63. ;*******************************************************************************
  64. ;*                  PRF EXTERNAL FUNCTION CALL JUMP TABLE                      *
  65. ;*******************************************************************************
  66. ; jump table for prf Software functions
  67. JumpTable    dw    OFFSET    PRF_START
  68.         dw    OFFSET    PRF_STOP
  69.  
  70. ;*******************************************************************************
  71. ;*                        PRF TIMER INTERRUPT VARIABLES                        *
  72. ;*******************************************************************************
  73.  
  74. TimerChain    dd    ?
  75. ProfileSegment    dw    0
  76.         even
  77.         dw    0
  78. ProfileData    dd    PROFILE_DWORDS dup (0)
  79.  
  80. ;*******************************************************************************
  81. ;*                                                                             *
  82. ;*                        PRF RESIDENT IDENTIFICATION                   *
  83. ;*             MUST BE PLACED JUST BEFORE PRF SOFTWARE ENTRY POINT             *
  84. ;*                                                                             *
  85. ;*******************************************************************************
  86.         db    'P','R','F'
  87.         dw    VERSION,REVISION,MODIFICATION,PRINT
  88.  
  89. ;*******************************************************************************
  90. ;*                                                                             *
  91. ;*                       PRF FUNCTION CALL ENTRY POINT                         *
  92. ;*  ENTRY:               SS:BP -> PARAMETERS                                   *
  93. ;*  EXIT:                DX:AX == RETURN PARAMETER                             *
  94. ;*                                                                             *
  95. ;*******************************************************************************
  96. _PRF_SWEntry:        
  97.         sti
  98.         push    ds            ;save registers
  99.         push    si
  100.         push    di
  101.  
  102. ; SS:BP --> parameters of call
  103.         mov    ax, cs            ;setup DS
  104.         mov    ds, ax
  105.         mov    es, ax
  106.         cld            
  107.  
  108. ; DS is PRF data segment (CS)
  109.         assume    cs:CODE, ds:CODE, es:CODE, ss:nothing
  110.         mov    bx, FunctionCode[bp]    ;get function code
  111.  
  112.         call    JumpTable[bx]        ;go to IT
  113.  
  114. PRF_SWBack:
  115.         pop    di            ;restore regs
  116.         pop    si
  117.         pop    ds                     
  118.         iret        
  119.  
  120. ;*******************************************************************************
  121. ;*                         PRF_START                                           *
  122. ;*******************************************************************************
  123.            
  124. PRF_START             proc    near
  125.             mov     cs:ProfileSegment, 0
  126.  
  127.             mov    ax, cs
  128.             mov    ds, ax
  129.  
  130.             mov    bx, OFFSET ProfileData
  131.             mov    cx, PROFILE_DWORDS
  132.             
  133.  
  134.             mov    word ptr [bx-2] , 0
  135. CLEAR_LOOP:        mov    word ptr [bx], 0
  136.             add    bx, 2         
  137.             mov    word ptr [bx], 0
  138.             add    bx, 2
  139.             loop    CLEAR_LOOP
  140.  
  141.             mov    ax, S0_CodeSegment[bp]
  142.             mov    cs:ProfileSegment, ax
  143.  
  144.             ret
  145.  
  146.         
  147. PRF_START             endp
  148.  
  149. ;*******************************************************************************
  150. ;*                         PRF_DEREGISTER_NAME                                 *
  151. ;*******************************************************************************
  152. PRF_STOP                proc    near
  153.  
  154.             mov    cs:ProfileSegment, 0
  155.             mov    ax, cs
  156.             mov    dx, ax
  157.             mov    ax, OFFSET ProfileData
  158.             ret
  159.  
  160. PRF_STOP                 endp
  161.                         
  162. ;*******************************************************************************
  163. ;*                                                                             *
  164. ;*                      PRF TIMER INTERRUPT ENTRY POINT                        *
  165. ;*                                                                             *
  166. ;*******************************************************************************
  167.  
  168. ; decrement timeouts, leave at zero when reaches zero
  169. TimerISR:            
  170.         test    cs: ProfileSegment, -1
  171.         je    TimerExit
  172.  
  173.         ;       FLAGS
  174.         ;       SEGMENT OF INTERRUPTEE
  175.         ; SP --->  OFFSET  OF INTERRUPTEE
  176.  
  177.         push    bp
  178.         mov    bp, sp
  179.  
  180.         ;       FLAGS
  181.         ;       SEGMENT OF INTERRUPTEE
  182.         ;          OFFSET  OF INTERRUPTEE
  183.         ; BP --->  PUSHED BP
  184.  
  185.         pusha
  186.         push    ds
  187.         push    es
  188.  
  189.         ; debug
  190.         mov    ax, 0b800h
  191.         mov    es, ax
  192.  
  193.         inc     WORD PTR cs:[ProfileData-2]
  194.  
  195.         mov    ax, cs:ProfileSegment
  196.         cmp    ax, 4[bp]
  197.         jne    SomeOneElse
  198.  
  199. Us:        mov    bx, 2[bp]
  200.         shr    bx, 1
  201.         and    bl, 0FCH
  202.         add    word ptr cs:[bx+ProfileData], 1
  203.         adc    word ptr cs:[2+bx+ProfileData], 0
  204.         jnc    IntExit
  205.  
  206.         dec    word ptr cs:[2+bx+ProfileData]
  207.  
  208.         jmp    IntExit
  209.  
  210. SomeOneElse:
  211.  
  212. IntExit:
  213.         pop    es
  214.         pop    ds
  215.         popa
  216.         pop    bp
  217.  
  218. TimerExit:    jmp    cs:[TimerChain]                    
  219.  
  220.  
  221. LastByte:                       
  222.  
  223. ;*******************************************************************************
  224. ;*                                                                             *
  225. ;*                            _InitPRF                          *
  226. ;* Purpose:                                                                    *
  227. ;* Initialises PRF                                                             *
  228. ;*                                                                             *
  229. ;*******************************************************************************
  230.  
  231.         PUBLIC    main
  232.  
  233. main        proc    near
  234.     
  235.         mov    ax, cs
  236.         mov    ds, ax            ;Data Seg for PRF
  237.  
  238.         cld
  239.  
  240.         mov    dx, OFFSET sPRF_Ok
  241.                    mov    ah, 9            ;print string
  242.         int    21h            ;MSDOS
  243.  
  244. ; See if PRF Sublayer is already loaded.
  245.  
  246.         mov    si, PRFInterrupt    ;get interrupt number
  247.         shl    si, 1
  248.         shl    si, 1            ;make into vector pointer
  249.         xor    ax, ax            ;will be segment zero
  250.         mov    es, ax            ;use ES
  251.         mov    ax, es:[si]        ;check vector is
  252.         or    ax, es:2[si]        ;zero (unused)
  253.         mov    dx, OFFSET sPRF_Loaded
  254.         je    PRFNotLoaded
  255.  
  256. PrintString:    mov    ah, 9            ;print string
  257.         int    21h            ;MSDOS
  258.  
  259.         mov    ax, 4c01h
  260.         int    21h            ;end process
  261.  
  262.  
  263. PRFNotLoaded:    
  264.  
  265. ; Set up the PRF interrupt vector so that programs may call the PRF.
  266.  
  267.         mov    si, PRFInterrupt
  268.         shl    si, 1
  269.         shl    si, 1
  270.         xor    ax, ax
  271.         mov    es, ax
  272.         mov    es:2[si], cs
  273.         mov    word ptr es:[si], OFFSET _PRF_SWEntry
  274.  
  275. ; Initialise timer interrupt chain
  276.                     
  277.         mov    bx, 20h                       
  278.         cli
  279.         mov    ax, es:[bx]    
  280.         mov    word ptr [TimerChain], ax
  281.         mov    ax, OFFSET TimerISR
  282.         mov    word ptr es:[bx], ax
  283.  
  284.         mov    ax, word ptr es:[bx+2]
  285.         mov    word ptr [TimerChain+2], ax
  286.         mov    ax, cs
  287.         mov    word ptr es:[bx+2], ax
  288.         sti
  289.  
  290. ;
  291. ; Terminate and stay resident with minimal (PSP) wastage
  292. ;
  293.  
  294. ; Calculate bytes to save
  295.  
  296.         mov    dx, ( ((OFFSET LastByte) - (OFFSET FirstByte)) + 256 + 16 ) / 16
  297.  
  298.         mov    ax, 03100h        ;KEEP PROCESS, no error
  299.         int    021h            ;MSDOS
  300.                                
  301. sPRF_Loaded:    db    'INT88 already used.', 13, 10, '$'
  302. sPRF_Ok:    db    "Profiling Tool            - "
  303.         db    "Version "
  304.         db    VERSION+'0'
  305.         db    '.'
  306.         db    REVISION+'0'
  307.         db    ':'
  308.         db    MODIFICATION+'0'
  309.         db    13, 10, '$'
  310.  
  311. main        endp
  312.  
  313. CODE        ends
  314.         end    main
  315.     
  316.  
  317.