Mips32 execution time

This topic contains 7 replies, has 2 voices, and was last updated by  wij 4 years ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #31491

    wij
    Member

    Hello,
    I am using mips32 to emulate some applications.
    As I want to get the number of ticks in a function, I have already tested the rdhwr instruction and mfc0 instruction. In deed, the rdhwr gives me always 0 ticks in a c program. Yet, the mfc0 ( in c code source) gives me the following message:Program received signal SIGILL, Illegal instruction.
    What do you think?

    Best regards,
    Wijdene

    #38009

    ChrisImgtec
    Moderator

    I think I can help. Show me the code lines you are using to read the count register.

    The SIGILL is probably because you are in user mod and the mfco instruction can only be done in kernel mode.

    #38010

    ChrisImgtec
    Moderator

    I just though of something else, to get access to the count register from user mode using the rdhwr instruction the HWREna CP0 register needs to have bit 2 set. This can only be done form Kernel mode so you will need access to the OS to be able to set this bit.

    #38011

    wij
    Member

    Good morning,

    Thanks a lot for your reply.
    I used the following function in two versions:
    unsigned mips_count ()
    {
    unsigned cc;
    __asm__ volatile (“mfc0 %0,$9″ :”=r” (cc));
    return (cc<<1);
    }
    or
    unsigned mips_count ()
    {
    unsigned cc;
    __asm__ volatile (“rdhwr %0,$2″ :”=r” (cc));
    return (cc<<1);
    }
    If I am not wrong, the HWREna register is used implicitly when using the rdhwr instruction for that reason we use the register 2 as a destination register for rdhwr.
    I find something else, the use of a defined function read_c0_count() fom mipsregs.h but when I made #include in the beginning of the program, I got:error: mipsregs.h: No such file or directory.

    Thanks a lot if you can help me!

    #38012

    ChrisImgtec
    Moderator

    While in Kernel mode execute the following to enable user mode reading of the count register:

    #include
    unsigned int v;
    v=0x00000004;
    mips32_sethwrena(v);

    In your user program to read the count register:

    unsigned int count;
    asm volatile (“rdhwr %[ count], 2”: [count] “=r”( count) 🙂 ;

    #38013

    ChrisImgtec
    Moderator

    Also to just read teh count register directly (If you are in Kernel mode)

    unsigned int count;

    asm volatile (“mfc0 %[count], $9”: [count] “=r”(count) 🙂 ;

    #38014

    ChrisImgtec
    Moderator

    Sorry I see a smilely face instead of an : and then )

    #38015

    wij
    Member

    Hello,
    Thanks a lot !

    I ave already tested what did you proposed but I got the following error:

    TestCycles.c:(.text+0x30): undefined reference to `mips32_sethwrena’
    collect2: ld returned 1 exit status

    In fact, the use of mips32_sethwrena is the problem. Should I implement specific library in he C code which is :
    #include

    int main(int argc, char *argv[])
    {
    unsigned int v;
    v=0x00000004;
    mips32_sethwrena(v);
    unsigned int c;
    __asm__ volatile (“rdhwr %0,$2”: “=r”( c));
    return 0;
    printf(“Count:%d”,c);
    }
    ??
    At this level, the problem can not be related to qemu? As I saw that qemu does not allow the kernel mode but only user and system mode,What do you think?

    Best regards,
    WR

Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic.