From: SourceForge.net <no...@so...> - 2009-01-06 15:35:42
|
Bugs item #2490164, was opened at 2009-01-06 17:43 Message generated for change (Comment added) made by aesok You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=520074&aid=2490164&group_id=68108 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: GCC Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: atxmfan (atxmfan) Assigned to: Nobody/Anonymous (nobody) Summary: XMega (128A1): subroutine calling may corrupt stack pointer Initial Comment: When calling a subroutine (esp. when using varargs) arguments are put on stack. To achieve this the stack pointer is decremented to make enough space on stack before calling. After returning from subroutine the stack pointer is adjusted back to its old value. The XMega needs special preparing before being able to change the stack pointer (protected I/O-registers) - register CCP must be set to 0xDA. Within the next 4 cycles changes to the SP registers are allowed. GCC generates the following code in the "cleaning up" code: mov __tmp_reg__,r24 ldi r24,0xD8 out __CCP__,r24 out __SP_H__,r25 out __SP_L__,r24 mov r24,__tmp_reg__ in which case r24 (SP_L) is destroyed. The next return lets the CPU crash. This happens only, when GCC chooses r24, r25. If different registers are used everything is OK. The correct XMega patch should look like this: mov __tmp_reg__,r24 ldi r24,0xD8 out __CCP__,r24 mov r24,__tmp_reg__ out __SP_H__,r25 out __SP_L__,r24 The libc library is also affected and must be recompiled. atxmfan ---------------------------------------------------------------------- Comment By: Anatoly (aesok) Date: 2009-01-06 18:35 Message: Hi Eric. Try change 52-gcc-4.3.2-xmega-v9.patch from: 180 + { 181 + *l = 6; 182 + return (AS2 (mov,__tmp_reg__,r24) CR_TAB 183 + AS2 (ldi,r24,0xD8) CR_TAB 184 + AS2 (out,__CCP__,r24) CR_TAB 185 + AS2 (out,__SP_H__,%B1) CR_TAB 186 + AS2 (out,__SP_L__,%A1) CR_TAB 187 + AS2 (mov,r24,__tmp_reg__)); 188 + } to: { *l = 6; return (AS2 (mov,__tmp_reg__,r24) CR_TAB AS2 (ldi,r24,0xD8) CR_TAB AS2 (out,__CCP__,r24) CR_TAB AS2 (mov,r24,__tmp_reg__) CR_TAB AS2 (out,__SP_H__,%B1) CR_TAB AS2 (out,__SP_L__,%A1)); } Anatoliy. ---------------------------------------------------------------------- Comment By: Eric Weddington (arcanum) Date: 2009-01-06 17:58 Message: What versions are you using? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=520074&aid=2490164&group_id=68108 |