Files
Upsilon/ion/src/device/boot/rt0.cpp
Romain Goyet 66298f5cb6 [ion] Enable building with --gc-sections
Change-Id: Ibddb03d5fc95f99954583a51c02257dfcba3a326
2016-09-16 11:43:14 +02:00

47 lines
1.3 KiB
C++

extern "C" {
#include "rt0.h"
}
#include <stdint.h>
#include <string.h>
#include <ion.h>
#include "../device.h"
extern char _data_section_start_flash;
extern char _data_section_start_ram;
extern char _data_section_end_ram;
extern char _bss_section_start_ram;
extern char _bss_section_end_ram;
void abort() {
#ifdef DEBUG
while (1) {
}
#else
Ion::reset();
#endif
}
void start() {
// This is where execution starts after reset.
// Many things are not initialized yet so the code here has to pay attention.
/* Copy data section to RAM
* The data section is R/W but its initialization value matters. It's stored
* in Flash, but linked as if it were in RAM. Now's our opportunity to copy
* it. Note that until then the data section (e.g. global variables) contains
* garbage values and should not be used. */
size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram);
memcpy(&_data_section_start_ram, &_data_section_start_flash, dataSectionLength);
/* Zero-out the bss section in RAM
* Until we do, any uninitialized global variable will be unusable. */
size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram);
memset(&_bss_section_start_ram, 0, bssSectionLength);
Ion::Device::init();
ion_app();
abort();
}