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

📄 os_cpu_a.s

📁 嵌入式操作系统源码
💻 S
字号:

.data                    # 数据段声明 


             .extern  OSIntExit
             .extern  OSIntEnter
             .extern  OSTimeTick
             .extern  OSTaskSwHook

             .extern  OSIntNesting
             .extern  OSTickDOSCtr
             .extern  OSPrioHighRdy
             .extern  OSPrioCur
             .extern  OSRunning
             .extern  OSTCBCur
             .extern  OSTCBHighRdy

.text  
.code32

.globl  OSStartHighRdy
                 
              
OSStartHighRdy:   


		call	OSTaskSwHook

		incl	OSRunning

//Load the processor stack pointer with OSTCBHighRdy->OSTCBStkPtr

		mov OSTCBHighRdy, %eax	//Point to TCB of highest priority task ready to run
		mov  (%eax), %esp			//ESP = OSTCBHighRdy->OSTCBStkPtr

//Pop all the processor registers from the stack

		popa

//Execute a Return from interrupt intruction;

		iret


.globl OSCtxSw
        
OSCtxSw:

	// PUSH processor registers onto the current task's stack

		pusha

	//Save the stack pointer into OSTCBCur->OSTCBStkPtr

		mov	OSTCBCur, %eax
		mov	%esp,(%eax)			//Stack pointer is ESP

	// Call OSTaskSwHook();

		call	OSTaskSwHook

	//OSPrioCur = OSPrioHighRdy

		mov	OSPrioHighRdy, %al     //AL is OSPrioHighRdy
		mov	%al, OSPrioCur

	//OSTCBCur = OSTCBHighRdy

		mov OSTCBHighRdy, %eax		//EAX is OSTCBHighRdy
		mov	%eax,OSTCBCur

	//Load the processor stack pointer with OSTCBHighRdy->OSTCBStkPtr
	//Note that EAX is still OSTCBHighRdy.

		mov	(%eax), %esp			//ESP = OSTCBHighRdy->OSTCBStkPtr

	//Pop all the processor registers from the stack

		popa

	//Execute a Return from interrupt intruction;

		iret
// ******************************************************************************************************           
//                PERFORM A CONTEXT SWITCH (From an ISR)
//                         void OSIntCtxSw(void)
                         
                       
.globl  OSIntCtxSw

OSIntCtxSw:

 

	//Adjust the stack pointer to remove call to OsIntExit(), locals in 
	//OsIntExit() and the call to OSIntCtxSw();

	 
	  add	$24, %esp			//Ignore calls to OSIntExit, PUSHFD and OSIntCtxSw


	//Save the stack pointer into OSTCBCur->OSTCBStkPtr

		mov	OSTCBCur, %eax
		mov	%esp, (%eax)			//Stack pointer is ESP

	//Call OSTaskSwHook();

		call	OSTaskSwHook
		//OSPrioCur = OSPrioHighRdy

		mov	OSPrioHighRdy, %al     //AL is OSPrioHighRdy
		mov	%al, OSPrioCur

	//OSTCBCur = OSTCBHighRdy

		mov OSTCBHighRdy, %eax		//EAX is OSTCBHighRdy
		mov	%eax,OSTCBCur

	//Load the processor stack pointer with OSTCBHighRdy->OSTCBStkPtr
	//Note that EAX is still OSTCBHighRdy.

		mov	(%eax), %esp			//ESP = OSTCBHighRdy->OSTCBStkPtr

	//Pop all the processor registers from the stack

		popa

	//Execute a Return from interrupt intruction;

		iret

// ******************************************************************************************************

.globl DefIntHandler

DefIntHandler:
		iret


.globl  OSTickISR	

OSTickISR: 

		pusha                                # Save interrupted task s context

		mov $0x20, %al
		out %al, $0x20

		call OSIntEnter
		call OSTimeTick
		call OSIntExit
				
		popa
		
		iret
.end
   

⌨️ 快捷键说明

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