Hi, I'm trying to convert the Compute through power loss assembly file (ctpl_low_level.asm) in to a GCC equivalent .S.
I'm pretty sure I've got everything figured out, except the equivalent to the linker symbol __STACK_END used in the file.
I've found that gcc linker has a __stack defined, but I believe it's to the top of the Stack.
Is there an equivalent to the __STACK_END in GCC?
I'm not yet well versed in linker files, but if there isn't one predefined
would modifying the linker file with something like this be equivalent (based from things found here sourceware.org/.../Assignments.html
SECTIONS
{
.stack :
{
*(.stack)
__STACK_END = .;
PROVIDE(__STACK_END = .);
}
}
Any help is appreciated. Sorry if it's been asked before, I did try searching though.
The code in question I'm trying to convert:
ctpl_saveCpuStackEnterLpm:
pushx.a SR ; Save SR to stack
dint ; disable interrupts
nop ; disable interrupts
pushm.a #12,R15 ; Save R4-R15 to stack
movx.a #__STACK_END,R4 ; Calculate stack usage
subx.a SP,R4 ; Calculate stack usage
movx.w R4,&ctpl_stackUsage ; Save stack usage
movx.a #ctpl_stackCopy,R6 ; dest ptr
movx.a SP,R5 ; src ptr
copyx R5,R6,R4 ; copy the stack
ctpl_wakeup:
mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop WDT
mov.b #CSKEY_H,&CSCTL0_H ; unlock CS registers
mov.w #DIVM__2,&CSCTL3 ; set DCO to 4MHz (maximum boot freq)
clr.b &CSCTL0_H ; lock CS registers
movx.a #__STACK_END,SP ; Reset stack pointer
movx.w &ctpl_stackUsage,R4 ; loop counter
subx.a R4,SP ; Reset stack pointer
movx.a SP,R6 ; dest ptr
movx.a #ctpl_stackCopy,R5 ; src ptr
copyx R5,R6,R4 ; copy the stack
popm.a #12,R15 ; Restore R4-R15 from stack
popx.a SR ; Restore interrupts
movx.w #CTPL_STATE_INVALID,&ctpl_state ; Mark the state as invalid
retx ; Return