2006-08-31 19:45:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-08-31 19:45:05 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
|
|
|
|
.section .init.text,"ax",%progbits
|
|
|
|
|
|
|
|
.global start
|
|
|
|
start:
|
|
|
|
|
|
|
|
/* PortalPlayer bootloader and startup code based on startup.s from the iPodLinux
|
|
|
|
* loader
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
|
|
|
|
* Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#if CONFIG_CPU == PP5002
|
2007-11-27 01:20:26 +00:00
|
|
|
.equ PROC_ID, 0xc4000000
|
|
|
|
.equ CPU_ICLR, 0xcf001028
|
|
|
|
.equ CPU_CTRL, 0xcf004054
|
|
|
|
.equ COP_ICLR, 0xcf001038
|
|
|
|
.equ COP_CTRL, 0xcf004058
|
|
|
|
.equ CPU_STATUS, 0xcf004050
|
|
|
|
.equ COP_STATUS, 0xcf004050
|
|
|
|
.equ SLEEP, 0x000000ca
|
|
|
|
.equ WAKE, 0x000000ce
|
|
|
|
.equ CPUSLEEPING, 0x00008000
|
|
|
|
.equ COPSLEEPING, 0x00004000
|
|
|
|
.equ CACHE_CTRL, 0xcf004024
|
|
|
|
.equ MMAP_LOG, 0xf000f000 /* MMAP0 */
|
|
|
|
.equ MMAP_PHYS, 0xf000f004
|
2007-10-04 04:53:01 +00:00
|
|
|
#if MEM > 32
|
2007-11-27 01:20:26 +00:00
|
|
|
.equ MMAP_MASK, 0x00003c00
|
2007-10-04 04:53:01 +00:00
|
|
|
#else
|
2007-11-27 01:20:26 +00:00
|
|
|
.equ MMAP_MASK, 0x00003e00
|
2007-10-04 04:53:01 +00:00
|
|
|
#endif
|
2007-11-27 01:20:26 +00:00
|
|
|
.equ MMAP_FLAGS, 0x00003f84
|
2006-08-31 19:45:05 +00:00
|
|
|
#else
|
2007-11-27 01:20:26 +00:00
|
|
|
.equ PROC_ID, 0x60000000
|
|
|
|
.equ CPU_ICLR, 0x60004028
|
|
|
|
.equ CPU_CTRL, 0x60007000
|
|
|
|
.equ CPU_STATUS, 0x60007000
|
|
|
|
.equ COP_ICLR, 0x60004038
|
|
|
|
.equ COP_CTRL, 0x60007004
|
|
|
|
.equ COP_STATUS, 0x60007004
|
|
|
|
.equ SLEEP, 0x80000000
|
|
|
|
.equ WAKE, 0x00000000
|
|
|
|
.equ CPUSLEEPING, 0x80000000
|
|
|
|
.equ COPSLEEPING, 0x80000000
|
|
|
|
.equ CACHE_CTRL, 0x6000c000
|
|
|
|
.equ MMAP_LOG, 0xf000f000 /* MMAP0 */
|
|
|
|
.equ MMAP_PHYS, 0xf000f004
|
2007-10-04 04:53:01 +00:00
|
|
|
#if MEM > 32
|
2007-11-27 01:20:26 +00:00
|
|
|
.equ MMAP_MASK, 0x00003c00
|
2007-10-04 04:53:01 +00:00
|
|
|
#else
|
2007-11-27 01:20:26 +00:00
|
|
|
.equ MMAP_MASK, 0x00003e00
|
2007-10-04 04:53:01 +00:00
|
|
|
#endif
|
2007-11-27 01:20:26 +00:00
|
|
|
.equ MMAP_FLAGS, 0x00000f84
|
2006-08-31 19:45:05 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
|
2006-08-31 19:45:05 +00:00
|
|
|
b pad_skip
|
2006-11-22 00:49:16 +00:00
|
|
|
|
2009-05-12 20:41:44 +00:00
|
|
|
.space 6*4 /* pad to offset 0x20 */
|
|
|
|
|
|
|
|
.ascii "Rockbox" /* signature for bootloader checking osos */
|
|
|
|
.byte 1 /* osos boot version, only 1 exists for now */
|
|
|
|
|
|
|
|
.space 56*4 /* (more than enough) space for exception vectors and mi4 magic */
|
2006-11-22 00:49:16 +00:00
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
pad_skip:
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Find out which processor we are - r0 should be preserved for the
|
|
|
|
* duration of the init to avoid constant reloading of the processor ID.
|
|
|
|
* For each stage, CPU proceeds first, then COP.
|
|
|
|
*/
|
|
|
|
ldr r0, =PROC_ID
|
|
|
|
ldrb r0, [r0]
|
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* We need to remap memory from wherever SDRAM is mapped natively, to
|
|
|
|
base address 0, so we can put our exception vectors there. We don't
|
|
|
|
want to do this remapping while executing from SDRAM, so we copy the
|
|
|
|
remapping code to IRAM, then execute from there. Hence, the following
|
|
|
|
code is compiled for address 0, but is currently executing at either
|
|
|
|
0x28000000 or 0x10000000, depending on chipset version. Do not use any
|
|
|
|
absolute addresses until remapping has been done. */
|
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Cores are stepped though the init in turn: CPU then COP. The the remap
|
|
|
|
stage is completed by each core in turn and then the COP waits for the
|
|
|
|
CPU to finish initializing its kernel where the CPU will wake the COP
|
|
|
|
and wait for the COP to finish. This ensures no threading activity
|
|
|
|
starts until it is safe. */
|
|
|
|
cmp r0, #0x55
|
|
|
|
|
|
|
|
/* mask all interrupt sources before setting anything up */
|
|
|
|
ldreq r2, =CPU_ICLR
|
|
|
|
ldrne r2, =COP_ICLR
|
|
|
|
mvn r1, #0
|
|
|
|
str r1, [r2]
|
|
|
|
|
|
|
|
/* put us (co-processor) to sleep and wait for CPU to remap */
|
|
|
|
ldrne r2, =COP_CTRL
|
|
|
|
movne r1, #SLEEP
|
|
|
|
strne r1, [r2]
|
2007-11-27 01:20:26 +00:00
|
|
|
nop
|
|
|
|
nop
|
|
|
|
nop
|
2007-09-28 10:20:02 +00:00
|
|
|
|
|
|
|
/* wait for co-processor to sleep then CPU can begin its remapping */
|
|
|
|
ldreq r2, =COP_STATUS
|
|
|
|
1:
|
|
|
|
ldreq r1, [r2]
|
2007-11-27 01:20:26 +00:00
|
|
|
tsteq r1, #COPSLEEPING
|
2007-09-28 10:20:02 +00:00
|
|
|
beq 1b
|
|
|
|
|
|
|
|
/* disable cache and local interrupt vectors - it is really not desireable
|
|
|
|
to have them enabled here */
|
|
|
|
ldr r2, =CACHE_CTRL
|
|
|
|
mov r1, #0
|
|
|
|
str r1, [r2]
|
|
|
|
|
|
|
|
mov r2, #0x40000000
|
|
|
|
ldr r3, =remap_start
|
|
|
|
ldr r4, =remap_end
|
|
|
|
|
|
|
|
and r6, pc, #0xff000000 /* adjust for execute address */
|
|
|
|
orr r3, r3, r6
|
|
|
|
orr r4, r4, r6
|
2006-08-31 19:45:05 +00:00
|
|
|
|
|
|
|
/* copy the code to 0x40000000 */
|
|
|
|
1:
|
2007-09-28 10:20:02 +00:00
|
|
|
ldr r5, [r3], #4
|
|
|
|
str r5, [r2], #4
|
|
|
|
cmp r3, r4
|
|
|
|
blo 1b
|
|
|
|
|
2007-10-04 04:53:01 +00:00
|
|
|
ldr r4, =MMAP_FLAGS
|
2007-09-28 10:20:02 +00:00
|
|
|
orr r4, r4, r6 /* adjust for execute address */
|
2007-10-04 04:53:01 +00:00
|
|
|
ldr r3, =MMAP_PHYS
|
|
|
|
ldr r2, =MMAP_MASK /* ldr is more flexible */
|
|
|
|
ldr r1, =MMAP_LOG
|
2006-08-31 19:45:05 +00:00
|
|
|
mov pc, #0x40000000
|
|
|
|
|
|
|
|
remap_start:
|
2007-09-28 10:20:02 +00:00
|
|
|
str r2, [r1]
|
|
|
|
str r4, [r3]
|
|
|
|
ldr r1, L_post_remap
|
|
|
|
mov pc, r1
|
|
|
|
L_post_remap:
|
|
|
|
.word remap_end
|
2006-08-31 19:45:05 +00:00
|
|
|
remap_end:
|
|
|
|
|
|
|
|
cmp r0, #0x55
|
2007-09-28 10:20:02 +00:00
|
|
|
ldr r4, =COP_CTRL
|
|
|
|
/* Wakeup co-processor to let it do remappings */
|
|
|
|
moveq r3, #WAKE
|
|
|
|
/* Sleep us (co-processor) and wait for CPU to do kernel initialization */
|
2007-08-01 20:26:04 +00:00
|
|
|
movne r3, #SLEEP
|
2007-09-28 10:20:02 +00:00
|
|
|
str r3, [r4]
|
2007-11-27 01:20:26 +00:00
|
|
|
nop
|
|
|
|
nop
|
|
|
|
nop
|
2006-08-31 19:45:05 +00:00
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Jump to co-processor init */
|
2007-08-01 20:26:04 +00:00
|
|
|
ldrne pc, =cop_init
|
2006-08-31 19:45:05 +00:00
|
|
|
|
2006-12-19 11:33:53 +00:00
|
|
|
cpu_init:
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Wait for COP to go to sleep before proceeding */
|
2006-12-19 11:33:53 +00:00
|
|
|
ldr r4, =COP_STATUS
|
|
|
|
1:
|
|
|
|
ldr r3, [r4]
|
2007-11-27 01:20:26 +00:00
|
|
|
tst r3, #COPSLEEPING
|
2006-12-19 11:33:53 +00:00
|
|
|
beq 1b
|
2009-02-20 02:33:40 +00:00
|
|
|
|
|
|
|
/* Vectors and IRAM copy is done first since they are reclaimed for
|
|
|
|
* other uninitialized sections */
|
2007-09-28 10:20:02 +00:00
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* Copy exception handler code to address 0 */
|
|
|
|
ldr r2, =_vectorsstart
|
|
|
|
ldr r3, =_vectorsend
|
|
|
|
ldr r4, =_vectorscopy
|
|
|
|
1:
|
|
|
|
cmp r3, r2
|
|
|
|
ldrhi r5, [r4], #4
|
|
|
|
strhi r5, [r2], #4
|
|
|
|
bhi 1b
|
2009-02-20 02:33:40 +00:00
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* Copy the IRAM */
|
|
|
|
ldr r2, =_iramcopy
|
|
|
|
ldr r3, =_iramstart
|
|
|
|
ldr r4, =_iramend
|
|
|
|
1:
|
|
|
|
cmp r4, r3
|
|
|
|
ldrhi r5, [r2], #4
|
|
|
|
strhi r5, [r3], #4
|
|
|
|
bhi 1b
|
|
|
|
|
2009-02-20 02:33:40 +00:00
|
|
|
/* Zero out IBSS */
|
|
|
|
ldr r2, =_iedata
|
|
|
|
ldr r3, =_iend
|
|
|
|
mov r4, #0
|
|
|
|
1:
|
|
|
|
cmp r3, r2
|
|
|
|
strhi r4, [r2], #4
|
|
|
|
bhi 1b
|
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* Initialise bss section to zero */
|
|
|
|
ldr r2, =_edata
|
|
|
|
ldr r3, =_end
|
|
|
|
mov r4, #0
|
|
|
|
1:
|
|
|
|
cmp r3, r2
|
|
|
|
strhi r4, [r2], #4
|
|
|
|
bhi 1b
|
2007-09-28 10:20:02 +00:00
|
|
|
|
|
|
|
/* Load stack munge value */
|
|
|
|
ldr r4, =0xdeadbeef
|
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* Set up some stack and munge it with 0xdeadbeef */
|
|
|
|
ldr r2, =stackbegin
|
2007-09-28 10:20:02 +00:00
|
|
|
ldr sp, =stackend
|
|
|
|
1:
|
|
|
|
cmp sp, r2
|
|
|
|
strhi r4, [r2], #4
|
|
|
|
bhi 1b
|
|
|
|
|
|
|
|
#if NUM_CORES > 1
|
|
|
|
/* Set up idle stack and munge it with 0xdeadbeef */
|
|
|
|
ldr r2, =cpu_idlestackbegin
|
|
|
|
ldr r3, =cpu_idlestackend
|
2006-08-31 19:45:05 +00:00
|
|
|
1:
|
|
|
|
cmp r3, r2
|
|
|
|
strhi r4, [r2], #4
|
|
|
|
bhi 1b
|
2007-09-28 10:20:02 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* Set up stack for IRQ mode */
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0x92 /* IRQ disabled, FIQ enabled */
|
2006-08-31 19:45:05 +00:00
|
|
|
ldr sp, =irq_stack
|
|
|
|
/* Set up stack for FIQ mode */
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0xd1 /* IRQ/FIQ disabled */
|
2006-08-31 19:45:05 +00:00
|
|
|
ldr sp, =fiq_stack
|
|
|
|
/* Let abort and undefined modes use IRQ stack */
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0xd7 /* IRQ/FIQ disabled */
|
2006-08-31 19:45:05 +00:00
|
|
|
ldr sp, =irq_stack
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0xdb /* IRQ/FIQ disabled */
|
2006-08-31 19:45:05 +00:00
|
|
|
ldr sp, =irq_stack
|
2007-08-01 20:59:27 +00:00
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Switch back to supervisor mode */
|
2006-08-31 19:45:05 +00:00
|
|
|
msr cpsr_c, #0xd3
|
2007-09-28 10:20:02 +00:00
|
|
|
|
|
|
|
/* Delay waking the COP until thread initialization is complete unless dual-core
|
|
|
|
support is not enabled in which case the cop_main function does not perform
|
|
|
|
any kernel or thread initialization. It's just a trivial sleep loop. */
|
|
|
|
#if NUM_CORES == 1
|
|
|
|
ldr r4, =COP_CTRL
|
|
|
|
mov r3, #WAKE
|
|
|
|
str r3, [r4]
|
|
|
|
#endif
|
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
bl main
|
|
|
|
/* main() should never return */
|
|
|
|
|
|
|
|
cop_init:
|
2007-09-28 10:20:02 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
/* Wait for CPU to go to sleep at the end of its kernel init */
|
|
|
|
ldr r4, =CPU_STATUS
|
2006-12-19 11:33:53 +00:00
|
|
|
1:
|
2007-09-28 10:20:02 +00:00
|
|
|
ldr r3, [r4]
|
2007-11-27 01:20:26 +00:00
|
|
|
tst r3, #CPUSLEEPING
|
2007-09-28 10:20:02 +00:00
|
|
|
beq 1b
|
2007-09-29 06:17:33 +00:00
|
|
|
#endif
|
2006-12-19 11:33:53 +00:00
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Set up idle stack for COP and munge it with 0xdeadbeef */
|
|
|
|
ldr sp, =cop_idlestackend
|
2007-09-29 06:17:33 +00:00
|
|
|
ldr r2, =cop_idlestackbegin
|
2006-08-31 19:45:05 +00:00
|
|
|
ldr r4, =0xdeadbeef
|
|
|
|
2:
|
2007-09-28 10:20:02 +00:00
|
|
|
cmp sp, r2
|
2006-08-31 19:45:05 +00:00
|
|
|
strhi r4, [r2], #4
|
|
|
|
bhi 2b
|
|
|
|
|
2007-03-04 20:06:41 +00:00
|
|
|
/* Set up stack for IRQ mode */
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0x92 /* IRQ disabled, FIQ enabled */
|
2007-03-04 20:06:41 +00:00
|
|
|
ldr sp, =cop_irq_stack
|
|
|
|
/* Set up stack for FIQ mode */
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0xd1 /* IRQ/FIQ disabled */
|
|
|
|
ldr sp, =cop_fiq_stack
|
2007-03-04 20:06:41 +00:00
|
|
|
|
|
|
|
/* Let abort and undefined modes use IRQ stack */
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0xd7 /* IRQ/FIQ disabled */
|
2007-03-04 20:06:41 +00:00
|
|
|
ldr sp, =cop_irq_stack
|
2007-08-01 20:26:04 +00:00
|
|
|
msr cpsr_c, #0xdb /* IRQ/FIQ disabled */
|
2007-03-04 20:06:41 +00:00
|
|
|
ldr sp, =cop_irq_stack
|
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Switch back to supervisor mode */
|
2007-08-01 20:59:27 +00:00
|
|
|
msr cpsr_c, #0xd3
|
2006-12-19 11:33:53 +00:00
|
|
|
|
|
|
|
/* Run cop_main() in apps/main.c */
|
2006-08-31 19:45:05 +00:00
|
|
|
bl cop_main
|
2007-09-28 10:20:02 +00:00
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* Exception handlers. Will be copied to address 0 after memory remapping */
|
|
|
|
.section .vectors,"aw"
|
|
|
|
ldr pc, [pc, #24]
|
|
|
|
ldr pc, [pc, #24]
|
|
|
|
ldr pc, [pc, #24]
|
|
|
|
ldr pc, [pc, #24]
|
|
|
|
ldr pc, [pc, #24]
|
|
|
|
ldr pc, [pc, #24]
|
|
|
|
ldr pc, [pc, #24]
|
|
|
|
ldr pc, [pc, #24]
|
|
|
|
|
|
|
|
/* Exception vectors */
|
|
|
|
.global vectors
|
|
|
|
vectors:
|
|
|
|
.word start
|
|
|
|
.word undef_instr_handler
|
|
|
|
.word software_int_handler
|
|
|
|
.word prefetch_abort_handler
|
|
|
|
.word data_abort_handler
|
|
|
|
.word reserved_handler
|
|
|
|
.word irq_handler
|
2007-10-06 22:27:27 +00:00
|
|
|
.word fiq_handler
|
2006-08-31 19:45:05 +00:00
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
/* All illegal exceptions call into UIE with exception address as first
|
|
|
|
parameter. This is calculated differently depending on which exception
|
|
|
|
we're in. Second parameter is exception number, used for a string lookup
|
|
|
|
in UIE.
|
|
|
|
*/
|
|
|
|
undef_instr_handler:
|
2010-01-24 15:04:21 +00:00
|
|
|
sub r0, lr, #4
|
2006-08-31 19:45:05 +00:00
|
|
|
mov r1, #0
|
|
|
|
b UIE
|
|
|
|
|
|
|
|
/* We run supervisor mode most of the time, and should never see a software
|
|
|
|
exception being thrown. Perhaps make it illegal and call UIE?
|
|
|
|
*/
|
|
|
|
software_int_handler:
|
|
|
|
reserved_handler:
|
|
|
|
movs pc, lr
|
|
|
|
prefetch_abort_handler:
|
|
|
|
sub r0, lr, #4
|
|
|
|
mov r1, #1
|
|
|
|
b UIE
|
|
|
|
|
|
|
|
data_abort_handler:
|
|
|
|
sub r0, lr, #8
|
|
|
|
mov r1, #2
|
|
|
|
b UIE
|
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Align stacks to cache line boundary */
|
2007-11-27 01:20:26 +00:00
|
|
|
.balign 32
|
2007-09-28 10:20:02 +00:00
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* 256 words of IRQ stack */
|
|
|
|
.space 256*4
|
|
|
|
irq_stack:
|
|
|
|
|
2007-03-04 20:06:41 +00:00
|
|
|
/* 256 words of COP IRQ stack */
|
|
|
|
.space 256*4
|
|
|
|
cop_irq_stack:
|
|
|
|
|
2006-08-31 19:45:05 +00:00
|
|
|
/* 256 words of FIQ stack */
|
|
|
|
.space 256*4
|
|
|
|
fiq_stack:
|
2007-08-01 20:26:04 +00:00
|
|
|
|
|
|
|
/* We'll need this soon - just reserve the symbol */
|
|
|
|
#if 0
|
|
|
|
/* 256 words of COP FIQ stack */
|
|
|
|
.space 256*4
|
|
|
|
#endif
|
|
|
|
cop_fiq_stack:
|