stack structure
stk[1] is the register of mstatus,MPIE must be set
stk[9] is task argument
stk[31] is task start address
other position can be ignored.
- store register (x1-x31)
- store mstatus
- get mcause,mepc,sp
- call trap_handler
- set mepc(next instruction or next task)
- restore mstatus
- load register
- mret
trap_handler
will analyise which interrupt or exception occur,and process it.
If mcause is lower than zero,it is interrput,or it is exception
ucos-ii will use OSCtxSw
to switch task,but now we use task_switch
.
In time_handler
,it will replace OSTickISR
.
And in OSIntExit
,OSIntCtxSw
is removed,but in time_handler
,task_switch
will do its work.
If task give up processor,scall
should be call,then syscall_handler
will finish task switch.(This work was originally completed by the macro OS_TASK_SW
)