1 /*-------------------------------------------------------------
6 Michael Wiedenbauer (shagkur)
7 Dave Murphy (WinterMute)
10 This software is provided 'as-is', without any express or implied
11 warranty. In no event will the authors be held liable for any
12 damages arising from the use of this software.
14 Permission is granted to anyone to use this software for any
15 purpose, including commercial applications, and to alter it and
16 redistribute it freely, subject to the following restrictions:
18 1. The origin of this software must not be misrepresented; you
19 must not claim that you wrote the original software. If you use
20 this software in a product, an acknowledgment in the product
21 documentation would be appreciated but is not required.
23 2. Altered source versions must be plainly marked as such, and
24 must not be misrepresented as being the original software.
26 3. This notice may not be removed or altered from any source
29 -------------------------------------------------------------*/
35 #include "processor.h"
42 #define IOS_HEAP_SIZE 0x1000
46 #define IOS_MAX_VERSION 36
47 #define IOS_MIN_VERSION 3
49 static s32 __ios_hid
= -1;
51 s32
__IOS_InitHeap(void)
54 __ios_hid
= iosCreateHeap(IOS_HEAP_SIZE
);
55 if(__ios_hid
< 0) return __ios_hid
;
60 // These two functions deal with the "internal" IOS subsystems that are used by default by libogc
61 // Other stuff should be inited by the user and deinited by the exit callbacks. The user is also responsible
62 // for deiniting other stuff before an IOS reload and reiniting them after.
63 s32
__IOS_InitializeSubsystems(void)
68 printf("IOS Subsystem Init\n");
74 printf("ES Init failed: %d\n",ret
);
81 printf("STM Init failed: %d\n",ret
);
85 printf("IOS Subsystem Init Done: %d\n",ret
);
90 s32
__IOS_ShutdownSubsystems(void)
95 printf("IOS Subsystem Close\n");
98 if(res
< 0) ret
= res
;
100 if(res
< 0) ret
= res
;
102 printf("IOS Subsystem Close Done: %d\n",ret
);
107 s32
IOS_GetPreferredVersion()
109 int ver
= IOS_EBADVERSION
;
116 res
= __IOS_InitHeap();
117 if(res
<0) return res
;
119 res
= ES_GetNumTitles(&count
);
122 printf(" GetNumTitles failed: %d\n",res
);
127 printf(" %d titles on card:\n",count
);
129 titles
= iosAlloc(__ios_hid
, sizeof(u64
)*count
);
131 printf(" iosAlloc titles failed\n");
134 res
= ES_GetTitles(titles
, count
);
137 printf(" GetTitles failed: %d\n",res
);
139 iosFree(__ios_hid
, titles
);
143 for(i
=0; i
<count
; i
++) {
145 b
= titles
[i
]&0xFFFFFFFF;
147 if(b
< IOS_MIN_VERSION
) continue;
148 if(b
> IOS_MAX_VERSION
) continue;
149 if(((s32
)b
) > ((s32
)ver
)) ver
= b
;
152 printf(" Preferred verson: %d\n",ver
);
154 iosFree(__ios_hid
, titles
);
162 DCInvalidateRange((void*)0x80003140,8);
163 vercode
= *((u32
*)0x80003140);
164 version
= vercode
>> 16;
165 if(version
== 0) return IOS_EBADVERSION
;
166 if(version
> 0xff) return IOS_EBADVERSION
;
170 s32
IOS_GetRevision()
174 DCInvalidateRange((void*)0x80003140,8);
175 vercode
= *((u32
*)0x80003140);
176 rev
= vercode
& 0xFFFF;
177 if(vercode
== 0 || rev
== 0) return IOS_EBADVERSION
;
181 s32
IOS_GetRevisionMajor()
184 rev
= IOS_GetRevision();
185 if(rev
< 0) return rev
;
186 return (rev
>>8)&0xFF;
189 s32
IOS_GetRevisionMinor()
192 rev
= IOS_GetRevision();
193 if(rev
< 0) return rev
;
197 s32
__IOS_LaunchNewIOS(int version
)
201 u64 titleID
= 0x100000000LL
;
202 STACK_ALIGN(tikview
,views
,4,32);
208 if(version
< 3 || version
> 0xFF) {
209 return IOS_EBADVERSION
;
213 oldversion
= IOS_GetVersion();
214 if(oldversion
>0) printf("Current IOS Version: IOS%d\n",oldversion
);
219 printf("Launching IOS TitleID: %016llx\n",titleID
);
222 res
= ES_GetNumTicketViews(titleID
, &numviews
);
225 printf(" GetNumTicketViews failed: %d\n",res
);
230 printf(" GetNumTicketViews too many views: %u\n",numviews
);
231 return IOS_ETOOMANYVIEWS
;
233 res
= ES_GetTicketViews(titleID
, views
, numviews
);
236 printf(" GetTicketViews failed: %d\n",res
);
240 res
= ES_LaunchTitle(titleID
, &views
[0]);
243 printf(" LaunchTitle failed: %d\n",res
);
248 newversion
= IOS_GetVersion();
250 printf(" IOS Version: IOS%d %d.%d\n",newversion
,IOS_GetRevisionMajor(),IOS_GetRevisionMinor());
252 if(newversion
!= version
) {
254 printf(" Version mismatch!\n");
256 return IOS_EMISMATCH
;
261 s32
__attribute__((weak
)) __IOS_LoadStartupIOS()
267 if(res
< 0) return res
;
268 version
= IOS_GetPreferredVersion();
271 printf("GetPreferredVersion failed: %d\n",version
);
277 printf("Loading startup IOS: %d\n",version
);
279 res
= __IOS_LaunchNewIOS(version
);
280 if(res
< 0) return res
;
284 s32
IOS_ReloadIOS(int version
)
289 printf("Reloading to IOS%d\n",version
);
291 res
= __IOS_ShutdownSubsystems();
292 if(res
< 0) ret
= res
;
294 if(res
< 0) ret
= res
;
296 res
= __IOS_LaunchNewIOS(version
);
302 res
= __IOS_InitializeSubsystems();
303 if(res
< 0) ret
= res
;
307 #endif /* defined(HW_RVL) */