⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cn_os_switch.s

📁 一个小的嵌入式os
💻 S
字号:
;//=================================================
;//		:Cn.oS[Operating System from China]
;//file	:	Cn_oS_switch.s
;//function:	Just to see this function,it looks like timer.s ,but it don't 
;//			use the timer5 to switch the processes .
;//			
;//			
;//			
;//			
;//			
;//author	:	kaka(sn.kaka@yahoo.com)
;//date	:	20080718
;//=================================================



        AREA    Cn_oS_sw, CODE, READONLY
        CODE32

        IMPORT  kaka                                			; //show that this variable has been defined 
											;//in other files
	IMPORT	Current_Task_P
	IMPORT	Current_PCB_P
	IMPORT	Current_PCB_P_NEXT
 	IMPORT	Current_Task_ID
 	IMPORT	Task_Max
	IMPORT	K_State
	IMPORT	Save_Info
 	IMPORT	Cn_oS_Start
 	IMPORT	Save_Info
 	IMPORT	Recover_Info
 	IMPORT	Switch_Task
 	IMPORT	Task_Create
	IMPORT	t
	IMPORT	TEST


	EXPORT	TASK_SWITCH
       EXPORT   ATTEMPER_first						;//this variable can be called in other file

NoInt       EQU 0x80  	
INTT 		EQU 0x01e00024
                               		; //no interrupt(for CPSR)
SYS32Mode   	EQU 0x1f                                    	; //SYS32Mode
IRQ32Mode   	EQU 0x12                                 		; //IRQ32Mode
SVC32Mode   	EQU 0x13 








TASK_SWITCH								;//software Switch
	STMFD	SP!,{R0-R3,R12,R14}

	MRS 	R12,CPSR						;//get the current processes's
	LDR 		R0,=Current_PCB_P				;//ProcessesControlBlock(PCB)(#Not Stack_Point!!!!)
	LDR  	R0,[R0]
	STR		R12,[R0],#8						;//if you don't understand this line
											;//you can see the commentary
											;//in file unsigned int   *Init_Stack (void   (*task),int	task_all_number)			
											;//Save the CPSR to ProcessesControlBlock(PCB)


	LDR      	R3,=kaka						;//kaka++
	LDR      	R2,[R3,#0]
	ADD     	R2,R2,#1
	STR     	R2,[R3,#0]


	

	LDMFD 	SP!,{R2,R3}
	STMIA 	R0!,{R2,R3}						;//Save R0,R1(Not R2,R3) to ProcessesControlBlock(PCB)
	LDMFD 	SP!,{R2,R3,R12,R14}
	STR 		R14,[R0,#-12]
	STMIA 	R0,{R2-R14}^					;//Save R2~R14 to ProcessesControlBlock(PCB)
											;//"^" show that :the register in the register list
											;//is under the USR_Mode			




	BL 		Switch_Task						;//make a new Current_Task_ID and				
ATTEMPER_first
	LDR 		R1,=Current_PCB_P_NEXT		;//set the Current_Stack_p_Next to 
	LDR 		R1,[R1]							;//point to newer's ProcessesControlBlock(PCB)	



	LDMIA 	R1!,{R12,R14}					;//recover the message about CPSR and LR
	MSR 	CPSR_cxsf,R12					;//from ProcessesControlBlock(PCB) to R12 and R14
											;



	LDMIA 	R1,{R0-R14}^					;//recover the register form ProcessesControlBlock(PCB)
	NOP										;//under the USR_Mode,you can't operate the Recover_Register
											;//at once ,so must NOP


	MOV 	PC,R14							;//recover the PC from LR,
											;//MOVS stand that:Recover the CPSR
											;//from the SPSR at the same time
	




;//=======================================================

;//=======================================================


		END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -