[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] function prologues
From: |
Theodore A. Roth |
Subject: |
[avr-gcc-list] function prologues |
Date: |
Tue, 3 Jun 2003 17:25:39 -0700 (PDT) |
Hi All,
I'm in the middle of a major overhaul of the avr port for gdb. Turns
out the prologue scanner was pretty badly broken. After studying the
asm generated by gcc-3.3, I've come up with this:
Some devices lack the sbiw instruction, so on those replace this:
sbiw r28, XX
with this:
subi r28,lo8(XX)
sbci r29,hi8(XX)
A typical AVR function prologue with a frame pointer might look like this:
push rXX ; saved regs
...
push r28
push r29
in r28,__SP_L__
in r29,__SP_H__
sbiw r28,<LOCALS_SIZE>
in __tmp_reg__,__SREG__
cli
out __SP_L__,r28
out __SREG__,__tmp_reg__
out __SP_H__,r29
A typical AVR function prologue without a frame pointer might look like
this:
push rXX ; saved regs
...
A main function prologue looks like this:
ldi r28,lo8(<RAM_ADDR> - <LOCALS_SIZE>)
ldi r29,hi8(<RAM_ADDR> - <LOCALS_SIZE>)
out __SP_H__,r29
out __SP_L__,r28
A signal or interrupt handler prologue looks like this:
sei ; interrupt only, not in signal function.
push __zero_reg__
push __tmp_reg__
in __tmp_reg__, __SREG__
push __tmp_reg__
clr __zero_reg__
push rXX ; save registers except for r29/r28
...
push r28 ; save frame pointer
push r29
in r28, __SP_L__
in r29, __SP_H__
sbiw r28, <LOCALS_SIZE>
out __SP_H__, r29
out __SP_L__, r28
A `-mcall-prologues' prologue looks like this (Note that the megas use a
jmp instead of a rjmp, thus the prologue is one word larger since jmp is a
32 bit insn and rjmp is a 16 bit insn):
ldi r26,lo8(<LOCALS_SIZE>)
ldi r27,hi8(<LOCALS_SIZE>)
ldi r30,pm_lo8(.L_foo_body)
ldi r31,pm_hi8(.L_foo_body)
rjmp __prologue_saves__+RRR
.L_foo_body:
I would appreciate if some kind souls could review this and send me
corrections.
Thanks.
Ted Roth
- [avr-gcc-list] function prologues,
Theodore A. Roth <=