⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_cpu_a.asm

📁 If you port &micro C/OS-II to a processor not listed and want to include your port on this web site,
💻 ASM
字号:
--Company         :  NEC Elecronics GmbH
--Title           :  OS CPU ASSEMBLY MODULE
--Description     :  RTOS kernel (hardware-specific) functions
--File            :  OS_CPU_A.asm
--Type            :  Assembly Green Hills
--Library         :
--
--Author          :  Lorenzo Altieri  AltieriL@ee.nec.de
--Comments        :
--
--
--Revisions       :
--Version         : (Version) (dd/mm/yy) changes
--               x.xx    ddmmyy                  Create file
--               0.01                    09/03/2004
--
--********************************************************************
--
--       function:
--       description:    Trap 0x10 vector used for context switch
--
--       --- Modifies ----------------------------------------------
--                  IO :
--                  Mem:
--                  CPU:
--       --- Uses --------------------------------------------------
--                  IO :
--                  Mem:
--       --- Input -------------------------------------------------
--       --- Output ------------------------------------------------
--       --- Notes -------------------------------------------------
--
--               Right now, all TRAPs to $1x are trated the same way
--
--
--====================================================================


--********************************************************************
--
--       function:
--       description:    Timer M compare match interrupt used for system
--                   tick interrupt
--
--       --- Modifies ----------------------------------------------
--                  IO :
--                  Mem:
--                  CPU:
--       --- Uses --------------------------------------------------
--                  IO :
--                  Mem:
--       --- Input -------------------------------------------------
--       --- Output ------------------------------------------------
--       --- Notes -------------------------------------------------
--
--
--
--====================================================================
--.org 0x50
--     jr _OSCtxSW

.org 0x220
  jr _OSTickIntr
     -- in interrupt.c timerM

--====================================================================
--====================================================================
--====================================================================
--====================================================================
.section ".text"
--====================================================================
--====================================================================
--====================================================================
--====================================================================



.extern      _OSTaskSwHook
.extern      _OSTCBHighRdy
.extern      _OSPrioHighRdy
.extern      _OSTCBCur
.extern      _OSRunning
.extern      _OSPrioCur
.extern      _OSIntNesting
.extern      _OSTimeTick
.extern      _OSIntExit
.extern      _OSIntEnter


        .global _OSStartHighRdy, _OSCtxSW, _OSIntCtxSw, _OS_Restore_CPU_Context , _OSTickIntr , _OS_Save_CPU_Context



--********************************************************************
--
--       function:               OS_Restore_CPU_Context
--       description:    Restore all CPU registers from current stack pointer
--
--       --- Modifies ----------------------------------------------
--                  IO :
--                  Mem:
--                  CPU:
--
--       --- Uses --------------------------------------------------
--                  IO :
--                  Mem:
--       --- Input -------------------------------------------------
--       --- Output ------------------------------------------------
--       --- Notes -------------------------------------------------
--
--====================================================================
_OS_Restore_CPU_Context:

     --   mov sp, ep
        mov _OSTCBCur, r21
        ld.w  0[r21], r21
        ld.w  0[r21], sp

        ld.w 4[sp], r2
        ld.w 8[sp], r5
        ld.w 12[sp],r6
        ld.w 16[sp],r7
        ld.w 20[sp],r8
        ld.w 24[sp],r9
        ld.w 28[sp],r10
        ld.w 32[sp],r11
        ld.w 36[sp],r12
        ld.w 40[sp],r13
        ld.w 44[sp],r14
        ld.w 48[sp],r15
        ld.w 52[sp],r16
        ld.w 56[sp],r17
        ld.w 60[sp],r18
        ld.w 64[sp],r19
        ld.w 68[sp],r20
        ld.w 72[sp],r21
        ld.w 76[sp],r22
        ld.w 80[sp],r23
        ld.w 84[sp],r24
        ld.w 88[sp],r25
        ld.w 92[sp],r26
        ld.w 96[sp],r27
        ld.w 100[sp],r28
        ld.w 104[sp],r29
     --  sld.w 108[ep],r30
        ld.w 112[sp],r31
        --See what was the latest interruption (trap or interrupt)
        stsr ECR, r17           --Move ecr to r17
        mov 0x050,r1
        cmp r1, r17             --If latest break was due to TRAP, set EP

        be _SetEP



_ClrEP:
        mov 0x20, r17           --Set only ID
        ldsr r17, PSW

        --Restore caller address
        ld.w 116[sp], r1
        ldsr r1, EIPC
        --Restore PSW
        ld.w 120[sp], r1
        ldsr r1, EIPSW

        ld.w 0[sp], r1

        --ld.w 124[sp],r3       -- stack pointer


        addi 124, sp, sp

        mov _OSTCBCur, r21
        ld.w  0[r21], r21
        st.w  sp ,0[r21]



     --Return from interrupt starts new task!
        reti

_SetEP:
        mov 0x60, r17          --Set both EIPC and ID bits
        ldsr r17, PSW



        ld.w 116[sp], r1
        ldsr r1, EIPC          --Restore caller address

        ld.w 120[sp], r1
        ldsr r1, EIPSW         --Restore PSW

        ld.w 0[sp], r1


        --Return from interrupt starts new task!
        --ld.w 124[sp],r3      -- stack pointer

        addi 124, sp, sp

        mov _OSTCBCur, r21
        ld.w  0[r21], r21
        st.w  sp ,0[r21]

        reti


--********************************************************************
--
--       function:
--       description:
--
--       --- Modifies ----------------------------------------------
--                  IO :
--                  Mem:
--                  CPU:
--
--       --- Uses --------------------------------------------------
--                  IO :
--                  Mem:
--
--       --- Input -------------------------------------------------
--
--
--
--
--
--       --- Output ------------------------------------------------
--
--
--       --- Notes -------------------------------------------------
--
--====================================================================_
_OSStartHighRdy:
                --Call user-specific Task Switch Hook function
                jarl _OSTaskSwHook, lp

                --Load stack pointer of the task to run
                mov _OSTCBHighRdy, r1                    --Point to the pointer variable OSTCBHighRdy
                ld.w 0[r1], r1                                  --Read pointer to struct
                ld.w 0[r1], sp                                  --load sp from struct

                --Set OSRunning to TRUE =0x01
                mov _OSRunning, r1
		mov 0x01, r2
		st.b r2, 0[r1]

                --Restore all Processor registers from stack and return from interrupt
                jr _OS_Restore_CPU_Context




--********************************************************************
--       function:
--       description:
--       --- Modifies ----------------------------------------------
--                  IO :
--                  Mem:
--                  CPU:
--       --- Uses --------------------------------------------------
--                  IO :
--                  Mem:
--       --- Input -------------------------------------------------
--       --- Output ------------------------------------------------
--       --- Notes -------------------------------------------------
--====================================================================
_OSCtxSW:
      --  SAVE_CPU_CTX                    --Save all CPU registers
      --  jarl _OS_Save_CPU_Context, lp
        addi -124, sp, sp
        st.w r2,   4[sp]
        st.w r5,   8[sp]
        st.w r6,  12[sp]
        st.w r7,  16[sp]
        st.w r8,  20[sp]
        st.w r9,  24[sp]
        st.w r10, 28[sp]
        st.w r11, 32[sp]
        st.w r12, 36[sp]
        st.w r13, 40[sp]
        st.w r14, 44[sp]
        st.w r15, 48[sp]
        st.w r16, 52[sp]
        st.w r17, 56[sp]
        st.w r18, 60[sp]
        st.w r19, 64[sp]
        st.w r20, 68[sp]
        st.w r21, 72[ep]
        st.w r22, 76[sp]
        st.w r23, 80[sp]
        st.w r24, 84[sp]
        st.w r25, 88[sp]
        st.w r26, 92[sp]
        st.w r27, 96[sp]
        st.w r28, 100[sp]
        st.w r29, 104[sp]
        st.w r31, 112[sp]
  --Save caller's PC
        stsr EIPC, r1
        st.w r1,  116[sp]
  --Save caller's PSW
        stsr EIPSW, r1
        st.w r1, 120[sp]

        st.w r3, 124[sp]   -- stack pointer al posto di r3

  --SAVE_SP                         --Save SP to current task TCB
  --Save stack pointer on OSTCBCur->OSTCBStkPtr (OSTCBStkPtr=0)
        mov _OSTCBCur, r21
        ld.w 0[r21], r21
        st.w sp, 0[r21]

_OSIntCtxSw:

        --Call user-specific Task Switch Hook function
        jarl _OSTaskSwHook, lp

        --Set current TCB the same as the HIGH tcb
        mov _OSTCBHighRdy, r1                    --Get the address of the HIGH TCB pointer
        ld.w 0[r1], r5                           --Get the address the pointer is pointing to
        mov _OSTCBCur, r2                        --Now point to the OSTCBCur
        st.w r5, 0[r2]                           --and make it show at the same TCB.

        --Update current priority for new task
        mov _OSPrioHighRdy, r1                   --Copy High priority
	ld.bu 0[r1], r2
        mov _OSPrioCur, r1                       --to current task's priority
	st.b r2, 0[r1]

        --Load stack pointer of the task to run
        ld.w 0[r5], sp                           --Reget pointer to struct

        --Restore all Processor registers from stack and return from interrupt
        jr _OS_Restore_CPU_Context




--********************************************************************
--
--       function:
--       description:
--
--       --- Modifies ----------------------------------------------
--                  IO :
--                  Mem:
--                  CPU:
--       --- Uses --------------------------------------------------
--                  IO :
--                  Mem:
--       --- Input -------------------------------------------------
--       --- Output ------------------------------------------------
--       --- Notes -------------------------------------------------
--
--       Normally, interrupts will be disabled while we are in this handler
--
--
--====================================================================
_OSTickIntr:
        --ISR_ENTRY  -->   SAVE_CPU_CTX
        --Save all CPU registers according to the standard stack frame
--        jarl _OS_Save_CPU_Context, lp
        addi -124, sp, sp
        st.w r2,   4[sp]
        st.w r5,   8[sp]
        st.w r6,  12[sp]
        st.w r7,  16[sp]
        st.w r8,  20[sp]
        st.w r9,  24[sp]
        st.w r10, 28[sp]
        st.w r11, 32[sp]
        st.w r12, 36[sp]
        st.w r13, 40[sp]
        st.w r14, 44[sp]
        st.w r15, 48[sp]
        st.w r16, 52[sp]
        st.w r17, 56[sp]
        st.w r18, 60[sp]
        st.w r19, 64[sp]
        st.w r20, 68[sp]
        st.w r21, 72[ep]
        st.w r22, 76[sp]
        st.w r23, 80[sp]
        st.w r24, 84[sp]
        st.w r25, 88[sp]
        st.w r26, 92[sp]
        st.w r27, 96[sp]
        st.w r28, 100[sp]
        st.w r29, 104[sp]
        st.w r31, 112[sp]
  --Save caller's PC
        stsr EIPC, r1
        st.w r1,  116[sp]
  --Save caller's PSW
        stsr EIPSW, r1
        st.w r1, 120[sp]

        st.w r3, 124[sp]

        mov _OSTCBCur, r21
        ld.w 0[r21], r21
        st.w sp, 0[r21]


        jarl _OSTimeTick, lp
        jarl _OSIntExit, lp   --Call OSIntExit()

        jr _OS_Restore_CPU_Context  --Restore processors registers and execute RETI





_OS_Save_CPU_Context:

        mov  sp , r22
        addi -124, sp, sp
        st.w r2,   4[sp]
        st.w r5,   8[sp]
        st.w r6,  12[sp]
        st.w r7,  16[sp]
        st.w r8,  20[sp]
        st.w r9,  24[sp]
        st.w r10, 28[sp]
        st.w r11, 32[sp]
        st.w r12, 36[sp]
        st.w r13, 40[sp]
        st.w r14, 44[sp]
        st.w r15, 48[sp]
        st.w r16, 52[sp]
        st.w r17, 56[sp]
        st.w r18, 60[sp]
        st.w r19, 64[sp]
        st.w r20, 68[sp]
        st.w r21, 72[ep]
        st.w r22, 76[sp]
        st.w r23, 80[sp]
        st.w r24, 84[sp]
        st.w r25, 88[sp]
        st.w r26, 92[sp]
        st.w r27, 96[sp]
        st.w r28, 100[sp]
        st.w r29, 104[sp]
        st.w r31, 112[sp]
  --Save caller's PC
        stsr EIPC, r1
        st.w r1,  116[sp]
  --Save caller's PSW
        stsr EIPSW, r1
        st.w r1, 120[sp]

        st.w r22, 124[sp]   -- stack pointer al posto di r3

        jmp [lp]














⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -