|
|
 | | From: | Not Really Me | | Subject: | Re: Link/load problem? | | Date: | Thu, 20 Jan 2005 09:52:50 -0700 |
|
|
 | Vadim Borshchev wrote: > Could you please consider crossposting: > http://www.uwasa.fi/~ts/http/crospost.html > > So, what is your corrected code that exhibits the problem? > > Vadim
Tauno Voipio wrote: > > Now, repair your cut-and-paste so that it compiles > and exhibits the undesired behaviour as posted, without > any modifications, and post the code.
Sorry, here is the corrected code. FWIW the code runs fine on Visual C also.
If the code is linked at RO Base 0x05000000 and RW Base 0x02000000, the load is not initialized correctly. The wrong data gets copied (by the C runtime initialization) to the RW base and a data error occurs on the 4th printf. Is this a bug, or does it need to have scatter loading specified?
Without a RW Base specified the output is:
Addr of sprintffmt = 05001a84
Addr of &sprintffmt[INDEX] = 05001a84
Addr of sprintffmt[INDEX] = 05001908 This is a test
With the RW Base specified as 0x02000000 the output should be:
Addr of sprintffmt = 02000000
Addr of &sprintffmt[INDEX] = 02000000
Addr of sprintffmt[INDEX] = 05001908 This is a test
If I run the second test directly after the first it works fine!. If I power off the board to erase all the ram and run only the second test I get:
Addr of sprintffmt = 02000000
Addr of &sprintffmt[INDEX] = 02000000
Addr of sprintffmt[INDEX] = 4bf7c776 Followed by a Data Abort error from Codewarrior.
Somehow the first load makes the second test work correctly. The first test does not need to be run, only loaded.
BTW, the debugger is an ARM MultiICE under CodeWarrior.
/* * File: main.c * Purpose: sample program * */ #include #include
#define SIZE 4
const char *sprintffmt[SIZE] = /* sprintf format strings */ { "%s\n", /* 0 */ "%s%s\n", /* 1 */ "%s%s%s\n", /* 2 */ "%s%s\n"}; /* 3 */
#define INDEX 0 /* Output buffer filename */ char buff[128]; /* output stream buffer */
int main() { strcpy(buff, "This is a test\n");
printf("\nAddr of sprintffmt = %p \n", sprintffmt ); printf("\nAddr of &sprintffmt[INDEX] = %p \n", &sprintffmt[INDEX] ); printf("\nAddr of sprintffmt[INDEX] = %p \n", sprintffmt[INDEX] );
printf(sprintffmt[INDEX], buff);
return 0; }
|
|
|