1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: crt0.cpp
4
5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 25011 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nn/types.h>
17 #include <nn/os/os_MemoryMapSelect.h>
18 #include <nn/init/init_StartUp.h>
19 #include <rt_sys.h>
20 #include <rt_locale.h>
21 #include <nn/os/os_SharedInfo.h>
22 #include <nn/svc.h>
23 #include <nn/assert.h>
24 #include <nn/version.h>
25 #include <nn/middleware.h>
26
27 namespace
28 {
29 #if defined(NN_BUILD_NOOPT) || defined(NN_BUILD_VERBOSE)
30 NN_DEFINE_MIDDLEWARE(s_DebugIndicator, "NINTENDO", "DEBUG");
31 #endif
32 }
33
34
35 extern "C" void nninitLocale();
36 extern "C" void nninitRegion();
37 extern "C" void nninitCheckVersion();
38
39 extern "C" NN_WEAK_SYMBOL void __cpp_initialize__aeabi_(void);
40 extern "C" bit32* __rt_locale(void);
41 extern "C" void _fp_init(void);
42
43 extern "C" bit8 Image$$ZI$$ZI$$Base[];
44 extern "C" bit8 Image$$ZI$$ZI$$Limit[];
45
46 #include <nn/hw/ARM/code32.h>
__ctr_start(void)47 extern "C" asm void __ctr_start( void )
48 {
49 PRESERVE8
50
51 // ZI領域の初期化
52 bl __cpp(nninitRegion)
53 bl __cpp(_fp_init)
54 bl __cpp(nninitLocale)
55
56 // 初期化
57 bl __cpp(nninitCheckVersion)
58 blx __cpp(nninitSystem)
59 blx __cpp(nninitStartUp)
60
61 // C++ のスタティックイニシャライザを呼ぶ
62 blx __cpp(__cpp_initialize__aeabi_)
63 // C のスタティックイニシャライザを呼ぶ
64 blx __cpp(nninitCallStaticInitializers)
65
66 // ライブラリのセットアップ
67 blx __cpp(nninitSetup)
68
69 //---- start (to 16bit code)
70 blx __cpp(nnMain)
71
72 terminate
73 b __cpp(nn::svc::ExitProcess)
74 }
75 #include <nn/hw/ARM/codereset.h>
76
77
78
nninitLocale()79 extern "C" void nninitLocale()
80 {
81 #if defined(NN_BUILD_NOOPT) || defined(NN_BUILD_VERBOSE)
82 NN_UTIL_REFER_SYMBOL(s_DebugIndicator);
83 #endif
84
85 bit32* p = __rt_locale();
86 *(p + 1) = (bit32)_get_lc_ctype(0, 0) + 1;
87 *(p + 3) = (bit32)_get_lc_numeric(0, 0);
88 }
89
90 #include <nn/hw/ARM/code32.h>
nninitRegion(void)91 extern "C" asm void nninitRegion(void)
92 {
93 ldr r0, =__cpp(Image$$ZI$$ZI$$Base)
94 ldr r1, =__cpp(Image$$ZI$$ZI$$Limit)
95 mov r2, #0
96 loop
97 cmp r0, r1
98 strcc r2, [r0], #4
99 bcc loop
100 bx lr
101 }
102 #include <nn/hw/ARM/codereset.h>
103
nninitCheckVersion()104 extern "C" void nninitCheckVersion()
105 {
106 if( nn::os::GetReadOnlySharedInfo().versionLo != NN_VERSION_FIRMWARE_MINOR )
107 {
108 NN_TPANIC_("System version check failed!\ncci expected=%d current system=%d",
109 NN_VERSION_FIRMWARE_MINOR, nn::os::GetReadOnlySharedInfo().versionLo );
110 }
111 }
112
113
114
115