Jumping between Programs

Sep 11, 2010 5 Replies

Hi,



i have two programs resident in FLASH. i am trying to call the second program using the following piece of code, but for some reason the jump fails to happen. Is there any reason why this may be happening ?



void handle_jump () { //UINT32 jump_addr = 0x20; //asm("b 0x00900000"); void(*funcPtr)(void); funcPtr=(void(*)(void))0x00900000; (*funcPtr)(); }



I also have the following pretty basic question


  1. Is it possible to compile a simple c program on an appropriate compiler and then call it from the bootstrap code ?

Any help would be appreciated



Thanks Nived


--------------------------------------- Posted through

formatting link


Which processor? Which compiler?

I guess that this is an ARM. The assembly code is not going to work as written. There are two ways to make an absolute jump in an ARM:

a) use bx or blx b) move target address directly to pc.

a)

asm("ldr r0,=0x09000000\n" "bx r0\n");

b)

asm("mov pc,=0x09000000\n");

If you want to call the target, you need to take care of the return link, either with a bl or blx.

Tauno Voipio tauno voipio (at) iki fi

FWIW, a gcc ARM7 compiler produces

.Ltext0: .section .text.handle_jump,"ax",%progbits .align 2 .global handle_jump .type handle_jump, %function handle_jump: .LFB2: .file 1 "xxx.c" .loc 1 2 0 @ args = 0, pretend = 0, frame = 0 @ frame_needed = 1, uses_anonymous_args = 0 mov ip, sp .LCFI0: stmfd sp!, {fp, ip, lr, pc} .LCFI1: .loc 1 7 0 mov r3, #9437184 .loc 1 2 0 sub fp, ip, #4 .LCFI2: .loc 1 7 0 mov lr, pc mov pc, r3 ldmfd sp, {fp, sp, pc} .LFE2: .size handle_jump, .-handle_jump

among other things. No particular reason to say this wouldn't work. IMHO the most likely (though not necessarily the real) causes are:

1) the target code is not really at 0x900000 2) the calling code isn't getting loaded or executed as expected.

Mel.

Or this, if you care to optimize:

ARM GAS /tmp/ccSU4bzc.s page 1

1 .file "jump.c" 2 .text 3 .align 2 4 .global handle_jump 5 .type handle_jump, %function 6 handle_jump: 7 @ args = 0, pretend = 0, frame = 0 8 @ frame_needed = 0, uses_anonymous_args = 0 9 0000 04E02DE5 str lr, [sp, #-4]! 10 0004 0936A0E3 mov r3, #9437184 11 0008 0FE0A0E1 mov lr, pc 12 000c 13FF2FE1 bx r3 13 0010 04F09DE4 ldr pc, [sp], #4 14 .size handle_jump, .-handle_jump 15 .ident "GCC: (GNU) 4.3.1" ARM GAS /tmp/ccSU4bzc.s page 2

DEFINED SYMBOLS *ABS*:00000000 jump.c /tmp/ccSU4bzc.s:6 .text:00000000 handle_jump /tmp/ccSU4bzc.s:9 .text:00000000 $a

NO UNDEFINED SYMBOLS

Tauno Voipio tauno voipio (at) iki fi

jump

IMHO

Thanks a lot, but i have a few other questions in relation to this

  1. If the first program that am compiling is compiled using an arm-none-eabi-gcc compiler and the second program using xscale-elf-gcc is it still possible to make this jump ?

  1. If both programs are of the same compiler but compiled separately and flashed onto different locations and if i have jump instruction in the first program would this still work ?

I am assuming the answer to both questions is a yes because thats how bootloaders may work ?

These questions may seem absurd, but kindly bear with me

Thanks once again

- Nived

--------------------------------------- Posted through

formatting link

The parameter transfer and register usage may be different, check the generated assembly code on both sides with:

-Wa,-ahlms=mylisting.lst

on the gcc command line.

Tauno Voipio tauno voipio (at) iki fi

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required