proxmark3/armsrc/start.c

54 lines
1.7 KiB
C
Raw Normal View History

//-----------------------------------------------------------------------------
// Jonathan Westhues, Mar 2006
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Just vector to AppMain(). This is in its own file so that I can place it
// with the linker script.
//-----------------------------------------------------------------------------
#ifndef __START_H
#define __START_H
#include "proxmark3_arm.h"
#include "appmain.h"
2020-06-05 22:24:05 +08:00
#include "lz4.h"
2015-06-25 18:22:34 +08:00
#include "BigBuf.h"
2020-06-07 18:46:05 +08:00
#include "string.h"
2015-06-25 18:22:34 +08:00
static uint8_t *next_free_memory;
extern struct common_area common_area;
extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__;
static void uncompress_data_section(void) {
2019-03-10 03:34:41 +08:00
next_free_memory = BigBuf_get_addr();
2020-06-07 18:46:05 +08:00
int avail_in;
memcpy(&avail_in, &__data_start__, sizeof(int));
2020-06-05 22:24:05 +08:00
int avail_out = &__data_end__ - &__data_start__; // uncompressed size. Correct.
// uncompress data segment to RAM
uintptr_t p = (uintptr_t)&__data_src_start__;
2020-06-08 09:15:10 +08:00
int res = LZ4_decompress_safe((char *)p + 4, &__data_start__, avail_in, avail_out);
2015-06-25 18:22:34 +08:00
2019-04-10 15:32:40 +08:00
if (res < 0)
return;
2019-03-10 03:34:41 +08:00
// save the size of the compressed data section
2020-06-05 22:24:05 +08:00
common_area.arg1 = res;
2015-06-25 18:22:34 +08:00
}
2020-05-10 22:59:38 +08:00
void __attribute__((section(".startos"))) Vector(void);
void Vector(void) {
2019-03-10 03:34:41 +08:00
/* Stack should have been set up by the bootloader */
2019-03-10 03:34:41 +08:00
uncompress_data_section();
2019-03-10 03:34:41 +08:00
/* Set up (that is: clear) BSS. */
2020-06-07 19:56:21 +08:00
char *dst = &__bss_start__;
char *end = &__bss_end__;
2019-03-10 07:00:59 +08:00
while (dst < end) *dst++ = 0;
2019-03-10 03:34:41 +08:00
AppMain();
}
2019-03-12 07:12:26 +08:00
#endif