📄 os_cpu_a.asm
字号:
STW .D2T1 A11,*+SP(_A11) ;
STW .D2T1 A12,*+SP(_A12) ;
STW .D2T1 A13,*+SP(_A13) ;
STW .D2T1 A14,*+SP(_A14) ;
STW .D2T1 A15,*+SP(_A15) ;
;-----------------------------------------------------------;
; Operating System Interrupt handler Context task switch ;
; Executing in always enabled interrupt mode
;-----------------------------------------------------------;
_OSIntCtxSw
;----------------------------------------;
; Get the address of the Task磗 TCB ;
; of the task that is going to execute ;
;----------------------------------------;
;----------------------------;
; Adjust the stack pointer for saving in the Current task磗 TCB;
;----------------------------;
LDW .D2T2 *+DP(_OSTCBCur),B0 ; B0 = OSTCBCur
|| mv SP,B1 ; b1 = SP
nop 4
b _OSStartHighRdy
|| addk .s2 (8),B1 ; save adjusted SP
STW .D2T2 B1,*B0 ; OSTCBCur->OSTCBStkPtr = SP ;
nop 4
;-----------------------------------------------------------;
; Operating System Context task switch ;
; Executing in always enabled interrupt mode
;-----------------------------------------------------------;
.align 32
_OSCtxSw_Fast
;
; TAKES 40 cycles to execute
; 240 nano sec
;
addk .s2 (4 -_Framesize),SP ; Push one Frame
STW .D2T2 B3,*+SP(_StartAddress) ; b3 start address
STW .D2T2 B3,*+SP(_B3) ; Save for cosmetical reasons
|| mvc AMR,B0
STW .D2T2 B0,*+SP(_AMR) ;
|| mvc CSR,B0
STW .D2T2 B0,*+SP(_CSR) ;
|| mvc IER,B0
STW .D2T2 B0,*+SP(_IER) ;
STW A3,*+SP(_A3) ;
LDW *+DP(_OSTCBCur),B0 ; B0 = OSTCBCur
;-------------------------------------------;
; Get the address of the TCB that is going ;
; to execute ;
;-------------------------------------------;
LDW .D2T2 *+DP(_OSTCBHighRdy),B4 ; B4 = OSTCBHighRdy
STW .D2T1 A10,*+SP(_A10) ;
STW .D2T1 A11,*+SP(_A11) ;
STW .D2T1 A12,*+SP(_A12) ;
STW .D2T1 A13,*+SP(_A13) ;
STW .D2T1 A14,*+SP(_A14) ;
STW .D2T1 A15,*+SP(_A15) ;
;-------------------------------;
; Set it as the current TCB ;
; OSTCBCur = OSTCBHighRdy
;-------------------------------;
STW .D2T2 B4,*+DP(_OSTCBCur)
STW SP,*B0 ; previous OSTCBCur->OSTCBStkPtr = SP ;
STW .D2T2 B10,*+SP(_B10) ;
|| MV SP,B10 ; B10 = SP
STW .D2T2 B11,*+SP(_B11) ;
|| addk (_IRP),B10 ; Correct SP for POP of TCB
;--------------------------------------------------;
; In the TCB is the task磗 stack pointer value ;
; Get it ;
;--------------------------------------------------;
; SP = OSTCBHighRdy->OSTCBStkPtr
LDW .D2T2 *B4,SP
STW B10,*+SP(_B15) ; Save correct SP
STW .D2T2 B12,*+SP(_B12) ;
STW .D2T2 B13,*+SP(_B13) ;
STW .D2T2 B14,*+SP(_B14) ;
; POP registers from new TCB
LDW .D2T2 *+SP(_StartAddress),B3 ; b3 start address
LDW .D2T1 *+SP(_A3),A3 ;
LDW .D2T1 *+SP(_A10),A10 ;
LDW .D2T1 *+SP(_A11),A11 ;
LDW .D2T1 *+SP(_A12),A12 ;
LDW .D2T1 *+SP(_A13),A13 ;
LDW .D2T1 *+SP(_A14),A14 ;
LDW .D2T1 *+SP(_A15),A15 ;
LDW .D2T2 *+SP(_B10),B10 ;
LDW .D2T2 *+SP(_B11),B11 ;
LDW .D2T2 *+SP(_B12),B12 ;
LDW .D2T2 *+SP(_B14),B14 ;
LDW .D2T2 *+SP(_B13),B13 ;
LDW .D2T2 *+SP(_B3),B3 ;
LDW .D2T2 *+SP(_B15),B15 ;
|| B .S2 b3 ;
nop 5
.align 32
;-----------------------------------------------------------;
; Operating System Context task switch ;
; Executing in always enabled interrupt mode
;-----------------------------------------------------------;
; OSCtxSw a little bit slower then _OSCtxSw_Fast but secure
; As it saves al registers
; Maybe Takes 200 nanosec more
;
; takes 90 cycles = 540 nanosec
; fast OSCtxSW takes 40 cycles = 240 nanosec
;
; 8000 swithes per second is thus 8000 * 300 nanosec
; = 2.4 milli seconds lost per second
_OSCtxSw
addk .s2 (4 -_Framesize),SP ; Push one Frame
STW .D2T2 B3,*+SP(_StartAddress) ; b3 start address
STW .D2T2 B0,*+SP(_B0) ;
|| mvc AMR,B0
STW .D2T2 B0,*+SP(_AMR) ;
|| mvc CSR,B0
STW .D2T2 B0,*+SP(_CSR) ;
|| mvc IER,B0
STW .D2T2 B0,*+SP(_IER) ;
STW .D2T1 A0,*+SP(_A0) ;
|| MV .L1X SP,A0 ; A0 = SP
STW .D2T1 A1,*+SP(_A1) ;
|| addk .s1 (_IRP),A0 ; Correct SP for POP of TCB
STW .D2T1 A0,*+SP(_B15) ; Save correct SP
STW .D2T1 A2,*+SP(_A2) ;
STW .D2T1 A3,*+SP(_A3) ;
STW .D2T1 A4,*+SP(_A4) ;
STW .D2T1 A5,*+SP(_A5) ;
STW .D2T1 A6,*+SP(_A6) ;
STW .D2T1 A7,*+SP(_A7) ;
STW .D2T1 A8,*+SP(_A8) ;
STW .D2T1 A9,*+SP(_A9) ;
STW .D2T1 A10,*+SP(_A10) ;
STW .D2T1 A11,*+SP(_A11) ;
STW .D2T1 A12,*+SP(_A12) ;
STW .D2T1 A13,*+SP(_A13) ;
STW .D2T1 A14,*+SP(_A14) ;
STW .D2T1 A15,*+SP(_A15) ;
LDW .D2T2 *+DP(_OSTCBCur),B0 ; B0 = OSTCBCur
STW .D2T2 B1,*+SP(_B1) ;
STW .D2T2 B2,*+SP(_B2) ;
STW .D2T2 B3,*+SP(_B3) ; Save for cosmetical reasons
STW .D2T2 B4,*+SP(_B4) ;
STW .D2T2 B5,*+SP(_B5) ;
STW .D2T2 B6,*+SP(_B6) ;
;----------------------------------------------------------------;
; Save the current task's stack pointer into the current task's ;
; OS TCB ;
;----------------------------------------------------------------;
STW SP,*B0 ; previous OSTCBCur->OSTCBStkPtr = SP ;
STW .D2T2 B7 ,*+SP(_B7 ) ;
STW .D2T2 B8 ,*+SP(_B8 ) ;
STW .D2T2 B9 ,*+SP(_B9 ) ;
STW .D2T2 B10,*+SP(_B10) ;
STW .D2T2 B11,*+SP(_B11) ;
STW .D2T2 B12,*+SP(_B12) ;
STW .D2T2 B13,*+SP(_B13) ;
STW .D2T2 B14,*+SP(_B14) ;
; STW .D2T2 B15,*+SP(_B15) ; already saved by first statement
;Pop NEW current task's context
*****************************************************************
* START MULTITASKING
* void OSStartHighRdy(void)
*****************************************************************
*****************************************************************
* PERFORM A CONTEXT SWITCH (From an ISR)
* void OSIntCtxSw(void)
* The current task磗 environment is already saved by c6201_save
* save the current stackpos in the TCB
*
*
*
*
*****************************************************************
_OSStartHighRdy
;---------------------------------------;
; Call User definable OSTaskSwHook(); ;
;---------------------------------------;
B .S1 _OSTaskSwHook
NOP 3
MVKL .S2 OSStartHighRdy_1,B3
MVKH .S2 OSStartHighRdy_1,B3
OSStartHighRdy_1
;-------------------------------------------;
; Get the address of the TCB that is going ;
; to execute ;
;-------------------------------------------;
LDW .D2T2 *+DP(_OSTCBHighRdy),B4 ; B4 = OSTCBHighRdy
LDB .D2T2 *+DP(_OSPrioHighRdy),B5 ; B5 = OSPrioHighRdy
nop 3
;-------------------------------;
; Set it as the current TCB ;
; OSTCBCur = OSTCBHighRdy
; OSPrioCur = OSPrioHighRdy
;-------------------------------;
STW .D2T2 B4,*+DP(_OSTCBCur)
STB .D2T2 B5,*+DP(_OSPrioCur)
|| mvk 1,b1
STB .D2T2 B1,*+DP(_OSRunning)
;--------------------------------------------------;
; In the TCB is the task磗 stack pointer value ;
; Get it ;
; Get the stack pointer of the task to resume
;--------------------------------------------------;
; StackPointer = OSTCBHighRdy->OSTCBStkPtr
LDW .D2T2 *B4,SP
nop 4
;Pop NEW current task's context
;-----------------------------------------------------------;
; Interrupt handlers restore after interrupt
; before going back into the interrupted environment
;-----------------------------------------------------------;
_c6201_Restor
;--------------------------------------;
; Restor executes in enabled mode ;
;--------------------------------------;
; ENABLED MODE
LDW .D2T2 *+SP(_StartAddress),B3 ; b3 start address
LDW .D2T2 *+SP(_AMR),B10 ; B10 = AMR
LDW .D2T2 *+SP(_CSR),B9 ; B9 = CSR
LDW .D2T2 *+SP(_IER),B8 ; B8 = IER
LDW .D2T1 *+SP(_A0),A0 ;
LDW .D2T1 *+SP(_A1),A1 ;
LDW .D2T1 *+SP(_A2),A2 ;
LDW .D2T1 *+SP(_A3),A3 ;
LDW .D2T1 *+SP(_A4),A4 ;
LDW .D2T1 *+SP(_A5),A5 ;
LDW .D2T1 *+SP(_A6),A6 ;
LDW .D2T1 *+SP(_A7),A7 ;
LDW .D2T1 *+SP(_A8),A8 ;
LDW .D2T1 *+SP(_A9),A9 ;
LDW .D2T1 *+SP(_A10),A10 ;
LDW .D2T1 *+SP(_A11),A11 ;
LDW .D2T1 *+SP(_A12),A12 ;
LDW .D2T1 *+SP(_A13),A13 ;
LDW .D2T1 *+SP(_A14),A14 ;
LDW .D2T1 *+SP(_A15),A15 ;
LDW .D2T2 *+SP(_B0),B0 ;
LDW .D2T2 *+SP(_B1),B1 ;
LDW .D2T2 *+SP(_B2),B2 ;
LDW .D2T2 *+SP(_B4),B4 ;
LDW .D2T2 *+SP(_B5),B5 ;
LDW .D2T2 *+SP(_B6),B6 ;
LDW .D2T2 *+SP(_B7 ),B7 ;
LDW .D2T2 *+SP(_B11),B11 ;
LDW .D2T2 *+SP(_B12),B12 ;
|| mvk 0,B13
LDW .D2T2 *+SP(_B14),B14 ;
|| mvc B13,IER
; DISABLED MODE NO INTERRUPTS ALLOWED
; DISABLED MODE NO INTERRUPTS ALLOWED
LDW .D2T2 *+SP(_B9 ),B9 ;
|| or 1,b9,b9 ; Set GIE
LDW .D2T2 *+SP(_B10),B10 ;
|| mvc B9,CSR ; set csr if IRP did not put a GIE
LDW .D2T2 *+SP(_B3),B3 ;
|| mvc B10,AMR ; Restore AMR
LDW .D2T2 *+SP(_B13),B13 ;
LDW .D2T2 *+SP(_B8 ),B8 ;
LDW .D2T2 *+SP(_B15),B15 ;
B .S2 b3 ;
mvc B8,IER ;
nop 5
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -