1 #include <ogc/machine/asm.h>
4 #define CTX_SAVE 0x80004004
5 #define RET_ADDR 0x80004000
7 #define CACHE_SCRATCH 0x81000000
15 .extern DCFlashInvalidate
16 .extern ICFlashInvalidate
17 .extern L2GlobalInvalidate
18 .extern DCFlushRangeNoSync
19 .extern ICInvalidateRange
21 .globl __distub_take_plunge
22 .globl __distub_enable_caches
23 .globl __distub_disable_caches
34 # save context address
36 stw r3, CTX_SAVE@l(r4)
97 addi r6, r3, MEM1_OFF - 4
105 # flush and disable caches
106 bl __distub_disable_caches
108 # set up return address for stub
109 lis r5, __distub_return@h
110 ori r5, r5, __distub_return@l
112 stw r5, RET_ADDR@l(r4)
121 # get the context address
123 lwz r3, CTX_SAVE@l(r4)
148 # initialize system partially
153 # get the context address (again), this time into r31
155 lwz r31, CTX_SAVE@l(r4)
165 addi r6, r31, MEM1_OFF - 4
173 # restore IOS version
179 li r4, (MEM1_WORDS * 4)
180 bl DCFlushRangeNoSync
182 li r4, (MEM1_WORDS * 4)
187 lwz r4, SPRG0_OFF(r31)
189 lwz r4, SPRG1_OFF(r31)
191 lwz r4, SPRG2_OFF(r31)
193 lwz r4, SPRG3_OFF(r31)
197 lwz r4, HID0_OFF(r31)
199 lwz r4, HID1_OFF(r31)
201 lwz r4, HID2_OFF(r31)
203 lwz r4, HID4_OFF(r31)
207 lwz r4, WPAR_OFF(r31)
210 # restore MSR (and interrupts)
214 # we grab the LR and r31 back from the (now configured) stack
246 __distub_disable_caches:
255 rlwinm r4,r31,0,17,15
260 # Flush and disable L1/L2 data caches
265 lis r4,CACHE_SCRATCH@h
266 ori r4,r4,CACHE_SCRATCH@l
269 addi r4,r4,0x20 # Move to next block
270 bdnz 1b # decrement ctr, branch if necessary
276 lis r4,CACHE_SCRATCH@h
277 ori r4,r4,CACHE_SCRATCH@l
281 addi r4,r4,0x20 # move to next block
282 bdnz 1b # decrement & branch as appropriate
289 bl L2GlobalInvalidate
302 __distub_enable_caches:
311 rlwinm r4,r31,0,17,15
317 # reenable interrupts