Hello mao jiu,
Please refer to the following code from CodeWarrior sample project.
##############################################################################
#
# isr_prologue
#
# Saves the necessary registers for an interrupt service routine
#
##############################################################################
isr_prologue: .macro
stwu rsp,-80(rsp)
stw r0,8(rsp)
mfctr r0
stw r0,12(rsp)
mfxer r0
stw r0,16(rsp)
mfcr r0
stw r0,20(rsp)
mflr r0
stw r0,24(rsp)
stw r3,40(rsp)
stw r4,44(rsp)
stw r5,48(rsp)
stw r6,52(rsp)
stw r7,56(rsp)
stw r8,60(rsp)
stw r9,64(rsp)
stw r10,68(rsp)
stw r11,72(rsp)
stw r12,76(rsp)
mfsrr0 r0
stw r0,28(rsp)
mfsrr1 r0
stw r0,32(rsp)
.endm
##############################################################################
#
# isr_epilogue
#
# Restores the necessary registers for an interrupt service routine
#
##############################################################################
isr_epilogue: .macro
lwz r0,32(rsp)
mtsrr1 r0
lwz r0,28(rsp)
mtsrr0 r0
lwz r3,40(rsp)
lwz r4,44(rsp)
lwz r5,48(rsp)
lwz r6,52(rsp)
lwz r7,56(rsp)
lwz r8,60(rsp)
lwz r9,64(rsp)
lwz r10,68(rsp)
lwz r11,72(rsp)
lwz r12,76(rsp)
lwz r0,24(rsp)
mtlr r0
lwz r0,20(rsp)
mtcrf 0xff,r0
lwz r0,16(rsp)
mtxer r0
lwz r0,12(rsp)
mtctr r0
lwz r0,8(rsp)
addi rsp,rsp,80
rfi
.endm
gInterruptVectorTable:
Have a great day,
Yiping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Yiping Wang:
I appreciate your help. However, when I use the statement “stwu rsp, -80(rsp)”, an error comes out and the error message is :” unsupported relocation against rsp”.
I am a fresh man in embedded world and mpc8306 is my first chip to work on, would you please recommend some materials about porting on mpc8306?
Moreover, I have a stupid question: Since I think the statement “stwu rsp, -80(rsp)” is writing the content in “rsp” (assume it is “ A”) to the address “A-80” and set “rsp” to “A-80”, what will happen if there is already some important data in the address “A-80” , can it be safely overwrote especially when saving state for task switching?
Hello Mao Jiu,
The variable rsp is stack frame pointer, it is R1 Register in CodeWarrior EABI Specification.
The above Code comes from CodeWarrior MPC8306 bareboard project(without OS).
Have a great day,
Yiping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Yiping:
Thank you for your reply.
I have an OS, freeRTOS, but I have trouble in switching tasks. Since I haven’t figured out whether the assembly code for task switching in timer interrupt handler is wrong or not, I’m now checking the C++ code in freeRTOS related to task switching again. However, I think the C++ code couldn’t be wrong, since I have read it for several times and I’m familiar with C++. Thus, as a fresh man in embedded world, I hope you can give me some advices for getting start on mpc8306. Any help will be appreciated.
Have a nice day,
Xue Liu
The CodeWarrior code appears to be depending on "#define rsp r1" in some header. It also appears to be written for a simple kernel-only environment that doesn't need to switch stacks on exception entry. Be wary of code samples given without context.