reworked "lf em 4x50 chk" to use dynamic memory for dictionary
[RRG-proxmark3.git] / armsrc / start.c
blob65d24ff5d1953884da412a869aa5a139b78f32ec
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 //-----------------------------------------------------------------------------
12 #ifndef __START_H
13 #define __START_H
15 #include "proxmark3_arm.h"
16 #include "appmain.h"
17 #ifndef WITH_NO_COMPRESSION
18 #include "lz4.h"
19 #endif
20 #include "BigBuf.h"
21 #include "string.h"
23 extern struct common_area common_area;
24 extern uint32_t __data_src_start__[], __data_start__[], __data_end__[], __bss_start__[], __bss_end__[];
26 #ifndef WITH_NO_COMPRESSION
27 static void uncompress_data_section(void) {
28 int avail_in;
29 memcpy(&avail_in, __data_src_start__, sizeof(int));
30 int avail_out = (uint32_t)__data_end__ - (uint32_t)__data_start__; // uncompressed size. Correct.
31 // uncompress data segment to RAM
32 char *p = (char *)__data_src_start__;
33 int res = LZ4_decompress_safe(p + 4, (char *)__data_start__, avail_in, avail_out);
35 if (res < 0)
36 return;
37 // save the size of the compressed data section
38 common_area.arg1 = avail_in;
40 #endif
42 void __attribute__((section(".startos"))) Vector(void);
43 void Vector(void) {
44 /* Stack should have been set up by the bootloader */
46 if (common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) {
47 /* Initialize common area */
48 memset(&common_area, 0, sizeof(common_area));
49 common_area.magic = COMMON_AREA_MAGIC;
50 common_area.version = 1;
52 common_area.flags.osimage_present = 1;
54 /* Set up data segment: Copy from flash to ram */
55 #ifdef WITH_NO_COMPRESSION
56 uint32_t *data_src = __data_src_start__;
57 uint32_t *data_dst = __data_start__;
58 while (data_dst < __data_end__) *data_dst++ = *data_src++;
59 #else
60 uncompress_data_section();
61 #endif
63 /* Set up (that is: clear) BSS. */
64 uint32_t *bss_dst = __bss_start__;
65 while (bss_dst < __bss_end__) *bss_dst++ = 0;
67 AppMain();
69 #endif