tct.s
来自「nuclues plus 源代码程序」· S 代码 · 共 1,126 行 · 第 1/5 页
S
1,126 行
;/* ERC_System_Error System error handler */
;/* */
;/* INPUTS */
;/* */
;/* None */
;/* */
;/* OUTPUTS */
;/* */
;/* available bytes in stack */
;/* */
;/* HISTORY */
;/* */
;/* NAME DATE REMARKS */
;/* */
;/* W. Lamie 06-01-1993 Created initial version 1.0 */
;/* D. Lamie 06-01-1993 Verified version 1.0 */
;/* */
;/*************************************************************************/
;UNSIGNED TCT_Check_Stack(void)
;{
.public _TCT_Check_Stack
_TCT_Check_Stack:
;
pshx ; Save IX on the stack
;
;TC_TCB *thread;
;UNSIGNED remaining;
;
; /* Pickup the current task/HISR pointer. */
; thread = (TC_TCB *) TCD_Current_Thread;
;
ldd _TCD_Current_Thread ; Pickup the thread pointer
;
; /* Determine if there is a current thread. */
; if (thread)
; {
jbeq _TCT_Check_Stack_Done ; If NULL, stack checking is done
;
; /* Determine if the stack pointers are out of range. */
; if ((SP -> tc_stack_start) ||
; (SP > thread -> tc_stack_end))
;
xgdx ; Move the thread pointer into IX
tsy ; Pickup the current sp
xgdy ; Move sp into D for comparisons
cpd 30,x ; Compare with start of stack area
blo _TCT_Stack_Out_Of_Range ; If below start, sp out of range
cpd 32,x ; Compare with end of stack area
bls _TCT_Stack_Within_Range ; If after end, sp out of range
_TCT_Stack_Out_Of_Range:
;
; /* Stack overflow condition exits. */
; ERC_System_Error(NU_STACK_OVERFLOW);
ldd #3 ; NU_STACK_OVERFLOW value
jsr _ERC_System_Error ; Call system error handler
_TCT_Stack_Within_Range:
;
; /* Calculate the amount of available space on the stack. */
; remaining = (BYTE_PTR) thread -> tc_stack_pointer -
; (BYTE_PTR) thread -> tc_stack_start;
;
subd 30,x ; Subtract start address of the
; stack to get remaining size
;
; /* Determine if there is enough memory on the stack to save all of the
; registers. */
; if (remaining < 10)
;
cpd #10 ; Compare with minimum stack size
bge _TCT_Enough_Room ; If more than minimum size, there
; is still enough room on stack
;
; /* Stack overflow condition is about to happen. */
; ERC_System_Error(NU_STACK_OVERFLOW);
;
ldd #3 ; NU_STACK_OVERFLOW
jsr _ERC_System_Error ; Call system error handler
_TCT_Enough_Room:
;
; /* Determine if this is a new minimum amount of stack space. */
; if (remaining < thread -> tc_stack_minimum)
;
cpd 42,x ; Compare with current stack min
bge _TCT_Not_New_Minimum ; If remaining is not a new minimum
; skip new minimum processing
;
; /* Save the new stack minimum. */
; thread -> tc_stack_minimum = remaining;
;
std 42,x ; Save new minimum
; }
_TCT_Not_New_Minimum:
; else
;
; /* Set the remaining bytes to 0. */
; remaining = 0;
;
; /* Return the remaining number of bytes on the stack. */
; return(remaining);
;
_TCT_Check_Stack_Done:
ldy #0 ; Clear upper part of return value
pulx ; Recover IX from stack
rts ; Return to caller
;}
;
;
;
;/*************************************************************************/
;/* */
;/* FUNCTION */
;/* */
;/* TCC_Schedule */
;/* */
;/* DESCRIPTION */
;/* */
;/* This function waits for a thread to become ready. Once a thread */
;/* is ready, this function initiates a transfer of control to that */
;/* thread. */
;/* */
;/* AUTHOR */
;/* */
;/* William E. Lamie, Accelerated Technology, Inc. */
;/* */
;/* CALLED BY */
;/* */
;/* INC_Initialize Main initialization routine */
;/* */
;/* CALLS */
;/* */
;/* TCT_Control_To_Thread Transfer control to a thread */
;/* */
;/* INPUTS */
;/* */
;/* TCD_Execute_Task Pointer to task to execute */
;/* */
;/* 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 */
;/* */
;/*************************************************************************/
;VOID TCT_Schedule(void)
;{
.public _TCT_Schedule
_TCT_Schedule:
;
; /* Restore interrupts according to the value contained in
; TCD_Interrupt_Level. */
;
tst _TCD_Interrupt_Level+1 ; Determine if interrupts need to
; be enabled
bne _TCT_Schedule_Loop ; If non-zero, leave interrupts
; disabled
cli ; Otherwise, enable interrupts
;
; /* Wait until a thread (task or HISR) is available to execute. */
; do
; {
_TCT_Schedule_Loop:
;
; } while ((!TCD_Execute_HISR) && (!TCD_Execute_Task));
;
ldd _TCD_Execute_HISR ; Pickup the HISR pointer
bne _TCT_Schedule_It ; If non-NULL, an HISR is ready
ldd _TCD_Execute_Task ; Pickup the Task pointer
beq _TCT_Schedule_Loop ; If NULL, keep checking
;
;
; /* Yes, either a task or an HISR is ready to execute. Lockout
; interrupts while the thread is transferred to. */
_TCT_Schedule_It:
;
; /* Transfer control to the thread by falling through to the following
; routine. */
sei ; Disable interrupts
;}
;
;
;
;/*************************************************************************/
;/* */
;/* FUNCTION */
;/* */
;/* TCT_Control_To_Thread */
;/* */
;/* DESCRIPTION */
;/* */
;/* This function transfers control to the specified thread. Each */
;/* time control is transferred to a thread, its scheduled counter */
;/* is incremented. Additionally, time-slicing for task threads is */
;/* enabled in this routine. The TCD_Current_Thread pointer is */
;/* setup by this function. */
;/* */
;/* AUTHOR */
;/* */
;/* William E. Lamie, Accelerated Technology, Inc. */
;/* */
;/* CALLED BY */
;/* */
;/* TCT_Schedule Indirectly called */
;/* TCT_Protect Protection task switch */
;/* */
;/* CALLS */
;/* */
;/* None */
;/* */
;/* INPUTS */
;/* */
;/* thread Thread control block pointer */
;/* */
;/* OUTPUTS */
;/* */
;/* None */
;/* */
;/* HISTORY */
;/* */
;/* NAME DATE REMARKS */
;/* */
;/* W. Lamie 06-01-1993 Created initial version 1.0 */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?