This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Writing to the inadmissible address

Hello all,

I got incorrect result in my program and searched the error
in assembler code.

Program code for Core0 used address = 0x0C37FF70 in the MSM memory
and this address contained correct value = 0x0084C880
untill Core1 executed following command:
while(flag_CoreMainPlus0 != 2);

This command represented with the assembler code - below this letter
(unfortunately I can't send the complete sourse code)

I did breakpoint in Core0 (at the appropriate command)
and breakpoint in the Core1 at the command
while(flag_CoreMainPlus0 != 2);
After both cores was stopped I went step by step in the assembler
code of Core1 and I found interesting thing:

Before command
0083292c: 003C8AF5 STW.D2T1 A0,*+B15[B4]
(and two parallel commands)
------------------------------------------------------------
B1=0x808FD478
A0=0x8092DBF8
B15=0x0C26B8B8
B4=0x000451AF
Address 0x0C37FF70 contained 0x0084C880 (i.e. correct value)
        B15 and B4 give address for writing:
0x0C26B8B8 + 0x000451AF*4 = 0x0C37FF74


After command
0083292c: 003C8AF5 STW.D2T1 A0,*+B15[B4]
------------------------------------------------------------
A0=0x808FD478
(as I understand A0 was changed with the parallel command MV.L1X B1,A0)
Address 0x0C37FF74 contained new lalue = 0x8092DBF8
and address 0x0C37FF70 still contained 0x0084C880 (i.e. correct value)

but after next command
00832934: 02146FAB MVK.S2 0x28df,B4
address 0x0C37FF70 contained already new (incorrect !) value = 0x808FD478
This incorrect value will lead to error later in the Core0
that will use address 0x0C37FF70


Please answer on the following questions:
- which operation did writting to the address 0x0C37FF70?
- what necessary to do in this situation?

I used:
Code Composer Studio 5.2.1.00018
mcsdk_2_01_02_06
pdk_C6678_1_1_2_6
Compiler version TIv7.4.7
MDSEVM6678L board

Best regards,
Viktor

===========================================================================================

3069 while(flag_CoreMainPlus0 != 2) // wait for flag_CoreMainPlus0 == 2
008328e0: 050004FB ZERO.L2 B11:B10
008328e4: 006DFC2B || MVK.S2 0xffffdbf8,B0
008328e8: 040004F9 || ZERO.L1 A9:A8
008328ec: 02800029 || MVK.S1 0x0000,A5
008328f0: 1B76 || MVK.D1 0,A6
008328f2: 1BF6 MVK.D1 0,A7
008328f4: 0040496B || MVKH.S2 0x80920000,B0
008328f8: 080004F9 || ZERO.L1 A17:A16
008328fc: E2000200 .fphead n, l, W, BU, nobr, nosat, 0010000b
00832900: 028841E8 MVKH.S1 0x10830000,A5
00832904: 06800029 MVK.S1 0x0000,A13
00832908: 00EA3C2B || MVK.S2 0xffffd478,B1
0083290c: 02212D99 || DMV.L1 A9,A8,A5:A4
00832910: 009C || LDW.D1T1 *A5[0],A1
00832912: 1046 MV.L1X B0,A0
00832914: 00C047EB || MVKH.S2 0x808f0000,B1
00832918: 06B69D89 || SET.S1 A13,20,29,A13
0083291c: E2000200 .fphead n, l, W, BU, nobr, nosat, 0010000b
00832920: 06000040 MVK.D1 0,A12
00832924: 0228D7AA MVK.S2 0x51af,B4
00832928: 0200026A MVKH.S2 0x40000,B4
0083292c: 003C8AF5 STW.D2T1 A0,*+B15[B4]
00832930: 10C6 || MV.L1X B1,A0
00832932: EE41 || ADD.L2 B4,-1,B4
00832934: 02146FAB MVK.S2 0x28df,B4
00832938: 003C8AF5 || STW.D2T1 A0,*+B15[B4]
0083293c: E2000100 .fphead n, l, W, BU, nobr, nosat, 0010000b
00832940: 00844A58 CMPEQ.L1 2,A1,A1
00832944: 80000A11 [ A1] B.S1 $C$DW$L$main$320$E (PC+80 = 0x00832990)
00832948: 0200016B || MVKH.S2 0x20000,B4
0083294c: 9004A358 || [!A1] MVK.L1 1,A0
00832950: 03422D99 DMV.L1 A17,A16,A7:A6
00832954: 033C8BC4 || STDW.D2T1 A7:A6,*+B15[B4]
00832958: 0210605A ADD.L2 3,B4,B4
0083295c: 023C8BC4 STDW.D2T1 A5:A4,*+B15[B4]
00832960: 0213E05A SUB.L2 B4,0x1,B4
00832964: 033C8BC4 STDW.D2T1 A7:A6,*+B15[B4]
$C$DW$L$main$318$E:
00832968: C303E000 [ A0] SPLOOPW 7
$C$L236:
0083296c: 0000A000 NOP 6
00832970: 01800028 MVK.S1 0x0000,A3
00832974: 0C6E NOP 1
00832976: 91CF MV.S2X A3,B4
00832978: 020841EA MVKH.S2 0x10830000,B4
0083297c: E4000000 .fphead n, l, W, BU, nobr, nosat, 0100000b
00832980: C29002E6 [ A0] LDW.D2T2 *+B4[0],B5
00832984: 6C6E NOP 4
00832986: 42A7 CMPEQ.L2 2,B5,B0

  • Hello Viktor,

    Does flag_CoreMainPlus0 need to be declared with the volatile keyword?

    Stephen

  • The STW at address 00832938 wrote to that address.   After the execute packet at PC 0083292c:

    • A0 = 808FD478
    • B4 = 000451AE (decremented by the ADD at 00832932)
    • 0C26B8B8 + 000451AE * 4 = 0C37FF70

    Now the STW at address 00832938 writes to 0C37FF70.

    B15 is the stack pointer, and 0x451AF * 4 implies a very large stack.  Make sure your stack is larger than that so that it doesn't grow into some other section.

    Also, as Stephen suggested, flag_CoreMainPlus0 almost assuredly must be declared volatile.

  • Hello Stevenh,

    yes, of course this variable was declared as

    volatile unsigned int flag_CoreMainPlus0;

    Thank you for your answer,

    Regards,

    Viktor.

  • Hello Archaeologist,

    yes, I have drawn attention on this parallel command too, some later.
    Now I have to understand why do the command
    while(flag_CoreMainPlus0 != 2);
    erases content of the address 0x0C37FF70 that uses another core,
    but it is another theme.
    I should to open new thread for this tipic.

    Thank you for your assistance.

    Regards,
    Viktor.
  • I should clarify a little bit.  Because the code uses the offset SP + 0x451AF * 4, we know that this function's frame is very large, meaning you have a very large local variable, which is usually not desirable.  You must do one of the following:

    • make sure your stack is large enough to handle this object, or
    • move that object to the global scope, or
    • dynamically allocate the object