Skip to content

mx4sio: read and write buffers that are not word aligned - #959

Open
rickgaiser wants to merge 1 commit into
ps2dev:masterfrom
rickgaiser:mx4sio-unaligned-buffers
Open

rickgaiser wants to merge 1 commit into
ps2dev:masterfrom
rickgaiser:mx4sio-unaligned-buffers

Conversation

@rickgaiser

Copy link
Copy Markdown
Member

Summary

mx4sio_bd crashes the IOP when a block read or write gets a buffer that is not word aligned.

FatFs passes the caller's buffer straight to the block device for whole sectors, at any offset, so a read from an odd position in a file gives an odd buffer address. The SIO2 DMA and reverse_buffer work on words, which ends in an address error exception, repeated forever.

Reads and writes with such a buffer now go a sector at a time through an aligned buffer. Aligned buffers take the same path as before, so normal transfers keep their speed.

How to reproduce

Run a program from MX4SIO that reads a file at unaligned positions. Hexen II crashed this way while loading its data: ioptrap reported an address error in mx4sio with an odd address in $a0. USB mass storage handles the same reads without trouble.

Testing

On a real PS2, with sio2man, padman, mcman, bdm and bdmfs_fatfs built from this tree, on an exFAT card:

  • 16 MiB read back and compared, 4 MiB written and compared, no errors; read speed unchanged at about 1.5 MB/s.
  • The pad and the memory card working beside it.
  • Hexen II loading a level and running from the card, with its swap file on it: no exceptions.

Note

#958 changes adjacent lines in the same file. The two do not depend on each other.

🤖 Generated with Claude Code

FatFs passes the caller's buffer to the block device, at any offset: a
read from an odd position in a file gives an odd address. The SIO2 DMA and
reverse_buffer work on words, so such a buffer ended in an address error
exception on the IOP, repeated forever.

Take those a sector at a time through an aligned buffer. Aligned buffers
are transferred as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant