[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] Stack location in atmega128

From: Theodore A. Roth
Subject: Re: [avr-libc-dev] Stack location in atmega128
Date: Tue, 27 May 2003 10:42:19 -0700 (PDT)

On Tue, 27 May 2003, Rainer Faulstich wrote:

:) Hi,
:) where is the stack located in atmega128 ? I dont have any operating
:) system on the mcu and must define a location for the user stack. I
:) use avr-libc and its features. Must i set some register with
:) appropriate values or are there any function calls in the avr-lib
:) doing the job ?

Have a look at this:


Also, here's the code that inits the stack from gcrt.S in avr-libc:

    107 #ifndef __AVR_ASM_ONLY__
    108         .weak   __stack
    109         .set    __stack, RAMEND
    111         /* By default, malloc() uses the current value of the stack 
    112            minus __malloc_margin as the highest available address.
    114            In some applications with external SRAM, the stack can be 
    115            the data section (in the internal SRAM - faster), and 
    116            should be set to the highest address available for malloc(). 
    117         .weak   __heap_end
    118         .set    __heap_end, 0
    120         .section .init2,"ax",@progbits
    121         clr     __zero_reg__
    122         out     _SFR_IO_ADDR(SREG), __zero_reg__
    123         ldi     r28,lo8(__stack)
    124 #ifdef SPH
    125         ldi     r29,hi8(__stack)
    126         out     _SFR_IO_ADDR(SPH), r29
    127 #endif
    128         out     _SFR_IO_ADDR(SPL), r28

By default, the stack pointer is initialized in the .init2 section and
points to the last address of the internal sram. Thus, on the mega128,
the stack pointer is initialized to 0x10FF.

Ted Roth

reply via email to

[Prev in Thread] Current Thread [Next in Thread]