]> git.zerfleddert.de Git - proxmark3-svn/blame - armsrc/start.c
Update CHANGELOG.md
[proxmark3-svn] / armsrc / start.c
CommitLineData
e30c654b 1//-----------------------------------------------------------------------------
bd20f8f4 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//-----------------------------------------------------------------------------
e30c654b 8// Just vector to AppMain(). This is in its own file so that I can place it
9// with the linker script.
e30c654b 10//-----------------------------------------------------------------------------
bd20f8f4 11
53d5dc64 12#ifndef __START_H
13#define __START_H
14
c3c241f3 15#include "proxmark3.h"
e30c654b 16#include "apps.h"
9783989b 17#include "zlib.h"
18#include "BigBuf.h"
19
20static uint8_t *next_free_memory;
21extern struct common_area common_area;
22extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__;
23
9783989b 24static 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
9783989b 33static void inflate_free(voidpf opaque, voidpf address)
34{
35 // nothing to do
9783989b 36}
37
38static 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
e30c654b 63void __attribute__((section(".startos"))) Vector(void)
64{
65 /* Stack should have been set up by the bootloader */
9783989b 66 // char *src;
67 char *dst, *end;
68
69 uncompress_data_section();
e30c654b 70
71 /* Set up (that is: clear) BSS. */
72 dst = &__bss_start__;
73 end = &__bss_end__;
74 while(dst < end) *dst++ = 0;
75
9783989b 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
e30c654b 82 AppMain();
83}
53d5dc64 84#endif
Impressum, Datenschutz