-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit.c
82 lines (71 loc) · 1.88 KB
/
init.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//=====================================================================//
/*! @file
@brief R8C 起動前初期化
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2015, 2017 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/R8C/blob/master/LICENSE
*/
//=====================================================================//
#include <stdlib.h>
#include "common/init.h"
int main(int argc, char**argv);
extern short _datainternal;
extern short _datastart;
extern short _dataend;
extern short _bssstart;
extern short _bssend;
extern short _preinit_array_start;
extern short _preinit_array_end;
extern short _init_array_start;
extern short _init_array_end;
extern short _fini_array_start;
extern short _fini_array_end;
//-----------------------------------------------------------------//
/*!
@brief メイン関数起動前初期化
*/
//-----------------------------------------------------------------//
void _init(void)
{
{ // R/W-data セクションのコピー
short *src = &_datainternal;
short *dst = &_datastart;
while(dst < &_dataend) {
*dst++ = *src++;
}
}
{ // bss セクションのクリア
short *dst = &_bssstart;
while(dst < &_bssend) {
*dst++ = 0;
}
}
{ // C++ 静的コンストラクターの実行
short *p = &_fini_array_start;
while(p < &_fini_array_end) {
void (*prog)(void) = (void *)*p++;
(*prog)();
}
}
{ // C++ 事前静的コンストラクターの実行
short *p = &_preinit_array_start;
while(p < &_preinit_array_end) {
void (*prog)(void) = (void *)*p++;
(*prog)();
}
}
{ // C++ 静的コンストラクターの実行
short *p = &_init_array_start;
while(p < &_init_array_end) {
void (*prog)(void) = (void *)*p++;
(*prog)();
}
}
// main の起動
static int argc = 0;
static char **argv = 0;
int ret = main(argc, argv);
exit(0);
}
// EOF