1 //-----------------------------------------------------------------------------
2 // Copyright (C) Jonathan Westhues, Mar 2006
3 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // See LICENSE.txt for the text of the license.
16 //-----------------------------------------------------------------------------
17 // Just vector to AppMain(). This is in its own file so that I can place it
18 // with the linker script.
19 //-----------------------------------------------------------------------------
24 #include "proxmark3_arm.h"
26 #ifdef WITH_COMPRESSION
33 extern common_area_t g_common_area
;
34 extern uint32_t __data_src_start__
[], __data_start__
[], __data_end__
[], __bss_start__
[], __bss_end__
[];
36 #ifdef WITH_COMPRESSION
37 static void uncompress_data_section(void) {
39 memcpy(&avail_in
, __data_src_start__
, sizeof(int));
40 int avail_out
= (uint32_t)__data_end__
- (uint32_t)__data_start__
; // uncompressed size. Correct.
41 // uncompress data segment to RAM
42 char *p
= (char *)__data_src_start__
;
43 int res
= LZ4_decompress_safe(p
+ 4, (char *)__data_start__
, avail_in
, avail_out
);
53 // save the size of the compressed data section
54 g_common_area
.arg1
= avail_in
;
58 void __attribute__((section(".startos"))) Vector(void);
60 /* Stack should have been set up by the bootloader */
62 if (g_common_area
.magic
!= COMMON_AREA_MAGIC
|| g_common_area
.version
!= 1) {
63 /* Initialize common area */
64 memset(&g_common_area
, 0, sizeof(g_common_area
));
65 g_common_area
.magic
= COMMON_AREA_MAGIC
;
66 g_common_area
.version
= 1;
68 g_common_area
.flags
.osimage_present
= 1;
70 /* Set up data segment: Copy from flash to ram */
71 #ifndef WITH_COMPRESSION
72 uint32_t *data_src
= __data_src_start__
;
73 uint32_t *data_dst
= __data_start__
;
74 while (data_dst
< __data_end__
) *data_dst
++ = *data_src
++;
76 uncompress_data_section();
79 /* Set up (that is: clear) BSS. */
80 uint32_t *bss_dst
= __bss_start__
;
81 while (bss_dst
< __bss_end__
) *bss_dst
++ = 0;