alexforencich / xboot

XBoot Extensible Bootloader
125 stars 69 forks source link

GCC 4.6.2 on Mac OS X corrupts r25 in get_2bytes method when compiling for X16A4. #7

Closed lrozema closed 10 years ago

lrozema commented 10 years ago

When building XBoot for X16A4 on Mac OS X using AVR-GCC 4.6.2 from CrossPack 20130212 the r25 register used by get_2bytes assembler method is corrupted by the get_char method. When I add push %B0 and pop %B0 around the second get_char inside get_2bytes then the bootloader starts to work.

alexforencich commented 10 years ago

Can you try replacing push %B0 with push r24 and then deleting the mov %B0,r24? I will commit this smaller change if it works.

lrozema commented 10 years ago

Yeah sure, that will work, squeezing out an extra few clocks. I can test this in two days when I'm back at the device.

alexforencich commented 10 years ago

I'm actually more worried about code size than clocks as xboot has to fit into 4k of code space. There are some parts of xboot that can probably use a lot more optimization, though.

lrozema commented 10 years ago

I have tested the suggested change, it works fine. The code is now: asm volatile ( "call get_char" "\n\t" "push r24" "\n\t" "call get_char" "\n\t" "pop %B0" "\n\t" "mov %A0,r24" "\n\t" : "=r" (result) : );

alexforencich commented 10 years ago

Alright, I just committed the fix. Thanks!