AVR32 exception.x hacking

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

Atmel use this assembly code:

.balign 4
.irp priority,0,1,2,3
_int\priority:
  mov r12, \priority
  call _get_interrupt_handler
  cp.w r12, 0
  movne pc, r12
  rete
.endr

I hack it this way:

.balign 4
.irp priority,0,1,2
_int\priority:
  mov r12, \priority
  call _get_interrupt_handler
  cp.w r12, 0
  movne pc, r12
  rete
.endr
.balign 4
_int3:
  mov r12, _lo_pwm_isr_handler
  orh r12, _hi_pwm_isr_handler
  mov pc, r12

It is simple and stupid - but it works !
You can have only ONE isr with highest priority, but it is OK for me.

One sidenote: avr-gcc don't complain about global C variable, but I can't get correct value this way. Finaly I have to set immidiate values, but who cares - it works !

QUESTION: anybody knows why avr-gcc did not put correct values for global C variables here ?

I declare C variables _lo_pwm_isr_handler and _hi_pwm_isr_handler in intc.h file:

unsigned short _lo_pwm_isr_handler;
unsigned short _hi_pwm_isr_handler;

I set value in INTC_register_interrupt in intc.c file this way:

if (int_level == 3)
{
  _lo_pwm_isr_handler = ((unsigned long) handler & 0xFFFF);
  _hi_pwm_isr_handler = ((unsigned long) handler >> 16);
}

Final note:

As I wrote in second post, you can use C variable to get ISR handler. But remember what is our goal - to be fast as possible. It is worth to repeat FASTEST solution - use immediate values:

.balign 4
_int3:
  mov r12, 0xC010     // lo part of handler address
  orh r12, 0x8001     // hi part
  mov pc, r12
Last Edited: Mon. Dec 24, 2012 - 09:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok - now I understand what is going on.

I can use C variables in assembly. but I have to know some basic. First of all, MOV command is for load IMMIDIATE values only. So - this one will not work:

mov r12, _lo_pwm_isr_handler

Here is solution:

    mov     r12, 0
    ld.w    r12, r12[_pwm_isr_handler]
    cp.w    r12, 0          
    movne   pc, r12       
    rete  

one more thing. This one is not trivial at all. If I don't have mkII debuger I will never find what is going on. This command fire _handle_Data_Address_Read: exception

    ld.w    r12, r12[_pwm_isr_handler]

and default handler for all exceptions are infinite loop - bad luck ! so - I have to change default behaviour, like this:

     .org  0x034
        // Data Address (Read).
_handle_Data_Address_Read:
		rete
        // rjmp $
  

and that's it !
regards to all - merry hacking !

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

Kepica, 

 

It looks like you handle the exception using rete instruction. 

But is there any way to know why this exception was generated ?

I am getting _handle_bus_error_data_fetch exception when try to use flash on my UC3B0512 chip.

 

How to know the instruction in C code that causes exception.

Please let me know if there is any way of doing it.