Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release/2.3.0' into playback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlee337 committed Feb 3, 2021
2 parents c8bd011 + 79c6062 commit 14f7268
Show file tree
Hide file tree
Showing 12 changed files with 544 additions and 502 deletions.
5 changes: 5 additions & 0 deletions Bootloader/EXISpoof.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
################################################################################
# Address: 80346314
################################################################################

b 0x58
103 changes: 103 additions & 0 deletions Bootloader/main.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
################################################################################
# Address: 803753b0
################################################################################

################################################################################
# Function: Bootloader
# ------------------------------------------------------------------------------
# Description: Requests codeset length and receives codeset file. Permanently
# allocates memory for the codeset in the heap.
# ------------------------------------------------------------------------------
# In: r3 = pointer to buffer
# r4 = buffer length
# r5 = read (0x0) or write (0x1)
################################################################################
.include "Common/Common.s"

.set REG_HeapLo,31
.set REG_FileSize,28
.set REG_File,27
.set REG_HeapID,26
.set REG_Buffer,25

# Original codeline
stw r31, -0x3FE8 (r13)

backup

#Create a temp heap for getting the codeset size
addi r4,REG_HeapLo,32 + 32 #heap hi, 32 bytes padding?
mr r3,REG_HeapLo #heap lo = start
branchl r12,0x803440e8
mr REG_HeapID,r3

# Alloc temp buffer
mr r3,REG_HeapID
li r4,32
branchl r12,0x80343ef0
mr REG_Buffer,r3

# request gct size from slippi
li r3, CONST_SlippiCmdGctLength # store gct length request ID
stb r3,0x0(REG_Buffer)
# Transfer buffer over DMA
mr r3,REG_Buffer #Buffer Pointer
li r4,1 #Buffer Length = command
li r5,CONST_ExiWrite
branchl r12,FN_EXITransferBuffer
# Receive response
mr r3,REG_Buffer
li r4,4 #Buffer Length
li r5,CONST_ExiRead
branchl r12,FN_EXITransferBuffer
# Read file size off buffer
lwz REG_FileSize,0x0(REG_Buffer)

# Destroy the temp heap
mr r3,REG_HeapID
branchl r12,0x80344154

#Align
addi REG_FileSize,REG_FileSize,31
rlwinm REG_FileSize, REG_FileSize, 0, 0, 26
#Create heap of this size
add r4,REG_HeapLo,REG_FileSize #heap hi = start + filesize
addi r4,r4, 32 #heap hi, 32 bytes padding?
mr r3,REG_HeapLo #heap lo = start
mr REG_HeapLo,r4 #new start = heap hi
branchl r12,0x803440e8
mr REG_HeapID,r3
#Alloc from this heap
mr r3,REG_HeapID
mr r4,REG_FileSize
branchl r12,0x80343ef0
mr REG_Buffer,r3

#Load file here
li r3, CONST_SlippiCmdGctLoad # store gct length request ID
stb r3,0x0(REG_Buffer)
stw REG_Buffer,0x1(REG_Buffer) # store buffer address to buffer
# Transfer buffer over DMA
mr r3,REG_Buffer #Buffer Pointer
li r4,5 #Buffer Length = command + address
li r5,CONST_ExiWrite
branchl r12,FN_EXITransferBuffer
# Receive response
mr r3,REG_Buffer
mr r4,REG_FileSize #Buffer Length
li r5,CONST_ExiRead
branchl r12,FN_EXITransferBuffer

stw REG_HeapLo, -0x3FE8 (r13) # store new heap low

# Save pointer to gecko codes
load r3,GeckoHeapPtr
stw REG_Buffer, 0 (r3)


Exit:
restore

# overwrite r31 which stores the low bound. A few upcoming instructions rely
# on this to initialize the heap
lwz r31, -0x3FE8(r13)
3 changes: 3 additions & 0 deletions Common/Common.s
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ rlwinm \reg, \reg, 8, 0xFFFF # Loads major and minor scene into bottom of reg
# For Slippi file loads
.set CONST_SlippiCmdFileLength, 0xD1
.set CONST_SlippiCmdFileLoad, 0xD2
.set CONST_SlippiCmdGctLength, 0xD3
.set CONST_SlippiCmdGctLoad, 0xD4

.set CONST_FirstFrameIdx, -123

Expand All @@ -337,6 +339,7 @@ rlwinm \reg, \reg, 8, 0xFFFF # Loads major and minor scene into bottom of reg
.set FSToggleAddr, RtocAddress + FSToggle
.set HideWaitingForGameAddress, RtocAddress + HideWaitingForGame
.set CFOptionsAddress, RtocAddress - ControllerFixOptions
.set GeckoHeapPtr, 0x80005600

################################################################################
# Offsets from r13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@ ExiTransferBuffer:
branchl r12, OSDisableInterrupts
mr REG_InterruptIdx, r3

# Start flush loop to write the data in buf through to RAM.
# Cache blocks are 32 bytes in length and the buffer obtained from malloc
# should be guaranteed to be aligned at the start of a cache block.
mr r3, REG_BufferPointer
add r4,REG_BufferPointer,REG_BufferLength
cmpwi REG_TransferBehavior,CONST_ExiRead # Check if writing or reading
beq InitializeEXI
cmpwi REG_TransferBehavior,CONST_ExiRead
beq FLUSH_WRITE_LOOP_END # Only flush before write when writing

# Start flush loop to write the data in buf through to RAM.
# Cache blocks are 32 bytes in length and the buffer obtained from malloc
# should be guaranteed to be aligned at the start of a cache block.
li r3, 0
FLUSH_WRITE_LOOP:
dcbf 0, r3
dcbf REG_BufferPointer, r3
addi r3, r3, 32
cmpw r3, r4
cmpw r3, REG_BufferLength
blt+ FLUSH_WRITE_LOOP
sync
isync
FLUSH_WRITE_LOOP_END:

InitializeEXI:
# Step 1 - Prepare slot
Expand Down Expand Up @@ -91,15 +92,20 @@ InitializeEXI:
li r3, STG_EXIIndex # Load input param for slot
branchl r12, EXIDetach

FLUSH_READ_LOOP:
cmpwi REG_TransferBehavior,CONST_ExiRead # Check if writing or reading
bne Exit
dcbi 0, r3
cmpwi REG_TransferBehavior,CONST_ExiRead
bne INVALIDATE_READ_LOOP_END # Only invalidate cache when doing a read

# Invalidate cache for the values we just read from EXI. This was actually
# broken forever and stuff still worked so it might not be needed
li r3, 0
INVALIDATE_READ_LOOP:
dcbi REG_BufferPointer, r3
addi r3, r3, 32
cmpw r3, r4
blt+ FLUSH_READ_LOOP
cmpw r3, REG_BufferLength
blt+ INVALIDATE_READ_LOOP
sync
isync
INVALIDATE_READ_LOOP_END:

Exit:
mr r3, REG_InterruptIdx
Expand Down
2 changes: 2 additions & 0 deletions Online/Core/InitPause.asm
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ ClientPause_Paused_Disconnect:
# Play SFX
li r3,2
branchl r12,0x80024030
# Stop Rumble
branchl r12, 0x80378330
# Set the address normally used to indicate who paused
load r3, 0x8046b6a0 # Some static match state struct
stb REG_PORT, 0x1(r3) # Write pauser index
Expand Down
Binary file added Output/Bootloader/bootloader.gct
Binary file not shown.
Loading

0 comments on commit 14f7268

Please sign in to comment.