is this app jump in my bootloader code correct?

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

just checking the asm code for my mega128 4K words bootloader now and I found out that

void (*startApplication)( void ) = 0x0000;
...
...

startApplication();

startApplication(); been translate to:

   1e7d2:	e0 91 10 01 	lds	r30, 0x0110
   1e7d6:	f0 91 11 01 	lds	r31, 0x0111
   1e7da:	09 95       	icall

in assmbly, shouldn't r30 and r31 both be 0x0000?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

LDS is load from storage - its loading the jump destination from SRAM locations 0x110 and 0x111 into Z and then calling through it. Those locations are the holding place for the variable startApplication which the C preamable will have copied the value 0x0000 into.

BTW why not simulate/JTAG this and watch the contents of R30/R13 ? You may also want to read the PDF that documents the AVR instruction set.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes, ok, thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I´m not familiar with C, but I am wondering:

* Why do you use ICALL instead of IJMP?
Do you expect the application return to the bootloader?

* doesn´t the application code allways start at 0x0000?
So couldn´t you simply write "JMP 0x0000"

Maybe this is because of compatibility reasons with other ucontrollers/processors and C?

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, Klaus,
those asm code are generate by WINAVR, so i don't know it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey dart,

I have the following code in two different bootloaders:

        asm volatile ("jmp 0x0000" );

And:

        asm volatile ("push __zero_reg__" "\n\t"
                      "push __zero_reg__" "\n\t"
                      "ret"               "\n\t"
                      ::); 

And they work OK.

---
ARod

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MegaUSBFreak wrote:
Hi,

I´m not familiar with C, but I am wondering:

* Why do you use ICALL instead of IJMP?
Do you expect the application return to the bootloader?

* doesn´t the application code allways start at 0x0000?
So couldn´t you simply write "JMP 0x0000"


In pure C alone the only way to make a JMP rather than a CALL is using goto but this requires you to be able to define a destination label at 0. The initial code in this thread just assigns 0 to a "function pointer" then invokes that function but this would usually be used in a context where the function was called and then control returned to the point after the function invocation - in other words a call. It doesn't actually matter in this case that a CALL is used (and hence a return address is pushed onto the stack) because the code accessed via 0 will reinitialise the stack as one of it first operations anyway. If you really want to code a JMP then you need to do what alejmrm says and resort to asm("") to hand code some Asm instructions into the C program

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

thanks Cliff

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To go from the bootloader to the app, you might want to force a watchdog timer reset instead of doing a jmp. Doing so ensures that all the registers/bits are in a known condition for the benefit of the app.

Also, on the mega128 and bigger, be sure to mind the page register value