tct.s
来自「nuclues plus 源代码程序」· S 代码 · 共 1,126 行 · 第 1/5 页
S
1,126 行
;/* D. Lamie 06-01-1993 Verified version 1.0 */
;/* */
;/*************************************************************************/
;VOID TCT_Control_To_Thread(TC_TCB *thread)
;{
.public _TCT_Control_To_Thread
_TCT_Control_To_Thread:
; Note: Thread to transfer control
; to is pointed to by D
;
; /* Setup the current thread pointer. */
; TCD_Current_Thread = (VOID *) thread;
;
std _TCD_Current_Thread ; Setup current thread pointer
;
; /* Increment the thread scheduled counter. */
; thread -> tc_scheduled++;
;
xgdx ; Move the thread pointer into X
ldd 24,x ; Increment the scheduled count,
addd #1 ; it is a 32-bit value so both
std 24,x ; halves must be manipulated
bcc _TCT_Count_Inc_Done ;
inc 23,x ;
bne _TCT_Count_Inc_Done ;
inc 22,x ;
_TCT_Count_Inc_Done:
;
; /* Check for time slice option. */
; if (thread -> tc_cur_time_slice)
; {
ldd 26,x ; Pickup the time slice value
bne _TCT_Start_TS ; If non-zero, start time slice
ldd 28,x ;
beq _TCT_No_Start_TS ;
_TCT_Start_TS:
;
; /* Start a time slice. */
; TMD_Time_Slice = thread -> tc_cur_time_slice;
; TMD_Time_Slice_State = 0;
;
ldd 28,x ; Pickup the time slice value and
std _TMD_Time_Slice+2 ; place it in the appropriate
ldd 26,x ; system variable
std _TMD_Time_Slice ;
;
; TMD_Time_Slice_State = 0;
clra ; Build state 0 (ACTIVE)
clrb ;
std _TMD_Time_Slice_State ; Setup state flag
; }
_TCT_No_Start_TS:
;
; /* Pickup the stack pointer and resume the thread. */
; REG_Stack_Ptr = thread -> tc_stack_pointer;
ldy 34,x ; Pickup stack pointer
tys ; Switch to thread's stack
;
; /* Pop off the saved information associated with the thread. After we
; determine which type of stack is present. A 1 on the top of the
; stack indicates an interrupt stack, while a 0 on the top of the
; stack indicates a solicited type of stack. */
;
pula ; Pickup the stack type
tsta ; Compare with 0
bne _TCT_Interrupt_Stack ; If non-zero, interrupt stack is
; present
; /* Otherwise, a solicited stack is present, recover IX and return to
; the caller. */
;
tst _TCD_Interrupt_Level+1 ; Determine if interrupts need to
; be enabled
bne _TCT_No_Enable_1 ; If non-zero, leave interrupts
; disabled
cli ; Otherwise, enable interrupts
_TCT_No_Enable_1:
pulx ; Recover IX
rts ; Return to caller
;
_TCT_Interrupt_Stack:
;
; /* An interrupt stack is present. Return to the point of interrupt.
; Note: the hardware recovers the registers. */
;
tsx ; Move stack pointer into IX
ldaa 0,x ; Pickup the CCR register
anda #7FH ; Clear enable bit
tst _TCD_Interrupt_Level+1 ; Determine if interrupts should
; be enabled
beq _TCT_Leave_Enabled ; If zero, leave interrupts enabled
oraa #10H ; Set the disable interrupt bit
_TCT_Leave_Enabled:
staa 0,x ; Put the CCR back on the stack
rti
;}
;
;
;
;/*************************************************************************/
;/* */
;/* FUNCTION */
;/* */
;/* TCT_Control_To_System */
;/* */
;/* DESCRIPTION */
;/* */
;/* This function returns control from a thread to the system. Note */
;/* that this service is called in a solicited manner, i.e. it is */
;/* not called from an interrupt thread. Registers required by the */
;/* compiler to be preserved across function boundaries are saved by */
;/* this routine. Note that this is usually a sub-set of the total */
;/* number of available registers. */
;/* */
;/* AUTHOR */
;/* */
;/* William E. Lamie, Accelerated Technology, Inc. */
;/* */
;/* CALLED BY */
;/* */
;/* Other Components */
;/* */
;/* CALLS */
;/* */
;/* TCT_Schedule Schedule the next thread */
;/* */
;/* INPUTS */
;/* */
;/* None */
;/* */
;/* OUTPUTS */
;/* */
;/* None */
;/* */
;/* HISTORY */
;/* */
;/* NAME DATE REMARKS */
;/* */
;/* W. Lamie 06-01-1993 Created initial version 1.0 */
;/* D. Lamie 06-01-1993 Verified version 1.0 */
;/* K. Homer 03-01-1994 Corrected problem in time-slice */
;/* reset logic, resulting in */
;/* version 1.1 */
;/* D. Lamie 03-18-1994 Verified version 1.1 */
;/* */
;/*************************************************************************/
;VOID TCT_Control_To_System(VOID)
;{
.public _TCT_Control_To_System
_TCT_Control_To_System:
;
; /* Lockout interrupts. */
;
sei ; Lockout interrupts
;
; /* Save a minimal context of the thread. */
;
pshx ; Save IX on the stack
clra ; Build solicited stack type
psha ; Save stack type on the stack
;
; /* Setup a pointer to the thread control block. */
; REG_Thread_Ptr = (TC_TCB *) TCD_Current_Thread;
ldd _TCD_Current_Thread ; Pickup TCB pointer
xgdx ; Place TCB pointer into IX
;
; /* Clear the current thread control block pointer. */
; TCD_Current_Thread = NU_NULL;
;
clra ; Build NULL value
clrb ;
std _TCD_Current_Thread ; Clear the current thread pointer
;
; /* Check to see if a time slice is active. If so, copy the original time
; slice into the current time slice field of the task's control block. */
; if (TMD_Time_Slice_State == 0)
; {
ldd _TMD_Time_Slice_State ; Determine if time slice active
bne _TCT_No_TS_Stop ; No, don't stop time slice
;
; /* Insure that the next time the task runs it gets a fresh time
; slice. */
; REG_Thread_Ptr -> tc_cur_time_slice = REG_Thread_Ptr -> tc_time_slice;
;
ldd 48,x ; Reset the time slice associated
std 26,x ; with this task (only task
ldd 50,x ; threads have time slices)
std 28,x ;
;
; /* Clear any active time slice by setting the state to NOT_ACTIVE. */
; TMD_Time_Slice_State = 1;
ldd #1 ; Build the NOT_ACTIVE value
std _TMD_Time_Slice_State ; Setup the state flag
; }
_TCT_No_TS_Stop:
;
; /* Save off the current stack pointer in the control block. */
; REG_Thread_Ptr -> tc_stack_pointer = (VOID *) REG_Stack_Ptr;
;
tsy ; Pickup the current sp
sty 34,x ; Save in TCB
;
; /* Clear the task's current protection. */
; (REG_Thread_Ptr -> tc_current_protect) -> tc_tcb_pointer = NU_NULL;
;
clra ; Build NULL value
clrb ;
ldy 44,x ; Point at protect structure with y
std 0,y ; Clear protect pointer
; REG_Thread_Ptr -> tc_current_protect = NU_NULL;
;
std 44,x ; Clear protect pointer
;
; /* Switch to the system stack. */
; REG_Stack_Ptr = TCD_System_Stack;
ldx _TCD_System_Stack ; Pickup system stack pointer
txs ; Modify actual sp
;
; /* Finished, return to the scheduling loop. */
;
jmp _TCT_Schedule ; Resume scheduling loop
;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?