This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Bug in HALCoGen in sys_pmu.asm _pmuGetOverflow_ function

Other Parts Discussed in Thread: HALCOGEN

Hi,


There is a bug in this function :

_pmuGetOverflow_

        mrc   p15, #0, r0, c9, c12, #3 ; read overflow
        mov   r1,  #0
        sub   r1,  r1,  #1
        mcr   p15, #0, r1, c9, c12, #3 ; clear flags
        bx    lr

If the overflow occurs after the read but before the clear, the overflow is not seen by the caller.
The correct  sequence to solve this problem is to use the read value to clear the overflow !

_pmuGetOverflow_

        mrc   p15, #0, r0, c9, c12, #3 ; read overflow
        mcr   p15, #0, r0, c9, c12, #3 ; clear flags
        bx    lr


Regards,

Bruno.

  • Bruno,

    Thank you for the catch.
    I will inform the Halcogen team.

  • Jean-Marc,


    I found an other bug in this module in the function _pmuInit_ :

    _pmuInit_

    ...

           ; clear flags
            mov   r0,  #0
            sub   r0,  r0,  #1
            mcr   p15, #0, r0, c9, c12, #3
            ; select counter 0 event
            mcr   p15, #0, r0, c9, c12, #5 ; select counter
            mov   r0,  #0x11
            mcr   p15, #0, r0, c9, c13, #1 ; select event
            ; select counter 1 event
            mov   r0,  #1
    ...

    As, after clearing the flags, r0 = -1 and not 0, the next instruction to select counter 0 event is unpredictable, the following instruction shall be added

    ...

           ; clear flags
            mov   r0,  #0
            sub   r0,  r0,  #1
            mcr   p15, #0, r0, c9, c12, #3
            ; select counter 0 event
            mov   r0,  #0
            mcr   p15, #0, r0, c9, c12, #5 ; select counter
            mov   r0,  #0x11
            mcr   p15, #0, r0, c9, c13, #1 ; select event
            ; select counter 1 event
            mov   r0,  #1
    ...

    Regards,

    Bruno.