home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 02a / pctj1186.zip / PRF.ASM < prev    next >
Assembly Source File  |  1986-09-19  |  12KB  |  293 lines

  1. ;USER-CHANGEABLE CONSTANTS
  2.  
  3. ;NUMBER OF BYTES IN DATA TABLE (F000 = 60K)
  4.   Table_Size        EQU    0F000H        
  5. ;NUMBER OF TICKS BETWEEN JUMPS TO ORIGINAL CLOCK INTERRUPT HANDLER
  6. ;  = CLOCK SPEEUP FACTOR
  7.   Number_Of_Ticks    EQU    1
  8.  
  9. ;OTHER CONSTANTS
  10.  
  11. ;MAXIMUM VALUE OF COUNTDOWN FOR TIMER 0 INTERRUPT
  12.   Max_Timer_Count    EQU    0FFFFH
  13. ;NEW VALUE OF COUNTDOWN FOR TIMER 0 INTERRUPT
  14.   New_Timer_Count    EQU    Max_Timer_Count / Number_Of_Ticks
  15.  
  16. PSP        SEGMENT    PUBLIC
  17.         ASSUME    CS:PSP, DS:PSP, ES:PSP, SS:PSP
  18.         ORG    100H            ;COM FILE!
  19. ;------------------------------------------------------------------
  20. ;  profiler kernel                                                ;
  21. ;                                                                 ;
  22. ; tricks:                                                         ;
  23. ;     1. program executes file 'subject.com' - which may be       ;
  24. ;        a com or exe file.  use a batch file to copy subject     ;
  25. ;     file to 'subject.com'.                                   ;
  26. ;     2. run with 'prf fn1 fn2', where 'fn1' and 'fn2'            ;
  27. ;        are the parameters you would have typed if you had been  ;
  28. ;     running the subject code itself.  this allows            ;
  29. ;     copying the formatted file info from the profiler's      ;
  30. ;     psp into the psp for the subject code.                   ;
  31. ;-----------------------------------------------------------------;
  32. PRF        PROC    FAR
  33.         MOV    SP, OFFSET END_STACK    ; set top of stack to
  34.                         ; internal area
  35.         CALL    FREE_MEM            ; free unused memory
  36.         CALL    REPLACE_TIMER    ; replace timer/interrupt
  37.         CALL    EXEC_SUBJECT    ; execute & collect data
  38.         CALL    RESTORE_TIMER    ; restore timer/interrupt
  39.         CALL    EXEC_PRINT    ; execute data reduction
  40.                                         ; and printout program
  41.         INT    20H        ; terminate
  42. PRF        ENDP
  43. ;-------------------------------------------------------------------
  44. ;    returns unused memory to dos                               ;
  45. ;-------------------------------------------------------------------
  46. FREE_MEM    PROC    NEAR
  47.         MOV    BX, OFFSET EOM    ; offset of top of memory
  48.         MOV    CL, 4        ; shift count
  49.         SHR    BX, CL        ; divide by 16 to get 
  50.                                         ; number of paragraphs
  51.         ADD    BX, 1        ; in case not multiple of 16
  52.         MOV    AH, 4AH        ; code for memory release
  53.         INT    21H        ; do the shrink
  54.         JNC    SUCCESS        ; go on if carry flag 
  55.                                         ; is zero (no error)
  56.         MOV    AH, 9        ; code for print string
  57.         MOV    DX, OFFSET MEM_ERR_STRNG    
  58.                                         ;  error message
  59.         INT    21H        ; dos function call for print
  60.         INT    20H        ; end if error returned
  61. SUCCESS:    RET            ; return
  62. FREE_MEM    ENDP
  63. ;-----------------------------------------------------------------;
  64. ;    run subject program under profiler                           ;
  65. ;-----------------------------------------------------------------;
  66. EXEC_SUBJECT    PROC    NEAR
  67.         MOV    AX, CS        ; to set seg registers
  68.         MOV    DS, AX          ; ds:dx point to asciiz 
  69.                                         ; string with name of 
  70.         MOV    DX, OFFSET SUBJECT_NAME  ; file to execute
  71.         MOV    ES, AX                     ; es:bx point to
  72.         MOV    BX, OFFSET EXEC_PARAMS     ; parameter block
  73.         MOV    CX, CS:[2CH]         ; set segment address 
  74.         MOV    ENVIRON_SEG, CX      ; of passed environment
  75.         MOV    COMMND_OFS, 80H    ; set offset and segment 
  76.         MOV    COMMND_SEG, CS     ; of passed command line
  77.         MOV    FCB1_OFS, 5CH      ; set offset and segment 
  78.         MOV    FCB1_SEG, CS       ; of unopened fcb1
  79.         MOV    FCB2_OFS, 6CH      ; set offset and 
  80.         MOV    FCB2_SEG, CS       ; segment of unopened fcb2
  81.         MOV    AX, 4B00H          ; set ax register for load
  82.                                            ; and execute dos call
  83.         MOV    ACCUM_FLAG, 1      ; turn on address accumulation 
  84.                                            ; flag
  85.         MOV    SAV_SP, SP    ; save stack pointer
  86.         INT    21H          ; do interrupt
  87.         MOV    AX, CS        ; restore
  88.         MOV    ES, AX        ; segment registers
  89.         MOV    DS, AX        ; and stack
  90.         MOV    SS, AX
  91.         MOV    SP, SAV_SP
  92.         MOV    ACCUM_FLAG, 0  ; turn off address 
  93.                                        ; accumulation flag
  94.         RET            
  95. EXEC_SUBJECT    ENDP
  96. ;--------------------------------------------------------------
  97. EXEC_PRINT    PROC    NEAR
  98.         MOV    AX, CS        ; to set seg registers
  99.         MOV    ES, AX
  100.         MOV    DS, AX
  101.         MOV    SS, AX
  102.         MOV    DS, AX                   ; ds:dx point to 
  103.         MOV    DX, OFFSET PRINT_NAME    ; asciiz string with
  104.                                                  ; name of file to
  105.                                                  ; execute
  106. ; move segment and offset of data into words 0-3 of cs:5ch (fcb1)
  107.         MOV    AX, OFFSET DATA_TABLE    ; offset of data
  108.         MOV    BX, 5CH            ; offset into cseg
  109.         MOV    CS:[BX], AX        ; move offset into fcb1
  110.         MOV    AX, CS            ; cs to ax
  111.         MOV    CS:[BX+2], AX        ; move cs into fcb1
  112.         
  113. ;     divide table offset by 4 to get number of samples
  114.         MOV    CL, 2            ; shift count to cl
  115.         SHR    TABLE_OFS, CL        ; shift to divide
  116.         MOV    ES, AX                     ; es:bx points to
  117.         MOV    BX, OFFSET EXEC_PARAMS     ; parameter block
  118.         MOV    CX, CS:[2CH]        ; turn off address 
  119.         MOV    ENVIRON_SEG, CX     ; accumulation flag
  120.         MOV    COMMND_OFS, 80H     ; set offset and segment 
  121.         MOV    COMMND_SEG, CS      ; of passed command line
  122.         MOV    FCB1_OFS, 5CH  ; set offset and segment
  123.         MOV    FCB1_SEG, CS   ; to unopened fcb1
  124.         MOV    FCB2_OFS, 6CH   ; set offset and segment
  125.         MOV    FCB2_SEG, CS    ; of unopened fcb2
  126.         MOV    SAV_SP, SP     ; save stack pointer
  127.         MOV    AX, 4B00H
  128.         INT    21H        ;dos function call
  129.         MOV    AX, CS
  130.         MOV    DS, AX     ; restore segment registers 
  131.         MOV    ES, AX     ; and stack pointer
  132.         MOV    SS, AX
  133.         MOV    SP, SAV_SP
  134.         RET            
  135. EXEC_PRINT    ENDP
  136. ;-----------------------------------------------------------------
  137. ;     replaces the existing timer 0 countdown value and the    ;
  138. ;     existing interrupt 8                                     ;
  139. ;-----------------------------------------------------------------
  140. REPLACE_TIMER    PROC    NEAR
  141.     PUSH    DS        ; save data segment
  142.     CLI            ; disable maskable interrupts
  143. ;     replace timer 0 countdown to (maybe) speed up timer
  144.         MOV    AL,  36H    ; timer 0, mode 3, will send
  145.                                         ; lsb, msb
  146.         OUT    43H, AL        ; write mode control word 
  147.                                         ; to timer
  148.         MOV    BX,  New_Timer_Count    
  149.                                         ; new countdown value
  150.         MOV    AL,  BL        ; lsb of new_timer_count
  151.         OUT    40H, AL        ; write lsb to timer 0
  152.         MOV    AL,  BH        ; msb of new_timer_count
  153.         OUT    40H, AL        ; write msb to timer 0
  154. ;     replace existing interrupt 8
  155.         XOR    AX, AX        ;0 to ax
  156.         MOV    DS, AX        ; seg for interrupt vectors
  157.         MOV    AX, DS:[20H]    ; contents of 0:20 to ax
  158.         MOV    CS:OLD_OFS, AX    ; save in old_ofs
  159.         MOV    AX, DS:[22H]    ; contents of 0:22 to ax
  160.         MOV    CS:OLD_SEG, AX    ; save in old_seg
  161.         MOV    DS:[20H], OFFSET NEW_TIMER    ; new offset
  162.         MOV    DS:[22H], CS            ; new seg
  163.         STI            ; enable maskable interrupts
  164.         POP    DS        ; restore data segment
  165.         RET            ; return
  166. REPLACE_TIMER    ENDP
  167. ;-------------------------------------------------------------------;
  168. ;     restores the original interrupt 8 and the timer 0           ;  
  169. ;     countdown to the power-up value                             ;
  170. ;-------------------------------------------------------------------;
  171. RESTORE_TIMER    PROC    NEAR
  172.         CLI            ; disable maskable interrupts
  173. ;     restore interrupt 8
  174.         MOV    AX, 0        ; 0 to ax
  175.         MOV    DS, AX        ; segment for interrupt
  176.                                         ; vectors
  177.         MOV    AX, CS:OLD_OFS    ; old_ofs to ax
  178.         MOV    DS:[20H], AX    ; contents of ax to 0:20
  179.         MOV    AX, CS:OLD_SEG    ; old_seg to ax
  180.         MOV    DS:[22H], AX    ; contents of ax to 0:22
  181. ;     restore timer 0 countdown to power-up value
  182.         MOV    AL,  36H    ; timer 0, mode 3, will 
  183.                                         ; send lsb, msb
  184.         OUT    43H, AL        ; write mode control word 
  185.                                         ; to timer
  186.         MOV    AL,  0        ; lsb and msb of 0
  187.         OUT    40H, AL        ; write lsb to timer 0
  188.         OUT    40H, AL        ; write msb to timer 0
  189.         STI            ; enable maskable interrupts
  190.         RET            ; return
  191. RESTORE_TIMER    ENDP
  192. ;-------------------------------------------------------------------;
  193. ;     replaces old timer interrupt.  accumulates data if          ;
  194. ;     accum_flag is set, and jumps to previous int 8 if           ;
  195. ;     timing is appropriate                                       ;
  196. ;-------------------------------------------------------------------;
  197. NEW_TIMER    PROC    NEAR
  198.         CMP    CS:ACCUM_FLAG, 0    ; check to see if 
  199.                                                 ; we accumulate
  200.         JE    DO_OLD_INT8?    ; skip accumulate if 0
  201.         CALL    ACCUMULATE        ; if not 0, 
  202.                                                 ; accumulate data
  203. DO_OLD_INT8?:            ; check to see if we do old int 8
  204.         INC    CS:TIMER_COUNT        ; increment counter
  205.         CMP    CS:TIMER_COUNT, Number_Of_Ticks    
  206.                                                 ; do it this tick?
  207.         JNE    SKIP_OLD_INT8        ; skip int 8 
  208.                                                 ; if not time
  209.         MOV    CS:TIMER_COUNT, 0    ; reset counter to 
  210.                                                 ; zero
  211.         JMP    CS:DWORD PTR OLD_INT8    ; jump to old 
  212.                                                 ; interrupt 8
  213. SKIP_OLD_INT8:    
  214.         PUSH    AX            ; save ax
  215.         MOV    AL, 20H            ; end of interrupt 
  216.                                                 ; code
  217.         OUT    20H, AL            ; send eoi to 8259
  218.         POP    AX            ; restore ax
  219.         IRET                ; return from this 
  220.                                                 ; interrupt
  221. NEW_TIMER    ENDP
  222. ;------------------------------------------------------------------
  223. ACCUMULATE    PROC    NEAR
  224. ;     accumulate data at clock interrupt
  225.         PUSH    AX            ; push registers
  226.         PUSH    BX
  227.         PUSH    CX
  228.         PUSH    BP
  229. ;     check for table overflow
  230.         MOV    AX, CS:MAX_OFS        ; load ax
  231.         CMP    CS:TABLE_OFS, AX    ; have we reached 
  232.                                                 ; end of table?
  233.         JAE    END_ACCUM        ; if so, skip 
  234.                                                 ; data accumulate
  235. ;    accumulate samples
  236.         MOV    BX, CS:TABLE_OFS    ; table address to bx
  237.         MOV    BP, SP            ; sp to bp
  238.         MOV    AX, SS:[BP+10]        ; load ax with 
  239.                                                 ; interrupted ip
  240.         MOV    CS:WORD PTR DATA_TABLE[BX], AX    ;save ip
  241.         MOV    AX, SS:[BP+12]        ;load ax with 
  242.                                                 ; interrupted cs
  243.         MOV    CS:WORD PTR DATA_TABLE[BX+2], AX ;save cs
  244.                  
  245.         ADD    CS:TABLE_OFS, 4        ;increment offset
  246.                                                 ; into table
  247. END_ACCUM:
  248.         POP    BP            ;restore registers
  249.         POP    CX
  250.         POP    BX
  251.         POP    AX
  252.         RET
  253. ACCUMULATE    ENDP
  254. ;-----------------------------------------------------------------;
  255. ;    DATA AREA                                                 ;
  256. ;-----------------------------------------------------------------;
  257. SUBJECT_NAME    DB    'SUBJECT.COM'    ;asciiz name of subject 
  258.         DB    0        ;asciiz terminator
  259. MEM_ERR_STRNG    DB    'ERROR SHRINKING MEMORY - PROFILE ENDS$'
  260. EXEC_PARAMS    EQU    $        ;parameters passed 
  261. ENVIRON_SEG    DW    ?        ;to exec'ed programs
  262. COMMND_OFS    DW    ?
  263. COMMND_SEG    DW    ?
  264. FCB1_OFS    DW    ?
  265. FCB1_SEG    DW    ?
  266. FCB2_OFS    DW    ?
  267. FCB2_SEG    DW    ?
  268. SAV_SP        DW    ?        ;word to save stack pointer
  269.                     ;  across exec's
  270. PRINT_NAME    DB    'LISTPRF.COM'    ;asciiz name of data 
  271.                                         ;reduction & printout program
  272.         DB    0        ;asciiz terminator
  273. TIMER_COUNT    DW    0        ;counts timer interrupts 
  274.                                         ; since
  275.                     ;  last jump to original 
  276.                                         ; interrupt 8
  277. ACCUM_FLAG    DW    0        ; flag to trigger address 
  278.                                         ; accumulation
  279. OLD_INT8    EQU    $    ;address of old timer interrupt
  280. OLD_OFS        DW    ?    ;offset of old timer interrupt
  281. OLD_SEG        DW    ?    ;segment of old timer interrupt
  282. OUR_STACK    DD    100H DUP (0)    ;space for our stack
  283. END_STACK    EQU    $        ;set sp to this offset
  284. MAX_OFS        DW    Table_Size    ;max offset from beginning 
  285.                                         ; of data table
  286. TABLE_OFS    DW    ?        ;current offset into 
  287.                                         ; data table
  288. DATA_TABLE    DB    Table_Size DUP(0)
  289. EOM        EQU    $        ;end of memory
  290. PSP        ENDS
  291. ;
  292.         END    PRF
  293.