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-06-04#$
14   $Rev: 10698 $
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 #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 
88 #ifdef SDK_TWLLTD
89     if (OS_IsLimitedRomRunningOnTwl() != TRUE)
90     {
91         OS_ShowAttentionOfLimitedRom(); // never return
92     }
93 #endif
94 
95 #endif  // SDK_ARM9
96 
97     //---- Initialize sdk os common
98     OSi_InitCommon();
99 }
100 #pragma profile reset
101 
102 
103 /*---------------------------------------------------------------------------*
104   Name:         OSi_InitCommon
105 
106   Description:  initialize sdk os common
107 
108   Arguments:    None
109 
110   Returns:      None
111  *---------------------------------------------------------------------------*/
112 #pragma profile off
OSi_InitCommon(void)113 void OSi_InitCommon(void)
114 {
115 #ifdef SDK_ARM9
116     //----------------------------------------------------------------
117     // for ARM9
118 
119 #ifdef SDK_ENABLE_ARM7_PRINT
120     // Init PrintServer for ARM7 (if specified)
121     OS_InitPrintServer();
122 #endif
123 
124     //---- Init interProcessor I/F
125     //  Sync with ARM7 to enable OS_GetConsoleType()
126     //  PXI_Init() must be called before OS_InitArenaEx()
127     PXI_Init();
128 
129     //---- Init Arena (arenas except SUBPRIV-WRAM)
130     OS_InitArena();
131 
132     //---- Init Spinlock
133     OS_InitLock();
134 
135     //---- Init Arena (extended main)
136     OS_InitArenaEx();
137 
138     //---- Init IRQ Table
139     OS_InitIrqTable();
140 
141     //---- Init IRQ Stack checker
142     OS_SetIrqStackChecker();
143 
144     //---- Init Exception System
145     OS_InitException();
146 
147     //---- Init MI (Wram bank and DMA0 arranged)
148     MI_Init();
149 
150     //---- Init VCountAlarm
151     OS_InitVAlarm();
152 
153     //---- Init VRAM exclusive System
154     OSi_InitVramExclusive();
155 
156     //---- Init Thread System
157 #ifndef SDK_NO_THREAD
158     OS_InitThread();
159 #endif
160     //---- Init Reset System
161 #ifndef SDK_SMALL_BUILD
162     OS_InitReset();
163 #endif
164 
165     //---- Init Cartridge
166     CTRDG_Init();
167 
168     //---- Init Card
169 #ifndef SDK_SMALL_BUILD
170     CARD_Init();
171 #endif
172 
173 #ifdef SDK_TWL
174 	MI_InitWramManager();
175 #endif
176 
177 	//---- init System config
178 #ifdef SDK_TWL
179 	if (OS_IsRunOnTwl() == TRUE)
180 	{
181 		SCFG_Init();
182 	}
183 #endif
184 
185     //---- Init Power Manager
186     PM_Init();
187 
188     //---- adjust VCOUNT
189     OSi_WaitVCount0();
190 
191 #ifdef SDK_TWL
192 	if (OS_IsRunOnTwl() == TRUE)
193 	{
194 		OSi_InitPrevTitleId();
195 	}
196 #endif
197 
198 #else  // SDK_ARM9
199     //----------------------------------------------------------------
200     // for ARM7
201 
202     //---- Init interProcessor I/F
203     PXI_Init();
204 
205     //---- Init Arena (SUBPRIV-WRAM arena)
206     OS_InitArena();
207 
208     //---- Init Spinlock
209     OS_InitLock();
210 
211     //---- Init IRQ Table
212     OS_InitIrqTable();
213 
214     //---- Init Exception System
215     OS_InitException();
216 
217     //---- Init MI
218 #ifdef SDK_TWL
219     MI_Init();
220 #endif
221 
222     //---- Init Tick
223     OS_InitTick();
224 
225     //---- Init Alarm System
226     OS_InitAlarm();
227 
228     //---- Init Thread System
229     OS_InitThread();
230 
231     //---- Init Reset System
232 #ifndef SDK_SMALL_BUILD
233     OS_InitReset();
234 #endif
235 
236     //---- Init Cartridge
237 #ifndef SDK_TWLLTD
238     CTRDG_Init();
239 #endif
240 
241 #ifdef SDK_TWL
242 	MI_InitWramManager();
243 #endif
244 
245 	//---- init System config
246 #ifdef SDK_TWL
247 	if (OS_IsRunOnTwl() == TRUE)
248 	{
249 		SCFG_Init();
250 	}
251 #endif
252 
253 #endif // SDK_ARM9
254 }
255 #pragma profile reset
256