.include "macros.inc"
.section .init, "ax"
.global __TRK_reset
__TRK_reset:
mflr r0
stw r0, 4(r1)
stwu r1, -8(r1)
bl __TRK_copy_vectors
addi r1, r1, 8
lwz r0, 4(r1)
mtlr r0
blr
.section .text, "ax"
.global InitMetroTRK
InitMetroTRK:
addi r1, r1, -4
stw r3, 0(r1)
lis r3, gTRKCPUState@h
ori r3, r3, gTRKCPUState@l
stmw r0, 0(r3)
lwz r4, 0(r1)
addi r1, r1, 4
stw r1, 4(r3)
stw r4, 0xc(r3)
mflr r4
stw r4, 0x84(r3)
stw r4, 0x80(r3)
mfcr r4
stw r4, 0x88(r3)
mfmsr r4
ori r3, r4, 0x8000
xori r3, r3, 0x8000
mtmsr r3
mtspr 0x1b, r4
bl TRKSaveExtended1Block
lis r3, gTRKCPUState@h
ori r3, r3, gTRKCPUState@l
.4byte 0xB8030000
li r0, 0
mtspr 0x3f2, r0
mtspr 0x3f5, r0
lis r1, 0x80426008@h
ori r1, r1, 0x80426008@l
mr r3, r5
bl InitMetroTRKCommTable
cmpwi r3, 1
bne lbl_8008BAA4
lwz r4, 0x84(r3)
mtlr r4
.4byte 0xB8030000
blr
lbl_8008BAA4:
b TRK_main
.global EnableMetroTRKInterrupts
EnableMetroTRKInterrupts:
mflr r0
stw r0, 4(r1)
stwu r1, -8(r1)
bl EnableEXI2Interrupts
addi r1, r1, 8
lwz r0, 4(r1)
mtlr r0
blr
.global TRKTargetTranslate
TRKTargetTranslate:
lis r4, lc_base@ha
addi r4, r4, lc_base@l
lwz r4, 0(r4)
cmplw r3, r4
blt lbl_8008BB04
addi r0, r4, 0x4000
cmplw r3, r0
bge lbl_8008BB04
lis r4, gTRKCPUState@ha
addi r4, r4, gTRKCPUState@l
lwz r0, 0x238(r4)
clrlwi r0, r0, 0x1e
cmplwi r0, 0
beq lbl_8008BB04
b lbl_8008BB0C
lbl_8008BB04:
clrlwi r0, r3, 2
oris r3, r0, 0x8000
lbl_8008BB0C:
blr
.global TRK_copy_vector
TRK_copy_vector:
mflr r0
stw r0, 4(r1)
stwu r1, -0x10(r1)
stw r31, 0xc(r1)
stw r30, 8(r1)
mr r30, r3
mr r3, r30
bl TRKTargetTranslate
lis r4, lbl_80003298@ha
addi r0, r4, lbl_80003298@l
mr r31, r3
add r4, r0, r30
mr r3, r31
li r5, 0x100
bl TRK_memcpy
mr r3, r31
li r4, 0x100
bl TRK_flush_cache
lwz r31, 0xc(r1)
lwz r30, 8(r1)
addi r1, r1, 0x10
lwz r0, 4(r1)
mtlr r0
blr
.global __TRK_copy_vectors
__TRK_copy_vectors:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
stw r29, 0xc(r1)
stw r28, 8(r1)
li r3, 0x44
bl TRKTargetTranslate
li r29, 0
lwz r28, 0(r3)
lis r3, TRK_ISR_OFFSETS@ha
slwi r4, r29, 2
addi r0, r3, TRK_ISR_OFFSETS@l
add r30, r0, r4
b lbl_8008BBB0
lbl_8008BBB0:
li r31, 1
b lbl_8008BBB8
lbl_8008BBB8:
b lbl_8008BBBC
lbl_8008BBBC:
slw r0, r31, r29
and r0, r28, r0
cmplwi r0, 0
beq lbl_8008BBD4
lwz r3, 0(r30)
bl TRK_copy_vector
lbl_8008BBD4:
addi r30, r30, 4
addi r29, r29, 1
cmpwi r29, 0xe
ble lbl_8008BBBC
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
lwz r29, 0xc(r1)
lwz r28, 8(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKInitializeTarget
TRKInitializeTarget:
mflr r0
stw r0, 4(r1)
stwu r1, -0x10(r1)
stw r31, 0xc(r1)
lis r3, gTRKState@ha
addi r31, r3, gTRKState@l
li r0, 1
stw r0, 0x98(r31)
bl __TRK_get_MSR
stw r3, 0x8c(r31)
lis r3, lc_base@ha
addi r3, r3, lc_base@l
lis r0, 0xe000
stw r0, 0(r3)
li r3, 0
lwz r31, 0xc(r1)
addi r1, r1, 0x10
lwz r0, 4(r1)
mtlr r0
blr
.section .data, "wa"
TRK_ISR_OFFSETS:
.4byte 0x00000100
.4byte 0x00000200
.4byte 0x00000300
.4byte 0x00000400
.4byte 0x00000500
.4byte 0x00000600
.4byte 0x00000700
.4byte 0x00000800
.4byte 0x00000900
.4byte 0x00000C00
.4byte 0x00000D00
.4byte 0x00000F00
.4byte 0x00001300
.4byte 0x00001400
.4byte 0x00001700
.4byte 0
.section .bss, "wa"
lc_base:
.skip 0x8