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

📄 uc_zsp_s.s

📁 ucosii for zsp400
💻 S
📖 第 1 页 / 共 2 页
字号:
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MODULE HEADER !!!!!!!!!
   !
   !  PROCESS NAME:  KERNEL
   !
   !
   !  FILENAME:
   !
   !     UC_ZSP_S.S
   !
   !  DESCRIPTION
   !  -----------
   !
   !     Contains ASM-level routines for the uC/OS-II port to LSI Logic
   !     ZSP.
   !
   !
   !     NB #1: The first instruction of _OSIntCtxSw() must be correct to the
   !        optimization level used in the 'C' compiler.  Read Labrosse text
   !        and comments for further details.
   !
   !     NB #2: _UCOS_UART_ISR() is contained withing this file but there is
   !        no supporting code for it.  This is an in-house utility currently
   !        under development.  The ISR may be disabled by replacing the branch
   !        instruction in the vector table with the default "-0x800".
   !
   !
   !  REVISION HISTORY
   !  ----------------
   !
   !  DATE        NAME        REASON/CHANGE ID
   !  ----        ----        ----------------
   !  02/22/01    S.Wright    ORG
   !  05/10/01    S.Wright    moved ISR vectors to another file to resolve
   !                             multi-section issues with ASM/LINK
   !
   !
   !                                   Copyright LSI Logic, 2001
   !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !
   !  STDU Behavior:
   !
   !     stdu  r0, r12, -2
   !
   !              (higher memory)
   !
   !                           --------------
   !     R12 (initially)  --> | R1 -->       |
   !                           --------------
   !                          | R0 -->       |
   !                           --------------
   !     R12 (afterwards) --> | (unused)     |
   !                           --------------
   !
   !              (lower memory)
   !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !
   !  LDDU Behavior:
   !
   !     lddu  r0, r12, 2
   !
   !              (higher memory)
   !
   !                           --------------
   !     R12 (afterwards) --> | !! USED !!   |
   !                           --------------
   !                          | --> R1       |
   !                           --------------
   !     R12 (initially)  --> | --> R0       |
   !                           --------------
   !
   !              (lower memory)
   !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !
   !  Stack Frame AFTER Context Save:
   !
   !              (higher memory)
   !
   !                           --------------
   !  SP (before save) -->    |  R0          |
   !                           --------------
   !                          |  R1          |
   !                           --------------
   !                          |  R2          |
   !                           --------------
   !                          |  R3          |
   !                           --------------
   !                          |  %FMODE      |
   !                           --------------
   !                          |  %AMODE      |
   !                           --------------
   !                          |  %HWFLAG     |
   !                           --------------
   !                          |  R5          |
   !                           --------------
   !                          |  R4          |
   !                           --------------
   !                          |  %TPC        |
   !                           --------------
   !                          |  %RPC        |
   !                           --------------
   !                          |  %IMASK      |
   !                           --------------
   !                          |  %IP0        |
   !                           --------------
   !                          |  R15         |
   !                           --------------
   !                          |  R14         |
   !                           --------------
   !                          |  R13         |
   !                           --------------
   !                          |  R11         |
   !                           --------------
   !                          |  R10         |
   !                           --------------
   !                          |  R9          |
   !                           --------------
   !                          |  R8          |
   !                           --------------
   !                          |  R7          |
   !                           --------------
   !                          |  R6          |
   !                           --------------
   !                          |  %CB1_END    |
   !                           --------------
   !                          |  %CB0_END    |
   !                           --------------
   !                          |  %CB1_BEG    |
   !                           --------------
   !                          |  %CB0_BEG    |
   !                           --------------
   !                          |  %LOOP3      |
   !                           --------------
   !                          |  %LOOP2      |
   !                           --------------
   !                          |  %LOOP1      |
   !                           --------------
   !                          |  %LOOP0      |
   !                           --------------
   !                          |  %VITR       |
   !                           --------------
   !                          |  %GUARD      |
   !                           --------------
   !                          |  %SMODE      |
   !                           --------------
   !  SP (after save) -->     |  (unused)    |
   !                           --------------
   !
   !              (lower memory)
   !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!   .equ     PROFILER_SUPPORT, 1

   .equ     ALIGN_MAJOR,8
   .equ     ALIGN_MINOR,2

   !  the following two constants MUST match the identically named
   !     constants in UCOS_ZSP.H

   .equ     IMASK_SAVE_MASK,0xC000
   .equ     IP0_SAVE_MASK,0xF000

   .equ     SMODE_SAVE_MASK,0x000C

   !   exports...

   .global  _OSStartHighRdy
   .global  _OSIntCtxSw

   .global  _OSCtxSw
   .global  _OSTickISR

   !   imports...

   .global  _OSIntEnter
   .global  _OSIntExit
   .global  _OSTimeTick
   .global  _OSTCBCur
   .global  _OSTCBHighRdy
   .global  _OSRunning
   
.ifdef PROFILER_SUPPORT
   .global  _OSProfilerRunning
.endif

   .section ".isrs", "ax"

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !   START MULTITASKING
   !
   !   void OSStartHighRdy (void)
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   .walign ALIGN_MAJOR

_OSStartHighRdy:

   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
   !
   !  disable interrupts
   !
   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !

   bitc     %imask, 15

   ! set OSRunning to TRUE -- refer to OSStart() in OS_CORE.C

   lda      r0, _OSRunning
   mov      r1, 1
   st       r1, r0

   lda      r2, _OSTCBHighRdy
   ld       r0, r2
   ld       r12, r0

   mov      r4, r12                    ! make R4 a frame pointer to start the restore
   add      r4, 1                      ! adjust the FP -- STDU/LDDU not complimentary

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !!                            !!
   !!    MASSAGE %SMODE          !!
   !!                            !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   ldu      r2, r4, 1

   mov      r0, SMODE_SAVE_MASK        ! mask off bits[15..4, 1..0] of the saved SMODE
   and      r2, r0                     ! (r2 holds saved SMODE from stack)
   not      r5, r0                     ! invert (one's-comp) the mask
   mov      r0, %smode                 ! load the current SMODE...
   and      r0, r5                     ! ...and mask off bits[3..2]
   or       r2, r0                     ! OR the whole works together

   lddu     r0, r4, 2

   mov      %smode, r2
   mov      %guard, r0
   mov      %vitr, r1

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   lddu     r2, r4, 2
   lddu     r0, r4, 2
   mov      %loop0, r2
   mov      %loop1, r3
   mov      %loop2, r0
   mov      %loop3, r1

   lddu     r2, r4, 2
   lddu     r0, r4, 2
   mov      %cb0_beg, r2
   mov      %cb1_beg, r3
   mov      %cb0_end, r0
   mov      %cb1_end, r1

   lddu     r6, r4, 2
   lddu     r8, r4, 2
   lddu     r10, r4, 2
   ldu      r13, r4, 1
   lddu     r14, r4, 2

   mov      r12, r4                    ! restore the normal SP from the FP
                                       !  and we can now use R4 as a "utility" register
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !!                            !!
   !!    MASSAGE %IP0, %IMASK    !!
   !!                            !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   lddu     r0, r12, 2                 ! load the values from the stack

   mov      r4, IP0_SAVE_MASK          ! mask off bits[11..0] of the saved IP0
   and      r0, r4                     ! (r0 holds saved IP0 from stack)
   not      r5, r4                     ! invert (one's-comp) the mask
   mov      r2, %ip0                   ! load the current IP0...
   and      r2, r5                     ! ...and mask off bits[15..12]
   or       r0, r2                     ! OR the whole works together

   mov      r4, IMASK_SAVE_MASK        ! mask off bits[13..0] of the saved IMASK
   and      r1, r4                     ! (r1 holds saved IMASK from stack)
   not      r5, r4                     ! invert (one's-comp) the mask
   mov      r3, %imask                 ! load the current IMASK...
   and      r3, r5                     ! ...and mask off bits[15..14]
   or       r1, r3                     ! OR the whole works together

   bitc     r1, 15                     ! make sure we get thru the restore successfully

   mov      %ip0, r0
   mov      %imask, r1

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   lddu     r0, r12, 2
   mov      %rpc, r0
   mov      %tpc, r1

   lddu     r4, r12, 2
   lddu     r0, r12, 2
   ldu      r2, r12, 1

   add      r12, 3

   mov      %hwflag, r0                ! restore %HWFLAG, %AMODE, & %FMODE
   mov      %amode, r1
   mov      %fmode, r2

   ld       r3, r12, -3
   ld       r2, r12, -2
   ld       r1, r12, -1
   ld       r0, r12, 0

   reti


   .walign   ALIGN_MINOR

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !   PERFORM A CONTEXT SWITCH (From task level)
   !
   !   void OSCtxSw (void)
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

_OSCtxSw:

   bitc     %imask, 15                 ! disable interrupts

   st       r0, r12, 0                 ! save R0 & R1
   st       r1, r12, -1
   st       r2, r12, -2                ! save R2 & R3
   st       r3, r12, -3

   mov      r2, %fmode                 ! save %FMODE, %AMODE, & %HWFLAG
   mov      r1, %amode
   mov      r0, %hwflag

   mov      %fmode, 0                  ! shut off all of %FMODE's oddities
   bitc     %amode, 0                  ! shut off bit reversal
   bitc     %amode, 1

   add      r12, -4                    ! move the SP to below what we saved

   stu      r2, r12, -1                ! save %FMODE
   stdu     r0, r12, -2                ! save %AMODE and %HWFLAG
   stdu     r4, r12, -2                ! save R4 & R5 -- we'll use R4 for a
                                       !  frame pointer later

   mov      r1, %tpc                   ! save %TPC & %RPC
   mov      r0, %rpc
   mov      r3, %imask                 ! save %IMASK & %IP0
   mov      r2, %ip0
   stdu     r0, r12, -2
   stdu     r2, r12, -2

   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
   !
   !  Now we can re-enable interrupts
   !
   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !

   bits     %imask, 15

   stdu     r14, r12, -2
   stu      r13, r12, -1
   stdu     r10, r12, -2
   stdu     r8, r12, -2
   stdu     r6, r12, -2

   mov      r1, %cb1_end
   mov      r0, %cb0_end
   mov      r3, %cb1_beg
   mov      r2, %cb0_beg
   stdu     r0, r12, -2
   stdu     r2, r12, -2

   mov      r1, %loop3
   mov      r0, %loop2
   mov      r3, %loop1
   mov      r2, %loop0
   stdu     r0, r12, -2
   stdu     r2, r12, -2

   mov      r1, %vitr
   mov      r0, %guard
   mov      r2, %smode
   stdu     r0, r12, -2
   stu      r2, r12, -1

   lda      r1, _OSTCBCur              ! OSTCBCur->OSTCBStkPtr = SP
   ld       r0, r1                     ! (save stack ptr in TCB)
   st       r12, r0

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !
   !  Profiler stuff
   !

.ifdef PROFILER_SUPPORT

   ! has the profiler been activated ??
   
   lda      r2, _OSProfilerRunning
   ld       r4, r2
   add      r4, 0                      ! if _OSProfilerRunning == 0, skip...
   bz       NoUpperIncrement_OSCtxSw

   mov      r4, r0                     ! get the OSTCBCur pointer into R4

   !  increment OSTCBCtxSwitchCounter

   add      r4, 3                      ! increment R4 to point to LSB of OSTCBCur->OSTCBCtxSwitchCounter

   ld       r2, r4                     ! load the LSB of current value of OSTCBCtxSwitchCounter
   add      r2, 1
   st       r2, r4

   bnc      NoUpperIncrement_OSCtxSw

   add      r4, 1                      ! increment R4 to point to MSB of OSTCBCur->OSTCBCtxSwitchCounter

   ld       r2, r4                     ! load the MSB of current value of OSTCBCtxSwitchCounter
   add      r2, 1
   st       r2, r4

NoUpperIncrement_OSCtxSw:

.endif

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   lda      r2, _OSTCBHighRdy          ! OSTCBCur = OSTCBHighRdy
   ld       r0, r2
   st       r0, r1                     ! (R1 still holds _OSTCBCur pointer)
   ld       r12, r0                    ! SP = OSTCBCur->OSTCBStkPtr

   lda      r1, _OSPrioHighRdy         ! OSPrioCur = OSPrioHighRdy
   ld       r0, r1
   lda      r1, _OSPrioCur
   st       r0, r1

   mov      r4, r12                    ! make R4 a frame pointer to start the restore
   add      r4, 1                      ! adjust the FP -- STDU/LDDU not complimentary

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !!                            !!
   !!    MASSAGE %SMODE          !!
   !!                            !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   ldu      r2, r4, 1

   mov      r0, SMODE_SAVE_MASK        ! mask off bits[15..4, 1..0] of the saved SMODE
   and      r2, r0                     ! (r2 holds saved SMODE from stack)
   not      r5, r0                     ! invert (one's-comp) the mask
   mov      r0, %smode                 ! load the current SMODE...
   and      r0, r5                     ! ...and mask off bits[3..2]
   or       r2, r0                     ! OR the whole works together

   lddu     r0, r4, 2

   mov      %smode, r2
   mov      %guard, r0
   mov      %vitr, r1

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   lddu     r2, r4, 2
   lddu     r0, r4, 2
   mov      %loop0, r2
   mov      %loop1, r3
   mov      %loop2, r0
   mov      %loop3, r1

   lddu     r2, r4, 2
   lddu     r0, r4, 2
   mov      %cb0_beg, r2
   mov      %cb1_beg, r3
   mov      %cb0_end, r0
   mov      %cb1_end, r1

⌨️ 快捷键说明

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