📄 os_cpu_a.asm
字号:
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
; All Rights Reserved
;
;
; 80x86/80x88 Specific code
; LARGE MEMORY MODEL
;
; IBM/PC Compatible Target
;
; File : OS_CPU_A.ASM
; By : Jean J. Labrosse
;********************************************************************************************************
TICKISRFOROTHERFUNC .SET 0
.mmregs
.def _OSTickISR
.def _OSStartHighRdy
.def _OSCtxSw
.def _OSIntCtxSw
.ref _OSIntExit; :FAR
.ref _OSTimeTick; :FAR
.ref _OSTaskSwHook; :FAR
.ref _OSIntNesting; :BYTE
.ref _OSTickDOSCtr; :BYTE
.ref _OSPrioHighRdy; :BYTE
.ref _OSPrioCur; :BYTE
.ref _OSRunning; :BYTE
.ref _OSTCBCur; :DWORD
.ref _OSTCBHighRdy; :DWORD
.if TICKISRFOROTHERFUNC
.ref _OSTickISRForOther
.ref _TickTimesForOther
.endif
.ref I$$SAVE
.ref I$$REST
;.MODEL LARGE
;.CODE
;.186
; PAGE ; /*$PAGE*/
;*********************************************************************************************************
; START MULTITASKING
; void OSStartHighRdy(void)
;
; The stack frame is assumed to look as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> DS (Low memory)
; ES
; DI
; SI
; BP
; SP
; BX
; DX
; CX
; AX
; OFFSET of task code address
; SEGMENT of task code address
; Flags to load in PSW
; OFFSET of task code address
; SEGMENT of task code address
; OFFSET of 'pdata'
; SEGMENT of 'pdata' (High memory)
;
; Note : OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;*********************************************************************************************************
.ref _OSTaskSwHook
_OSStartHighRdy:; PROC FAR
; MOV AX,SEG _OSTCBHighRdy; Reload DS
; MOV DS,AX;
;;
; CALL FAR PTR _OSTaskSwHook; Call user defined task switch hook
;;
; INC BYTE PTR DS:_OSRunning; Indicate that multitasking has started
;;
; LES BX,DWORD PTR DS:_OSTCBHighRdy ; SS:SP = OSTCBHighRdy->OSTCBStkPtr
; MOV SS,ES:[BX+2] ;
; MOV SP,ES:[BX+0] ;
;;
; POP DS; Load task's context
; POP ES;
; POPA;
;;
; IRET ; Run task
;ldpk _OSTCBHighRdy
call _OSTaskSwHook,ar1
ldpk _OSRunning
lac _OSRunning
addk 1
sacl _OSRunning
ldpk _OSTCBHighRdy
lar ar1,_OSTCBHighRdy
lar ar1,*
;mar *,ar1
b I$$REST
;_OSStartHighRdy ENDP
;
; PAGE ; /*$PAGE*/
;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From task level)
; void OSCtxSw(void)
;
; Note(s): 1) Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
; 2) The stack frame of the task to suspend looks as follows:
;
; SP -> OFFSET of task to suspend (Low memory)
; SEGMENT of task to suspend
; PSW of task to suspend (High memory)
;
; 3) The stack frame of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> DS (Low memory)
; ES
; DI
; SI
; BP
; SP
; BX
; DX
; CX
; AX
; OFFSET of task code address
; SEGMENT of task code address
; Flags to load in PSW (High memory)
;*********************************************************************************************************
_OSCtxSw:; PROC FAR
;;
; PUSHA ; Save current task's context
; PUSH ES ;
; PUSH DS ;
;;
; MOV AX, SEG _OSTCBCur ; Reload DS in case it was altered
; MOV DS, AX ;
;;
; LES BX, DWORD PTR DS:_OSTCBCur ; OSTCBCur->OSTCBStkPtr = SS:SP
; MOV ES:[BX+2], SS ;
; MOV ES:[BX+0], SP ;
;;
; CALL FAR PTR _OSTaskSwHook ; Call user defined task switch hook
;;
; MOV AX, WORD PTR DS:_OSTCBHighRdy+2 ; OSTCBCur = OSTCBHighRdy
; MOV DX, WORD PTR DS:_OSTCBHighRdy ;
; MOV WORD PTR DS:_OSTCBCur+2, AX ;
; MOV WORD PTR DS:_OSTCBCur, DX ;
;;
; MOV AL, BYTE PTR DS:_OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
; MOV BYTE PTR DS:_OSPrioCur, AL ;
;;
; LES BX, DWORD PTR DS:_OSTCBHighRdy ; SS:SP = OSTCBHighRdy->OSTCBStkPtr
; MOV SS, ES:[BX+2] ;
; MOV SP, ES:[BX] ;
;;
; POP DS ; Load new task's context
; POP ES ;
; POPA ;
;;
; IRET ; Return to new task
;
call I$$SAVE
ldpk _OSTCBCur
lar ar3,_OSTCBCur
mar *,ar3
sar ar1,*,ar1
call _OSTaskSwHook
ldpk _OSTCBHighRdy
lar ar1,_OSTCBHighRdy
;ldpk _OSTCBCur
sar ar1,_OSTCBCur
lacl _OSPrioHighRdy
sacl _OSPrioCur
lar ar1,*
b I$$REST,ar1
;_OSCtxSw ENDP
;
; PAGE ; /*$PAGE*/
;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From an ISR)
; void OSIntCtxSw(void)
;
; Note(s): 1) Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
; 2) The stack frame of the task to suspend looks as follows:
;
; SP+0 --> OFFSET of return address of OSIntCtxSw() (Low memory)
; +2 SEGMENT of return address of OSIntCtxSw()
; +4 PSW saved by OS_ENTER_CRITICAL() in OSIntExit()
; +6 OFFSET of return address of OSIntExit()
; +8 SEGMENT of return address of OSIntExit()
; +10 DS
; ES
; DI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -