]>
git.zerfleddert.de Git - proxmark3-svn/blob - armsrc/start.c
1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, Mar 2006
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // Just vector to AppMain(). This is in its own file so that I can place it
9 // with the linker script.
10 //-----------------------------------------------------------------------------
15 #include "proxmark3.h"
20 static uint8_t *next_free_memory
;
21 extern struct common_area common_area
;
22 extern char __data_src_start__
, __data_start__
, __data_end__
, __bss_start__
, __bss_end__
;
24 static voidpf
inflate_malloc(voidpf opaque
, uInt items
, uInt size
)
26 uint8_t *allocated_memory
;
28 allocated_memory
= next_free_memory
;
29 next_free_memory
+= items
*size
;
30 return allocated_memory
;
33 static void inflate_free(voidpf opaque
, voidpf address
)
38 static void uncompress_data_section(void)
40 z_stream data_section
;
42 next_free_memory
= BigBuf_get_addr();
44 // initialize zstream structure
45 data_section
.next_in
= (uint8_t *) &__data_src_start__
;
46 data_section
.avail_in
= &__data_end__
- &__data_start__
; // uncompressed size. Wrong but doesn't matter.
47 data_section
.next_out
= (uint8_t *) &__data_start__
;
48 data_section
.avail_out
= &__data_end__
- &__data_start__
; // uncompressed size. Correct.
49 data_section
.zalloc
= &inflate_malloc
;
50 data_section
.zfree
= &inflate_free
;
51 data_section
.opaque
= NULL
;
53 // initialize zlib for inflate
54 inflateInit2(&data_section
, 15);
56 // uncompress data segment to RAM
57 inflate(&data_section
, Z_FINISH
);
59 // save the size of the compressed data section
60 common_area
.arg1
= data_section
.total_in
;
63 void __attribute__((section(".startos"))) Vector(void)
65 /* Stack should have been set up by the bootloader */
69 uncompress_data_section();
71 /* Set up (that is: clear) BSS. */
74 while(dst
< end
) *dst
++ = 0;
76 // Set up data segment: Copy from flash to ram
77 // src = &__data_src_start__;
78 // dst = &__data_start__;
79 // end = &__data_end__;
80 // while(dst < end) *dst++ = *src++;