TI E2E Community
Digital Signal Processors (DSP)
C6000 Multicore DSP
Keystone Multicore Forum (C66, 66A, AM5)
Is there a way to access the C66x registers from C-level or do I have to write an asm function?
I would like to save the A and B registers into a structure from C level, is there an easy way of doing that? Is there an easy way of doing that from C-level by using intrinsics or other tricks? Anything like the gnu compiler supported asm-format which can process c-variables? Do I have to write a c-callable asm function ?
there's no way to do that from C. You need to write a C-callable (linear) assembly function.
one and zero
Please click the Verify Answer button on this post if it answers your question.
You can also follow me on Twitter: http://twitter.com/oneandzeroTI
Do you want to read interesting multicore articles? Check out our Multicore Mix
On C55x, the ST and some other registers are all memory mapped so that I can access it directly. I could also use the asm in C to move data from registers to memory location directly. Is there a similar way to do that on C66x, as I am not so familiar with the C66x linear assembly?
To do a automatic calling convention validation (I want to validate algorithm we buy including asm), what else do I have to check on C66x? From the compiler manual, I only saw those related to A0~A15, B0~B15, LC, IRP, NRP, RILC. I do not see any status registers as I used to have to maintain in C54x and C55x. Do I miss anything there? Do you know any existing code somewhere within TI or on the web for such thing?
In C66x, you can also use "asm(" ");" statement to operate on registers in C code. Such as:
asm(" STW A0,*B15--"); // There must exist a space between the first double quotes and STW.
asm(" STW A1,*B15--");
In this way, you can save all the registers to stack. And then copy out the entire data block to your structure in C.
Why do you want to make the calling convention validation? It's clearly described by compiler user guide. The status register in C66x is defined in C66x CPU and Instruction Set.
please be very careful with asm statements in your C-Code. The compiler rearranges code segments, uses registers freely, and can completely remove variables orexpressions. Although the compiler never optimizes out an asm statement (except when it is unreachable), the surrounding environment where the assembly code is inserted can differ significantly from the original C/C++ source code.It is usually safe to use asm statements to manipulate hardware controls such as interrupt masks, but asm statements that attempt to interface with the C/C++ environment or access C/C++ variables can have unexpected results. After compilation, check the assembly output to make sure your asm statements are correct and maintain the integrity of the program.
I would really recommend to write an assembly routine that is C-callable rather than using asm statements ...
Thanks for the advice, an assembly routine is definitely a better way. I'm just worrying about the calling of a routine will take effect on the runtime environment such as position of stack pointer or registers' value. So I'm just trying on asm statement.
Anyway, learned a lot from your reply about the background info of asm, thanks.
how to interface between assembly and C is described in the Compiler User's Guide (SPRU 187).
Chapter 7.5 Interfacing C and C++ With Assembly Language
Please find an example from a previous post:
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.