proxmark3/armsrc/start.c

83 lines
2.5 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"
2015-06-25 18:22:34 +08:00
#include "zlib.h"
#include "BigBuf.h"
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 voidpf inflate_malloc(voidpf opaque, uInt items, uInt size) {
2019-03-10 03:34:41 +08:00
uint8_t *allocated_memory;
2019-03-10 03:34:41 +08:00
allocated_memory = next_free_memory;
2019-03-10 07:00:59 +08:00
next_free_memory += items * size;
2019-03-10 03:34:41 +08:00
return allocated_memory;
2015-06-25 18:22:34 +08:00
}
static void inflate_free(voidpf opaque, voidpf address) {
2019-03-10 03:34:41 +08:00
// nothing to do
2015-06-25 18:22:34 +08:00
}
static void uncompress_data_section(void) {
2019-03-10 03:34:41 +08:00
z_stream data_section;
2015-06-25 18:22:34 +08:00
2019-03-10 03:34:41 +08:00
next_free_memory = BigBuf_get_addr();
2019-03-10 03:34:41 +08:00
// initialize zstream structure
data_section.next_in = (uint8_t *) &__data_src_start__;
data_section.avail_in = &__data_end__ - &__data_start__; // uncompressed size. Wrong but doesn't matter.
data_section.next_out = (uint8_t *) &__data_start__;
data_section.avail_out = &__data_end__ - &__data_start__; // uncompressed size. Correct.
data_section.zalloc = &inflate_malloc;
data_section.zfree = &inflate_free;
data_section.opaque = NULL;
2015-06-25 18:22:34 +08:00
2019-03-10 03:34:41 +08:00
// initialize zlib for inflate
int res = inflateInit2(&data_section, 15);
2019-04-10 15:32:40 +08:00
if (res < 0)
return;
2015-06-25 18:22:34 +08:00
2019-03-10 03:34:41 +08:00
// uncompress data segment to RAM
inflate(&data_section, Z_FINISH);
2019-03-10 03:34:41 +08:00
// save the size of the compressed data section
common_area.arg1 = data_section.total_in;
2015-06-25 18:22:34 +08:00
}
void __attribute__((section(".startos"))) Vector(void) {
2019-03-10 03:34:41 +08:00
/* Stack should have been set up by the bootloader */
// char *src;
char *dst, *end;
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. */
dst = &__bss_start__;
end = &__bss_end__;
2019-03-10 07:00:59 +08:00
while (dst < end) *dst++ = 0;
2019-03-10 03:34:41 +08:00
// Set up data segment: Copy from flash to ram
// src = &__data_src_start__;
// dst = &__data_start__;
// end = &__data_end__;
// while(dst < end) *dst++ = *src++;
2015-06-25 18:22:34 +08:00
2019-03-10 03:34:41 +08:00
AppMain();
}
2019-03-12 07:12:26 +08:00
#endif