mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
[sdmmc] sdmmc_handle_cpu_transfer: handle unaligned buffers
This commit is contained in:
parent
b9b13e215f
commit
ff2472385f
2 changed files with 40 additions and 4 deletions
|
@ -1033,10 +1033,28 @@ static int sdmmc_handle_cpu_transfer(struct mmc *mmc, uint16_t blocks, bool is_w
|
|||
|
||||
// Transfer the data to the relevant
|
||||
if (is_write) {
|
||||
if ((uintptr_t)buffer & 3) {
|
||||
// Handle unaligned buffers
|
||||
uint32_t w;
|
||||
uint8_t *data = (uint8_t *)buffer;
|
||||
w = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
|
||||
mmc->regs->buffer = w;
|
||||
} else {
|
||||
mmc->regs->buffer = *buffer;
|
||||
}
|
||||
} else {
|
||||
if ((uintptr_t)buffer & 3) {
|
||||
// Handle unaligned buffers
|
||||
uint32_t w = mmc->regs->buffer;
|
||||
uint8_t *data = (uint8_t *)buffer;
|
||||
data[0] = w & 0xFF;
|
||||
data[1] = (w >> 8) & 0xFF;
|
||||
data[2] = (w >> 16) & 0xFF;
|
||||
data[3] = (w >> 24) & 0xFF;
|
||||
} else {
|
||||
*buffer = mmc->regs->buffer;
|
||||
}
|
||||
}
|
||||
|
||||
// Advance by a register size...
|
||||
bytes_remaining_in_block -= sizeof(mmc->regs->buffer);
|
||||
|
|
|
@ -1033,10 +1033,28 @@ static int sdmmc_handle_cpu_transfer(struct mmc *mmc, uint16_t blocks, bool is_w
|
|||
|
||||
// Transfer the data to the relevant
|
||||
if (is_write) {
|
||||
if ((uintptr_t)buffer & 3) {
|
||||
// Handle unaligned buffers
|
||||
uint32_t w;
|
||||
uint8_t *data = (uint8_t *)buffer;
|
||||
w = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
|
||||
mmc->regs->buffer = w;
|
||||
} else {
|
||||
mmc->regs->buffer = *buffer;
|
||||
}
|
||||
} else {
|
||||
if ((uintptr_t)buffer & 3) {
|
||||
// Handle unaligned buffers
|
||||
uint32_t w = mmc->regs->buffer;
|
||||
uint8_t *data = (uint8_t *)buffer;
|
||||
data[0] = w & 0xFF;
|
||||
data[1] = (w >> 8) & 0xFF;
|
||||
data[2] = (w >> 16) & 0xFF;
|
||||
data[3] = (w >> 24) & 0xFF;
|
||||
} else {
|
||||
*buffer = mmc->regs->buffer;
|
||||
}
|
||||
}
|
||||
|
||||
// Advance by a register size...
|
||||
bytes_remaining_in_block -= sizeof(mmc->regs->buffer);
|
||||
|
|
Loading…
Reference in a new issue