1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - OS
3 File: os_init.c
4
5 Copyright 2003-2008 Nintendo. 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 $Date:: 2008-09-17#$
14 $Rev: 8556 $
15 $Author: okubata_ryoma $
16
17 *---------------------------------------------------------------------------*/
18 #include <nitro/os.h>
19 #include <nitro/mi/wram.h>
20 #include <nitro/pxi.h>
21 #include <nitro/ctrdg/common/ctrdg_common.h>
22 #include <nitro/card/common.h>
23
24 #ifdef SDK_ARM9
25 #include <nitro/spi/ARM9/pm.h>
26 #else //SDK_ARM7
27 #include <nitro/spi/ARM7/pm.h>
28 #endif
29
30
31 #ifdef SDK_TWL
32 #include <application_jump_private.h>
33 #include <twl/scfg.h>
34 #endif
35
36 //#include <nitro/spi.h>
37
38 #ifndef SDK_TEG
39 //#include <nitro/ctrdg.h>
40 #endif
41
42 #include <nitro/code32.h>
OSi_WaitVCount0(void)43 static asm void OSi_WaitVCount0( void )
44 {
45 //---- set IME = 0
46 // ( use that LSB of HW_REG_BASE equal to 0 )
47 mov r12, #HW_REG_BASE
48 ldr r1, [r12, #REG_IME_OFFSET]
49 str r12, [r12, #REG_IME_OFFSET]
50
51 //---- adjust VCOUNT.
52 @wait_vcount_0:
53 ldrh r0, [r12, #REG_VCOUNT_OFFSET]
54 cmp r0, #0
55 bne @wait_vcount_0
56 str r1, [r12, #REG_IME_OFFSET]
57 bx lr
58 }
59 #include <nitro/codereset.h>
60
61 /*---------------------------------------------------------------------------*
62 Name: OS_Init
63
64 Description: initialize sdk os
65
66 Arguments: None
67
68 Returns: None
69 *---------------------------------------------------------------------------*/
70 #pragma profile off
OS_Init(void)71 void OS_Init(void)
72 {
73 #ifdef SDK_ARM9
74 //---- system shared area check
75 SDK_ASSERT((u32)&(OS_GetSystemWork()->command_area) == HW_CMD_AREA);
76
77 //----------------------------------------------------------------
78 // for ARM9
79
80 #ifdef SDK_ENABLE_ARM7_PRINT
81 // Init PrintServer for ARM7 (if specified)
82 OS_InitPrintServer();
83 #endif
84
85 //---- Init interProcessor I/F
86 // Sync with ARM7 to enable OS_GetConsoleType()
87 // PXI_Init() must be called before OS_InitArenaEx()
88 PXI_Init();
89
90 //---- Init Arena (arenas except SUBPRIV-WRAM)
91 OS_InitArena();
92
93 //---- Init Spinlock
94 OS_InitLock();
95
96 //---- Init Arena (extended main)
97 OS_InitArenaEx();
98
99 //---- Init IRQ Table
100 OS_InitIrqTable();
101
102 //---- Init IRQ Stack checker
103 OS_SetIrqStackChecker();
104
105 //---- Init Exception System
106 OS_InitException();
107
108 //---- Init MI (Wram bank and DMA0 arranged)
109 MI_Init();
110
111 //---- Init VCountAlarm
112 OS_InitVAlarm();
113
114 //---- Init VRAM exclusive System
115 OSi_InitVramExclusive();
116
117 //---- Init Thread System
118 #ifndef SDK_NO_THREAD
119 OS_InitThread();
120 #endif
121 //---- Init Reset System
122 #ifndef SDK_SMALL_BUILD
123 OS_InitReset();
124 #endif
125
126 //---- Init Cartridge
127 CTRDG_Init();
128
129 //---- Init Card
130 #ifndef SDK_SMALL_BUILD
131 CARD_Init();
132 #endif
133
134 #ifdef SDK_TWL
135 MI_InitWramManager();
136 #endif
137
138 //---- init System config
139 #ifdef SDK_TWL
140 if (OS_IsRunOnTwl() == TRUE)
141 {
142 SCFG_Init();
143 }
144 #endif
145
146 //---- Init Power Manager
147 PM_Init();
148
149 //---- adjust VCOUNT
150 OSi_WaitVCount0();
151
152 #ifdef SDK_TWL
153 if (OS_IsRunOnTwl() == TRUE)
154 {
155 OSi_InitPrevTitleId();
156 }
157 #endif
158
159 #else // SDK_ARM9
160 //----------------------------------------------------------------
161 // for ARM7
162
163 //---- Init interProcessor I/F
164 PXI_Init();
165
166 //---- Init Arena (SUBPRIV-WRAM arena)
167 OS_InitArena();
168
169 //---- Init Spinlock
170 OS_InitLock();
171
172 //---- Init IRQ Table
173 OS_InitIrqTable();
174
175 //---- Init Exception System
176 OS_InitException();
177
178 //---- Init MI
179 #ifdef SDK_TWL
180 MI_Init();
181 #endif
182
183 //---- Init Tick
184 OS_InitTick();
185
186 //---- Init Alarm System
187 OS_InitAlarm();
188
189 //---- Init Thread System
190 OS_InitThread();
191
192 //---- Init Reset System
193 #ifndef SDK_SMALL_BUILD
194 OS_InitReset();
195 #endif
196
197 //---- Init Cartridge
198 #ifndef SDK_TWLLTD
199 CTRDG_Init();
200 #endif
201
202 #ifdef SDK_TWL
203 MI_InitWramManager();
204 #endif
205
206 //---- init System config
207 #ifdef SDK_TWL
208 if (OS_IsRunOnTwl() == TRUE)
209 {
210 SCFG_Init();
211 }
212 #endif
213
214 #endif // SDK_ARM9
215 }
216
217 #pragma profile reset
218