MPC55xx: force value PC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MPC55xx: force value PC

4,155 Views
mudy
Contributor I
Hello!
I'm using MPC5553 and I want to write the code to force the value of the Program counter.I don't know how I can do!

Please help me!

thanks

mudy

Message Edited by CrasyCat on 2007-04-13 11:37 AM

Labels (1)
0 Kudos
12 Replies

783 Views
mudy
Contributor I
Thank...if I use the branch the problem is solved...but:

If I force the value of PC to an address of flash with this line of asm
 asm(ba 0x0);
is ok, but if I force the value of PC to an address of RAM with this line of asm
 asm("ba 0x4000D000);
there's an error message.It's:

C:\....\Temp/ccMDaaaa.s:365: Error: operand out of range (0x4000d000 is not between 0xfe000000 and 0x01ffffff).

How can I do to force the PC to an address of RAM...because the second program is located in RAM!

thanks

mudy
0 Kudos

783 Views
Alban
Senior Contributor II
Hello,
 
A code area needs to be declared as READ ONLY in the PRM file.
You need to declare a zone of RAM as READ ONLY to be able to execute from it.
This is on the S12 compiler. You may get away with it as you are using direct ASM.
 
Cheers,
Alban.

Message Edited by Alban on 2006-11-29 03:27 PM

0 Kudos

783 Views
CompilerGuru
NXP Employee
NXP Employee
Isn't the MPC5553 an Embedded PPC? (it does not have prm files then....)

Whatever the processor is, if you have a C compiler, you can use it to call a certain address.
something like
typedef void (*FunPtrType)(void);
void blubs(void) {
FunPtrType ptr= (FunPtrType)12345678;
ptr();
}

There is one drawback here as the compiler will also
store the return address as it assumes that the call returns too (not sure if this is true or if it does matter for the OP)

There is no portable way to encode a goto in C (function call without storing the return address), so if you need this, you have to use HLI or an assembler :smileysad:.

But anyway, if you can compile the above code, you see how to make the call.
For EPPC, I think the usual pattern is to load the destination address into a GPR, then transfer the GPR into either LR or CTR, and then branch via this SPR with a blr/bctr.

Daniel
0 Kudos

783 Views
mudy
Contributor I
Hi. I'm trying to write some lines of asm (as indicated by compiler guru)...but I'm newbie for asm an I have some big difficulties. I'm trying to implement the steps that Compiler Guru wrote.


CompilerGuru wrote:
For EPPC, I think the usual pattern is to load the destination address into a GPR, then transfer the GPR into either LR or CTR, and then branch via this SPR with a blr/bctr.

.

My code asm is:
asm("lwz R11,0x40000000"); // copy address into R11
asm("mtctr R11"); // load Count Register
asm("blr ");// branch to contents of Count Register


But I have the some problem. The error message is:

C:\......./ccEHaaaa.s: Assembler messages:
C:\......./ccEHaaaa.s:384: Error: operand out of range (0x40000000 is not between 0xffff8000 and 0x00007fff)
C:\......./ccEHaaaa.s:384: Error: syntax error; found `

I don't know how i can solve these problems...but I'm continuing to try, try and try waiting with confidence yours councils!

thanks a lot to everybody.

mudy
0 Kudos

783 Views
CompilerGuru
NXP Employee
NXP Employee
My first and main advice would to use C, do you have a C compiler?
Checking the output that the compiler did generate really helps.
And read some PPC assembly manual before you try to code things, there are just too many details to know before assembly code works.
Maybe someone has some good links where to start looking.

Here's what the MW EPPC C compiler did generate for a branch to 0x40000000
00000034: 00000000: 3D804000 lis r12,16384
00000038: 00000004: 7D8903A6 mtctr r12
0000003C: 00000008: 4E800420 bctr

About your code snippet,
lwz load from memory at the given address, it does not load the address.
Also the maximum offset is a signed 16 bit value, you have to use 2 instructions in general to load a 32 bit address.
blr This branches to the link register, not to the ctr which you tried to load. use bctr instead.

Daniel
0 Kudos

783 Views
mudy
Contributor I
I have solved my problem!..or, better, you have solved my problem!
Now, with the code asm given by Compiler Guru I force the value of PC as I want without mistakes or problems! I'm very happy!:-))

Thanks a lot to everybody!

mudy
0 Kudos

783 Views
NewbieMCULover
Contributor II

hi, I am trying to follow your discussions here. And I placed a jmp assembly on my code (I need to jump to an address because of the bootloader)

 

asm(jmp 0x20000);

 

but it throws an error "Unknown assembler instruction mnemonic"

 

what could be the problem here?

0 Kudos

783 Views
CrasyCat
Specialist III
Hello
 
I would use the instruction JMP and specify the destination address.
This should do it.
 
CrasyCat
0 Kudos

783 Views
mke_et
Contributor IV
Well, you could jmp...

Or you could push the PC onto the stack and do a ret

Or do you mean to force the PC while you're single stepping to be able to debug a routine?
0 Kudos

783 Views
mudy
Contributor I
Hi!
I want to force the PC because I want to flash two different programs in two different parts of memory that I established. If at the end of a program I want to jump to the other program I must force the PC to the correct value that I know (because I established a specified location of two programs in memory).
I don't know how force the PC...Could I jmp? or what?
My problems is that I don't know the address of PC, in the reference manual I did't find this information...how I force the value of PC or push it into a stack if I don't know how call it?

thanks

regards

mudy
0 Kudos

783 Views
Alban
Senior Contributor II
Hello Mudy,
 
CPU Registers are being used directly with the instruction set.
 
They are not in the memory map at all.
 
You cannot address the Program Counter, but you can use instructions dedicated to alter PC, like the
JUMP offered in the previous post.
 
Cheers,
Alban.
0 Kudos

783 Views
J2MEJediMaster
Specialist I
1) Why would you want to force a change in the PC?

2) You could use jump statement, using in-line assembly, although doing that blithely without regards to the consequences to preserving the processor's context will land you in a lot of trouble. See 1). Might what you want to do be best managed by an exception handler?

---Tom
0 Kudos