start_rvds.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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-2007 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. ; * EXTERNAL_MODE: when set the PIN2SEL values are written that enable
  31. ; * the external BUS at startup.
  32. ; */
  33. ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  34. Mode_USR EQU 0x10
  35. Mode_FIQ EQU 0x11
  36. Mode_IRQ EQU 0x12
  37. Mode_SVC EQU 0x13
  38. Mode_ABT EQU 0x17
  39. Mode_UND EQU 0x1B
  40. Mode_SYS EQU 0x1F
  41. I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
  42. F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
  43. ;// <h> Stack Configuration (Stack Sizes in Bytes)
  44. ;// <o0> Undefined Mode <0x0-0xFFFFFFFF:8>
  45. ;// <o1> Supervisor Mode <0x0-0xFFFFFFFF:8>
  46. ;// <o2> Abort Mode <0x0-0xFFFFFFFF:8>
  47. ;// <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
  48. ;// <o4> Interrupt Mode <0x0-0xFFFFFFFF:8>
  49. ;// <o5> User/System Mode <0x0-0xFFFFFFFF:8>
  50. ;// </h>
  51. UND_Stack_Size EQU 0x00000000
  52. SVC_Stack_Size EQU 0x00000100
  53. ABT_Stack_Size EQU 0x00000000
  54. FIQ_Stack_Size EQU 0x00000000
  55. IRQ_Stack_Size EQU 0x00000100
  56. USR_Stack_Size EQU 0x00000100
  57. ISR_Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + \
  58. FIQ_Stack_Size + IRQ_Stack_Size)
  59. AREA STACK, NOINIT, READWRITE, ALIGN=3
  60. Stack_Mem SPACE USR_Stack_Size
  61. __initial_sp SPACE ISR_Stack_Size
  62. Stack_Top
  63. ;// <h> Heap Configuration
  64. ;// <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF>
  65. ;// </h>
  66. Heap_Size EQU 0x00000000
  67. AREA HEAP, NOINIT, READWRITE, ALIGN=3
  68. __heap_base
  69. Heap_Mem SPACE Heap_Size
  70. __heap_limit
  71. ; VPBDIV definitions
  72. VPBDIV EQU 0xE01FC100 ; VPBDIV Address
  73. ;// <e> VPBDIV Setup
  74. ;// <i> Peripheral Bus Clock Rate
  75. ;// <o1.0..1> VPBDIV: VPB Clock
  76. ;// <0=> VPB Clock = CPU Clock / 4
  77. ;// <1=> VPB Clock = CPU Clock
  78. ;// <2=> VPB Clock = CPU Clock / 2
  79. ;// <o1.4..5> XCLKDIV: XCLK Pin
  80. ;// <0=> XCLK Pin = CPU Clock / 4
  81. ;// <1=> XCLK Pin = CPU Clock
  82. ;// <2=> XCLK Pin = CPU Clock / 2
  83. ;// </e>
  84. VPBDIV_SETUP EQU 0
  85. VPBDIV_Val EQU 0x00000000
  86. ; Phase Locked Loop (PLL) definitions
  87. PLL_BASE EQU 0xE01FC080 ; PLL Base Address
  88. PLLCON_OFS EQU 0x00 ; PLL Control Offset
  89. PLLCFG_OFS EQU 0x04 ; PLL Configuration Offset
  90. PLLSTAT_OFS EQU 0x08 ; PLL Status Offset
  91. PLLFEED_OFS EQU 0x0C ; PLL Feed Offset
  92. PLLCON_PLLE EQU (1<<0) ; PLL Enable
  93. PLLCON_PLLC EQU (1<<1) ; PLL Connect
  94. PLLCFG_MSEL EQU (0x1F<<0) ; PLL Multiplier
  95. PLLCFG_PSEL EQU (0x03<<5) ; PLL Divider
  96. PLLSTAT_PLOCK EQU (1<<10) ; PLL Lock Status
  97. ;// <e> PLL Setup
  98. ;// <o1.0..4> MSEL: PLL Multiplier Selection
  99. ;// <1-32><#-1>
  100. ;// <i> M Value
  101. ;// <o1.5..6> PSEL: PLL Divider Selection
  102. ;// <0=> 1 <1=> 2 <2=> 4 <3=> 8
  103. ;// <i> P Value
  104. ;// </e>
  105. PLL_SETUP EQU 1
  106. PLLCFG_Val EQU 0x00000024
  107. ; Memory Accelerator Module (MAM) definitions
  108. MAM_BASE EQU 0xE01FC000 ; MAM Base Address
  109. MAMCR_OFS EQU 0x00 ; MAM Control Offset
  110. MAMTIM_OFS EQU 0x04 ; MAM Timing Offset
  111. ;// <e> MAM Setup
  112. ;// <o1.0..1> MAM Control
  113. ;// <0=> Disabled
  114. ;// <1=> Partially Enabled
  115. ;// <2=> Fully Enabled
  116. ;// <i> Mode
  117. ;// <o2.0..2> MAM Timing
  118. ;// <0=> Reserved <1=> 1 <2=> 2 <3=> 3
  119. ;// <4=> 4 <5=> 5 <6=> 6 <7=> 7
  120. ;// <i> Fetch Cycles
  121. ;// </e>
  122. MAM_SETUP EQU 1
  123. MAMCR_Val EQU 0x00000002
  124. MAMTIM_Val EQU 0x00000004
  125. ; External Memory Controller (EMC) definitions
  126. EMC_BASE EQU 0xFFE00000 ; EMC Base Address
  127. BCFG0_OFS EQU 0x00 ; BCFG0 Offset
  128. BCFG1_OFS EQU 0x04 ; BCFG1 Offset
  129. BCFG2_OFS EQU 0x08 ; BCFG2 Offset
  130. BCFG3_OFS EQU 0x0C ; BCFG3 Offset
  131. ;// <e> External Memory Controller (EMC)
  132. EMC_SETUP EQU 0
  133. ;// <e> Bank Configuration 0 (BCFG0)
  134. ;// <o1.0..3> IDCY: Idle Cycles <0-15>
  135. ;// <o1.5..9> WST1: Wait States 1 <0-31>
  136. ;// <o1.11..15> WST2: Wait States 2 <0-31>
  137. ;// <o1.10> RBLE: Read Byte Lane Enable
  138. ;// <o1.26> WP: Write Protect
  139. ;// <o1.27> BM: Burst ROM
  140. ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
  141. ;// <2=> 32-bit <3=> Reserved
  142. ;// </e>
  143. BCFG0_SETUP EQU 0
  144. BCFG0_Val EQU 0x0000FBEF
  145. ;// <e> Bank Configuration 1 (BCFG1)
  146. ;// <o1.0..3> IDCY: Idle Cycles <0-15>
  147. ;// <o1.5..9> WST1: Wait States 1 <0-31>
  148. ;// <o1.11..15> WST2: Wait States 2 <0-31>
  149. ;// <o1.10> RBLE: Read Byte Lane Enable
  150. ;// <o1.26> WP: Write Protect
  151. ;// <o1.27> BM: Burst ROM
  152. ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
  153. ;// <2=> 32-bit <3=> Reserved
  154. ;// </e>
  155. BCFG1_SETUP EQU 0
  156. BCFG1_Val EQU 0x0000FBEF
  157. ;// <e> Bank Configuration 2 (BCFG2)
  158. ;// <o1.0..3> IDCY: Idle Cycles <0-15>
  159. ;// <o1.5..9> WST1: Wait States 1 <0-31>
  160. ;// <o1.11..15> WST2: Wait States 2 <0-31>
  161. ;// <o1.10> RBLE: Read Byte Lane Enable
  162. ;// <o1.26> WP: Write Protect
  163. ;// <o1.27> BM: Burst ROM
  164. ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
  165. ;// <2=> 32-bit <3=> Reserved
  166. ;// </e>
  167. BCFG2_SETUP EQU 0
  168. BCFG2_Val EQU 0x0000FBEF
  169. ;// <e> Bank Configuration 3 (BCFG3)
  170. ;// <o1.0..3> IDCY: Idle Cycles <0-15>
  171. ;// <o1.5..9> WST1: Wait States 1 <0-31>
  172. ;// <o1.11..15> WST2: Wait States 2 <0-31>
  173. ;// <o1.10> RBLE: Read Byte Lane Enable
  174. ;// <o1.26> WP: Write Protect
  175. ;// <o1.27> BM: Burst ROM
  176. ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
  177. ;// <2=> 32-bit <3=> Reserved
  178. ;// </e>
  179. BCFG3_SETUP EQU 0
  180. BCFG3_Val EQU 0x0000FBEF
  181. ;// </e> End of EMC
  182. ; External Memory Pins definitions
  183. PINSEL2 EQU 0xE002C014 ; PINSEL2 Address
  184. PINSEL2_Val EQU 0x0E6149E4 ; CS0..3, OE, WE, BLS0..3,
  185. ; D0..31, A2..23, JTAG Pins
  186. PRESERVE8
  187. ; Area Definition and Entry Point
  188. ; Startup Code must be linked first at Address at which it expects to run.
  189. AREA RESET, CODE, READONLY
  190. ARM
  191. ; Exception Vectors
  192. ; Mapped to Address 0.
  193. ; Absolute addressing mode must be used.
  194. ; Dummy Handlers are implemented as infinite loops which can be modified.
  195. Vectors LDR PC, Reset_Addr
  196. LDR PC, Undef_Addr
  197. LDR PC, SWI_Addr
  198. LDR PC, PAbt_Addr
  199. LDR PC, DAbt_Addr
  200. NOP ; Reserved Vector
  201. LDR PC, IRQ_Addr
  202. LDR PC, FIQ_Addr
  203. Reset_Addr DCD Reset_Handler
  204. Undef_Addr DCD Undef_Handler
  205. SWI_Addr DCD SWI_Handler
  206. PAbt_Addr DCD PAbt_Handler
  207. DAbt_Addr DCD DAbt_Handler
  208. DCD 0 ; Reserved Address
  209. IRQ_Addr DCD IRQ_Handler
  210. FIQ_Addr DCD FIQ_Handler
  211. Undef_Handler B Undef_Handler
  212. SWI_Handler B SWI_Handler
  213. PAbt_Handler B PAbt_Handler
  214. DAbt_Handler B DAbt_Handler
  215. FIQ_Handler B FIQ_Handler
  216. ; Reset Handler
  217. EXPORT Reset_Handler
  218. Reset_Handler
  219. ; Setup External Memory Pins
  220. IF :DEF:EXTERNAL_MODE
  221. LDR R0, =PINSEL2
  222. LDR R1, =PINSEL2_Val
  223. STR R1, [R0]
  224. ENDIF
  225. ; Setup External Memory Controller
  226. IF EMC_SETUP <> 0
  227. LDR R0, =EMC_BASE
  228. IF BCFG0_SETUP <> 0
  229. LDR R1, =BCFG0_Val
  230. STR R1, [R0, #BCFG0_OFS]
  231. ENDIF
  232. IF BCFG1_SETUP <> 0
  233. LDR R1, =BCFG1_Val
  234. STR R1, [R0, #BCFG1_OFS]
  235. ENDIF
  236. IF BCFG2_SETUP <> 0
  237. LDR R1, =BCFG2_Val
  238. STR R1, [R0, #BCFG2_OFS]
  239. ENDIF
  240. IF BCFG3_SETUP <> 0
  241. LDR R1, =BCFG3_Val
  242. STR R1, [R0, #BCFG3_OFS]
  243. ENDIF
  244. ENDIF ; EMC_SETUP
  245. ; Setup VPBDIV
  246. IF VPBDIV_SETUP <> 0
  247. LDR R0, =VPBDIV
  248. LDR R1, =VPBDIV_Val
  249. STR R1, [R0]
  250. ENDIF
  251. ; Setup PLL
  252. IF PLL_SETUP <> 0
  253. LDR R0, =PLL_BASE
  254. MOV R1, #0xAA
  255. MOV R2, #0x55
  256. ; Configure and Enable PLL
  257. MOV R3, #PLLCFG_Val
  258. STR R3, [R0, #PLLCFG_OFS]
  259. MOV R3, #PLLCON_PLLE
  260. STR R3, [R0, #PLLCON_OFS]
  261. STR R1, [R0, #PLLFEED_OFS]
  262. STR R2, [R0, #PLLFEED_OFS]
  263. ; Wait until PLL Locked
  264. PLL_Loop LDR R3, [R0, #PLLSTAT_OFS]
  265. ANDS R3, R3, #PLLSTAT_PLOCK
  266. BEQ PLL_Loop
  267. ; Switch to PLL Clock
  268. MOV R3, #(PLLCON_PLLE:OR:PLLCON_PLLC)
  269. STR R3, [R0, #PLLCON_OFS]
  270. STR R1, [R0, #PLLFEED_OFS]
  271. STR R2, [R0, #PLLFEED_OFS]
  272. ENDIF ; PLL_SETUP
  273. ; Setup MAM
  274. IF MAM_SETUP <> 0
  275. LDR R0, =MAM_BASE
  276. MOV R1, #MAMTIM_Val
  277. STR R1, [R0, #MAMTIM_OFS]
  278. MOV R1, #MAMCR_Val
  279. STR R1, [R0, #MAMCR_OFS]
  280. ENDIF ; MAM_SETUP
  281. ; Memory Mapping (when Interrupt Vectors are in RAM)
  282. MEMMAP EQU 0xE01FC040 ; Memory Mapping Control
  283. IF :DEF:REMAP
  284. LDR R0, =MEMMAP
  285. IF :DEF:EXTMEM_MODE
  286. MOV R1, #3
  287. ELIF :DEF:RAM_MODE
  288. MOV R1, #2
  289. ELSE
  290. MOV R1, #1
  291. ENDIF
  292. STR R1, [R0]
  293. ENDIF
  294. ; Initialise Interrupt System
  295. ; ...
  296. ; Setup Stack for each mode
  297. LDR R0, =Stack_Top
  298. ; Enter Undefined Instruction Mode and set its Stack Pointer
  299. MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
  300. MOV SP, R0
  301. SUB R0, R0, #UND_Stack_Size
  302. ; Enter Abort Mode and set its Stack Pointer
  303. MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
  304. MOV SP, R0
  305. SUB R0, R0, #ABT_Stack_Size
  306. ; Enter FIQ Mode and set its Stack Pointer
  307. MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
  308. MOV SP, R0
  309. SUB R0, R0, #FIQ_Stack_Size
  310. ; Enter IRQ Mode and set its Stack Pointer
  311. MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
  312. MOV SP, R0
  313. SUB R0, R0, #IRQ_Stack_Size
  314. ; Enter Supervisor Mode and set its Stack Pointer
  315. MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
  316. MOV SP, R0
  317. ; SUB R0, R0, #SVC_Stack_Size
  318. ; Enter User Mode and set its Stack Pointer
  319. ; RT-Thread does not use user mode
  320. ; MSR CPSR_c, #Mode_USR
  321. IF :DEF:__MICROLIB
  322. EXPORT __initial_sp
  323. ELSE
  324. ; MOV SP, R0
  325. ; SUB SL, SP, #USR_Stack_Size
  326. ENDIF
  327. ; Enter the C code
  328. IMPORT __main
  329. LDR R0, =__main
  330. BX R0
  331. IMPORT rt_interrupt_enter
  332. IMPORT rt_interrupt_leave
  333. IMPORT rt_thread_switch_interrupt_flag
  334. IMPORT rt_interrupt_from_thread
  335. IMPORT rt_interrupt_to_thread
  336. IMPORT rt_hw_trap_irq
  337. IMPORT rt_hw_context_switch_interrupt_do
  338. IRQ_Handler PROC
  339. EXPORT IRQ_Handler
  340. STMFD sp!, {r0-r12,lr}
  341. BL rt_interrupt_enter
  342. BL rt_hw_trap_irq
  343. BL rt_interrupt_leave
  344. ; if rt_thread_switch_interrupt_flag set, jump to
  345. ; rt_hw_context_switch_interrupt_do and don't return
  346. LDR r0, =rt_thread_switch_interrupt_flag
  347. LDR r1, [r0]
  348. CMP r1, #1
  349. BEQ rt_hw_context_switch_interrupt_do
  350. LDMFD sp!, {r0-r12,lr}
  351. SUBS pc, lr, #4
  352. ENDP
  353. IF :DEF:__MICROLIB
  354. EXPORT __heap_base
  355. EXPORT __heap_limit
  356. ELSE
  357. ; User Initial Stack & Heap
  358. AREA |.text|, CODE, READONLY
  359. IMPORT __use_two_region_memory
  360. EXPORT __user_initial_stackheap
  361. __user_initial_stackheap
  362. LDR R0, = Heap_Mem
  363. LDR R1, =(Stack_Mem + USR_Stack_Size)
  364. LDR R2, = (Heap_Mem + Heap_Size)
  365. LDR R3, = Stack_Mem
  366. BX LR
  367. ENDIF
  368. END