.include "macros.inc"
.section .text, "ax"
.global GXCPInterruptHandler
GXCPInterruptHandler:
mflr r0
stw r0, 4(r1)
stwu r1, -0x2e0(r1)
stw r31, 0x2dc(r1)
mr r31, r4
lwz r5, __cpReg@sda21(r13)
lwz r3, gx@sda21(r13)
lhz r0, 0(r5)
stw r0, 0xc(r3)
lwz r3, gx@sda21(r13)
lwz r0, 8(r3)
rlwinm. r0, r0, 0x1d, 0x1f, 0x1f
beq lbl_800A603C
lwz r0, 0xc(r3)
rlwinm. r0, r0, 0x1f, 0x1f, 0x1f
beq lbl_800A603C
lwz r3, __GXCurrentThread@sda21(r13)
bl OSResumeThread
li r0, 0
stw r0, GXOverflowSuspendInProgress@sda21(r13)
li r3, 1
li r4, 1
bl __GXWriteFifoIntReset
li r3, 1
li r4, 0
bl __GXWriteFifoIntEnable
lbl_800A603C:
lwz r3, gx@sda21(r13)
lwz r0, 8(r3)
rlwinm. r0, r0, 0x1e, 0x1f, 0x1f
beq lbl_800A608C
lwz r0, 0xc(r3)
clrlwi. r0, r0, 0x1f
beq lbl_800A608C
lwz r5, __GXOverflowCount@sda21(r13)
li r3, 0
li r4, 1
addi r0, r5, 1
stw r0, __GXOverflowCount@sda21(r13)
bl __GXWriteFifoIntEnable
li r3, 1
li r4, 0
bl __GXWriteFifoIntReset
li r0, 1
lwz r3, __GXCurrentThread@sda21(r13)
stw r0, GXOverflowSuspendInProgress@sda21(r13)
bl OSSuspendThread
lbl_800A608C:
lwz r3, gx@sda21(r13)
lwz r4, 8(r3)
addi r5, r3, 8
rlwinm. r0, r4, 0x1b, 0x1f, 0x1f
beq lbl_800A60FC
lwz r0, 0xc(r3)
rlwinm. r0, r0, 0x1c, 0x1f, 0x1f
beq lbl_800A60FC
rlwinm r0, r4, 0, 0x1b, 0x19
stw r0, 0(r5)
lwz r4, gx@sda21(r13)
lwz r3, __cpReg@sda21(r13)
lwz r0, 8(r4)
sth r0, 2(r3)
lwz r0, BreakPointCB@sda21(r13)
cmplwi r0, 0
beq lbl_800A60FC
addi r3, r1, 0x10
bl OSClearContext
addi r3, r1, 0x10
bl OSSetCurrentContext
lwz r12, BreakPointCB@sda21(r13)
mtlr r12
blrl
addi r3, r1, 0x10
bl OSClearContext
mr r3, r31
bl OSSetCurrentContext
lbl_800A60FC:
lwz r0, 0x2e4(r1)
lwz r31, 0x2dc(r1)
addi r1, r1, 0x2e0
mtlr r0
blr
.global GXInitFifoBase
GXInitFifoBase:
mflr r0
stw r0, 4(r1)
addi r0, r5, -4
stwu r1, -0x20(r1)
stw r31, 0x1c(r1)
addi r31, r4, 0
add r0, r31, r0
stw r30, 0x18(r1)
addi r30, r3, 0
addi r4, r5, -16384
stw r31, 0(r3)
stw r0, 4(r3)
li r0, 0
stw r5, 8(r3)
rlwinm r5, r5, 0x1f, 1, 0x1a
stw r0, 0x1c(r30)
bl GXInitFifoLimits
addi r3, r30, 0
addi r4, r31, 0
addi r5, r31, 0
bl GXInitFifoPtrs
lwz r0, 0x24(r1)
lwz r31, 0x1c(r1)
lwz r30, 0x18(r1)
addi r1, r1, 0x20
mtlr r0
blr
.global GXInitFifoPtrs
GXInitFifoPtrs:
mflr r0
stw r0, 4(r1)
stwu r1, -0x28(r1)
stw r31, 0x24(r1)
addi r31, r5, 0
stw r30, 0x20(r1)
addi r30, r4, 0
stw r29, 0x1c(r1)
addi r29, r3, 0
bl OSDisableInterrupts
stw r30, 0x14(r29)
subf r0, r30, r31
stw r31, 0x18(r29)
stw r0, 0x1c(r29)
lwz r4, 0x1c(r29)
cmpwi r4, 0
bge lbl_800A61CC
lwz r0, 8(r29)
add r0, r4, r0
stw r0, 0x1c(r29)
lbl_800A61CC:
bl OSRestoreInterrupts
lwz r0, 0x2c(r1)
lwz r31, 0x24(r1)
lwz r30, 0x20(r1)
lwz r29, 0x1c(r1)
addi r1, r1, 0x28
mtlr r0
blr
.global GXInitFifoLimits
GXInitFifoLimits:
stw r4, 0xc(r3)
stw r5, 0x10(r3)
blr
.global GXSetCPUFifo
GXSetCPUFifo:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
mr r30, r3
bl OSDisableInterrupts
lwz r0, GPFifo@sda21(r13)
addi r31, r3, 0
stw r30, CPUFifo@sda21(r13)
cmplw r30, r0
bne lbl_800A6288
lwz r5, 0(r30)
li r0, 1
lwz r4, __piReg@sda21(r13)
li r3, 1
clrlwi r5, r5, 2
stw r5, 0xc(r4)
li r4, 1
lwz r6, 4(r30)
lwz r5, __piReg@sda21(r13)
clrlwi r6, r6, 2
stw r6, 0x10(r5)
lwz r6, 0x18(r30)
lwz r5, __piReg@sda21(r13)
rlwinm r6, r6, 0, 2, 0x1a
rlwinm r6, r6, 0, 6, 4
stw r6, 0x14(r5)
stb r0, CPGPLinked@sda21(r13)
bl __GXWriteFifoIntReset
li r3, 1
li r4, 0
bl __GXWriteFifoIntEnable
li r3, 1
bl __GXFifoLink
b lbl_800A62E4
lbl_800A6288:
lbz r0, CPGPLinked@sda21(r13)
cmplwi r0, 0
beq lbl_800A62A4
li r3, 0
bl __GXFifoLink
li r0, 0
stb r0, CPGPLinked@sda21(r13)
lbl_800A62A4:
li r3, 0
li r4, 0
bl __GXWriteFifoIntEnable
lwz r0, 0(r30)
lwz r3, __piReg@sda21(r13)
clrlwi r0, r0, 2
stw r0, 0xc(r3)
lwz r0, 4(r30)
lwz r3, __piReg@sda21(r13)
clrlwi r0, r0, 2
stw r0, 0x10(r3)
lwz r0, 0x18(r30)
lwz r3, __piReg@sda21(r13)
rlwinm r0, r0, 0, 2, 0x1a
rlwinm r0, r0, 0, 6, 4
stw r0, 0x14(r3)
lbl_800A62E4:
sync 0
mr r3, r31
bl OSRestoreInterrupts
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
mtlr r0
blr
.global GXSetGPFifo
GXSetGPFifo:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
mr r30, r3
bl OSDisableInterrupts
mr r31, r3
bl __GXFifoReadDisable
li r3, 0
li r4, 0
bl __GXWriteFifoIntEnable
stw r30, GPFifo@sda21(r13)
lwz r3, __cpReg@sda21(r13)
lwz r0, 0(r30)
sth r0, 0x20(r3)
lwz r0, 4(r30)
lwz r3, __cpReg@sda21(r13)
sth r0, 0x24(r3)
lwz r0, 0x1c(r30)
lwz r3, __cpReg@sda21(r13)
sth r0, 0x30(r3)
lwz r0, 0x18(r30)
lwz r3, __cpReg@sda21(r13)
sth r0, 0x34(r3)
lwz r0, 0x14(r30)
lwz r3, __cpReg@sda21(r13)
sth r0, 0x38(r3)
lwz r0, 0xc(r30)
lwz r3, __cpReg@sda21(r13)
sth r0, 0x28(r3)
lwz r0, 0x10(r30)
lwz r3, __cpReg@sda21(r13)
sth r0, 0x2c(r3)
lwz r0, 0(r30)
lwz r3, __cpReg@sda21(r13)
rlwinm r0, r0, 0x10, 0x12, 0x1f
sth r0, 0x22(r3)
lwz r0, 4(r30)
lwz r3, __cpReg@sda21(r13)
rlwinm r0, r0, 0x10, 0x12, 0x1f
sth r0, 0x26(r3)
lwz r0, 0x1c(r30)
lwz r3, __cpReg@sda21(r13)
srawi r0, r0, 0x10
sth r0, 0x32(r3)
lwz r0, 0x18(r30)
lwz r3, __cpReg@sda21(r13)
rlwinm r0, r0, 0x10, 0x12, 0x1f
sth r0, 0x36(r3)
lwz r0, 0x14(r30)
lwz r3, __cpReg@sda21(r13)
rlwinm r0, r0, 0x10, 0x12, 0x1f
sth r0, 0x3a(r3)
lwz r0, 0xc(r30)
lwz r3, __cpReg@sda21(r13)
srwi r0, r0, 0x10
sth r0, 0x2a(r3)
lwz r0, 0x10(r30)
lwz r3, __cpReg@sda21(r13)
srwi r0, r0, 0x10
sth r0, 0x2e(r3)
sync 0
lwz r3, CPUFifo@sda21(r13)
lwz r0, GPFifo@sda21(r13)
cmplw r3, r0
bne lbl_800A6434
li r0, 1
stb r0, CPGPLinked@sda21(r13)
li r3, 1
li r4, 0
bl __GXWriteFifoIntEnable
li r3, 1
bl __GXFifoLink
b lbl_800A6450
lbl_800A6434:
li r0, 0
stb r0, CPGPLinked@sda21(r13)
li r3, 0
li r4, 0
bl __GXWriteFifoIntEnable
li r3, 0
bl __GXFifoLink
lbl_800A6450:
li r3, 1
li r4, 1
bl __GXWriteFifoIntReset
bl __GXFifoReadEnable
mr r3, r31
bl OSRestoreInterrupts
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
mtlr r0
blr
.global GXGetFifoPtrs
GXGetFifoPtrs:
lwz r0, CPUFifo@sda21(r13)
cmplw r3, r0
bne lbl_800A64A0
lwz r6, __piReg@sda21(r13)
lwz r0, 0x14(r6)
rlwinm r6, r0, 0, 6, 4
addis r0, r6, 0x8000
stw r0, 0x18(r3)
lbl_800A64A0:
lwz r0, GPFifo@sda21(r13)
cmplw r3, r0
bne lbl_800A64DC
lwz r7, __cpReg@sda21(r13)
lhz r6, 0x3a(r7)
lhz r7, 0x38(r7)
rlwimi r7, r6, 0x10, 0, 0xf
addis r0, r7, 0x8000
stw r0, 0x14(r3)
lwz r7, __cpReg@sda21(r13)
lhz r6, 0x32(r7)
lhz r0, 0x30(r7)
rlwimi r0, r6, 0x10, 0, 0xf
stw r0, 0x1c(r3)
b lbl_800A6504
lbl_800A64DC:
lwz r6, 0x14(r3)
lwz r0, 0x18(r3)
subf r0, r6, r0
stw r0, 0x1c(r3)
lwz r6, 0x1c(r3)
cmpwi r6, 0
bge lbl_800A6504
lwz r0, 8(r3)
add r0, r6, r0
stw r0, 0x1c(r3)
lbl_800A6504:
lwz r0, 0x14(r3)
stw r0, 0(r4)
lwz r0, 0x18(r3)
stw r0, 0(r5)
blr
.global GXEnableBreakPt
GXEnableBreakPt:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
mr r31, r3
stw r30, 0x10(r1)
bl OSDisableInterrupts
mr r30, r3
bl __GXFifoReadDisable
lwz r3, __cpReg@sda21(r13)
rlwinm r0, r31, 0x10, 0x12, 0x1f
sth r31, 0x3c(r3)
lwz r3, __cpReg@sda21(r13)
sth r0, 0x3e(r3)
lwz r3, gx@sda21(r13)
lwzu r0, 8(r3)
rlwinm r0, r0, 0, 0x1f, 0x1d
ori r0, r0, 2
stw r0, 0(r3)
lwz r3, gx@sda21(r13)
lwzu r0, 8(r3)
rlwinm r0, r0, 0, 0x1b, 0x19
ori r0, r0, 0x20
stw r0, 0(r3)
lwz r4, gx@sda21(r13)
lwz r3, __cpReg@sda21(r13)
lwz r0, 8(r4)
sth r0, 2(r3)
stw r31, __GXCurrentBP@sda21(r13)
bl __GXFifoReadEnable
mr r3, r30
bl OSRestoreInterrupts
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
mtlr r0
blr
.global GXDisableBreakPt
GXDisableBreakPt:
mflr r0
stw r0, 4(r1)
stwu r1, -8(r1)
bl OSDisableInterrupts
lwz r4, gx@sda21(r13)
li r0, 0
addi r5, r4, 8
lwz r4, 8(r4)
rlwinm r4, r4, 0, 0x1f, 0x1d
stw r4, 0(r5)
lwz r4, gx@sda21(r13)
addi r5, r4, 8
lwz r4, 8(r4)
rlwinm r4, r4, 0, 0x1b, 0x19
stw r4, 0(r5)
lwz r5, gx@sda21(r13)
lwz r4, __cpReg@sda21(r13)
lwz r5, 8(r5)
sth r5, 2(r4)
stw r0, __GXCurrentBP@sda21(r13)
bl OSRestoreInterrupts
lwz r0, 0xc(r1)
addi r1, r1, 8
mtlr r0
blr
.global __GXFifoInit
__GXFifoInit:
mflr r0
lis r3, GXCPInterruptHandler@ha
stw r0, 4(r1)
addi r4, r3, GXCPInterruptHandler@l
li r3, 0x11
stwu r1, -8(r1)
bl __OSSetInterruptHandler
li r3, 0x4000
bl __OSUnmaskInterrupts
bl OSGetCurrentThread
li r0, 0
stw r3, __GXCurrentThread@sda21(r13)
stw r0, GXOverflowSuspendInProgress@sda21(r13)
stw r0, CPUFifo@sda21(r13)
stw r0, GPFifo@sda21(r13)
lwz r0, 0xc(r1)
addi r1, r1, 8
mtlr r0
blr
.global __GXFifoReadEnable
__GXFifoReadEnable:
lwz r3, gx@sda21(r13)
lwzu r0, 8(r3)
rlwinm r0, r0, 0, 0, 0x1e
ori r0, r0, 1
stw r0, 0(r3)
lwz r4, gx@sda21(r13)
lwz r3, __cpReg@sda21(r13)
lwz r0, 8(r4)
sth r0, 2(r3)
blr
.global __GXFifoReadDisable
__GXFifoReadDisable:
lwz r3, gx@sda21(r13)
lwzu r0, 8(r3)
rlwinm r0, r0, 0, 0, 0x1e
stw r0, 0(r3)
lwz r4, gx@sda21(r13)
lwz r3, __cpReg@sda21(r13)
lwz r0, 8(r4)
sth r0, 2(r3)
blr
.global __GXFifoLink
__GXFifoLink:
clrlwi. r0, r3, 0x18
beq lbl_800A66BC
li r0, 1
b lbl_800A66C0
lbl_800A66BC:
li r0, 0
lbl_800A66C0:
lwz r3, gx@sda21(r13)
slwi r0, r0, 4
addi r4, r3, 8
lwz r3, 8(r3)
rlwinm r3, r3, 0, 0x1c, 0x1a
or r0, r3, r0
stw r0, 0(r4)
lwz r4, gx@sda21(r13)
lwz r3, __cpReg@sda21(r13)
lwz r0, 8(r4)
sth r0, 2(r3)
blr
.global __GXWriteFifoIntEnable
__GXWriteFifoIntEnable:
lwz r5, gx@sda21(r13)
rlwinm r3, r3, 2, 0x16, 0x1d
rlwinm r0, r4, 3, 0x15, 0x1c
addi r6, r5, 8
lwz r5, 8(r5)
rlwinm r4, r5, 0, 0x1e, 0x1c
or r3, r4, r3
stw r3, 0(r6)
lwz r3, gx@sda21(r13)
addi r4, r3, 8
lwz r3, 8(r3)
rlwinm r3, r3, 0, 0x1d, 0x1b
or r0, r3, r0
stw r0, 0(r4)
lwz r4, gx@sda21(r13)
lwz r3, __cpReg@sda21(r13)
lwz r0, 8(r4)
sth r0, 2(r3)
blr
.global __GXWriteFifoIntReset
__GXWriteFifoIntReset:
lwz r5, gx@sda21(r13)
clrlwi r3, r3, 0x18
rlwinm r0, r4, 1, 0x17, 0x1e
addi r6, r5, 0x10
lwz r5, 0x10(r5)
rlwinm r4, r5, 0, 0, 0x1e
or r3, r4, r3
stw r3, 0(r6)
lwz r3, gx@sda21(r13)
addi r4, r3, 0x10
lwz r3, 0x10(r3)
rlwinm r3, r3, 0, 0x1f, 0x1d
or r0, r3, r0
stw r0, 0(r4)
lwz r4, gx@sda21(r13)
lwz r3, __cpReg@sda21(r13)
lwz r0, 0x10(r4)
sth r0, 4(r3)
blr
.global GXGetCPUFifo
GXGetCPUFifo:
lwz r3, CPUFifo@sda21(r13)
blr
.section .sbss, "wa"
CPUFifo:
.skip 0x4
GPFifo:
.skip 0x4
__GXCurrentThread:
.skip 0x4
CPGPLinked:
.skip 0x4
GXOverflowSuspendInProgress:
.skip 0x4
BreakPointCB:
.skip 0x4
__GXOverflowCount:
.skip 0x4
__GXCurrentBP:
.skip 0x4