home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / utilslib / Profile / S / ProfileAsm
Encoding:
Text File  |  1991-06-02  |  8.9 KB  |  454 lines

  1. ; Asm.ProfileAsm: Low level profiling routines
  2. ;
  3. ; Version 1.00, 04-06-1990
  4. ;
  5. ; Copyright (C) Ferdinand Oeinck 1990
  6. ;
  7. ; Modified, Paul Moore 02/06/91.
  8. ;   To conform to the conventions of my "Utils" library.
  9. ;
  10.  
  11. a1 RN 0
  12. a2 RN 1
  13. a3 RN 2
  14. a4 RN 3
  15. v1 RN 4
  16. v2 RN 5
  17. v3 RN 6
  18. v4 RN 7
  19. v5 RN 8
  20. v6 RN 9
  21. sl RN 10
  22. fp RN 11
  23. ip RN 12
  24. sp RN 13
  25. lr RN 14
  26. pc RN 15
  27.  
  28. f0 FN 0
  29. f1 FN 1
  30. f2 FN 2
  31. f3 FN 3
  32. f4 FN 4
  33. f5 FN 5
  34. f6 FN 6
  35. f7 FN 7
  36.  
  37. r0 RN 0
  38. r1 RN 1
  39. r2 RN 2
  40. r3 RN 3
  41. r4 RN 4
  42. r5 RN 5
  43. r6 RN 6
  44. r7 RN 7
  45. r8 RN 8
  46. r9 RN 9
  47. r10 RN 10
  48. r11 RN 11
  49. r12 RN 12
  50. r13 RN 13
  51. r14 RN 14
  52. r15 RN 15
  53.  
  54. R0 RN 0
  55. R1 RN 1
  56. R2 RN 2
  57. R3 RN 3
  58. R4 RN 4
  59. R5 RN 5
  60. R6 RN 6
  61. R7 RN 7
  62. R8 RN 8
  63. R9 RN 9
  64. R10 RN 10
  65. R11 RN 11
  66. R12 RN 12
  67. R13 RN 13
  68. R14 RN 14
  69. PC  RN 15
  70.  
  71. ; SWI numbers
  72.  
  73. XOS_Bit            *    &020000
  74. OS_CallEvery        *    &00003C
  75. OS_RemoveTickerEvent    *    &00003D
  76. Wimp_Poll        *    &0400C7
  77. Wimp_PollIdle        *    &0400E1
  78.  
  79. ; Hard coded address/contents from the OS ROM. Blechh!
  80.  
  81. OS_check_address    *    &38006CC
  82. OS_check_cont        *    &E58CD108
  83.  
  84. ; Macro to declare C-style function headers
  85.     MACRO
  86.     Func    $name
  87.     ROUT
  88.  
  89.     LCLS    lab
  90. lab    SETS    "|"
  91. lab    SETS    lab :CC: "$name" :CC: lab
  92.  
  93. 01
  94.     DCB    "$name",0
  95.     ALIGN
  96.     DCD    &FF000000 + {PC} - %BT01
  97. $lab
  98.     MEND
  99.  
  100.     AREA    |C$$code|, CODE, READONLY
  101.  
  102. ;    Exported functions for this package
  103.  
  104.     EXPORT    |_profile_ClaimIntDeviceVector|
  105.     EXPORT    |_profile_ReleaseIntDeviceVector|
  106.     EXPORT    |_profile_getstart|
  107.     EXPORT    |_profile_getend|
  108.     EXPORT    |_profile_getlangdesblock|
  109.     EXPORT    |_profile_fp_return_address|
  110.  
  111. ;    Replacement Risc_OSLib functions
  112.  
  113.     EXPORT    wimp_poll
  114.     EXPORT    wimp_pollidle
  115.     EXPORT    wimp_save_fp_state_on_poll
  116.     EXPORT    wimp_corrupt_fp_state_on_poll
  117.  
  118. ;    Imported functions and data
  119.  
  120.     IMPORT    binsearch
  121.     IMPORT    |C$$code$$Base|
  122.     IMPORT    |C$$code$$Limit|
  123.     IMPORT    |RTSK$$Data$$Base|
  124.     IMPORT    |_kernel_fpavailable|
  125.  
  126. ;    ----------------------------------------------------------------------
  127. ;    Function to claim the interrupt and interupt handler
  128. ;    void    _profile_ClaimIntDeviceVector (int *adr, int *cnt, int count);
  129. ;    ----------------------------------------------------------------------
  130.  
  131.     Func    _profile_ClaimIntDeviceVector
  132.  
  133.     LDR    a1, |_profile_check|
  134.     LDR    a2, |_profile_check| + 4
  135.     LDR    a1, [a1]
  136.     CMP    a1, a2                ; check if running under RISCOS 2.00
  137.     MOVNE    a1, #0
  138.     MOVNES    pc, lr                ; no
  139.  
  140.     MOV    a1, #0
  141.     LDR    a3, [a1, #4]            ; load undefined instr vector
  142.     STR    a3, default_undef_vector
  143.     BIC    a3, a3, #&FF000000        ; clear branch bits
  144.     MOV    a3, a3, LSL #2
  145.     ADD    a3, a3, #12            ; address 
  146.     STR    a3, default_undef_instr        ; save undefined instr. address
  147.  
  148.     ADR    a2, undefined_instr
  149.     SUB    a2, a2, #12
  150.     MOV    a2, a2, LSR #2
  151.     ORR    a2, a2, #&EA000000
  152.     STR    a2, [a1, #4]            ; save my undefined instr. address
  153.     STR    a2, my_undef_branch
  154.  
  155.     MOV    a1, #1                ; yes
  156.     ADR    a2, |_profile_every|
  157.     MOV    a3, #0
  158.     SWI    OS_CallEvery
  159.  
  160.     MOV    a1, #1
  161.     LDR    a2, |_profile_claimed|
  162.     STR    a1, [a2]
  163.  
  164.     MOVS    pc, lr
  165.  
  166. |_profile_check|
  167.     &    OS_check_address
  168.     &    OS_check_cont
  169.  
  170. default_undef_vector
  171.     &    0
  172.  
  173. my_undef_branch
  174.     &    0
  175.  
  176. |_profile_claimed|
  177.     &    |x$dataseg| + 4
  178.  
  179. |_profile_fp_return_address|
  180.     DCD    0
  181.  
  182. ;    ----------------------------------------------------------------------
  183. ;    Function to release the interrupt and interupt handler
  184. ;    void    _profile_ReleaseIntDeviceVector (void);
  185. ;    ----------------------------------------------------------------------
  186.  
  187.     Func    _profile_ReleaseIntDeviceVector
  188.  
  189.     ADR    a1, |_profile_every|
  190.     MOV    a2, #0
  191.     SWI    OS_RemoveTickerEvent
  192.  
  193.     LDR    a1, default_undef_vector
  194.     MOV    a2, #0
  195.     STR    a1, [a2, #4]            ; restore undefined inst vector
  196.  
  197.     MOV    a1, #0
  198.     LDR    a2, |_profile_claimed|
  199.     STR    a1, [a2]
  200.  
  201.     MOVS    pc, lr
  202.  
  203. ;    ----------------------------------------------------------------------
  204. ;    Called every 1/100 second
  205. ;    void    _profile_every (void);
  206. ;    ----------------------------------------------------------------------
  207.  
  208.     Func    _profile_every
  209.  
  210.     STMFD    sp!, {a1-a4, ip, lr}
  211.     MOV    a1, #0
  212.     LDR    a2, [a1, #264]            ; OS stack storage
  213.     LDR    a1, [a2, #28]            ; 8 regs on stack => 7 * 4 = 28
  214.     BIC    a1, a1, #&FC000003
  215.     BL    binsearch
  216.     LDMFD    sp!, {a1-a4, ip, pc}
  217.  
  218. undefined_instr    
  219.     STMFD    sp!, {a1}
  220.     BIC    a1, lr, #&FC000003         ; return address
  221.     STR    a1, |_profile_fp_return_address|
  222.     LDMFD    sp!, {a1}
  223.     LDR    pc, default_undef_instr
  224.  
  225. default_undef_instr
  226.     &    0
  227.  
  228. ;    ----------------------------------------------------------------------
  229. ;    Get the start of the linker code area
  230. ;    void _profile_getstart(void);
  231. ;    ----------------------------------------------------------------------
  232.  
  233.     Func    _profile_getstart
  234.     ADR    a1, |_profile_data|
  235.     LDR    a1, [a1, #0]
  236.     MOV    pc, lr
  237.  
  238. ;    ----------------------------------------------------------------------
  239. ;    Get the end of the linker code area
  240. ;    void _profile_getend(void);
  241. ;    ----------------------------------------------------------------------
  242.  
  243.     Func    _profile_getend
  244.     ADR    a1, |_profile_data|
  245.     LDR    a1, [a1, #4]
  246.     MOV    pc, lr
  247.  
  248. ;    ----------------------------------------------------------------------
  249. ;    Get the language description block
  250. ;    void _profile_getlangdesblock (void);
  251. ;    ----------------------------------------------------------------------
  252.  
  253. |_profile_getlangdesblock|
  254.     ADR    a1, |_profile_data|
  255.     LDR    a1, [a1, #8]
  256.     MOV    pc, lr
  257.  
  258. |_profile_data|
  259.     DCD    |C$$code$$Base|
  260.     DCD    |C$$code$$Limit|
  261.     DCD    |RTSK$$Data$$Base|
  262.  
  263.  
  264. ;    ----------------------------------------------------------------------
  265. ;    Redefinitions of wimp_poll() and wimp_pollidle().
  266. ;    To be linked, the exepro library must be linked before Risc_OSLib.
  267. ;    ----------------------------------------------------------------------
  268.  
  269. ;    ----------------------------------------------------------------------
  270. ;    Replacement for wimp_poll in Risc_OSLib.
  271. ;    os_error *wimp_poll (wimp_emask, wimp_eventstr *);
  272. ;    ----------------------------------------------------------------------
  273.  
  274. wimp_poll
  275.     MOV    R12,R13
  276.     STMDB    R13!,{R4,R5,R11,R12,R14,PC}
  277.     SUB    R11,R12,#4
  278.     MOV    R5,R0
  279.     MOV    R4,R1
  280.     LDR    R0, fp_state_ptr
  281.     LDR    R0,[R0],#0
  282.     CMP    R0,#0
  283.     BLNE    |_kernel_fpavailable|
  284.     CMPNE    R0,#0
  285.     BLNE    save_fpe_state
  286.     MOV    R14,R0
  287.  
  288.     LDR    r0, |_profile_claimed|
  289.     LDR    r0, [r0]
  290.     CMP    r0, #1
  291.     BNE    poll_no_profile1
  292.  
  293.     ADR    r0, |_profile_every|
  294.     MOV    r1, #0
  295.     SWI    OS_RemoveTickerEvent
  296.     LDR    r0, default_undef_vector
  297.     MOV    r1, #0
  298.     STR    r0, [r1, #4]
  299.  
  300. poll_no_profile1          
  301.     MOV    R0,R5
  302.     ADD    R1,R4,#4
  303.     SWI    XOS_Bit:OR:Wimp_Poll
  304.     SUB    R1,R1,#4
  305.     STR    R0,[R1,#0]
  306.     MOVVC    R0,#0
  307.     CMP    R14,#0
  308.     BLNE    restore_fpe_state
  309.  
  310.     MOV    r5, r0
  311.     LDR    r0, |_profile_claimed|
  312.     LDR    r0, [r0]
  313.     CMP    r0, #1
  314.     BNE    poll_no_profile2
  315.  
  316.     LDR    a2, my_undef_branch
  317.     MOV    a1, #0
  318.     STR    a2, [a1, #4]
  319.     MOV    a1, #1
  320.     ADR    a2, |_profile_every|
  321.     MOV    a3, #0
  322.     SWI    OS_CallEvery
  323.         
  324. poll_no_profile2
  325.     MOV    r0, r5
  326.     LDMDB    R11,{R4,R5,R11,R13,PC}^
  327.  
  328. ;    ----------------------------------------------------------------------
  329. ;    Replacement for wimp_pollidle in Risc_OSLib.
  330. ;    os_error *wimp_pollidle (wimp_emask, wimp_eventstr *, int);
  331. ;    ----------------------------------------------------------------------
  332.  
  333. wimp_pollidle
  334.     MOV    R12,R13
  335.     STMDB    R13!,{R4-R6,R11,R12,R14,PC}
  336.     SUB    R11,R12,#4
  337.     MOV    R5,R0
  338.     MOV    R4,R1
  339.     MOV    R6,R2
  340.     LDR    R0, fp_state_ptr
  341.     LDR    R0,[R0],#0
  342.     CMP    R0,#0
  343.     BLNE    |_kernel_fpavailable|
  344.     CMPNE    R0,#0
  345.     BLNE    save_fpe_state
  346.     MOV    R14,R0
  347.  
  348.     LDR    r0, |_profile_claimed|
  349.     LDR    r0, [r0]
  350.     CMP    r0, #1
  351.     BNE    pollidle_no_profile1
  352.  
  353.     ADR    r0, |_profile_every|
  354.     MOV    r1, #0
  355.     SWI    OS_RemoveTickerEvent
  356.     LDR    r0, default_undef_vector
  357.     MOV    r1, #0
  358.     STR    r0, [r1, #4]
  359.  
  360. pollidle_no_profile1
  361.     MOV    R0,R5
  362.     ADD    R1,R4,#4
  363.     MOV    R2,R6
  364.     SWI    XOS_Bit:OR:Wimp_PollIdle
  365.     CMP    R14,#0
  366.     BLNE    restore_fpe_state
  367.     SUB    R1,R1,#4
  368.     STR    R0,[R1,#0]
  369.     MOVVC    R0,#0
  370.  
  371.     MOV    r5, r0
  372.     LDR    r0, |_profile_claimed|
  373.     LDR    r0, [r0]
  374.     CMP    r0, #1
  375.     BNE    pollidle_no_profile2
  376.  
  377.     LDR    a2, my_undef_branch
  378.     MOV    a1, #0
  379.     STR    a2, [a1, #4]
  380.     MOV    a1, #1
  381.     ADR    a2, |_profile_every|
  382.     MOV    a3, #0
  383.     SWI    OS_CallEvery
  384.  
  385. pollidle_no_profile2
  386.     MOV    r0, r5
  387.  
  388.     LDMDB    R11,{R4-R6,R11,R13,PC}^
  389.  
  390. save_fpe_state
  391.     RFS    R1
  392.     STMDB    R13!,{R1}
  393.     MOV    R1,#0
  394.     WFS    R1
  395.     SUB    R13,R13,#&30
  396.     STFE    f4,[R13,#0]
  397.     STFE    f5,[R13,#12]
  398.     STFE    f6,[R13,#24]
  399.     STFE    f7,[R13,#36]
  400.     MOVS    PC,R14
  401.  
  402. restore_fpe_state
  403.     MOV    R4,#0
  404.     WFS    R4
  405.     LDFE    f4,[R13,#0]
  406.     LDFE    f5,[R13,#12]
  407.     LDFE    f6,[R13,#24]
  408.     LDFE    f7,[R13,#36]
  409.     ADD    R13,R13,#&30
  410.     LDMIA    R13!,{R4}
  411.     WFS    R4
  412.     MOVS    PC,R14
  413.  
  414. ;    ----------------------------------------------------------------------
  415. ;    Replacement for wimp_save_fp_state_on_poll in Risc_OSLib.
  416. ;    void wimp_save_fp_state_on_poll (void);
  417. ;    ----------------------------------------------------------------------
  418.  
  419. wimp_save_fp_state_on_poll
  420.     LDR    R0, fp_state_ptr
  421.     MOV    R1,#1
  422.     STR    R1,[R0],#0
  423.     MOVS    PC,R14
  424.  
  425. ;    ----------------------------------------------------------------------
  426. ;    Replacement for wimp_corrupt_fp_state_on_poll in Risc_OSLib.
  427. ;    void wimp_corrupt_fp_state_on_poll (void);
  428. ;    ----------------------------------------------------------------------
  429.  
  430. wimp_corrupt_fp_state_on_poll
  431.     LDR    R0, fp_state_ptr
  432.     MOV    R1,#0
  433.     STR    R1,[R0],#0
  434.     MOVS    PC,R14
  435.  
  436. fp_state_ptr
  437.     &    |x$dataseg|
  438.  
  439. ;    ----------------------------------------------------------------------
  440. ;    Run time data segment. Note that this module actually stores some of
  441. ;    its internal variables in the code segment. This is bad practice, as
  442. ;    the code segment is nominally read-only. However, the issue is not so
  443. ;    urgent as to require solving (with the consequent code changes) in
  444. ;    the immediate future...
  445. ;    ----------------------------------------------------------------------
  446.  
  447.     AREA    |C$$data|
  448.  
  449. |x$dataseg|
  450.     &    0
  451.     &    0
  452.  
  453.     END
  454.