start_rvds.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. ;/*****************************************************************************/
  2. ;/* S3C2440.S: Startup file for Samsung S3C440 */
  3. ;/*****************************************************************************/
  4. ;/* <<< Use Configuration Wizard in Context Menu >>> */
  5. ;/*****************************************************************************/
  6. ;/* This file is part of the uVision/ARM development tools. */
  7. ;/* Copyright (c) 2005-2008 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 S3C2440.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. ; * NO_CLOCK_SETUP: when set the startup code will not initialize Clock
  18. ; * (used mostly when clock is aLReady initialized from script .ini
  19. ; * file).
  20. ; *
  21. ; * NO_MC_SETUP: when set the startup code will not initialize Memory
  22. ; * Controller (used mostly when clock is aLReady initialized from script
  23. ; * .ini file).
  24. ; *
  25. ; * NO_GP_SETUP: when set the startup code will not initialize General Ports
  26. ; * (used mostly when clock is aLReady initialized from script .ini
  27. ; * file).
  28. ; *
  29. ; * RAM_INTVEC: when set the startup code copies exception vectors
  30. ; * from execution address to on-chip RAM.
  31. ; */
  32. ;/*
  33. ; * File : start_rvds.s
  34. ; * This file is part of RT-Thread RTOS
  35. ; * COPYRIGHT (C) 2006, RT-Thread Development Team
  36. ; *
  37. ; * The license and diSTRibution terms for this file may be
  38. ; * found in the file LICENSE in this diSTRibution or at
  39. ; * http://openlab.rt-thread.com/license/LICENSE
  40. ; *
  41. ; * Change Logs:
  42. ; * Date Author Notes
  43. ; * 2010-01-12 Gary Lee Change the STRucture of the code,
  44. ; the configuration file's name is config.inc
  45. ; * 2010-01-22 Gary Lee Add interrupt config for startup 2440
  46. ; * 2010-01-23 Gary Lee Add copy myself for startup from nand
  47. ; */
  48. ; Area Definition and Entry Point
  49. ; Startup Code must be linked first at Address at which it expects to run.
  50. ; Exception Vectors
  51. ; Mapped to Address 0.
  52. ; Absolute addressing mode must be used.
  53. ; Dummy Handlers are implemented as infinite loops which can be modified.
  54. GET config.inc
  55. PRESERVE8
  56. AREA RESET, CODE, READONLY
  57. ARM
  58. EXPORT Entry_Point
  59. Entry_Point
  60. Vectors LDR PC, Reset_Addr
  61. LDR PC, Undef_Addr
  62. LDR PC, SWI_Addr
  63. LDR PC, PAbt_Addr
  64. LDR PC, DAbt_Addr
  65. NOP
  66. LDR PC, IRQ_Addr
  67. LDR PC, FIQ_Addr
  68. Reset_Addr DCD Reset_Handler
  69. Undef_Addr DCD Undef_Handler
  70. SWI_Addr DCD SWI_Handler
  71. PAbt_Addr DCD PAbt_Handler
  72. DAbt_Addr DCD DAbt_Handler
  73. DCD 0 ; Reserved Address
  74. IRQ_Addr DCD IRQ_Handler
  75. FIQ_Addr DCD FIQ_Handler
  76. Undef_Handler B Undef_Handler
  77. SWI_Handler B SWI_Handler
  78. PAbt_Handler B PAbt_Handler
  79. DAbt_Handler B DAbt_Handler
  80. FIQ_Handler B FIQ_Handler
  81. ;=========================================================================
  82. ; Reset Handler
  83. EXPORT Reset_Handler
  84. Reset_Handler
  85. BL WatchDog_Config ; shutdown watchdog
  86. BL Interrupt_Config ; shutdown interrupt
  87. BL SysClock_Config ; setup system clock, default value is 400MHz
  88. BL SDRAM_Config ; setup sdram clock, default value is 100MHz
  89. ;BL Copymyself_Config ; copy myself from 0x1000 with size of 1MB to sdram address of 0x30000000
  90. BL GPIO_Config ; setup gpio
  91. BL RAM_INTVEC_Config ; install interrupt handler to sdram
  92. BL Stack_Config ; setup stack for every mode
  93. ; a technology about trampoline
  94. LDR R1, =ON_THE_RAM
  95. ADD PC, R1, #0
  96. NOP
  97. NOP
  98. 1
  99. B %B1
  100. ON_THE_RAM
  101. ; setup by APCS
  102. MOV FP, #0 ; no previous frame, so fp=0
  103. MOV a2, #0 ; set argv to NULL
  104. IMPORT __main
  105. BL __main ; call main
  106. MOV R0, #FLASH_BASE_ADDR
  107. MOV PC, R0 ; otherwise, reboot
  108. ;=========================================================================
  109. IMPORT rt_interrupt_enter
  110. IMPORT rt_interrupt_leave
  111. IMPORT rt_thread_switch_interrput_flag
  112. IMPORT rt_interrupt_from_thread
  113. IMPORT rt_interrupt_to_thread
  114. IMPORT rt_hw_trap_irq
  115. IMPORT nand_read_ll
  116. IRQ_Handler PROC
  117. EXPORT IRQ_Handler
  118. STMFD SP!, {R0-R12,LR}
  119. BL rt_interrupt_enter
  120. BL rt_hw_trap_irq
  121. BL rt_interrupt_leave
  122. LDR R0, =rt_thread_switch_interrput_flag
  123. LDR R1, [R0]
  124. CMP R1, #1
  125. BEQ rt_hw_context_switch_interrupt_do
  126. LDMFD SP!, {R0-R12,LR}
  127. SUBS PC, LR, #4
  128. ENDP
  129. rt_hw_context_switch_interrupt_do PROC
  130. EXPORT rt_hw_context_switch_interrupt_do
  131. MOV R1, #0 ; clear flag
  132. STR R1, [R0]
  133. LDMFD SP!, {R0-R12,LR}; reload saved registers
  134. STMFD SP!, {R0-R3} ; save R0-R3
  135. MOV R1, SP
  136. ADD SP, SP, #16 ; restore SP
  137. SUB R2, LR, #4 ; save old task's PC to R2
  138. MRS R3, SPSR ; get cpsr of interrupt thread
  139. ; switch to SVC mode and no interrupt
  140. MSR cpsr_c, #I_Bit|F_Bit|Mode_SVC
  141. STMFD SP!, {R2} ; push old task's PC
  142. STMFD SP!, {r4-R12,LR}; push old task's LR,R12-r4
  143. MOV r4, R1 ; SPecial optimised code below
  144. MOV r5, R3
  145. LDMFD r4!, {R0-R3}
  146. STMFD SP!, {R0-R3} ; push old task's R3-R0
  147. STMFD SP!, {r5} ; push old task's cpsr
  148. MRS r4, SPSR
  149. STMFD SP!, {r4} ; push old task's SPsr
  150. LDR r4, =rt_interrupt_from_thread
  151. LDR r5, [r4]
  152. STR SP, [r5] ; store SP in preempted tasks's TCB
  153. LDR r6, =rt_interrupt_to_thread
  154. LDR r6, [r6]
  155. LDR SP, [r6] ; get new task's stack pointer
  156. LDMFD SP!, {r4} ; pop new task's SPsr
  157. MSR SPSR_cxsf, r4
  158. LDMFD SP!, {r4} ; pop new task's psr
  159. MSR cpsr_cxsf, r4
  160. LDMFD SP!, {R0-R12,LR} ; pop new task's R0-R12,LR & PC
  161. LDMFD SP!, {PC}
  162. ENDP
  163. ; Use microlib
  164. IF :DEF:__MICROLIB
  165. EXPORT __heap_base
  166. EXPORT __heap_limit
  167. ELSE
  168. ; User Initial Stack & Heap
  169. AREA |.text|, CODE, READONLY
  170. IMPORT __use_two_region_memory
  171. EXPORT __user_initial_stackheap
  172. __user_initial_stackheap
  173. LDR R0, = Heap_Mem
  174. LDR R1, =(Stack_Mem + USR_Stack_Size)
  175. LDR R2, = (Heap_Mem + Heap_Size)
  176. LDR R3, = Stack_Mem
  177. BX LR
  178. ENDIF
  179. ;=========================================================================
  180. ; Subroutines
  181. WatchDog_Config PROC
  182. IF WT_SETUP != 0
  183. LDR R0, =WT_BASE
  184. LDR R1, =WTCON_Val
  185. LDR R2, =WTDAT_Val
  186. STR R2, [R0, #WTCNT_OFS]
  187. STR R2, [R0, #WTDAT_OFS]
  188. STR R1, [R0, #WTCON_OFS]
  189. ENDIF
  190. BX LR
  191. ENDP
  192. Interrupt_Config PROC
  193. LDR R0,=INTMSK
  194. LDR R1,=0xffffffff ;/*all interrupt disable关闭所有中断 */
  195. STR R1,[R0]
  196. LDR R0,=INTSUBMSK
  197. LDR R1,=0x7fff ;/*all sub interrupt disable关闭子中断 */
  198. STR R1,[R0]
  199. BX LR
  200. ENDP
  201. SysClock_Config PROC
  202. IF (:LNOT:(:DEF:NO_CLOCK_SETUP)):LAND:(CLOCK_SETUP != 0)
  203. LDR R0, =CLOCK_BASE
  204. LDR R1, =LOCKTIME_Val
  205. STR R1, [R0, #LOCKTIME_OFS]
  206. MOV R1, #CLKDIVN_Val
  207. STR R1, [R0, #CLKDIVN_OFS]
  208. LDR R1, =CAMDIVN_Val
  209. STR R1, [R0, #CAMDIVN_OFS]
  210. LDR R1, =MPLLCON_Val
  211. STR R1, [R0, #MPLLCON_OFS]
  212. LDR R1, =UPLLCON_Val
  213. STR R1, [R0, #UPLLCON_OFS]
  214. MOV R1, #CLKSLOW_Val
  215. STR R1, [R0, #CLKSLOW_OFS]
  216. LDR R1, =CLKCON_Val
  217. STR R1, [R0, #CLKCON_OFS]
  218. ENDIF
  219. BX LR
  220. ENDP
  221. Copymyself_Config PROC
  222. MOV R1, #NAND_CTL_BASE ; inital NAND初始化
  223. LDR R2, =((7<<12)|(7<<8)|(7<<4)|(0<<0)) ; initial value
  224. STR R2, [R1, #oNFCONF]
  225. ; reset nand flash ; 复位NAND
  226. LDR R2, [R1, #oNFCONF]
  227. LDR R2, =((1<<4)|(0<<1)|(1<<0)) ; nFCE active
  228. STR R2, [R1, #oNFCONT]
  229. LDR R2, [R1, #oNFCONT]
  230. LDR R2, =(0x6) ; RnB Clear
  231. STR R2, [R1, #oNFSTAT]
  232. LDR R2, [R1, #oNFSTAT]
  233. MOV R2, #0xff ; reset command
  234. STRB R2, [R1, #oNFCMD]
  235. ; 延时
  236. MOV R3, #0x0A
  237. 1
  238. SUBS R3, R3, #1
  239. BNE %B1
  240. ; wait idle state 就绪
  241. 2
  242. LDR R2, [R1, #oNFSTAT]
  243. TST R2, #0x04
  244. BEQ %B2
  245. LDR R2, [R1, #oNFCONF]
  246. ORR R2, R2, #0x2 ; nFCE inactive
  247. STR R2, [R1, #oNFCONF]
  248. LDR SP, =4096 ; nand_read.c needed
  249. LDR R0, =0x30000000 ; nand_read_ll argument 1 buffer addr
  250. MOV R1, #4096 ; nand_read_ll argument 2 start addr
  251. MOV R2, #0x100000 ; nand_read_ll argument 3 copy size
  252. ; 1MB enough for this example
  253. BL nand_read_ll
  254. BX LR
  255. ENDP
  256. SDRAM_Config PROC
  257. IF (:LNOT:(:DEF:NO_MC_SETUP)):LAND:(CLOCK_SETUP != 0)
  258. LDR R0, =MC_BASE
  259. LDR R1, =BWSCON_Val
  260. STR R1, [R0, #BWSCON_OFS]
  261. LDR R1, =BANKCON0_Val
  262. STR R1, [R0, #BANKCON0_OFS]
  263. LDR R1, =BANKCON1_Val
  264. STR R1, [R0, #BANKCON1_OFS]
  265. LDR R1, =BANKCON2_Val
  266. STR R1, [R0, #BANKCON2_OFS]
  267. LDR R1, =BANKCON3_Val
  268. STR R1, [R0, #BANKCON3_OFS]
  269. LDR R1, =BANKCON4_Val
  270. STR R1, [R0, #BANKCON4_OFS]
  271. LDR R1, =BANKCON5_Val
  272. STR R1, [R0, #BANKCON5_OFS]
  273. LDR R1, =BANKCON6_Val
  274. STR R1, [R0, #BANKCON6_OFS]
  275. LDR R1, =BANKCON7_Val
  276. STR R1, [R0, #BANKCON7_OFS]
  277. LDR R1, =REFRESH_Val
  278. STR R1, [R0, #REFRESH_OFS]
  279. MOV R1, #BANKSIZE_Val
  280. STR R1, [R0, #BANKSIZE_OFS]
  281. MOV R1, #MRSRB6_Val
  282. STR R1, [R0, #MRSRB6_OFS]
  283. MOV R1, #MRSRB7_Val
  284. STR R1, [R0, #MRSRB7_OFS]
  285. ENDIF
  286. BX LR
  287. ENDP
  288. GPIO_Config PROC
  289. IF (:LNOT:(:DEF:NO_GP_SETUP)):LAND:(GP_SETUP != 0)
  290. IF GPA_SETUP != 0
  291. LDR R0, =GPA_BASE
  292. LDR R1, =GPACON_Val
  293. STR R1, [R0, #GPCON_OFS]
  294. ENDIF
  295. IF GPB_SETUP != 0
  296. LDR R0, =GPB_BASE
  297. LDR R1, =GPBCON_Val
  298. STR R1, [R0, #GPCON_OFS]
  299. LDR R1, =GPBUP_Val
  300. STR R1, [R0, #GPUP_OFS]
  301. ENDIF
  302. IF GPC_SETUP != 0
  303. LDR R0, =GPC_BASE
  304. LDR R1, =GPCCON_Val
  305. STR R1, [R0, #GPCON_OFS]
  306. LDR R1, =GPCUP_Val
  307. STR R1, [R0, #GPUP_OFS]
  308. ENDIF
  309. IF GPD_SETUP != 0
  310. LDR R0, =GPD_BASE
  311. LDR R1, =GPDCON_Val
  312. STR R1, [R0, #GPCON_OFS]
  313. LDR R1, =GPDUP_Val
  314. STR R1, [R0, #GPUP_OFS]
  315. ENDIF
  316. IF GPE_SETUP != 0
  317. LDR R0, =GPE_BASE
  318. LDR R1, =GPECON_Val
  319. STR R1, [R0, #GPCON_OFS]
  320. LDR R1, =GPEUP_Val
  321. STR R1, [R0, #GPUP_OFS]
  322. ENDIF
  323. IF GPF_SETUP != 0
  324. LDR R0, =GPF_BASE
  325. LDR R1, =GPFCON_Val
  326. STR R1, [R0, #GPCON_OFS]
  327. LDR R1, =GPFUP_Val
  328. STR R1, [R0, #GPUP_OFS]
  329. ENDIF
  330. IF GPG_SETUP != 0
  331. LDR R0, =GPG_BASE
  332. LDR R1, =GPGCON_Val
  333. STR R1, [R0, #GPCON_OFS]
  334. LDR R1, =GPGUP_Val
  335. STR R1, [R0, #GPUP_OFS]
  336. ENDIF
  337. IF GPH_SETUP != 0
  338. LDR R0, =GPH_BASE
  339. LDR R1, =GPHCON_Val
  340. STR R1, [R0, #GPCON_OFS]
  341. LDR R1, =GPHUP_Val
  342. STR R1, [R0, #GPUP_OFS]
  343. ENDIF
  344. IF GPJ_SETUP != 0
  345. LDR R0, =GPJ_BASE
  346. LDR R1, =GPJCON_Val
  347. STR R1, [R0, #GPCON_OFS]
  348. LDR R1, =GPJUP_Val
  349. STR R1, [R0, #GPUP_OFS]
  350. ENDIF
  351. ENDIF
  352. BX LR
  353. ENDP
  354. RAM_INTVEC_Config PROC
  355. IF :DEF:RAM_INTVEC
  356. ADR R8, Vectors ; Source
  357. LDR R9, =IRAM_BASE ; Destination
  358. LDMIA R8!, {R0-R7} ; Load Vectors
  359. STMIA R9!, {R0-R7} ; Store Vectors
  360. LDMIA R8!, {R0-R7} ; Load Handler Addresses
  361. STMIA R9!, {R0-R7} ; Store Handler Addresses
  362. ENDIF
  363. BX LR
  364. ENDP
  365. Stack_Config PROC
  366. LDR R0, =Stack_Top
  367. MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
  368. MOV SP, R0
  369. SUB R0, R0, #UND_Stack_Size
  370. MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
  371. MOV SP, R0
  372. SUB R0, R0, #ABT_Stack_Size
  373. MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
  374. MOV SP, R0
  375. SUB R0, R0, #FIQ_Stack_Size
  376. MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
  377. MOV SP, R0
  378. SUB R0, R0, #IRQ_Stack_Size
  379. MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
  380. MOV SP, R0
  381. SUB R0, R0, #SVC_Stack_Size
  382. ; MSR CPSR_c, #Mode_USR
  383. MOV SP, R0
  384. SUB SL, SP, #USR_Stack_Size
  385. BX LR
  386. ENDP
  387. END