Startup.s
上传用户:cchhkk2004
上传日期:2022-05-10
资源大小:78k
文件大小:14k
源码类别:

VxWorks

开发平台:

Others

  1. ;/*****************************************************************************/
  2. ;/* STARTUP.S: Startup file for Philips LPC2000                               */
  3. ;/*****************************************************************************/
  4. ;/* <<< Use Configuration Wizard in Context Menu >>>                          */ 
  5. ;/*****************************************************************************/
  6. ;/* This file is part of the uVision/ARM development tools.                   */
  7. ;/* Copyright (c) 2005-2006 Keil Software. All rights reserved.               */
  8. ;/* This software may only be used under the terms of a valid, current,       */
  9. ;/* end user licence from KEIL for a compatible version of KEIL software      */
  10. ;/* development tools. Nothing else gives you the right to use this software. */
  11. ;/*****************************************************************************/
  12. ;/*
  13. ; *  The STARTUP.S code is executed after CPU Reset. This file may be 
  14. ; *  translated with the following SET symbols. In uVision these SET 
  15. ; *  symbols are entered under Options - ASM - Define.
  16. ; *
  17. ; *  REMAP: when set the startup code initializes the register MEMMAP 
  18. ; *  which overwrites the settings of the CPU configuration pins. The 
  19. ; *  startup and interrupt vectors are remapped from:
  20. ; *     0x00000000  default setting (not remapped)
  21. ; *     0x80000000  when EXTMEM_MODE is used
  22. ; *     0x40000000  when RAM_MODE is used
  23. ; *
  24. ; *  EXTMEM_MODE: when set the device is configured for code execution
  25. ; *  from external memory starting at address 0x80000000.
  26. ; *
  27. ; *  RAM_MODE: when set the device is configured for code execution
  28. ; *  from on-chip RAM starting at address 0x40000000. 
  29. ; */
  30. ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  31. Mode_USR        EQU     0x10
  32. Mode_FIQ        EQU     0x11
  33. Mode_IRQ        EQU     0x12
  34. Mode_SVC        EQU     0x13
  35. Mode_ABT        EQU     0x17
  36. Mode_UND        EQU     0x1B
  37. Mode_SYS        EQU     0x1F
  38. I_Bit           EQU     0x80            ; when I bit is set, IRQ is disabled
  39. F_Bit           EQU     0x40            ; when F bit is set, FIQ is disabled
  40. ;// <h> Stack Configuration (Stack Sizes in Bytes)
  41. ;//   <o0> Undefined Mode      <0x0-0xFFFFFFFF:8>
  42. ;//   <o1> Supervisor Mode     <0x0-0xFFFFFFFF:8>
  43. ;//   <o2> Abort Mode          <0x0-0xFFFFFFFF:8>
  44. ;//   <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
  45. ;//   <o4> Interrupt Mode      <0x0-0xFFFFFFFF:8>
  46. ;//   <o5> User/System Mode    <0x0-0xFFFFFFFF:8>
  47. ;// </h>
  48. UND_Stack_Size  EQU     0x00000000
  49. SVC_Stack_Size  EQU     0x00000008
  50. ABT_Stack_Size  EQU     0x00000000
  51. FIQ_Stack_Size  EQU     0x00000000
  52. IRQ_Stack_Size  EQU     0x00000080
  53. USR_Stack_Size  EQU     0x00000400
  54. Stack_Size      EQU     (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + 
  55.                          FIQ_Stack_Size + IRQ_Stack_Size + USR_Stack_Size)
  56.                 AREA    STACK, NOINIT, READWRITE, ALIGN=3
  57. Stack_Mem       SPACE   Stack_Size
  58. Stack_Top       EQU     Stack_Mem + Stack_Size
  59. ;// <h> Heap Configuration
  60. ;//   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF>
  61. ;// </h>
  62. Heap_Size       EQU     0x00000000
  63.                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
  64. Heap_Mem        SPACE   Heap_Size
  65. ; VPBDIV definitions
  66. VPBDIV          EQU     0xE01FC100      ; VPBDIV Address
  67. ;// <e> VPBDIV Setup
  68. ;// <i> Peripheral Bus Clock Rate
  69. ;//   <o1.0..1>   VPBDIV: VPB Clock
  70. ;//               <0=> VPB Clock = CPU Clock / 4
  71. ;//               <1=> VPB Clock = CPU Clock
  72. ;//               <2=> VPB Clock = CPU Clock / 2
  73. ;//   <o1.4..5>   XCLKDIV: XCLK Pin
  74. ;//               <0=> XCLK Pin = CPU Clock / 4
  75. ;//               <1=> XCLK Pin = CPU Clock
  76. ;//               <2=> XCLK Pin = CPU Clock / 2
  77. ;// </e>
  78. VPBDIV_SETUP    EQU     0
  79. VPBDIV_Val      EQU     0x00000000
  80. ; Phase Locked Loop (PLL) definitions
  81. PLL_BASE        EQU     0xE01FC080      ; PLL Base Address
  82. PLLCON_OFS      EQU     0x00            ; PLL Control Offset
  83. PLLCFG_OFS      EQU     0x04            ; PLL Configuration Offset
  84. PLLSTAT_OFS     EQU     0x08            ; PLL Status Offset
  85. PLLFEED_OFS     EQU     0x0C            ; PLL Feed Offset
  86. PLLCON_PLLE     EQU     (1<<0)          ; PLL Enable
  87. PLLCON_PLLC     EQU     (1<<1)          ; PLL Connect
  88. PLLCFG_MSEL     EQU     (0x1F<<0)       ; PLL Multiplier
  89. PLLCFG_PSEL     EQU     (0x03<<5)       ; PLL Divider
  90. PLLSTAT_PLOCK   EQU     (1<<10)         ; PLL Lock Status
  91. ;// <e> PLL Setup
  92. ;//   <o1.0..4>   MSEL: PLL Multiplier Selection
  93. ;//               <1-32><#-1>
  94. ;//               <i> M Value
  95. ;//   <o1.5..6>   PSEL: PLL Divider Selection
  96. ;//               <0=> 1   <1=> 2   <2=> 4   <3=> 8
  97. ;//               <i> P Value
  98. ;// </e>
  99. PLL_SETUP       EQU     1
  100. PLLCFG_Val      EQU     0x00000024
  101. ; Memory Accelerator Module (MAM) definitions
  102. MAM_BASE        EQU     0xE01FC000      ; MAM Base Address
  103. MAMCR_OFS       EQU     0x00            ; MAM Control Offset
  104. MAMTIM_OFS      EQU     0x04            ; MAM Timing Offset
  105. ;// <e> MAM Setup
  106. ;//   <o1.0..1>   MAM Control
  107. ;//               <0=> Disabled
  108. ;//               <1=> Partially Enabled
  109. ;//               <2=> Fully Enabled
  110. ;//               <i> Mode
  111. ;//   <o2.0..2>   MAM Timing
  112. ;//               <0=> Reserved  <1=> 1   <2=> 2   <3=> 3
  113. ;//               <4=> 4         <5=> 5   <6=> 6   <7=> 7
  114. ;//               <i> Fetch Cycles
  115. ;// </e>
  116. MAM_SETUP       EQU     1
  117. MAMCR_Val       EQU     0x00000002
  118. MAMTIM_Val      EQU     0x00000004
  119. ; External Memory Controller (EMC) definitions
  120. EMC_BASE        EQU     0xFFE00000      ; EMC Base Address
  121. BCFG0_OFS       EQU     0x00            ; BCFG0 Offset
  122. BCFG1_OFS       EQU     0x04            ; BCFG1 Offset
  123. BCFG2_OFS       EQU     0x08            ; BCFG2 Offset
  124. BCFG3_OFS       EQU     0x0C            ; BCFG3 Offset
  125. ;// <e> External Memory Controller (EMC)
  126. EMC_SETUP       EQU     0
  127. ;//   <e> Bank Configuration 0 (BCFG0)
  128. ;//     <o1.0..3>   IDCY: Idle Cycles <0-15>
  129. ;//     <o1.5..9>   WST1: Wait States 1 <0-31>
  130. ;//     <o1.11..15> WST2: Wait States 2 <0-31>
  131. ;//     <o1.10>     RBLE: Read Byte Lane Enable
  132. ;//     <o1.26>     WP: Write Protect
  133. ;//     <o1.27>     BM: Burst ROM
  134. ;//     <o1.28..29> MW: Memory Width  <0=>  8-bit  <1=> 16-bit
  135. ;//                                   <2=> 32-bit  <3=> Reserved
  136. ;//   </e>
  137. BCFG0_SETUP EQU         0
  138. BCFG0_Val   EQU         0x0000FBEF
  139. ;//   <e> Bank Configuration 1 (BCFG1)
  140. ;//     <o1.0..3>   IDCY: Idle Cycles <0-15>
  141. ;//     <o1.5..9>   WST1: Wait States 1 <0-31>
  142. ;//     <o1.11..15> WST2: Wait States 2 <0-31>
  143. ;//     <o1.10>     RBLE: Read Byte Lane Enable
  144. ;//     <o1.26>     WP: Write Protect
  145. ;//     <o1.27>     BM: Burst ROM
  146. ;//     <o1.28..29> MW: Memory Width  <0=>  8-bit  <1=> 16-bit
  147. ;//                                   <2=> 32-bit  <3=> Reserved
  148. ;//   </e>
  149. BCFG1_SETUP EQU         0
  150. BCFG1_Val   EQU         0x0000FBEF
  151. ;//   <e> Bank Configuration 2 (BCFG2)
  152. ;//     <o1.0..3>   IDCY: Idle Cycles <0-15>
  153. ;//     <o1.5..9>   WST1: Wait States 1 <0-31>
  154. ;//     <o1.11..15> WST2: Wait States 2 <0-31>
  155. ;//     <o1.10>     RBLE: Read Byte Lane Enable
  156. ;//     <o1.26>     WP: Write Protect
  157. ;//     <o1.27>     BM: Burst ROM
  158. ;//     <o1.28..29> MW: Memory Width  <0=>  8-bit  <1=> 16-bit
  159. ;//                                   <2=> 32-bit  <3=> Reserved
  160. ;//   </e>
  161. BCFG2_SETUP EQU         0
  162. BCFG2_Val   EQU         0x0000FBEF
  163. ;//   <e> Bank Configuration 3 (BCFG3)
  164. ;//     <o1.0..3>   IDCY: Idle Cycles <0-15>
  165. ;//     <o1.5..9>   WST1: Wait States 1 <0-31>
  166. ;//     <o1.11..15> WST2: Wait States 2 <0-31>
  167. ;//     <o1.10>     RBLE: Read Byte Lane Enable
  168. ;//     <o1.26>     WP: Write Protect
  169. ;//     <o1.27>     BM: Burst ROM
  170. ;//     <o1.28..29> MW: Memory Width  <0=>  8-bit  <1=> 16-bit
  171. ;//                                   <2=> 32-bit  <3=> Reserved
  172. ;//   </e>
  173. BCFG3_SETUP EQU         0
  174. BCFG3_Val   EQU         0x0000FBEF
  175. ;// </e> End of EMC
  176. ; External Memory Pins definitions
  177. PINSEL2         EQU     0xE002C014      ; PINSEL2 Address
  178. PINSEL2_Val     EQU     0x0E6149E4      ; CS0..3, OE, WE, BLS0..3, 
  179.                                         ; D0..31, A2..23, JTAG Pins
  180.                 PRESERVE8
  181.                 
  182. ; Area Definition and Entry Point
  183. ;  Startup Code must be linked first at Address at which it expects to run.
  184.                 AREA    RESET, CODE, READONLY
  185.                 ARM
  186. ; Exception Vectors
  187. ;  Mapped to Address 0.
  188. ;  Absolute addressing mode must be used.
  189. ;  Dummy Handlers are implemented as infinite loops which can be modified.
  190. Vectors         LDR     PC, Reset_Addr         
  191.                 LDR     PC, Undef_Addr
  192.                 LDR     PC, SWI_Addr
  193.                 LDR     PC, PAbt_Addr
  194.                 LDR     PC, DAbt_Addr
  195.                 NOP                            ; Reserved Vector 
  196. ;               LDR     PC, IRQ_Addr
  197.                 LDR     PC, [PC, #-0x0FF0]     ; Vector from VicVectAddr
  198.                 LDR     PC, FIQ_Addr
  199. Reset_Addr      DCD     Reset_Handler
  200. Undef_Addr      DCD     Undef_Handler
  201. SWI_Addr        DCD     SWI_Handler
  202. PAbt_Addr       DCD     PAbt_Handler
  203. DAbt_Addr       DCD     DAbt_Handler
  204.                 DCD     0                      ; Reserved Address 
  205. IRQ_Addr        DCD     IRQ_Handler
  206. FIQ_Addr        DCD     FIQ_Handler
  207. Undef_Handler   B       Undef_Handler
  208. SWI_Handler     B       SWI_Handler
  209. PAbt_Handler    B       PAbt_Handler
  210. DAbt_Handler    B       DAbt_Handler
  211. IRQ_Handler     B       IRQ_Handler
  212. FIQ_Handler     B       FIQ_Handler
  213. ; Reset Handler
  214.                 EXPORT  Reset_Handler
  215. Reset_Handler   
  216. ; Setup External Memory Pins
  217.                 IF      :DEF:EXTERNAL_MODE
  218.                 LDR     R0, =PINSEL2
  219.                 LDR     R1, =PINSEL2_Val
  220.                 STR     R1, [R0]
  221.                 ENDIF
  222. ; Setup External Memory Controller
  223.                 IF      EMC_SETUP <> 0
  224.                 LDR     R0, =EMC_BASE
  225.                 IF      BCFG0_SETUP <> 0
  226.                 LDR     R1, =BCFG0_Val
  227.                 STR     R1, [R0, #BCFG0_OFS]
  228.                 ENDIF
  229.                 IF      BCFG1_SETUP <> 0
  230.                 LDR     R1, =BCFG1_Val
  231.                 STR     R1, [R0, #BCFG1_OFS]
  232.                 ENDIF
  233.                 IF      BCFG2_SETUP <> 0
  234.                 LDR     R1, =BCFG2_Val
  235.                 STR     R1, [R0, #BCFG2_OFS]
  236.                 ENDIF
  237.                 IF      BCFG3_SETUP <> 0
  238.                 LDR     R1, =BCFG3_Val
  239.                 STR     R1, [R0, #BCFG3_OFS]
  240.                 ENDIF
  241.                 ENDIF   ; EMC_SETUP
  242. ; Setup VPBDIV
  243.                 IF      VPBDIV_SETUP <> 0
  244.                 LDR     R0, =VPBDIV
  245.                 LDR     R1, =VPBDIV_Val
  246.                 STR     R1, [R0]
  247.                 ENDIF
  248. ; Setup PLL
  249.                 IF      PLL_SETUP <> 0
  250.                 LDR     R0, =PLL_BASE
  251.                 MOV     R1, #0xAA
  252.                 MOV     R2, #0x55
  253. ;  Configure and Enable PLL
  254.                 MOV     R3, #PLLCFG_Val
  255.                 STR     R3, [R0, #PLLCFG_OFS] 
  256.                 MOV     R3, #PLLCON_PLLE
  257.                 STR     R3, [R0, #PLLCON_OFS]
  258.                 STR     R1, [R0, #PLLFEED_OFS]
  259.                 STR     R2, [R0, #PLLFEED_OFS]
  260. ;  Wait until PLL Locked
  261. PLL_Loop        LDR     R3, [R0, #PLLSTAT_OFS]
  262.                 ANDS    R3, R3, #PLLSTAT_PLOCK
  263.                 BEQ     PLL_Loop
  264. ;  Switch to PLL Clock
  265.                 MOV     R3, #(PLLCON_PLLE:OR:PLLCON_PLLC)
  266.                 STR     R3, [R0, #PLLCON_OFS]
  267.                 STR     R1, [R0, #PLLFEED_OFS]
  268.                 STR     R2, [R0, #PLLFEED_OFS]
  269.                 ENDIF   ; PLL_SETUP
  270. ; Setup MAM
  271.                 IF      MAM_SETUP <> 0
  272.                 LDR     R0, =MAM_BASE
  273.                 MOV     R1, #MAMTIM_Val
  274.                 STR     R1, [R0, #MAMTIM_OFS] 
  275.                 MOV     R1, #MAMCR_Val
  276.                 STR     R1, [R0, #MAMCR_OFS] 
  277.                 ENDIF   ; MAM_SETUP
  278. ; Memory Mapping (when Interrupt Vectors are in RAM)
  279. MEMMAP          EQU     0xE01FC040      ; Memory Mapping Control
  280.                 IF      :DEF:REMAP
  281.                 LDR     R0, =MEMMAP
  282.                 IF      :DEF:EXTMEM_MODE
  283.                 MOV     R1, #3
  284.                 ELIF    :DEF:RAM_MODE
  285.                 MOV     R1, #2
  286.                 ELSE
  287.                 MOV     R1, #1
  288.                 ENDIF
  289.                 STR     R1, [R0]
  290.                 ENDIF
  291. ; Initialise Interrupt System
  292. ;  ...
  293. ; Setup Stack for each mode
  294.                 LDR     R0, =Stack_Top
  295. ;  Enter Undefined Instruction Mode and set its Stack Pointer
  296.                 MSR     CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
  297.                 MOV     SP, R0
  298.                 SUB     R0, R0, #UND_Stack_Size
  299. ;  Enter Abort Mode and set its Stack Pointer
  300.                 MSR     CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
  301.                 MOV     SP, R0
  302.                 SUB     R0, R0, #ABT_Stack_Size
  303. ;  Enter FIQ Mode and set its Stack Pointer
  304.                 MSR     CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
  305.                 MOV     SP, R0
  306.                 SUB     R0, R0, #FIQ_Stack_Size
  307. ;  Enter IRQ Mode and set its Stack Pointer
  308.                 MSR     CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
  309.                 MOV     SP, R0
  310.                 SUB     R0, R0, #IRQ_Stack_Size
  311. ;  Enter Supervisor Mode and set its Stack Pointer
  312.                 MSR     CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
  313.                 MOV     SP, R0
  314.                 SUB     R0, R0, #SVC_Stack_Size
  315. ;  Enter User Mode and set its Stack Pointer
  316.                 MSR     CPSR_c, #Mode_USR
  317.                 MOV     SP, R0
  318.                 SUB     SL, SP, #USR_Stack_Size
  319. ; Enter the C code
  320.                 IMPORT  __main
  321.                 LDR     R0, =__main
  322.                 BX      R0
  323. ; User Initial Stack & Heap
  324.                 AREA    |.text|, CODE, READONLY
  325.                 IMPORT  __use_two_region_memory
  326.                 EXPORT  __user_initial_stackheap
  327. __user_initial_stackheap
  328.                 LDR     R0, =  Heap_Mem
  329.                 LDR     R1, =(Stack_Mem + USR_Stack_Size)
  330.                 LDR     R2, = (Heap_Mem +      Heap_Size)
  331.                 LDR     R3, = Stack_Mem
  332.                 BX      LR
  333.                 END