diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-11-28 23:40:57 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-11-28 23:40:57 +0000 |
commit | 104b81ea9a1a9c7b67e9e060fef4d0a97a547b7b (patch) | |
tree | 5234c4b9fe280b128bac7bc5ccbbeb7e7ac90915 | |
parent | d371141493a6863890e3867e5fef4f9c1b9d3add (diff) | |
download | rockbox-104b81ea9a1a9c7b67e9e060fef4d0a97a547b7b.tar.gz rockbox-104b81ea9a1a9c7b67e9e060fef4d0a97a547b7b.zip |
Fixed self-extracting loader: (1) Proper startup code, ensuring the stack pointer is set to the desired location. (2) Code cleanup.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8103 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/decompressor/Makefile | 2 | ||||
-rw-r--r-- | firmware/decompressor/decompressor.c | 33 | ||||
-rwxr-xr-x | firmware/decompressor/startup.S | 57 |
3 files changed, 68 insertions, 24 deletions
diff --git a/firmware/decompressor/Makefile b/firmware/decompressor/Makefile index 99e91aa35e..29a78523ea 100644 --- a/firmware/decompressor/Makefile +++ b/firmware/decompressor/Makefile | |||
@@ -21,7 +21,7 @@ MEMORYSIZE = 2 | |||
21 | 21 | ||
22 | LDS := link.lds | 22 | LDS := link.lds |
23 | LINKFILE = $(OBJDIR)/linkage.lds | 23 | LINKFILE = $(OBJDIR)/linkage.lds |
24 | OBJS := $(OBJDIR)/decompressor.o $(OBJDIR)/rockboxucl.o | 24 | OBJS := $(OBJDIR)/decompressor.o $(OBJDIR)/rockboxucl.o $(OBJDIR)/startup.o |
25 | 25 | ||
26 | CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns | 26 | CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns |
27 | 27 | ||
diff --git a/firmware/decompressor/decompressor.c b/firmware/decompressor/decompressor.c index 1223ff2f05..9cd7d5998e 100644 --- a/firmware/decompressor/decompressor.c +++ b/firmware/decompressor/decompressor.c | |||
@@ -31,7 +31,8 @@ extern char imgstart[], imgend[]; | |||
31 | extern char loadaddress[], dramend[]; | 31 | extern char loadaddress[], dramend[]; |
32 | 32 | ||
33 | /* Prototypes */ | 33 | /* Prototypes */ |
34 | void start(void) __attribute__ ((section (".start"))); | 34 | extern void start(void); |
35 | |||
35 | void main(void) ICODE_ATTR; | 36 | void main(void) ICODE_ATTR; |
36 | int ucl_nrv2e_decompress_8(const unsigned char *src, unsigned char *dst, | 37 | int ucl_nrv2e_decompress_8(const unsigned char *src, unsigned char *dst, |
37 | unsigned long *dst_len) ICODE_ATTR; | 38 | unsigned long *dst_len) ICODE_ATTR; |
@@ -45,22 +46,6 @@ void (*vbr[]) (void) __attribute__ ((section (".vectors"))) = | |||
45 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | 46 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
46 | }; | 47 | }; |
47 | 48 | ||
48 | /* Inline copy function */ | ||
49 | static inline void longcopy(long *dst, long *dst_end, const long *src) | ||
50 | __attribute__ ((always_inline)); | ||
51 | static inline void longcopy(long *dst, long *dst_end, const long *src) | ||
52 | { | ||
53 | while (dst < dst_end) | ||
54 | *dst++ = *src++; | ||
55 | } | ||
56 | |||
57 | /* Entry point */ | ||
58 | void start(void) | ||
59 | { | ||
60 | longcopy((long *)iramstart, (long *)iramend, (long *)iramcopy); | ||
61 | main(); | ||
62 | } | ||
63 | |||
64 | /** All subsequent functions are executed from IRAM **/ | 49 | /** All subsequent functions are executed from IRAM **/ |
65 | 50 | ||
66 | /* Thinned out version of the UCL 2e decompression sourcecode | 51 | /* Thinned out version of the UCL 2e decompression sourcecode |
@@ -133,18 +118,20 @@ void main(void) | |||
133 | { | 118 | { |
134 | unsigned long dst_len; /* dummy */ | 119 | unsigned long dst_len; /* dummy */ |
135 | unsigned long img_len = (unsigned long)(imgend - imgstart); | 120 | unsigned long img_len = (unsigned long)(imgend - imgstart); |
136 | 121 | unsigned long *src = (unsigned long *)imgstart; | |
137 | longcopy((long *)(dramend - img_len), (long *) dramend, | 122 | unsigned long *dst = (unsigned long *)(dramend - img_len); |
138 | (long *) imgstart); | 123 | |
139 | 124 | do | |
125 | *dst++ = *src++; | ||
126 | while (dst < (unsigned long *)dramend); | ||
127 | |||
140 | ucl_nrv2e_decompress_8(dramend - img_len + UCL_HEADER, | 128 | ucl_nrv2e_decompress_8(dramend - img_len + UCL_HEADER, |
141 | loadaddress, &dst_len); | 129 | loadaddress, &dst_len); |
142 | 130 | ||
143 | asm( | 131 | asm( |
144 | "mov.l @%0+,r0 \n" | 132 | "mov.l @%0+,r0 \n" |
145 | "mov.l @%0+,r15 \n" | ||
146 | "jmp @r0 \n" | 133 | "jmp @r0 \n" |
147 | "nop \n" | 134 | "mov.l @%0+,r15 \n" |
148 | : : "r"(loadaddress) : "r0" | 135 | : : "r"(loadaddress) : "r0" |
149 | ); | 136 | ); |
150 | } | 137 | } |
diff --git a/firmware/decompressor/startup.S b/firmware/decompressor/startup.S new file mode 100755 index 0000000000..62efef9cc3 --- /dev/null +++ b/firmware/decompressor/startup.S | |||
@@ -0,0 +1,57 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 by Jens Arnold | ||
11 | * based on crt0.S by Linus Nielsen Feltzing | ||
12 | * | ||
13 | * All files in this archive are subject to the GNU General Public License. | ||
14 | * See the file COPYING in the source tree root for full license agreement. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | .section .start,"ax",@progbits | ||
21 | .global _start | ||
22 | _start: | ||
23 | /* copy the .iram section */ | ||
24 | mov.l .iramcopy_k,r0 | ||
25 | mov.l .iram_k,r1 | ||
26 | mov.l .iramend_k,r2 | ||
27 | /* Note: We cannot put a PC relative load into the delay slot of a 'bra' | ||
28 | instruction (the offset would be wrong), but there is nothing else to | ||
29 | do before the loop, so the delay slot would be 'nop'. The cmp / bf | ||
30 | sequence is the same length, but more efficient. */ | ||
31 | cmp/hi r1,r2 | ||
32 | bf .noiramcopy | ||
33 | .iramloop: | ||
34 | mov.l @r0+,r3 | ||
35 | mov.l r3,@r1 | ||
36 | add #4,r1 | ||
37 | cmp/hi r1,r2 | ||
38 | bt .iramloop | ||
39 | .noiramcopy: | ||
40 | |||
41 | /* call the mainline */ | ||
42 | mov.l .main_k,r0 | ||
43 | mov.l .stackend_k,r15 | ||
44 | jmp @r0 | ||
45 | nop | ||
46 | |||
47 | .align 2 | ||
48 | .iramcopy_k: | ||
49 | .long _iramcopy | ||
50 | .iram_k: | ||
51 | .long _iramstart | ||
52 | .iramend_k: | ||
53 | .long _iramend | ||
54 | .stackend_k: | ||
55 | .long _stackend | ||
56 | .main_k: | ||
57 | .long _main | ||