(This turned into a bit of a ramble - I'll post it anyway
).
Part I
I declare a value at the top of the file. At the start of the code, I store the stack into it, like this:
If I then have this code, a little while after (call this A):
all works just fine.
If I copy the code to close to the end of the file, like this (call this B):
And replace the A code with:
... it crashes, or infinite loops or something unpleasant.
So, I disassembled the code and inspected it, and it all seems to be fine.
So, I poked it a bit more. If I replace the ldr in B with:
It works...
When compiled, the ldr is:
The adrl + ldr combo compiles to:
I just can't work out what on earth is going wrong; the offsets are the same, and the offset fits within the 12-bit range for the instruction. The instructions aren't misaligned either.
Has anybody seen this kind of strangeness before, or know of anything that might be causing this?!
Part II
I figured that as the code was effectively the same (at last to my mind), the only thing that could be screwing it up was the branch instruction. :S
So, I had a look at it.
Its address is 0x0000014C, and the instruction is:
0xea000226
Which equates to branching to the instruction at PC + 226 :
0x226<<2 + 0x14c + 8 (PC is ahead by 8 in the pipeline)
= 0x898 + 0x154
= 0x9eC
Which is indeed the address of the instruction I want to branch to.
So now I just have no clue what the problem is.
I'll be making a better test function later today, and trying with a later assembler. :S
Any ideas appreciated...
Addendum:
It seems that now the adrl isn't working either. Nor is ldr r13,=|$L_StackDump|
So, to summarize, this works:
And this doesn't:
(And it doesn't matter whether the code at |$THE_END$| uses adrl lrd r13,= or just ldr).
Not having fun.
Part I
I declare a value at the top of the file. At the start of the code, I store the stack into it, like this:
- Code:
stmfd r13!,{r4-r11,r14}
str r13,|$L_StackDump|
If I then have this code, a little while after (call this A):
- Code:
ldr r13,|$L_StackDump|
ldmfd r13!,{r4-r11,pc}
all works just fine.
If I copy the code to close to the end of the file, like this (call this B):
- Code:
|$THE_END$|
ldr r13,|$L_StackDump|
ldmfd r13!,{r4-r11,pc}
ENDP
And replace the A code with:
- Code:
B |$THE_END$|
... it crashes, or infinite loops or something unpleasant.
So, I disassembled the code and inspected it, and it all seems to be fine.
So, I poked it a bit more. If I replace the ldr in B with:
- Code:
adrl r13,|$L_StackDump|
ldr r13,[r13]
It works...
When compiled, the ldr is:
- Code:
ldr r13,[pc,#-0x9e4]
ldmfd r13!,{r4-r11,pc}
The adrl + ldr combo compiles to:
- Code:
sub r13, pc, #0x800
sub r13, r13, #0x1E4
ldr r13, [r13]
ldmfd r13!,{r4-r11,pc}
I just can't work out what on earth is going wrong; the offsets are the same, and the offset fits within the 12-bit range for the instruction. The instructions aren't misaligned either.
Has anybody seen this kind of strangeness before, or know of anything that might be causing this?!
Part II
I figured that as the code was effectively the same (at last to my mind), the only thing that could be screwing it up was the branch instruction. :S
So, I had a look at it.
Its address is 0x0000014C, and the instruction is:
0xea000226
Which equates to branching to the instruction at PC + 226 :
0x226<<2 + 0x14c + 8 (PC is ahead by 8 in the pipeline)
= 0x898 + 0x154
= 0x9eC
Which is indeed the address of the instruction I want to branch to.
So now I just have no clue what the problem is.
I'll be making a better test function later today, and trying with a later assembler. :S
Any ideas appreciated...
Addendum:
It seems that now the adrl isn't working either. Nor is ldr r13,=|$L_StackDump|
So, to summarize, this works:
- Code:
stmfd r13!,{r4-r11,r14}
str r13,|$L_StackDump|
... more code ... (no stores)
ldr r13,|$L_StackDump| ;
ldmfd r13!,{r4-r11,pc} ;
And this doesn't:
- Code:
stmfd r13!,{r4-r11,r14}
str r13,|$L_StackDump|
... more code ... (no stores)
b |$THE_END$|
... more code ...
|$THE_END$|
ldr r13,|$L_StackDump| ;
ldmfd r13!,{r4-r11,pc} ;
(And it doesn't matter whether the code at |$THE_END$| uses adrl lrd r13,= or just ldr).
Not having fun.