Reply by Stefan Reuther July 15, 20112011-07-15
John McDermick wrote:
> If I have some asm routine (lets call it _mysub) which ...just for the > sake of simplicity....adds 1 to what ever is in R2...how do I declare > a wrapper function (or prototype) in C which loads the value I am > calling with into register R2? > > I tried doing it like this: > > void wrapper(register r2) > { > _mysub; > }
If that's C, this declares a function which takes in 'int' parameter named 'r2' and does nothing :-> To do what you want to do, you can use asm. The syntax is 'asm("some asm instruction" : outputs : inputs)', so you can use "call _mysub;" for the asm instruction, and describe its inputs and outputs. If your calling conventions are so off-standard, you probably have different return registers, different caller-saved/caller-preserved registers, etc., so you'd have to describe those, too. Stefan
Reply by Jerry Avins July 15, 20112011-07-15
On Jul 15, 2:34&#2013266080;pm, Rob Gaddi <rga...@technologyhighland.com> wrote:
> On 7/15/2011 10:43 AM, John McDermick wrote: > > > > >> I think the answer to that is pretty compiler specific; which are you > >> using? &#2013266080;Also, it might be easier to change your ASM routine to conform > >> to the C calling convention for that platform than the other way around. > > > If I have 100 asm routines (which at the time of their creation > > adhered to > > one calling convention) is moved to a system which has another calling > > convention, it is probably easier just to change the interfaces > > of those asm routines instead of changing 100 asm routines? Or am I > > missing > > something here? > > Then it sounds like your wrapper may need to be assembly. &#2013266080;Put the > parameters you want into the registers they need to be in, branch to the > sub, and then put the parameters back where C expects to find them.
That works fine provided none of the registers involved are sacred. It may also cost time. Jerry -- Engineering is the art of making what you want from things you can get.
Reply by Roberto Waltman July 15, 20112011-07-15
Roberto Waltman wrote:

>Opening "blackfin.compiler.library.mn" and searchin for "assembly"
Sorry, that's the title once opened. The file name is "50_cc_bf.chm"
> how do I declare a wrapper function (or prototype) in C which loads the value I am calling with into register R2?
From the help file above: "Passing Arguments The details of argument passing are most easily understood in terms of a conceptual argument list. This is a list of words on the stack. Double arguments are placed starting on the next available word in the list, as are structures. Each argument appears in the argument list exactly as it would in storage, and each separate argument begins on a word boundary. The actual argument list is like the conceptual argument list except that the contents of the first three words are placed in registers R0, R1, and R2. Normally, this means that the first three arguments (if they are integers or pointers) are passed in registers R0 to R2 with any additional arguments being passed on the stack. " So, functions that match that signature (one parameter), this should do the trick: function(int dummy_param1, int dummy_param2, int actual_param) { ... } You still need to get the result into R0. -- Roberto Waltman [ Please reply to the group. Return address is invalid ]
Reply by Rob Gaddi July 15, 20112011-07-15
On 7/15/2011 10:43 AM, John McDermick wrote:
> >> >> I think the answer to that is pretty compiler specific; which are you >> using? Also, it might be easier to change your ASM routine to conform >> to the C calling convention for that platform than the other way around. >> > > If I have 100 asm routines (which at the time of their creation > adhered to > one calling convention) is moved to a system which has another calling > convention, it is probably easier just to change the interfaces > of those asm routines instead of changing 100 asm routines? Or am I > missing > something here?
Then it sounds like your wrapper may need to be assembly. Put the parameters you want into the registers they need to be in, branch to the sub, and then put the parameters back where C expects to find them. -- Rob Gaddi, Highland Technology Email address is currently out of order
Reply by Roberto Waltman July 15, 20112011-07-15
On Fri, 15 Jul 2011 14:04:04 -0400, Roberto Waltman
<usenet@rwaltman.com> wrote:

>John McDermick wrote: >>... I wasn't able to find any information about how the C >>interface function arguments can be manually assigned to registers of >>the programmer's choice. >>The compiler is C/C++ Compiler for Blackfin (VisualDSP) > >In the general case, that is not possible. (I want to say never, but I >have not tried every C compiler under the Sun.) > >The compiler as a well defined calling mechanism, and the assembly >code needs to adapt to it, not the other way around. >I only used the SHARC family, not Blackfin, but took a peek at the >documentation installed with VisualDSP. > >Opening "blackfin.compiler.library.mn" and searching for "assembly" >lead me to the section titled "Calling Assembly Subroutines From C/C++ >Programs" > >They do not provide full details here, but they suggest, (and it is a >good suggestion,) to write a dummy C function with the same signature >of the assembly function you need. Then, inspect the generated >assembly code for the function to see how the arguments are accessed >*from the stack* Then you can copy them to registers if needed. > >Other relevant sections (sorry, no page numbers in that help file): > > "C/C++ Run-Time Model and Environment" > >and from there to: > > * Register usage conventions > > &#2013266067;Dedicated Registers&#2013266068; > > &#2013266067;Call-Preserved Registers&#2013266068; > > &#2013266067;Scratch Registers&#2013266068; > > &#2013266067;Stack Registers&#2013266068; > > * Program control conventions > > &#2013266067;Managing the Stack&#2013266068; > > &#2013266067;Transferring Function Arguments and Return Value&#2013266068; <=======
Just read your response to Rob Gaddi. I wrote my previous response thinking if new code. You may be able to write a *single* wrapper that just moves the parameters to where your old code expects then, calls the function, and moves the return value to where the Blackfin compiler expects it. Be careful with registers that must be preserved - That may also be different between the old and the new calling conventions. -- Roberto Waltman [ Please reply to the group. Return address is invalid ]
Reply by Tim Wescott July 15, 20112011-07-15
On 07/15/2011 10:43 AM, John McDermick wrote:
> >> >> I think the answer to that is pretty compiler specific; which are you >> using? Also, it might be easier to change your ASM routine to conform >> to the C calling convention for that platform than the other way around. >> > > If I have 100 asm routines (which at the time of their creation > adhered to > one calling convention) is moved to a system which has another calling > convention, it is probably easier just to change the interfaces > of those asm routines instead of changing 100 asm routines? Or am I > missing > something here?
Depending on your assembler, perhaps you can write a sed script that changes all register references to something more abstract "reg0, reg1, ...", or if you can more meaningful "param0, param1, scratch0, scratch1, ...". Then make an include file that maps those functional names to the actual registers used by your compiler. This will make the bugs much more subtle and hard to detect, thereby insuring your continued employment for years to come. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by Vladimir Vassilevsky July 15, 20112011-07-15

John McDermick wrote:

>>The VDSP manual has entire chapter about interfacing C to assembly. > > > > Yes, but I wasn't able to find any information about how the C > interface function arguments can be manually assigned to registers of > the programmer's choice. > > The compiler is C/C++ Compiler for Blackfin (VisualDSP)
The VDSP environment always places first three arguments of a C-callable function correspondingly to R0,R1,R2 registers. The only way to change that in VDSP is by a GNU-style inline assembly. You can explicitly specify the registers which are used for passing the parameters into inline function. That's bad style and cryptic syntax; I would avoid that. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by Tim Wescott July 15, 20112011-07-15
On 07/15/2011 08:31 AM, John McDermick wrote:
> It's been a while so please bear with me... > > > If I have some asm routine (lets call it _mysub) which ...just for the > sake of simplicity....adds 1 to what ever is in R2...how do I declare > a wrapper function (or prototype) in C which loads the value I am > calling with into register R2? > > I tried doing it like this: > > > void wrapper(register r2) > { > _mysub; > } > > > void main() > { > wrapper(5); > } > > > > but 5 just gets loaded into R0...
Does the compiler have an 'asm' pseudo-instruction that lets you insert assembly into your C code? The gnu version is very versatile, and would let you do this. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by Tim Wescott July 15, 20112011-07-15
On 07/15/2011 10:43 AM, John McDermick wrote:
> >> >> I think the answer to that is pretty compiler specific; which are you >> using? Also, it might be easier to change your ASM routine to conform >> to the C calling convention for that platform than the other way around. >> > > If I have 100 asm routines (which at the time of their creation > adhered to > one calling convention) is moved to a system which has another calling > convention, it is probably easier just to change the interfaces > of those asm routines instead of changing 100 asm routines? Or am I > missing > something here?
Hey -- now there's a good reason to somehow parameterize your register references! -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by Roberto Waltman July 15, 20112011-07-15
John McDermick wrote:
>... I wasn't able to find any information about how the C >interface function arguments can be manually assigned to registers of >the programmer's choice. >The compiler is C/C++ Compiler for Blackfin (VisualDSP)
In the general case, that is not possible. (I want to say never, but I have not tried every C compiler under the Sun.) The compiler as a well defined calling mechanism, and the assembly code needs to adapt to it, not the other way around. I only used the SHARC family, not Blackfin, but took a peek at the documentation installed with VisualDSP. Opening "blackfin.compiler.library.mn" and searchin for "assembly" lead me to the section titled "Calling Assembly Subroutines From C/C++ Programs" They do not provide full details here, but they suggest, (and it is a good suggestion,) to write a dummy C function with the same signature of the assembly function you need. Then, inspect the generated assembly code for the function to see how the arguments are accessed *from the stack* Then you can copy them to registers if needed. Other relevant sections (sorry, no page numbers in that help file): "C/C++ Run-Time Model and Environment" and from there to: * Register usage conventions &#2013266067;Dedicated Registers&#2013266068; &#2013266067;Call-Preserved Registers&#2013266068; &#2013266067;Scratch Registers&#2013266068; &#2013266067;Stack Registers&#2013266068; * Program control conventions &#2013266067;Managing the Stack&#2013266068; &#2013266067;Transferring Function Arguments and Return Value&#2013266068; <======= -- Roberto Waltman [ Please reply to the group. Return address is invalid ]