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 //-----------------------------------------------------------------------------
12 #include "proxmark3.h"
17 static uint8_t *next_free_memory
;
18 extern struct common_area common_area
;
19 extern char __data_src_start__
, __data_start__
, __data_end__
, __bss_start__
, __bss_end__
;
22 static voidpf
inflate_malloc(voidpf opaque
, uInt items
, uInt size
)
24 uint8_t *allocated_memory
;
26 allocated_memory
= next_free_memory
;
27 next_free_memory
+= items
*size
;
28 return allocated_memory
;
32 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
;
64 void __attribute__((section(".startos"))) Vector(void)
66 /* Stack should have been set up by the bootloader */
70 uncompress_data_section();
72 /* Set up (that is: clear) BSS. */
75 while(dst
< end
) *dst
++ = 0;
77 // Set up data segment: Copy from flash to ram
78 // src = &__data_src_start__;
79 // dst = &__data_start__;
80 // end = &__data_end__;
81 // while(dst < end) *dst++ = *src++;