]> git.zerfleddert.de Git - proxmark3-svn/blob - armsrc/start.c
CHG: moved into header files.
[proxmark3-svn] / armsrc / start.c
1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, Mar 2006
3 //
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
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Just vector to AppMain(). This is in its own file so that I can place it
9 // with the linker script.
10 //-----------------------------------------------------------------------------
11
12 #ifndef __START_H
13 #define __START_H
14
15 #include "proxmark3.h"
16 #include "apps.h"
17 #include "zlib.h"
18 #include "BigBuf.h"
19
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__;
23
24 static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size)
25 {
26 uint8_t *allocated_memory;
27
28 allocated_memory = next_free_memory;
29 next_free_memory += items*size;
30 return allocated_memory;
31 }
32
33 static void inflate_free(voidpf opaque, voidpf address)
34 {
35 // nothing to do
36 }
37
38 static void uncompress_data_section(void)
39 {
40 z_stream data_section;
41
42 next_free_memory = BigBuf_get_addr();
43
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;
52
53 // initialize zlib for inflate
54 inflateInit2(&data_section, 15);
55
56 // uncompress data segment to RAM
57 inflate(&data_section, Z_FINISH);
58
59 // save the size of the compressed data section
60 common_area.arg1 = data_section.total_in;
61 }
62
63 void __attribute__((section(".startos"))) Vector(void)
64 {
65 /* Stack should have been set up by the bootloader */
66 // char *src;
67 char *dst, *end;
68
69 uncompress_data_section();
70
71 /* Set up (that is: clear) BSS. */
72 dst = &__bss_start__;
73 end = &__bss_end__;
74 while(dst < end) *dst++ = 0;
75
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++;
81
82 AppMain();
83 }
84 #endif
Impressum, Datenschutz