Flag to prevent use of temporary variables for avrgcc?

Go To Last Post
64 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SprinterSB wrote:
You are saying
    "No local variable lives past an OS call"
but you mean
    "No value held in the frame lives past an OS call"
None of these statements implies the other or is needed by the other.

I'm not sure if the OS stores/restores anything from the frame but I know (from what the author says) that local variable values are not preserved.

What values that live in the frame and are not a local variable do you say will be lost?

You have tasks that may call other functions but will return in the task before you actually call a OS_yield so it's not like you have a task that calls another function and that one another function and suddenly there is a OS_yield there.

As I said all these low level mechanisms are not exactly an area that I'm very familiar with so I describe them the best I can.

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just for a better understanding of the artifact. Suppose

extern void twice (void) __attribute__((returns_twice)) ;
extern char C;

void func (void)
{
    char c = C;
    twice();
    C = c;
}

that may be compiled to

func:
	push r28
	push r29
	push __zero_reg__
	in r28,__SP_L__
	in r29,__SP_H__
/* prologue: function */
/* frame size = 1 */
/* stack size = 3 */
.L__stack_usage = 3
	lds r24,C
	std Y+1,r24
	rcall twice
	ldd r24,Y+1
	sts C,r24
/* epilogue start */
	pop __tmp_reg__
	pop r29
	pop r28
	ret

Why does it not work?

• Because twice will clobber the frame (content of Y+1 here)?
• And / or because twice clobbers the frame pointer (Y).

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have used the __attribute__((returns_twice)) for the function that gets called from withing the task (I assume func is the task), how ofter is a library function using this attribute?

I mean from my task I may call LCD functions, NRF24L01 functions, GLCD functions or what ever but I don't think that any of them include a function with such an attribute.

Do you have an example of a library that includes a function with such an attribute?

Alex

P.S. I'm happy you have mentioned that case so that I can be aware of it.

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just look at your original example.

There you call a returns_twice.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not sure which post you refer to, it doesn't seem to be the first post of the thread.

Can you please provide a link or the timestamp of the post so that I may locate it.

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Posted: Nov 23, 2012 - 02:56 PM

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you mean https://www.avrfreaks.net/index.p... ?
(It is shown as Nov 23, 2012 - 03:56 PM but I guess it is because of time difference)

I don't see that attribute and I don't see any calls to functions either from the task.
Maybe you see it in the ASM code of that post?
I'm confused...

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The you don't see it does not mean it is not there.

Are you looking at the text you posted or at the code the compiler proper will get? IIRC, one piece of the code is a function-like macro that expands to several functions, one of which is returns_twice.

avrfreaks does not support Opera. Profile inactive.

Last Edited: Sun. Nov 25, 2012 - 06:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SprinterSB wrote:
The you don't see it does not mean it is not there.

I didn't say it to doubt your word, that is why I said "Maybe you see it in the ASM code of that post?", because I can't understand much of what is going on there.

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are confused?

Well, I was also confused because I used your source with the same compiler binary and with the same command options but got completely different compilation results.

This is the reason why it is almost pointless to post a snippet of C text that will undergo heavy preprocessing text transformations: Declaring functions in a special way, defining macros, adding qualifiers, replcaing text or whatever.

Or are you saying that the text in the OP does not expand to a preprocessed source that calls at least one returns_twice function, namely _OS_ReturnSave?

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think it was wrong to me to provide the partial code as I did in the first post because it is just a single task from a five task code that also included LCD library etc.
I should have posted from the start the complete simplified project example taht demonstrated the problem as I did https://www.avrfreaks.net/index.p...

I think now that you refer to OS calls but these returns_twice functions are called when we pass control to the next task (OS_yield() etc).

The only functions that use returns_twice in the OSA core folder are in the osa_avr_winavr.h and .c file including the one you refer to

void _OS_ReturnSave      (void) __attribute__ ((naked, noinline, returns_twice));

/*
 ********************************************************************************
 *
 *  void _OS_ReturnSave (void)
 *
 *------------------------------------------------------------------------------
 *
 *  description:    Return to sheduler with saving current task return point
 *                  Called througth "jmp" or "rjmp"
 *
 *  parameters:     none
 *
 *  on return:      none
 *
 ********************************************************************************
 */

void _OS_ReturnSave (void)
{
    _OS_SET_FSR_CUR_TASK();
    _OS_SAVE_PC();
    _OS_bTaskReady = 1;
    _OS_JMP("_OS_ReturnNoSave");
}

I think this is already considered one of the points where you loose the frame content since you pass control to the task scheduler.

Alex

Attachment(s): 

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexan_e wrote:
The only functions that use returns_twice in the OSA core folder are in the osa_avr_winavr.h and .c file including the one you refer to
I did not refer to whatever OS source, I refered to some preprocessed code you posted — and that's the only thing that counts because that is the code you finally feed into the compiler.

void _OS_ReturnSave (void) __attribute__ ((naked, noinline, returns_twice));

[...]

What matters and where you will see different code generated depending on returns_twice, are the call sites of returns_twice, not the implementation.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I misunderstood what you were trying to explain with your example using __attribute__((returns_twice)).

You were just trying to demonstrate the behaviour of returns_twice and why the frame content is lost after that (similar to a OS_YIELD call in a task).

I originally though you meant that I may loose the frame content without being aware of it if I call a library function that has a returns_twice attribute (which is true but such an attribute is not common for a peripheral library)

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

Pages