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: 28521 $
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     NN_DEFINE_MIDDLEWARE(s_SdkVersion,      "NINTENDO", NN_CURRENT_SDK_VERSION);
34     NN_DEFINE_MIDDLEWARE(s_FirmwareVersion, "NINTENDO", NN_CURRENT_FIRMWARE_VERSION);
35 }
36 
37 
38 extern "C" void     nninitLocale();
39 extern "C" void     nninitRegion();
40 
41 extern "C" NN_WEAK_SYMBOL void __cpp_initialize__aeabi_(void);
42 extern "C" bit32*   __rt_locale(void);
43 extern "C" void     _fp_init(void);
44 
45 extern "C" bit8     Image$$ZI$$ZI$$Base[];
46 extern "C" bit8     Image$$ZI$$ZI$$Limit[];
47 
48 #include <nn/hw/ARM/code32.h>
__ctr_start(void)49 extern "C" asm void __ctr_start( void )
50 {
51         PRESERVE8
52 
53         // ZI領域の初期化
54         bl              __cpp(nninitRegion)
55         bl              __cpp(_fp_init)
56         bl              __cpp(nninitLocale)
57 
58         // 初期化
59         blx             __cpp(nninitSystem)
60         blx             __cpp(nninitStartUp)
61 
62         // C++ のスタティックイニシャライザを呼ぶ
63         blx             __cpp(__cpp_initialize__aeabi_)
64         // C のスタティックイニシャライザを呼ぶ
65         blx             __cpp(nninitCallStaticInitializers)
66 
67         // ライブラリのセットアップ
68         blx             __cpp(nninitSetup)
69 
70         //---- start (to 16bit code)
71         blx             __cpp(nnMain)
72 
73 terminate
74         b               __cpp(nn::svc::ExitProcess)
75 }
76 #include <nn/hw/ARM/codereset.h>
77 
78 
79 
nninitLocale()80 extern "C" void nninitLocale()
81 {
82 #if defined(NN_BUILD_NOOPT) || defined(NN_BUILD_VERBOSE)
83     NN_UTIL_REFER_SYMBOL(s_DebugIndicator);
84 #endif
85     NN_UTIL_REFER_SYMBOL(s_SdkVersion);
86     NN_UTIL_REFER_SYMBOL(s_FirmwareVersion);
87 
88     bit32* p = __rt_locale();
89     *(p + 1) = (bit32)_get_lc_ctype(0, 0) + 1;
90     *(p + 3) = (bit32)_get_lc_numeric(0, 0);
91 }
92 
93 #include <nn/hw/ARM/code32.h>
nninitRegion(void)94 extern "C" asm void nninitRegion(void)
95 {
96         ldr     r0, =__cpp(Image$$ZI$$ZI$$Base)
97         ldr     r1, =__cpp(Image$$ZI$$ZI$$Limit)
98         mov     r2, #0
99 loop
100         cmp     r0, r1
101         strcc   r2, [r0], #4
102         bcc     loop
103         bx      lr
104 }
105 #include <nn/hw/ARM/codereset.h>
106 
107 
108 
109 
110