📄 os_cpu_a.asm
字号:
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 1999, Jean J. Labrosse, Weston, FL
; All Rights Reserved
;
;
; H8/300H Specific code
; (ADVANCED mode)
;
; File : OS_CPU_A.ASM
; By : Bill Knight (GNU/ADVANCED port)
; Jean J. Labrosse
; Dr. Odd Arild Olsen (original uC/OS port)
; Port Version : V1.00
;********************************************************************************************************
.h8300h ; Recognize additional instructions
;********************************************************************************************************
; Cross references
;********************************************************************************************************
;
.global _OSStartHighRdy ; Public functions
.global _OSCtxSw
.global _OSIntCtxSw
.global _OSTickISR
.extern _OSIntEnter ; External functions
.extern _OSIntExit
.extern _OSTimeTick
.extern _OSTaskSwHook
.extern _OSTCBCur ; External variables (uC/OS-II)
.extern _OSTCBHighRdy
.extern _OSPrioCur
.extern _OSPrioHighRdy
.extern _OSIntNesting
.extern _OSRunning
;********************************************************************************************************
; MACROS
;
; Note(s): 1) Save 32-bit registers in case they were used in the application code.
;********************************************************************************************************
;
.macro PUSHALL
PUSH er6
PUSH er5
PUSH er4
PUSH er3
PUSH er2
PUSH er1
PUSH er0
.endm
.macro POPALL
POP er0
POP er1
POP er2
POP er3
POP er4
POP er5
POP er6
.endm
;/*$PAGE*/
;*********************************************************************************************************
; START MULTITASKING
;
; Description : This function is called by OSStart() to start the highest priority task that was created
; by your application before calling OSStart().
;
; Arguments : none
;
; Note(s) : 1) The stack frame is assumed to look as follows:
;
; LOW MEMORY
; OSTCBHighRdy->OSTCBStkPtr + 0 ----> er0 (H) (Upper 8-bits of 'pdata')
; + 2 er0 (L) (Lower 16-bits of 'pdata')
; + 4 er1 (H)
; + 6 er1 (L)
; + 8 er2 (H)
; + 10 er2 (L)
; + 12 er3 (H)
; + 14 er3 (L)
; + 16 er4 (H)
; + 18 er4 (L)
; + 20 er5 (H)
; + 22 er5 (L)
; + 24 er6 (H)
; + 26 er6 (L)
; + 28 task (H) (CCR & Upper 8-bits of PC)
; + 30 task (L) (Lower 16-bits of PC)
; + 32 task (H) (Upper 8-bits of PC)
; + 34 task (L) (Lower 16-bits of PC)
; + 36 pdata (H) (Upper 8-bits of PC)
; + 38 pdata (L) (Lower 16-bits of PC)
; HIGH MEMORY
;
; 2) OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;*********************************************************************************************************
.section .text
_OSStartHighRdy:
JSR @_OSTaskSwHook ; Execute task switch hook
;
MOV.B #1,r6l ; Set OSRunning to TRUE
MOV.B r6l,@_OSRunning
;
MOV.L @_OSTCBHighRdy,er0 ; SP = OSTCBHighRdy->OSTCBStkPtr
MOV.L er0,@_OSTCBCur
MOV.L @er0,sp
;
POPALL ; Restore task registers
;
RTE
;/*$PAGE*/
;*********************************************************************************************************
; TASK LEVEL CONTEXT SWITCH
;
; Description : This function is called when a task makes a higher priority task ready-to-run.
;
; Arguments : none
;
; 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. This was caused by the
; execution of a TRAPA #0 instruction (the registers for the task to suspend need to be
; saved):
;
; LOW MEMORY
; SP + 0 ----> task (CCR & Upper 8-bits of PC)
; + 2 task (Lower 16-bits of PC)
; HIGH MEMORY
;
; 3) The stack frame of the task to resume looks as follows:
;
; LOW MEMORY
; OSTCBHighRdy->OSTCBStkPtr + 0 ----> er0 (H)
; + 2 er0 (L)
; + 4 er1 (H)
; + 6 er1 (L)
; + 8 er2 (H)
; + 10 er2 (L)
; + 12 er3 (H)
; + 14 er3 (L)
; + 16 er4 (H)
; + 18 er4 (L)
; + 20 er5 (H)
; + 22 er5 (L)
; + 24 er6 (H)
; + 26 er6 (L)
; + 28 task (CCR & Upper 8-bits of PC)
; + 30 task (Lower 16-bits of PC)
; HIGH MEMORY
;*********************************************************************************************************
_OSCtxSw:
PUSHALL ; Save processor registers er0 to er6 (not saved by TRAPA)
;
MOV.L @_OSTCBCur,er6 ; Save current task's SP into its TCB
MOV.L sp,@er6
;
JSR @_OSTaskSwHook ; Execute task switch hook
;
MOV.B @_OSPrioHighRdy,r1l ; OSPrioCur = OSPrioHighRdy
MOV.B r1l,@_OSPrioCur
;
MOV.L @_OSTCBHighRdy,er6 ; Get new task's SP from its TCB
MOV.L er6,@_OSTCBCur ; OSTCBCur = OSTCBHighRdy
MOV.L @er6,sp
;
POPALL ; Restore processor registers er0 to er6
;
RTE ; Return to task
;/*$PAGE*/
;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From an ISR)
;
; Description : This function is called when an ISR makes a higher priority task ready-to-run.
;
; Arguments : none
;
; 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.
;
; LOW MEMORY
; +------ SP + 0 Rtn addr of OSIntCtxSw() (Upper 8-bits of PC)
; | + 2 Rtn addr of OSIntCtxSw() (Lower 16-bits of PC)
; | + 4 OS_ENTER_CRITICAL using OS_CRTITCAL_METHOD #2
; + 14 | + 6 er6 Stack Frame Pointer (Upper 8-bits)
; | + 8 er6 Stack Frame Pointer (Lower 16-bits)
; | + 10 Rtn addr of OSIntExit() (Upper 8-bits of PC)
; | + 12 Rtn addr of OSIntExit() (Lower 16-bits of PC)
; +-----> + 14 er0 (H) Low Memory
; + 16 er0 (L)
; + 18 er1 (H)
; + 20 er1 (L)
; + 22 er2 (H)
; + 24 er2 (L)
; + 26 er3 (H)
; + 28 er3 (L)
; + 30 er4 (H)
; + 32 er4 (L)
; + 34 er5 (H)
; + 36 er5 (L)
; + 38 er6 (H)
; + 40 er6 (L)
; + 42 task (CCR & Upper 8-bits of PC)
; + 44 task (Lower 16-bits of PC)
; HIGH MEMORY
;
; 3) The stack frame of the task to resume looks as follows:
;
; LOW MEMORY
; OSTCBHighRdy->OSTCBStkPtr + 0 ----> er0 (H)
; + 2 er0 (L)
; + 4 er1 (H)
; + 6 er1 (L)
; + 8 er2 (H)
; + 10 er2 (L)
; + 12 er3 (H)
; + 14 er3 (L)
; + 16 er4 (H)
; + 18 er4 (L)
; + 20 er5 (H)
; + 22 er5 (L)
; + 24 er6 (H)
; + 26 er6 (L)
; + 28 task (CCR & Upper 8-bits of PC)
; + 30 task (Lower 16-bits of PC)
; HIGH MEMORY
;*********************************************************************************************************
_OSIntCtxSw:
ADD.L #14,sp ; Adjust stack pointer to remove return address of OSIntExit() ..
; ; ... and OSIntCtxSw().
;
MOV.L @_OSTCBCur,er6 ; Save current task's SP into its TCB
MOV.L sp,@er6
;
JSR @_OSTaskSwHook ; Execute task switch hook
;
MOV.B @_OSPrioHighRdy,r1l ; OSPrioCur = OSPrioHighRdy
MOV.B r1l,@_OSPrioCur
;
MOV.L @_OSTCBHighRdy,er6 ; Get new task's SP from its TCB
MOV.L er6,@_OSTCBCur ; OSTCBCur = OSTCBHighRdy
MOV.L @er6,sp
;
POPALL
;
RTE
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -