Advertisement
Guest User

ctr0-pp.s

a guest
Aug 15th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.08 KB | None | 0 0
  1. /***************************************************************************
  2. * __________ __ ___.
  3. * Open \______ \ ____ ____ | | _\_ |__ _______ ___
  4. * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
  5. * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
  6. * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
  7. * \/ \/ \/ \/ \/
  8. * $Id$
  9. *
  10. * Copyright (C) 2002 by Linus Nielsen Feltzing
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  18. * KIND, either express or implied.
  19. *
  20. ****************************************************************************/
  21. #include "config.h"
  22. #include "cpu.h"
  23.  
  24. #if defined(HAVE_BOOTDATA) && !defined(BOOTLOADER)
  25. #include "bootdata.h"
  26. #endif
  27.  
  28. .section .init.text,"ax",%progbits
  29.  
  30. .global start
  31. start:
  32.  
  33. /* PortalPlayer bootloader and startup code based on startup.s from the iPodLinux
  34. * loader
  35. *
  36. * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
  37. * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
  38. *
  39. */
  40. #if CONFIG_CPU == PP5002
  41. .equ PROC_ID, 0xc4000000
  42. .equ CPU_ICLR, 0xcf001028
  43. .equ CPU_CTRL, 0xcf004054
  44. .equ COP_ICLR, 0xcf001038
  45. .equ COP_CTRL, 0xcf004058
  46. .equ CPU_STATUS, 0xcf004050
  47. .equ COP_STATUS, 0xcf004050
  48. .equ SLEEP, 0x000000ca
  49. .equ WAKE, 0x000000ce
  50. .equ CPUSLEEPING, 0x00008000
  51. .equ COPSLEEPING, 0x00004000
  52. .equ CACHE_CTRL, 0xcf004024
  53. .equ MMAP_LOG, 0xf000f000 /* MMAP0 */
  54. .equ MMAP_PHYS, 0xf000f004
  55. #if MEMORYSIZE > 32
  56. .equ MMAP_MASK, 0x00003c00
  57. #else
  58. .equ MMAP_MASK, 0x00003e00
  59. #endif
  60. .equ MMAP_FLAGS, 0x00003f84
  61. #else
  62. .equ PROC_ID, 0x60000000
  63. .equ CPU_ICLR, 0x60004028
  64. .equ CPU_CTRL, 0x60007000
  65. .equ CPU_STATUS, 0x60007000
  66. .equ COP_ICLR, 0x60004038
  67. .equ COP_CTRL, 0x60007004
  68. .equ COP_STATUS, 0x60007004
  69. .equ SLEEP, 0x80000000
  70. .equ WAKE, 0x00000000
  71. .equ CPUSLEEPING, 0x80000000
  72. .equ COPSLEEPING, 0x80000000
  73. .equ CACHE_CTRL, 0x6000c000
  74. .equ MMAP_LOG, 0xf000f000 /* MMAP0 */
  75. .equ MMAP_PHYS, 0xf000f004
  76. #if MEMORYSIZE > 32
  77. .equ MMAP_MASK, 0x00003c00
  78. #else
  79. .equ MMAP_MASK, 0x00003e00
  80. #endif
  81. .equ MMAP_FLAGS, 0x00000f84
  82. #endif
  83.  
  84. msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
  85. b pad_skip
  86.  
  87. .space 6*4 /* pad to offset 0x20 */
  88.  
  89. .ascii "Rockbox" /* signature for bootloader checking osos */
  90. .byte 1 /* osos boot version, only 1 exists for now */
  91.  
  92. .space 56*4 /* (more than enough) space for exception vectors and mi4 magic */
  93.  
  94. pad_skip:
  95. /* Find out which processor we are - r0 should be preserved for the
  96. * duration of the init to avoid constant reloading of the processor ID.
  97. * For each stage, CPU proceeds first, then COP.
  98. */
  99. ldr r0, =PROC_ID
  100. ldrb r0, [r0]
  101.  
  102. /* We need to remap memory from wherever SDRAM is mapped natively, to
  103. base address 0, so we can put our exception vectors there. We don't
  104. want to do this remapping while executing from SDRAM, so we copy the
  105. remapping code to IRAM, then execute from there. Hence, the following
  106. code is compiled for address 0, but is currently executing at either
  107. 0x28000000 or 0x10000000, depending on chipset version. Do not use any
  108. absolute addresses until remapping has been done. */
  109.  
  110. /* Cores are stepped though the init in turn: CPU then COP. The the remap
  111. stage is completed by each core in turn and then the COP waits for the
  112. CPU to finish initializing its kernel where the CPU will wake the COP
  113. and wait for the COP to finish. This ensures no threading activity
  114. starts until it is safe. */
  115. cmp r0, #0x55
  116.  
  117. /* mask all interrupt sources before setting anything up */
  118. ldreq r2, =CPU_ICLR
  119. ldrne r2, =COP_ICLR
  120. mvn r1, #0
  121. str r1, [r2]
  122.  
  123. /* put us (co-processor) to sleep and wait for CPU to remap */
  124. ldrne r2, =COP_CTRL
  125. movne r1, #SLEEP
  126. strne r1, [r2]
  127. nop
  128. nop
  129. nop
  130.  
  131. /* wait for co-processor to sleep then CPU can begin its remapping */
  132. ldreq r2, =COP_STATUS
  133. 1:
  134. ldreq r1, [r2]
  135. tsteq r1, #COPSLEEPING
  136. beq 1b
  137.  
  138. /* disable cache and local interrupt vectors - it is really not desireable
  139. to have them enabled here */
  140. ldr r2, =CACHE_CTRL
  141. mov r1, #0
  142. str r1, [r2]
  143.  
  144. #if defined(IPOD_VIDEO)
  145. /* detect 32mb vs 64mb model */
  146. /* we do this here because after SDRAM is remapped, we already assumed */
  147. /* its size to be whatever we were compiled for. */
  148.  
  149. mov r2, #0x12000000
  150. mov r3, #64
  151. strb r3, [r2, #-1] /* first write 64 to last byte of first 32MB bank */
  152.  
  153. mov r2, #0x14000000
  154. mov r3, #32
  155. strb r3, [r2, #-1] /* now write 32 to last byte of second 32MB bank */
  156.  
  157. /* now the last word of the first 32MB bank tells you the RAM size */
  158. /* since on a 32MB model both writes will touch the same actual location */
  159. /* this is read later on in boot */
  160. #endif
  161.  
  162. mov r2, #0x40000000
  163. ldr r3, =remap_start
  164. ldr r4, =remap_end
  165.  
  166. and r6, pc, #0xff000000 /* adjust for execute address */
  167. orr r3, r3, r6
  168. orr r4, r4, r6
  169.  
  170. /* copy the code to 0x40000000 */
  171. 1:
  172. ldr r5, [r3], #4
  173. str r5, [r2], #4
  174. cmp r3, r4
  175. blo 1b
  176.  
  177. ldr r4, =MMAP_FLAGS
  178. orr r4, r4, r6 /* adjust for execute address */
  179. ldr r3, =MMAP_PHYS
  180. ldr r2, =MMAP_MASK /* ldr is more flexible */
  181. ldr r1, =MMAP_LOG
  182. mov pc, #0x40000000
  183.  
  184. remap_start:
  185. str r2, [r1]
  186. str r4, [r3]
  187. ldr r1, L_post_remap
  188. bx r1
  189. L_post_remap:
  190. .word remap_end
  191. remap_end:
  192.  
  193. cmp r0, #0x55
  194. ldr r4, =COP_CTRL
  195. /* Wakeup co-processor to let it do remappings */
  196. moveq r3, #WAKE
  197. /* Sleep us (co-processor) and wait for CPU to do kernel initialization */
  198. movne r3, #SLEEP
  199. str r3, [r4]
  200. nop
  201. nop
  202. nop
  203.  
  204. /* Jump to co-processor init */
  205. ldrne pc, =cop_init
  206.  
  207. cpu_init:
  208. /* Wait for COP to go to sleep before proceeding */
  209. ldr r4, =COP_STATUS
  210. 1:
  211. ldr r3, [r4]
  212. tst r3, #COPSLEEPING
  213. beq 1b
  214.  
  215. /* Vectors and IRAM copy is done first since they are reclaimed for
  216. * other uninitialized sections */
  217.  
  218. /* Copy exception handler code to address 0 */
  219. ldr r2, =_vectorsstart
  220. ldr r3, =_vectorsend
  221. ldr r4, =_vectorscopy
  222. 1:
  223. cmp r3, r2
  224. ldrhi r5, [r4], #4
  225. strhi r5, [r2], #4
  226. bhi 1b
  227.  
  228. /* Copy the IRAM */
  229. ldr r2, =_iramcopy
  230. ldr r3, =_iramstart
  231. ldr r4, =_iramend
  232. 1:
  233. cmp r4, r3
  234. ldrhi r5, [r2], #4
  235. strhi r5, [r3], #4
  236. bhi 1b
  237.  
  238. #ifdef HAVE_INIT_ATTR
  239. /* copy init code to codec buffer */
  240. ldr r2, =_initstart
  241. ldr r3, =_initend
  242. ldr r4, =_initcopy
  243.  
  244. 1:
  245. cmp r3, r2
  246. ldrhi r5, [r4], #4
  247. strhi r5, [r2], #4
  248. bhi 1b
  249. #endif
  250.  
  251. /* Zero out IBSS */
  252. ldr r2, =_iedata
  253. ldr r3, =_iend
  254. mov r4, #0
  255. 1:
  256. cmp r3, r2
  257. strhi r4, [r2], #4
  258. bhi 1b
  259.  
  260. /* Initialise bss section to zero */
  261. ldr r2, =_edata
  262. ldr r3, =_end
  263. mov r4, #0
  264. 1:
  265. cmp r3, r2
  266. strhi r4, [r2], #4
  267. bhi 1b
  268.  
  269. /* Load stack munge value */
  270. ldr r4, =0xdeadbeef
  271.  
  272. #if NUM_CORES > 1
  273. /* Set up idle stack and munge it with 0xdeadbeef */
  274. ldr r2, =cpu_idlestackbegin
  275. ldr r3, =cpu_idlestackend
  276. 1:
  277. cmp r3, r2
  278. strhi r4, [r2], #4
  279. bhi 1b
  280. #endif
  281.  
  282. /* Set up stack for IRQ mode */
  283. msr cpsr_c, #0x92 /* IRQ disabled, FIQ enabled */
  284. ldr sp, =irq_stack
  285. /* Set up stack for FIQ mode */
  286. msr cpsr_c, #0xd1 /* IRQ/FIQ disabled */
  287. ldr sp, =fiq_stack
  288.  
  289. /* Let svc, abort and undefined modes use irq stack */
  290. msr cpsr_c, #0xd3 /* IRQ/FIQ disabled */
  291. ldr sp, =irq_stack
  292. msr cpsr_c, #0xd7 /* IRQ/FIQ disabled */
  293. ldr sp, =irq_stack
  294. msr cpsr_c, #0xdb /* IRQ/FIQ disabled */
  295. ldr sp, =irq_stack
  296.  
  297. /* Switch to sys mode */
  298. msr cpsr_c, #0xdf
  299.  
  300. /* Set up some stack and munge it with 0xdeadbeef */
  301. ldr r2, =stackbegin
  302. ldr sp, =stackend
  303. 1:
  304. cmp sp, r2
  305. strhi r4, [r2], #4
  306. bhi 1b
  307.  
  308. /* Delay waking the COP until thread initialization is complete unless dual-core
  309. support is not enabled in which case the cop_main function does not perform
  310. any kernel or thread initialization. It's just a trivial sleep loop. */
  311. #if NUM_CORES == 1
  312. ldr r4, =COP_CTRL
  313. mov r3, #WAKE
  314. str r3, [r4]
  315. #endif
  316.  
  317. ldr pc, =main
  318. /* main() should never return */
  319.  
  320. cop_init:
  321. #if NUM_CORES > 1
  322. /* Wait for CPU to go to sleep at the end of its kernel init */
  323. ldr r4, =CPU_STATUS
  324. 1:
  325. ldr r3, [r4]
  326. tst r3, #CPUSLEEPING
  327. beq 1b
  328. #endif
  329.  
  330. /* Set up stack for IRQ mode */
  331. msr cpsr_c, #0x92 /* IRQ disabled, FIQ enabled */
  332. ldr sp, =cop_irq_stack
  333. /* Set up stack for FIQ mode */
  334. msr cpsr_c, #0xd1 /* IRQ/FIQ disabled */
  335. ldr sp, =cop_fiq_stack
  336.  
  337. /* Let svc, abort and undefined modes use irq stack */
  338. msr cpsr_c, #0xd3 /* IRQ/FIQ disabled */
  339. ldr sp, =cop_irq_stack
  340. msr cpsr_c, #0xd7 /* IRQ/FIQ disabled */
  341. ldr sp, =cop_irq_stack
  342. msr cpsr_c, #0xdb /* IRQ/FIQ disabled */
  343. ldr sp, =cop_irq_stack
  344.  
  345. /* Switch to sys mode */
  346. msr cpsr_c, #0xdf
  347.  
  348. /* Set up idle stack for COP and munge it with 0xdeadbeef */
  349. ldr sp, =cop_idlestackend
  350. ldr r2, =cop_idlestackbegin
  351. ldr r4, =0xdeadbeef
  352. 2:
  353. cmp sp, r2
  354. strhi r4, [r2], #4
  355. bhi 2b
  356.  
  357. /* Run cop_main() in apps/main.c */
  358. ldr pc, =cop_main
  359.  
  360. /* Exception handlers. Will be copied to address 0 after memory remapping */
  361. .section .vectors,"aw"
  362. ldr pc, [pc, #24]
  363. ldr pc, [pc, #24]
  364. ldr pc, [pc, #24]
  365. ldr pc, [pc, #24]
  366. ldr pc, [pc, #24]
  367. ldr pc, [pc, #24]
  368. ldr pc, [pc, #24]
  369. ldr pc, [pc, #24]
  370.  
  371. /* Exception vectors */
  372. .global vectors
  373. vectors:
  374. .word start
  375. .word undef_instr_handler
  376. .word software_int_handler
  377. .word prefetch_abort_handler
  378. .word data_abort_handler
  379. .word reserved_handler
  380. .word irq_handler
  381. .word fiq_handler
  382.  
  383. .text
  384.  
  385. /* All illegal exceptions call into UIE with exception address as first
  386. parameter. This is calculated differently depending on which exception
  387. we're in. Second parameter is exception number, used for a string lookup
  388. in UIE.
  389. */
  390. undef_instr_handler:
  391. sub r0, lr, #4
  392. mov r1, #0
  393. b UIE
  394.  
  395. /* We run sys mode most of the time, and should never see a software
  396. exception being thrown. Make it illegal and call UIE.
  397. */
  398. software_int_handler:
  399. reserved_handler:
  400. sub r0, lr, #4
  401. mov r1, #4
  402. b UIE
  403.  
  404. prefetch_abort_handler:
  405. sub r0, lr, #4
  406. mov r1, #1
  407. b UIE
  408.  
  409. #if defined(HAVE_BOOTDATA) && !defined(BOOTLOADER)
  410. /* boot data structure */
  411. put_boot_data_here
  412. #endif
  413.  
  414. /* Align stacks to cache line boundary */
  415. .balign 32
  416.  
  417. /* 256 words of IRQ stack */
  418. .space 256*4
  419. irq_stack:
  420.  
  421. /* 256 words of COP IRQ stack */
  422. .space 256*4
  423. cop_irq_stack:
  424.  
  425. /* 256 words of FIQ stack */
  426. .space 256*4
  427. fiq_stack:
  428.  
  429. /* We'll need this soon - just reserve the symbol */
  430. #if 0
  431. /* 256 words of COP FIQ stack */
  432. .space 256*4
  433. #endif
  434. cop_fiq_stack:
  435.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement