-
Notifications
You must be signed in to change notification settings - Fork 165
/
crt0_init_ram.cpp
45 lines (38 loc) · 1.83 KB
/
crt0_init_ram.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2013 - 2020.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <algorithm>
#include <cstddef>
#include <cstdint>
extern "C"
{
extern std::uintptr_t _rom_data_begin; // Start address for the initialization values of the rom-to-ram section.
extern std::uintptr_t _data_begin; // Start address for the .data section.
extern std::uintptr_t _data_end; // End address for the .data section.
extern std::uintptr_t _bss_begin; // Start address for the .bss section.
extern std::uintptr_t _bss_end; // End address for the .bss section.
}
namespace crt
{
void init_ram();
}
void crt::init_ram()
{
typedef std::uint32_t memory_aligned_type;
// Copy the data segment initializers from ROM to RAM.
// Note that all data segments are aligned by 4.
const std::size_t size_data =
std::size_t( static_cast<const memory_aligned_type*>(static_cast<const void*>(&_data_end))
- static_cast<const memory_aligned_type*>(static_cast<const void*>(&_data_begin)));
std::copy(static_cast<const memory_aligned_type*>(static_cast<const void*>(&_rom_data_begin)),
static_cast<const memory_aligned_type*>(static_cast<const void*>(&_rom_data_begin)) + size_data,
static_cast< memory_aligned_type*>(static_cast< void*>(&_data_begin)));
// Clear the bss segment.
// Note that the bss segment is aligned by 4.
std::fill(static_cast<memory_aligned_type*>(static_cast<void*>(&_bss_begin)),
static_cast<memory_aligned_type*>(static_cast<void*>(&_bss_end)),
static_cast<memory_aligned_type>(0U));
}