13 #define _LANGUAGE_ASSEMBLY
14 #include <ogc/machine/asm.h>
15 #undef _LANGUAGE_ASSEMBLY
19 #include <ogc/lwp_threads.h>
20 #include <ogc/machine/processor.h>
22 context_storage di_ctx
;
24 #define DVD_TITLEID 0x0001000844564458LL
25 //#define DVD_TITLEID 0x1000148415858LL
27 void __IPC_Reinitialize(void);
28 extern void __exi_init();
30 static vu16
* const _viReg
= (u16
*)0xCC002000;
31 static vu32
* const _piReg
= (u32
*)0xCC003000;
32 static vu16
* const _memReg
= (u16
*)0xCC004000;
33 static vu16
* const _dspReg
= (u16
*)0xCC005000;
35 //#define DEBUG_DVD_STUB
38 #define dprintf printf
45 dprintf(" MSR: %08x\n",mfmsr());
46 dprintf(" SPRGx: %08x %08x %08x %08x\n", mfspr(SPRG0
), mfspr(SPRG1
), mfspr(SPRG2
), mfspr(SPRG3
));
47 dprintf(" HID0124: %08x %08x %08x %08x\n", mfspr(HID0
), mfspr(HID1
), mfspr(HID2
), mfspr(HID4
));
48 dprintf(" L2CR: %08x\n", mfspr(L2CR
));
49 dprintf(" WPAR: %08x\n", mfspr(WPAR
));
50 dprintf(" PMCx: %08x %08x %08x %08x\n", mfspr(PMC1
), mfspr(PMC2
), mfspr(PMC3
), mfspr(PMC4
));
51 dprintf(" MMCRx: %08x %08x\n", mfspr(MMCR0
), mfspr(MMCR1
));
53 dprintf(" PI Regs: %08x %08x %08x %08x\n", _piReg[0], _piReg[1], _piReg[2], _piReg[3]);
54 dprintf(" %08x %08x %08x %08x\n", _piReg[4], _piReg[5], _piReg[6], _piReg[7]);
55 dprintf(" %08x %08x %08x %08x\n", _piReg[8], _piReg[9], _piReg[10], _piReg[11]);
58 dprintf(" MI Regs: %04x %04x %04x %04x %04x %04x %04x %04x\n", _memReg[0], _memReg[1], _memReg[2], _memReg[3], _memReg[4], _memReg[5], _memReg[6], _memReg[7]);
59 dprintf(" %04x %04x %04x %04x %04x %04x %04x %04x\n", _memReg[8], _memReg[9], _memReg[10], _memReg[11], _memReg[12], _memReg[13], _memReg[14], _memReg[15]);
60 dprintf(" %04x %04x %04x %04x %04x %04x %04x %04x\n", _memReg[16], _memReg[17], _memReg[18], _memReg[19], _memReg[20], _memReg[21], _memReg[22], _memReg[23]);
61 dprintf(" %04x %04x %04x %04x %04x %04x %04x %04x\n", _memReg[24], _memReg[25], _memReg[26], _memReg[27], _memReg[28], _memReg[29], _memReg[30], _memReg[31]);
62 dprintf(" %04x %04x %04x %04x %04x %04x %04x %04x\n", _memReg[32], _memReg[33], _memReg[34], _memReg[35], _memReg[36], _memReg[37], _memReg[38], _memReg[39]);
63 dprintf(" %04x %04x %04x %04x %04x %04x %04x %04x\n", _memReg[40], _memReg[41], _memReg[42], _memReg[43], _memReg[44], _memReg[45], _memReg[46], _memReg[47]);
67 register_storage di_regs
;
69 void __distub_saveregs(void)
72 di_regs
.timebase
= gettime();
74 di_regs
.piReg
[i
] = _piReg
[i
];
77 void __distub_restregs(void)
81 _piReg
[i
] = di_regs
.piReg
[i
];
82 //i = _piReg[0]; //clear all interrupts
83 settime(di_regs
.timebase
);
87 s32
__DI_StubLaunch(void)
89 u64 titleID
= DVD_TITLEID
;
90 static tikview views
[4] ATTRIBUTE_ALIGN(32);
96 dprintf("Stopping thread timeslice ticker\n");
97 __lwp_thread_stoptimeslice();
99 dprintf("Shutting down IOS subsystems\n");
100 res
= __IOS_ShutdownSubsystems();
102 dprintf("Shutdown failed: %d\n",res
);
104 dprintf("Initializing ES\n");
107 dprintf("ES init failed: %d\n",res
);
111 dprintf("Launching TitleID: %016llx\n",titleID
);
113 res
= ES_GetNumTicketViews(titleID
, &numviews
);
115 dprintf(" GetNumTicketViews failed: %d\n",res
);
119 dprintf(" GetNumTicketViews too many views: %u\n",numviews
);
120 return IOS_ETOOMANYVIEWS
;
122 res
= ES_GetTicketViews(titleID
, views
, numviews
);
124 dprintf(" GetTicketViews failed: %d\n",res
);
127 dprintf("Ready to launch channel\n");
128 res
= ES_LaunchTitleBackground(titleID
, &views
[0]);
130 dprintf("Launch failed: %d\n",res
);
133 dprintf("Channel launching in the background\n");
134 dprintf("Pre-stub status:\n");
136 dprintf("ISR Disable...\n");
137 _CPU_ISR_Disable( ints
);
138 dprintf("Saving regs...\n");
140 dprintf("Taking the plunge...\n");
141 __distub_take_plunge(&di_ctx
);
143 dprintf("We're back!\n");
144 dprintf("Restoring regs...\n");
146 dprintf("ISR Enable...\n");
147 _CPU_ISR_Restore( ints
);
149 dprintf("Post-stub status:\n");
152 __IPC_Reinitialize();
155 dprintf("IPC reinitialized\n");
157 dprintf("Restarting IOS subsystems\n");
159 res
= __IOS_InitializeSubsystems();
161 dprintf("Subsystems running!\n");
163 res
= ES_GetNumTicketViews(titleID
, &numviews
);
165 dprintf(" GetNumTicketViews failed: %d\n",res
);
168 dprintf(" GetNumTicketViews: %d",numviews
);
170 dprintf("Restarting threads timeslice ticker\n");
171 __lwp_thread_starttimeslice();
177 s32
__DI_LoadStub(void)
182 dprintf("Reloading to IOS%d\n",version
);
184 res
= __IOS_ShutdownSubsystems();
185 if(res
< 0) ret
= res
;
187 if(res
< 0) ret
= res
;
189 res
= __DI_StubLaunch();
195 res
= __IOS_InitializeSubsystems();
196 if(res
< 0) ret
= res
;