<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: New to S12X stack frame structure (need assistance) repost in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158893#M4900</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Check this thread:&lt;BR /&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=10109" target="test_blank"&gt;http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=10109&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;It is for the S08, but for the S12(X) I would do the exactly same thing, of course the struct has to be adapted to the S12X, and the HLI has to be adapted to the S12X too. (transfer the stackpointer to the argument register: TFR SP,D)&lt;BR /&gt;&lt;BR /&gt;Note that there are basically the same challenges for the S12X, as for the S08, the S12 compiler does also reorder the local variables for example. By using a small just HLI function as in the post, all such problems are avoided.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 May 2008 02:29:54 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2008-05-27T02:29:54Z</dc:date>
    <item>
      <title>New to S12X stack frame structure (need assistance) repost</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158889#M4896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello all,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;i would like to read the PC and global page register from the stack, on an event of an access violation interrupt (or perhaps an interrupt in general). I am not familiar with the stack frame structure.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;here is what i have initially:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;&lt;SPAN style="color: #0000ff; font-size: 2;"&gt;
void&lt;SPAN style=": ; color: #000000; font-size: 2;"&gt;AccessViolation_InterruptHandler(void){&lt;/SPAN&gt;

int pc_t;

char gpage_t;

 &lt;SPAN style="font-size: 2;"&gt;&amp;nbsp;&amp;nbsp; asm movw 2,sp+7, pc_t;&amp;nbsp; //im not sure about this&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; asm movb 1, sp+6, gpage_t; //this too
&lt;/SPAN&gt;&lt;SPAN style="font-size: 2;"&gt;
}
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;i still need to be&amp;nbsp;walked thru the assembler codes as well.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks,&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:03:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158889#M4896</guid>
      <dc:creator>Xbot</dc:creator>
      <dc:date>2020-10-29T09:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: New to S12X stack frame structure (need assistance) repost</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158890#M4897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Immediately after CPU stacks its registers and&amp;nbsp;jumps to your AccesViolation ISR (before any function prolog, before allocating variables on stack etc), CPU12X stack frame looks as follows:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PC @ SP+8 , 16bit CPU return address,&lt;/DIV&gt;&lt;DIV&gt;Y @ SP+6&lt;/DIV&gt;&lt;DIV&gt;X @ SP+4&lt;/DIV&gt;&lt;DIV&gt;B:A @ SP+2&lt;/DIV&gt;&lt;DIV&gt;CCRH:CCRL @ SP&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;No page registers (GPAGE, PPAGE, etc ) are stacked when servicing interrupts. You can read GPAGE&amp;nbsp;directly from GPAGE register.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The rest depends on your compiler and version of your compiler. Compiler can allocate 3 bytes on stack for your char and int variables, it may also decide to allocate some temporary variables on stack, above your vars&amp;nbsp;or below. So we can only guess what is offset to PC return address on stack. Try disassembling you code and see what is that offset. For example it could be something like that:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;AccessViolation_InterruptHandler:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leas -3,sp&amp;nbsp; ; allocating pc_t and gpage_t on stack&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; if offset is&amp;nbsp;really +3, then&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; movw&amp;nbsp; 8+3,SP,&amp;nbsp; pc_t&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; movb&amp;nbsp;&amp;nbsp; GPAGE, gpage_t&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 May 2008 20:57:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158890#M4897</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2008-05-26T20:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: New to S12X stack frame structure (need assistance) repost</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158891#M4898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Im using cw4 by the way.&lt;/DIV&gt;&lt;DIV&gt;from your code "movw&amp;nbsp; 8+3,SP,&amp;nbsp; pc_t" -- the first parameter of this instruction is the offset of the second?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;how about in this code:&lt;DIV class="O"&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;MOVW&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; 2,X+ , 2,-Y&lt;/FONT&gt;&lt;STRONG&gt;&amp;nbsp; &lt;FONT size="2"&gt;-- can you please explain&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;thanks,&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 May 2008 21:28:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158891#M4898</guid>
      <dc:creator>Xbot</dc:creator>
      <dc:date>2008-05-26T21:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: New to S12X stack frame structure (need assistance) repost</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158892#M4899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;Xbot wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Im using cw4 by the way.&lt;/DIV&gt;&lt;DIV&gt;from your code "movw&amp;nbsp; 8+3,SP,&amp;nbsp; pc_t" -- the first parameter of this instruction is the offset of the second?&lt;/DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;the fisrt parameter&amp;nbsp;(8+&lt;FONT color="#3300CC"&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/FONT&gt;,SP) , the source argument of movw, is a ISR return address on stack,&amp;nbsp;provided&amp;nbsp;CW&amp;nbsp;allocated &lt;FONT color="#330099"&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/FONT&gt; bytes on stack for local variables. I don't know this figure in advance, it depends on a lot of factors. If both your variables are used in the code and aren't optimized out, then chances are CW is issuing "LEAS -3,SP" and my gues is valid. You should disassemble your code and check what compiler is doing with stack.&lt;/DIV&gt;&lt;DIV&gt;And pc_t is&amp;nbsp;your pc_t variable. CW will replace pc_t with something like ?,SP.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;Xbot wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;how about in this code:&lt;DIV class="O"&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;MOVW&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; 2,X+ , 2,-Y&lt;/FONT&gt;&lt;STRONG&gt;&amp;nbsp; &lt;FONT size="2"&gt;-- can you please explain&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;I'm not sure what are you asking to explain? Are you wondering what above instruction&amp;nbsp;means? Well, predecrement Y register by 2, move a word from memory at X to memory at Y, then postincrement X by two. I welcome you reading CPU reference manual:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://www.freescale.com/files/microcontrollers/doc/ref_manual/S12XCPUV2.pdf?fpsp=1" rel="nofollow" target="_blank"&gt;http://www.freescale.com/files/microcontrollers/doc/ref_manual/S12XCPUV2.pdf?fpsp=1&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 May 2008 23:14:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158892#M4899</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2008-05-26T23:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: New to S12X stack frame structure (need assistance) repost</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158893#M4900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Check this thread:&lt;BR /&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=10109" target="test_blank"&gt;http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=10109&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;It is for the S08, but for the S12(X) I would do the exactly same thing, of course the struct has to be adapted to the S12X, and the HLI has to be adapted to the S12X too. (transfer the stackpointer to the argument register: TFR SP,D)&lt;BR /&gt;&lt;BR /&gt;Note that there are basically the same challenges for the S12X, as for the S08, the S12 compiler does also reorder the local variables for example. By using a small just HLI function as in the post, all such problems are avoided.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 May 2008 02:29:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158893#M4900</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-05-27T02:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: New to S12X stack frame structure (need assistance) repost</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158894#M4901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;thanks for the help guys, appreciate it...&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 May 2008 12:11:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/New-to-S12X-stack-frame-structure-need-assistance-repost/m-p/158894#M4901</guid>
      <dc:creator>Xbot</dc:creator>
      <dc:date>2008-05-27T12:11:13Z</dc:date>
    </item>
  </channel>
</rss>

