UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer sidns5
Observer
5,650 Views
Registered: ‎12-29-2007

Microblaze , vertex 4 ML403, Accessing register values from C

Jump to solution

Hi,

 

I am trying to read PC value and print it out in C.

 

Here the code;

 

 

main(){

 

int x;

 

 

-- some huge C code;

 

 

asm("mfs r2 0");    -- this loads the value into r2 <- PC.

 

now how to load the value from r2 into x,   x <- PC.

 

}

 

 

 

How do i access register values from C?

 

Please  HELP, Is their anydocs on this assembly n C,

I did checked out the processor reference guide. no luck:(

 

Thanks,

Sid

 

0 Kudos
1 Solution

Accepted Solutions
Explorer
Explorer
6,657 Views
Registered: ‎08-14-2007

Re: Microblaze , vertex 4 ML403, Accessing register values from C

Jump to solution

When assembly is intermixed with C, there are two conventions used for it:

 

1) Wrap the assembly in a separate C function.

 Here's an example of this:

 

   unsigned long read_pc(void) {

      asm("mfs r3 0");

   }

 

 Per the ABI, as documented in the Microblaze UG, r3 is the return value register. Therefore you could invoke this function like so:

 

    unsigned long pc_val;

    pc_val = read_pc();

 

 In this case pc_val will hold the value of the PC register.

 

2) Embed the assembly in another C function and use compiler-specific mnemonics to access C-based storage.

   Here's a link to this from GCC manual . It can be kind of confusing to read, but I recommend it since you should know what you're invoking, before you invoke it.

 

  Here's an example of that usage:

    unsigned long pc;

    asm("mfs %0 0" : "=r" (pc));

  Theoretically the compiler should use the register storage location for PC and properly fill in the value. If not, you may have to 'register' the variable first:

    register unsigned long pc;

    asm("mfs %0 0" : "=r" (pc));

 

HTH,

- Mike

0 Kudos
3 Replies
Explorer
Explorer
6,658 Views
Registered: ‎08-14-2007

Re: Microblaze , vertex 4 ML403, Accessing register values from C

Jump to solution

When assembly is intermixed with C, there are two conventions used for it:

 

1) Wrap the assembly in a separate C function.

 Here's an example of this:

 

   unsigned long read_pc(void) {

      asm("mfs r3 0");

   }

 

 Per the ABI, as documented in the Microblaze UG, r3 is the return value register. Therefore you could invoke this function like so:

 

    unsigned long pc_val;

    pc_val = read_pc();

 

 In this case pc_val will hold the value of the PC register.

 

2) Embed the assembly in another C function and use compiler-specific mnemonics to access C-based storage.

   Here's a link to this from GCC manual . It can be kind of confusing to read, but I recommend it since you should know what you're invoking, before you invoke it.

 

  Here's an example of that usage:

    unsigned long pc;

    asm("mfs %0 0" : "=r" (pc));

  Theoretically the compiler should use the register storage location for PC and properly fill in the value. If not, you may have to 'register' the variable first:

    register unsigned long pc;

    asm("mfs %0 0" : "=r" (pc));

 

HTH,

- Mike

0 Kudos
Observer sidns5
Observer
5,625 Views
Registered: ‎12-29-2007

Re: Microblaze , vertex 4 ML403, Accessing register values from C

Jump to solution

Hi Mike,

 

That was great info, It really answered my question.

Thanks very much for taking you time , for writing such a nice n detailed reply.

The link to gcc was quite useful.

 

thanks,

Sid

0 Kudos
Highlighted
Observer sidns5
Observer
5,582 Views
Registered: ‎12-29-2007

Re: Microblaze , vertex 4 ML403, Accessing register values from C

Jump to solution

line 43:   register unsigned long pc;

 

line 121: asm("mfs %0 0" : "=r" (pc));

 

No errors when I compile the above code but...

 

When i tried to print..

 

 

line 43:   register unsigned long pc;

 

line 121: asm("mfs %0 0" : "=r" (pc));
line 122: xil_printf("PC is:%u.\r\n",pc);

 

I have this from the compiler

 

/cygdrive/c/DOCUME~1/siddu/LOCALS~1/Temp/cceypCcN.s: Assembler messages:
/cygdrive/c/DOCUME~1/siddu/LOCALS~1/Temp/cceypCcN.s:121: Error: register expected, but saw '0'
/cygdrive/c/DOCUME~1/siddu/LOCALS~1/Temp/cceypCcN.s:121: Fatal error: invalid value for special purpose register
make: *** [TestApp_Peripheral/executable.elf] Error 1

 

 

 

--------------------------------------------

please HELP,

 

Sid

0 Kudos