Running routine off of the stack

Started by liszewski_jason October 29, 2004

I am trying to run a routine completely off of the stack. The routine
will update the firmware the system runs. I am using the MC9S12DJ256
which has 256kB of flash. The flash has been divided in two. Half of
the flash is used to run the system. The other half stores the new
firmware that is sent over. After a complete image has been
downloaded it has to be copied from one half of flash to the other.
The routine that does the copying has to be run off the stack because
the source code will be over written during the update.

My question is this: is there a way to use some inline assembly to
label the beginning and end of my routine so that I can push it on to
the stack without having to know the lenght of the routine at compile
time.

Here is some pseudo code:

Address = TopOfRoutine;
while(Address != BottomOfRoutine)
{
asm("ldx _Address");
asm("pshx");
Address--;
}
asm("jmp TopOfRoutine"); void copyFlashRoutine(void)
{
asm("TopOfRoutine:");
// Routine Code here
asm("BottomeOfRoutine:");
}

Thanks for any help.

Jason M. Liszewski





When I list the compiled asm code from my C source, I see how it
defines the size. It defines "funcname:" at beginning, "_funcname" at
end, but I suppose does not add the tag to export (globalize) that end
symbol. --jeffs

--- In , "liszewski_jason"
<liszewski_jason@y...> wrote:
>
> I am trying to run a routine completely off of the stack. The routine
> will update the firmware the system runs. I am using the MC9S12DJ256
> which has 256kB of flash. The flash has been divided in two. Half of
> the flash is used to run the system. The other half stores the new
> firmware that is sent over. After a complete image has been
> downloaded it has to be copied from one half of flash to the other.
> The routine that does the copying has to be run off the stack because
> the source code will be over written during the update.
>
> My question is this: is there a way to use some inline assembly to
> label the beginning and end of my routine so that I can push it on to
> the stack without having to know the lenght of the routine at compile
> time.
>
> Here is some pseudo code:
>
> Address = TopOfRoutine;
> while(Address != BottomOfRoutine)
> {
> asm("ldx _Address");
> asm("pshx");
> Address--;
> }
> asm("jmp TopOfRoutine"); > void copyFlashRoutine(void)
> {
> asm("TopOfRoutine:");
> // Routine Code here
> asm("BottomeOfRoutine:");
> }
>
> Thanks for any help.
>
> Jason M. Liszewski



Hi,

Would just like to add to your bootloader strategy. I once used a dual image
strategy, however if you are transfering the image to the boot block and the
power fails..... you still loose everything and the system is unrecoverable.
A dual image system to be effective is to have hardware logic to control
with a flip-flop which address range to switch in at boot time. This way the
system can never completey be unrecoverable. The worst is to reboot from the
old image. However, that said, the system that I used had external flash.

With internal flash, I have succesfully run the boot/upgrade code from the
"4k eeprom" A4. I implemented the same strategy on the DP256. Having a
common bootloader allows recovery from almost all disaster cenarios. If I
understand your implementation correcty, while updating code running from
memory and busy copying the one image over the other might be rendered
unrecoverable if power gets interrupted.

Just my 2 cents.
----- Original Message -----
From: "liszewski_jason" <>
To: <>
Sent: Friday, October 29, 2004 6:53 AM
Subject: [68HC12] Running routine off of the stack >
>
> I am trying to run a routine completely off of the stack. The routine
> will update the firmware the system runs. I am using the MC9S12DJ256
> which has 256kB of flash. The flash has been divided in two. Half of
> the flash is used to run the system. The other half stores the new
> firmware that is sent over. After a complete image has been
> downloaded it has to be copied from one half of flash to the other.
> The routine that does the copying has to be run off the stack because
> the source code will be over written during the update.
>
> My question is this: is there a way to use some inline assembly to
> label the beginning and end of my routine so that I can push it on to
> the stack without having to know the lenght of the routine at compile
> time.
>
> Here is some pseudo code:
>
> Address = TopOfRoutine;
> while(Address != BottomOfRoutine)
> {
> asm("ldx _Address");
> asm("pshx");
> Address--;
> }
> asm("jmp TopOfRoutine"); > void copyFlashRoutine(void)
> {
> asm("TopOfRoutine:");
> // Routine Code here
> asm("BottomeOfRoutine:");
> }
>
> Thanks for any help.
>
> Jason M. Liszewski >
>
> Yahoo! Groups Links >
>