UCOS-II implementation and analysis based on ARM920T osctxsw

Source: Internet
Author: User

Implementation Analysis of osctxsw Based on ARM920T:

First, you must understand that when porting uCOS-II to ARM920T, the following structure of the task stack is used:

 


 

Program list: Based onARM920TOfOsctxswImplementation Analysis

Note:ArmSave manuallyPCAndPsw

Osctxsw

; Special optimised code below:

1. Press the stack separately based on the task stack structure to save the site of the old task

Stmfd SP !, {LR}; push PC (LR shocould be pushed in place of PC)

Stmfd SP !, {R0-r12, LR}; push LR & Register File

Mrs R4, CPSR

Stmfd SP !, {R4}; push current PSR

Mrs R4, spsr

Stmfd SP !, {R4}; push current spsr

 

; 2, Ospriocur = ospriohighrdy

LDR R4, = ospriocur

LDR R5, = ospriohighrdy

Ldrb R6, [R5]

Strb R6, [R4]

; 3, Get current task TCB address: R5 = Ostcbcur

LDR R4, = ostcbcur; r4 = & ostcbcur

LDR R5, [R4]

 

; 4. ostcbcur-> ostcbstkptr = sp;

STR sp, [R5]; store SP in preempted tasks's TCB

 

BL ostaskswhook; call Task Switch hook

 

; 5, Get highest priority task TCB address: R6 = Ostcbhighrdy

LDR R6, = ostcbhighrdy

LDR R6, [R6]

; 6. sp = ostcbhighrdy-> ostcbstkptr;

LDR sp, [R6]; get new task's stack pointer

; 7, Ostcbcur = ostcbhighrdy

STR R6, [R4]; set new current task TCB address

8. Release stacks separately based on the task stack structure to restore the site of the new task.

Ldmfd SP !, {R4}; pop new task's spsr

MSR spsr_cxsf, r4

Ldmfd SP !, {R4}; pop new task's SRS

MSR cpsr_cxsf, r4

 

Ldmfd SP !, {R0-r12, LR, PC}; pop new task's r0-r12, LR & PC

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.