board_cstartup_keil.s
上传用户:xukun0987
上传日期:2022-07-16
资源大小:216k
文件大小:7k
源码类别:

微处理器开发

开发平台:

C/C++

  1. ; * ----------------------------------------------------------------------------
  2. ; *         ATMEL Microcontroller Software Support 
  3. ; * ----------------------------------------------------------------------------
  4. ; * Copyright (c) 2008, Atmel Corporation
  5. ; *
  6. ; * All rights reserved.
  7. ; *
  8. ; * Redistribution and use in source and binary forms, with or without
  9. ; * modification, are permitted provided that the following conditions are met:
  10. ; *
  11. ; * - Redistributions of source code must retain the above copyright notice,
  12. ; * this list of conditions and the disclaimer below.
  13. ; *
  14. ; * Atmel's name may not be used to endorse or promote products derived from
  15. ; * this software without specific prior written permission.
  16. ; *
  17. ; * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
  18. ; * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. ; * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  20. ; * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. ; * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. ; * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  23. ; * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24. ; * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  25. ; * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  26. ; * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. ; * ----------------------------------------------------------------------------
  28. ;     KEIL startup file for AT91SAM7X microcontrollers.
  29. ; ------------------------------------------------------------------------------
  30. ;          Definitions
  31. ; ------------------------------------------------------------------------------
  32. ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  33. ARM_MODE_USR        EQU     0x10
  34. ARM_MODE_FIQ        EQU     0x11
  35. ARM_MODE_IRQ        EQU     0x12
  36. ARM_MODE_SVC        EQU     0x13
  37. ARM_MODE_ABT        EQU     0x17
  38. ARM_MODE_UND        EQU     0x1B
  39. ARM_MODE_SYS        EQU     0x1F
  40. I_BIT               EQU     0x80            ; when I bit is set, IRQ is disabled
  41. F_BIT               EQU     0x40            ; when F bit is set, FIQ is disabled
  42. AT91C_BASE_AIC      EQU     0xFFFFF000
  43. AIC_IVR             EQU     0x100
  44. AIC_EOICR           EQU     0x130
  45. UND_Stack_Size      EQU     0x00000000
  46. SVC_Stack_Size      EQU     0x00000100
  47. ABT_Stack_Size      EQU     0x00000000
  48. FIQ_Stack_Size      EQU     0x00000000
  49. IRQ_Stack_Size      EQU     0x00000080
  50. USR_Stack_Size      EQU     0x00000400
  51.         PRESERVE8
  52. ; Area Definition and Entry Point
  53. ; Startup Code must be linked first at Address at which it expects to run.
  54.         AREA    VECTOR, CODE
  55.         ARM
  56. ; Exception Vectors
  57. Vectors         
  58. LDR     pc,=resetHandler 
  59. undefVector  
  60.     b    undefVector             ; Undefined instruction
  61. swiVector
  62.          b       swiVector               ; Software interrupt
  63. prefetchAbortVector
  64.          b       prefetchAbortVector     ; Prefetch abort
  65. dataAbortVector
  66.          b       dataAbortVector         ; Data abort
  67. reservedVector
  68.          b       reservedVector          ; Reserved for future use
  69. irqVector
  70.         b       irqHandler              ; Interrupt
  71. fiqVector
  72.                                         ; Fast interrupt
  73. ;------------------------------------------------------------------------------
  74. ; Handles a fast interrupt request by branching to the address defined in the
  75. ; AIC.
  76. ;------------------------------------------------------------------------------
  77. fiqHandler
  78.         b       fiqHandler
  79. ;------------------------------------------------------------------------------
  80. ; Handles incoming interrupt requests by branching to the corresponding
  81. ; handler, as defined in the AIC. Supports interrupt nesting.
  82. ;------------------------------------------------------------------------------
  83. irqHandler
  84.         ;  Save interrupt context on the stack to allow nesting */
  85.         SUB     lr, lr, #4
  86.         STMFD   sp!, {lr}
  87.         MRS     lr, SPSR
  88.         STMFD   sp!, {r0,r1,lr}
  89.         ; Write in the IVR to support Protect Mode */
  90.         LDR     lr, =AT91C_BASE_AIC
  91.         LDR     r0, [r14, #AIC_IVR]
  92.         STR     lr, [r14, #AIC_IVR]
  93.         ; Branch to interrupt handler in Supervisor mode */
  94.         MSR     CPSR_c, #ARM_MODE_SVC
  95.         STMFD   sp!, {r1-r4, r12, lr}
  96.         MOV     lr, pc
  97.         BX      r0
  98.         LDMIA   sp!, {r1-r4, r12, lr}
  99.         MSR     CPSR_c, #ARM_MODE_IRQ | I_BIT
  100.         ; Acknowledge interrupt */
  101.         LDR     lr, =AT91C_BASE_AIC
  102.         STR     lr, [r14, #AIC_EOICR]
  103.         ; Restore interrupt context and branch back to calling code
  104.         LDMIA   sp!, {r0,r1,lr}
  105.         MSR     SPSR_cxsf, lr
  106.         LDMIA   sp!, {pc}^
  107. ;------------------------------------------------------------------------------
  108. ; After a reset, execution starts here, the mode is ARM, supervisor
  109. ; with interrupts disabled.
  110. ; Initializes the chip and branches to the main() function.
  111. ;------------------------------------------------------------------------------
  112.                 
  113.     AREA  cstartup, CODE
  114.     ENTRY        ; Entry point for the application
  115.    
  116.    
  117. ; Reset Handler
  118.         EXPORT  resetHandler
  119.         IMPORT |Image$$Fixed_region$$Limit|
  120.         IMPORT  |Image$$Relocate_region$$Base|
  121.         IMPORT  |Image$$Relocate_region$$ZI$$Base|
  122.         IMPORT  |Image$$Relocate_region$$ZI$$Limit|
  123.         IMPORT  |Image$$ARM_LIB_STACK$$Base|
  124.         IMPORT  |Image$$ARM_LIB_STACK$$ZI$$Limit|
  125.         
  126. ; Perform low-level initialization of the chip using LowLevelInit()
  127. IMPORT  LowLevelInit
  128. resetHandler   
  129.         
  130.         ; Set pc to actual code location (i.e. not in remap zone)
  131.     LDR     pc, =label
  132. label     
  133. ; Set up temporary stack (Top of the SRAM)
  134. LDR     r0, = |Image$$ARM_LIB_STACK$$ZI$$Limit|
  135.         MOV     sp, r0
  136. ; Call Low level init
  137.     LDR     r0, =LowLevelInit
  138.         MOV     lr, pc
  139.         BX      r0
  140. ;Initialize the Relocate_region segment 
  141. LDR  r0, = |Image$$Fixed_region$$Limit|
  142. LDR  r1, = |Image$$Relocate_region$$Base|
  143. LDR  r3, = |Image$$Relocate_region$$ZI$$Base|
  144.     
  145.     CMP     r0, r1                 
  146.       BEQ     %1
  147.      
  148.      
  149.         ; Copy init data
  150. 0       CMP     r1, r3         
  151.         LDRCC   r2, [r0], #4   
  152.         STRCC   r2, [r1], #4
  153.         BCC     %0
  154. 1       LDR     r1, =|Image$$Relocate_region$$ZI$$Limit|
  155.         MOV     r2, #0
  156. 2       CMP     r3, r1                  
  157.         STRCC   r2, [r3], #4
  158.         BCC     %2
  159.        
  160.                
  161. ; Setup Stack for each mode
  162.         LDR     R0, = |Image$$ARM_LIB_STACK$$ZI$$Limit|
  163. ;  Enter IRQ Mode and set its Stack Pointer
  164.         MSR     CPSR_c, #ARM_MODE_IRQ:OR:I_BIT:OR:F_BIT
  165.         MOV     SP, R0
  166.         SUB     R4, SP, #IRQ_Stack_Size
  167. ; Supervisor mode (interrupts enabled) 
  168.         MSR     CPSR_c, #ARM_MODE_SVC | F_BIT
  169.         MOV     SP, R4   
  170. ; Enter the C code
  171.         IMPORT  __main
  172.         LDR     R0, =__main
  173.         BX      R0
  174. loop4
  175.         B       loop4                
  176.        END