2016-11-01 19:05:04 +01:00
|
|
|
; Code by Normmatt
|
|
|
|
|
2016-03-21 03:20:15 +01:00
|
|
|
.arm.little
|
2015-08-05 03:57:37 +02:00
|
|
|
|
2016-05-25 14:34:43 +02:00
|
|
|
.create "build/emunand.bin", 0
|
2015-08-05 03:57:37 +02:00
|
|
|
.arm
|
2016-10-17 23:39:13 +02:00
|
|
|
; Original code that still needs to be executed
|
2016-01-13 21:16:03 +01:00
|
|
|
mov r4, r0
|
|
|
|
mov r5, r1
|
|
|
|
mov r7, r2
|
|
|
|
mov r6, r3
|
2016-10-17 23:39:13 +02:00
|
|
|
; End
|
2015-08-05 03:57:37 +02:00
|
|
|
|
2016-10-17 23:39:13 +02:00
|
|
|
; If we're already trying to access the SD, return
|
2016-01-13 21:16:03 +01:00
|
|
|
ldr r2, [r0, #4]
|
2016-03-21 03:20:15 +01:00
|
|
|
ldr r1, [sdmmc]
|
2016-01-13 21:16:03 +01:00
|
|
|
cmp r2, r1
|
2016-10-17 23:39:13 +02:00
|
|
|
beq out
|
2015-08-05 03:57:37 +02:00
|
|
|
|
2016-10-17 23:39:13 +02:00
|
|
|
str r1, [r0, #4] ; Set object to be SD
|
|
|
|
ldr r2, [r0, #8] ; Get sector to read
|
|
|
|
cmp r2, #0 ; For GW compatibility, see if we're trying to read the ncsd header (sector 0)
|
2016-01-13 21:16:03 +01:00
|
|
|
|
2016-03-21 03:20:15 +01:00
|
|
|
ldr r3, [nand_offset]
|
2016-10-17 23:39:13 +02:00
|
|
|
add r2, r3 ; Add the offset to the NAND in the SD
|
2016-01-13 21:16:03 +01:00
|
|
|
|
2016-03-21 03:20:15 +01:00
|
|
|
ldreq r3, [ncsd_header_offset]
|
2016-10-17 23:39:13 +02:00
|
|
|
addeq r2, r3 ; If we're reading the ncsd header, add the offset of that sector
|
2016-01-13 21:16:03 +01:00
|
|
|
|
2016-10-17 23:39:13 +02:00
|
|
|
str r2, [r0, #8] ; Store sector to read
|
2016-01-13 21:16:03 +01:00
|
|
|
|
2016-10-17 23:39:13 +02:00
|
|
|
out:
|
2016-01-13 21:16:03 +01:00
|
|
|
; Restore registers.
|
|
|
|
mov r1, r5
|
|
|
|
mov r2, r7
|
|
|
|
mov r3, r6
|
|
|
|
|
|
|
|
; Return 4 bytes behind where we got called,
|
2016-10-17 23:39:13 +02:00
|
|
|
; due to the offset of this function being stored there
|
2016-01-13 21:16:03 +01:00
|
|
|
mov r0, lr
|
|
|
|
add r0, #4
|
|
|
|
bx r0
|
2016-10-17 23:39:13 +02:00
|
|
|
|
2015-08-05 03:57:37 +02:00
|
|
|
.pool
|
2016-03-21 03:20:15 +01:00
|
|
|
sdmmc: .ascii "SDMC"
|
2016-10-17 23:39:13 +02:00
|
|
|
nand_offset: .ascii "NAND" ; For rednand this should be 1
|
|
|
|
ncsd_header_offset: .ascii "NCSD" ; Depends on nand manufacturer + emunand type (GW/RED)
|
2016-08-28 13:49:15 +02:00
|
|
|
.close
|