diff options
Diffstat (limited to 'firmware/target/arm/tcc77x/crt0.S')
-rw-r--r-- | firmware/target/arm/tcc77x/crt0.S | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/firmware/target/arm/tcc77x/crt0.S b/firmware/target/arm/tcc77x/crt0.S new file mode 100644 index 0000000000..e4ecb05a4e --- /dev/null +++ b/firmware/target/arm/tcc77x/crt0.S | |||
@@ -0,0 +1,153 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | /* Arm bootloader and startup code based on startup.s from the iPodLinux loader | ||
21 | * | ||
22 | * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org) | ||
23 | * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org> | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | #include "config.h" | ||
28 | #include "cpu.h" | ||
29 | |||
30 | .section .init.text,"ax",%progbits | ||
31 | |||
32 | .global start | ||
33 | |||
34 | /* Telechips firmware files start with a 32-byte header, as part of the code. */ | ||
35 | |||
36 | start: | ||
37 | #ifdef TCCBOOT | ||
38 | /* Add -DTCCBOOT to EXTRA_DEFINES in the bootloader Makefile to | ||
39 | enable building the bootloader to be appended to the end of the | ||
40 | original firmware, dual-booting based on a key-press. | ||
41 | |||
42 | The following two values are filled in by mktccboot. | ||
43 | */ | ||
44 | .word 0 /* Saved entrypoint of original firmware*/ | ||
45 | .word 0 /* Location in RAM of the start of our bootloader */ | ||
46 | #else | ||
47 | ldr pc, =start_loc /* jump to the main entry point */ | ||
48 | |||
49 | .word 0xffff0601 /* Unknown magic */ | ||
50 | .word 0x3a726556 /* "Ver:" */ | ||
51 | .word 0x31373030 /* "0071" */ | ||
52 | .word 0 /* First CRC32 */ | ||
53 | .word 0 /* Unknown - always 0 */ | ||
54 | .word 0 /* Second CRC32 */ | ||
55 | .word 0 /* length of firmware file */ | ||
56 | |||
57 | #ifdef LOGIK_DAX | ||
58 | /* Some original firmwares have 0x40 bytes of zeroes here - we | ||
59 | don't know why, but err on the side of caution and include it | ||
60 | here. */ | ||
61 | .space 0x40 | ||
62 | #endif | ||
63 | #endif | ||
64 | |||
65 | start_loc: | ||
66 | |||
67 | #ifdef BOOTLOADER | ||
68 | #ifdef TCCBOOT | ||
69 | #ifdef LOGIK_DAX | ||
70 | mov r0, #0x80000000 | ||
71 | ldr r0, [r0, #0x300] /* Read GPIO A */ | ||
72 | tst r0, #0x2 | ||
73 | ldrne pc, [pc, #-28] /* Jump to original firmware if HOLD button not pressed */ | ||
74 | #else | ||
75 | #error No bootup key detection implemented for this target | ||
76 | #endif | ||
77 | |||
78 | /* Copy bootloader to safe area - 0x21000000 (DRAM) */ | ||
79 | /* TODO: Adjust this for other targets - DRAM + DRAMSIZE - 0x100000 */ | ||
80 | ldr r0, [pc, #-28] | ||
81 | mov r1, #0x20000000 | ||
82 | add r1, r1, #0x100000 | ||
83 | ldr r2, =_dataend | ||
84 | 1: | ||
85 | cmp r2, r1 | ||
86 | ldrhi r3, [r0], #4 | ||
87 | strhi r3, [r1], #4 | ||
88 | bhi 1b | ||
89 | |||
90 | ldr pc, =copied_start /* jump to the relocated start_loc: */ | ||
91 | |||
92 | copied_start: | ||
93 | #endif | ||
94 | #else | ||
95 | /* We don't use interrupts in the bootloader */ | ||
96 | |||
97 | /* Set up stack for IRQ mode */ | ||
98 | mov r0,#0xd2 | ||
99 | msr cpsr, r0 | ||
100 | ldr sp, =irq_stack | ||
101 | /* Set up stack for FIQ mode */ | ||
102 | mov r0,#0xd1 | ||
103 | msr cpsr, r0 | ||
104 | ldr sp, =fiq_stack | ||
105 | |||
106 | /* Let abort and undefined modes use IRQ stack */ | ||
107 | mov r0,#0xd7 | ||
108 | msr cpsr, r0 | ||
109 | ldr sp, =irq_stack | ||
110 | mov r0,#0xdb | ||
111 | msr cpsr, r0 | ||
112 | ldr sp, =irq_stack | ||
113 | #endif | ||
114 | |||
115 | /* Switch to supervisor mode */ | ||
116 | mov r0,#0xd3 | ||
117 | msr cpsr, r0 | ||
118 | ldr sp, =stackend | ||
119 | |||
120 | /* Initialise bss section to zero */ | ||
121 | ldr r2, =_edata | ||
122 | ldr r3, =_end | ||
123 | mov r4, #0 | ||
124 | 1: | ||
125 | cmp r3, r2 | ||
126 | strhi r4, [r2], #4 | ||
127 | bhi 1b | ||
128 | |||
129 | /* Set up some stack and munge it with 0xdeadbeef */ | ||
130 | ldr sp, =stackend | ||
131 | mov r3, sp | ||
132 | ldr r2, =stackbegin | ||
133 | ldr r4, =0xdeadbeef | ||
134 | 1: | ||
135 | cmp r3, r2 | ||
136 | strhi r4, [r2], #4 | ||
137 | bhi 1b | ||
138 | |||
139 | bl main | ||
140 | /* main() should never return */ | ||
141 | |||
142 | #ifndef BOOTLOADER | ||
143 | /* We don't use interrupts in the bootloader */ | ||
144 | |||
145 | /* 256 words of IRQ stack */ | ||
146 | .space 256*4 | ||
147 | irq_stack: | ||
148 | |||
149 | /* 256 words of FIQ stack */ | ||
150 | .space 256*4 | ||
151 | fiq_stack: | ||
152 | |||
153 | #endif | ||