1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - OS
3   File:     os_init.c
4 
5   Copyright 2003-2009 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:: 2009-08-20#$
14   $Rev: 10997 $
15   $Author: yada $
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 #if defined(SDK_ARM9) && defined(SDK_TWLLTD)
62 #include <os_attention.h>
63 #endif
64 
65 
66 /*---------------------------------------------------------------------------*
67  * Function
68  *---------------------------------------------------------------------------*/
69 void OSi_InitCommon(void);
70 
71 
72 /*---------------------------------------------------------------------------*
73   Name:         OS_Init
74 
75   Description:  initialize sdk os
76 
77   Arguments:    None
78 
79   Returns:      None
80  *---------------------------------------------------------------------------*/
81 #pragma profile off
OS_Init(void)82 void OS_Init(void)
83 {
84 #ifdef SDK_ARM9
85     //---- system shared area check
86     SDK_ASSERT((u32)&(OS_GetSystemWork()->command_area) == HW_CMD_AREA);
87 #endif  // SDK_ARM9
88 
89     //---- Initialize sdk os common
90     OSi_InitCommon();
91 }
92 #pragma profile reset
93 
94 
95 /*---------------------------------------------------------------------------*
96   Name:         OSi_InitCommon
97 
98   Description:  initialize sdk os common
99 
100   Arguments:    None
101 
102   Returns:      None
103  *---------------------------------------------------------------------------*/
104 #pragma profile off
OSi_InitCommon(void)105 void OSi_InitCommon(void)
106 {
107 #ifdef SDK_ARM9
108     //----------------------------------------------------------------
109     // for ARM9
110 
111 #ifdef SDK_ENABLE_ARM7_PRINT
112     // Init PrintServer for ARM7 (if specified)
113     OS_InitPrintServer();
114 #endif
115 
116     //---- Init interProcessor I/F
117     //  Sync with ARM7 to enable OS_GetConsoleType()
118     //  PXI_Init() must be called before OS_InitArenaEx()
119     PXI_Init();
120 
121     //---- Init Arena (arenas except SUBPRIV-WRAM)
122     OS_InitArena();
123 
124     //---- Init Spinlock
125     OS_InitLock();
126 
127     //---- Init Arena (extended main)
128     OS_InitArenaEx();
129 
130     //---- Init IRQ Table
131     OS_InitIrqTable();
132 
133     //---- Init IRQ Stack checker
134     OS_SetIrqStackChecker();
135 
136     //---- Init Exception System
137     OS_InitException();
138 
139     //---- Init MI (Wram bank and DMA0 arranged)
140     MI_Init();
141 
142     //---- Init VCountAlarm
143     OS_InitVAlarm();
144 
145     //---- Init VRAM exclusive System
146     OSi_InitVramExclusive();
147 
148     //---- Init Thread System
149 #ifndef SDK_NO_THREAD
150     OS_InitThread();
151 #endif
152     //---- Init Reset System
153 #ifndef SDK_SMALL_BUILD
154     OS_InitReset();
155 #endif
156 
157     //---- Init Cartridge
158     CTRDG_Init();
159 
160     //---- Init Card
161 #ifndef SDK_SMALL_BUILD
162     CARD_Init();
163 #endif
164 
165 #ifdef SDK_TWL
166 	MI_InitWramManager();
167 #endif
168 
169 	//---- init System config
170 #ifdef SDK_TWL
171 	if (OS_IsRunOnTwl() == TRUE)
172 	{
173 		SCFG_Init();
174 	}
175 #endif
176 
177     //---- Init Power Manager
178     PM_Init();
179 
180     //---- adjust VCOUNT
181     OSi_WaitVCount0();
182 
183 #ifdef SDK_TWL
184 	if (OS_IsRunOnTwl() == TRUE)
185 	{
186 		OSi_InitPrevTitleId();
187 	}
188 #endif
189 
190 #else  // SDK_ARM9
191     //----------------------------------------------------------------
192     // for ARM7
193 
194     //---- Init interProcessor I/F
195     PXI_Init();
196 
197     //---- Init Arena (SUBPRIV-WRAM arena)
198     OS_InitArena();
199 
200     //---- Init Spinlock
201     OS_InitLock();
202 
203     //---- Init IRQ Table
204     OS_InitIrqTable();
205 
206     //---- Init Exception System
207     OS_InitException();
208 
209     //---- Init MI
210 #ifdef SDK_TWL
211     MI_Init();
212 #endif
213 
214     //---- Init Tick
215     OS_InitTick();
216 
217     //---- Init Alarm System
218     OS_InitAlarm();
219 
220     //---- Init Thread System
221     OS_InitThread();
222 
223     //---- Init Reset System
224 #ifndef SDK_SMALL_BUILD
225     OS_InitReset();
226 #endif
227 
228     //---- Init Cartridge
229 #ifndef SDK_TWLLTD
230     CTRDG_Init();
231 #endif
232 
233 #ifdef SDK_TWL
234 	MI_InitWramManager();
235 #endif
236 
237 	//---- init System config
238 #ifdef SDK_TWL
239 	if (OS_IsRunOnTwl() == TRUE)
240 	{
241 		SCFG_Init();
242 	}
243 #endif
244 
245 #endif // SDK_ARM9
246 }
247 #pragma profile reset
248