• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Digital Signal Processors (DSP) » C6000 Single Core DSP » C64x Single Core DSP Forum » How to handle stack in ASM (BIOS context)
Share
C6000 Single Core DSP
  • Forums
  • Announcements
Options
  • Subscribe via RSS

How to handle stack in ASM (BIOS context)

How to handle stack in ASM (BIOS context)

  • KrzysztofCh
    Posted by KrzysztofCh
    on Jan 13 2009 07:13 AM
    Prodigy140 points

    I wrote an assembly function which is called by a task in DSP/BIOS. I also have HWI from McASP enabled. I wrote HWI handler in C and I'm using HWI dispatcher. I noticed that there is some stack corruption which is caused by interrupt. I found out that this error happens when I am using stack in assembly function like this:
     
    STDW .D2T1 A27:A26,*--B15[1]
    STDW .D2T1 A29:A28,*--B15[1]
    STDW .D2T1 A31:A30,*--B15[1]
     
    ;assembly function body
     
    LDDW .D2T1 *B15++[1],A31:A30
    LDDW .D2T1 *B15++[1],A29:A28
    LDDW .D2T1 *B15++[1],A27:A26

     
    When I'm disabling interrupts during LDDW from stack there are no errors
     
    when I've changed stack operations like this:
     
     ADDK -32,B15
     STDW .D2T1 A27:A26,*+B15(8)
     STDW .D2T1 A29:A28,*+B15(16)
     STDW .D2T1 A31:A30,*+B15(24
     
    ;assembly function body
     
     LDDW .D2T1 *+B15(24),A31:A30
     LDDW .D2T1 *+B15(16),A29:A28
     LDDW .D2T1 *+B15(8),A27:A26
     
    ADDK 32,B15

     
    There are no errors in that case. Is there some straightforward explanation for that? What is wrong with gradual stack incrementation at the end of asm function (that's where error occurs).

    ASM BIOS
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Brad Griffis
    Posted by Brad Griffis
    on Jan 15 2009 11:08 AM
    Guru57330 points

    So when does the assembly function get called?  Does your HWI handler make a call to your assembly function?

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

    Please click the Verify Answer button on this post if it answers your question.
    --------------------------------------------------------------------------------------------------------- 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • KrzysztofCh
    Posted by KrzysztofCh
    on Jan 15 2009 11:22 AM
    Prodigy140 points

    Sorry for being imprecise.

    HWI function is written in C. It's handled by HWI dispatcher. HWI is an interrupt from McASP so it's triggered based on sampling rate (96kHz). In my application I have also task which calls assembler function and this assembler function handles stack in two ways as i discribed previously.

    My task is in forever loop so it runs and is interrupted by HWI after a while there is stack corruption when method 1 is used for stack handling.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Brad Griffis
    Posted by Brad Griffis
    on Jan 15 2009 11:50 AM
    Guru57330 points

    Let me make sure I understand the scenario.  The assembly function you mentioned is only being called from within the task, right?  When you say there is stack corruption, are you referring to corruption of the system stack or of the task stack?

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

    Please click the Verify Answer button on this post if it answers your question.
    --------------------------------------------------------------------------------------------------------- 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • KrzysztofCh
    Posted by KrzysztofCh
    on Jan 15 2009 11:56 AM
    Prodigy140 points

    I mean the corruption of task stack. 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Brad Griffis
    Posted by Brad Griffis
    on Jan 15 2009 12:48 PM
    Guru57330 points

    Ah, I think I see it now.  I just looked at the compiler guide:

    spru187n page 170

    Even though the compiler guarantees a doubleword alignment of the stack and the stack
    pointer (SP) points to the next free location in the stack space
    , there is only enough
    guaranteed room to store one 32-bit word at that location. The called function must
    allocate space to store the doubleword.

    The processor is expecting to be able to write to whatever location is pointed to by B15.  You are doing the PUSH using a pre-decrement.  Therefore B15 is not pointing to the next FREE location, but rather to the last used location.  When you get interrupted the HWI is going to blow away whatever is at the location being pointed to.

    In the case where you did decremented the stack by 32 bytes, you filled up 24 of those bytes.  Therefore B15 was pointing to an unused location which is the correct usage of the stack.

    Side note -- why are you preserving registers A26-A31?  Those are "save on call" registers as shown in Section 8.3 of that same doc.  Therefore those functions would be saved by the C function calling your assembly function and you are free to use them without preserving them.

    Brad

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

    Please click the Verify Answer button on this post if it answers your question.
    --------------------------------------------------------------------------------------------------------- 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Brad Griffis
    Posted by Brad Griffis
    on Jan 15 2009 12:58 PM
    Guru57330 points

    A few additional thoughts:

    • You cannot change your PUSH to do a post-decrement because then you would be writing 2 words to the stack, when you're only guaranteed that one is free.
    • You cannot change your PUSH from a STDW to a STW because then you would not be maintaining double-word alignment.

    So really the only option is to do it with adding/subtracting a fixed offset, which happens to be exactly how the compiler guide says to do it...

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

    Please click the Verify Answer button on this post if it answers your question.
    --------------------------------------------------------------------------------------------------------- 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

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.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use