Add a module for IPC with the Starlet running IOS#22
Add a module for IPC with the Starlet running IOS#22linkmauve wants to merge 4 commits intorust-wii:mainfrom
Conversation
libstd’s runtime changed the prototype of lang = "start" in ddee45e1d7fd34563c13513d974f792fae41a2f7 to support changing the SIGPIPE behaviour on Linux, so this function now takes a third argument on every platform. Additionally, it now supports user_main() returning any Termination, so we don’t need a transmute() any longer. :)
This fixes the build on current nightly (since 2023-04-22).
This lets us open file descriptors and perform actions on them. MINI uses a different protocol, so this can’t currently be used to talk with this Starlet firmware, see https://wiibrew.org/wiki/MINI TODO: Figure out why it only works on Dolphin and not on a real Wii.
This is done using the /dev/stm/immediate device, see https://wiibrew.org/wiki//dev/stm/immediate
ProfElements
left a comment
There was a problem hiding this comment.
This looks rough. Why not use the interrupt provided via the PI interface
| const HW_IPC_ARMMSG: u32 = BASE + 8; | ||
|
|
||
| /// The type of a file descriptor in IOS. | ||
| pub type RawFd = i32; |
There was a problem hiding this comment.
The file descriptor is never less then zero, using a u32 would be a better option
| let ptr = Box::into_raw(self); | ||
|
|
||
| // Flush the IPC data from its cache line, so that the Starlet will see it. | ||
| unsafe { DCFlushRange(ptr as *const _, core::mem::size_of::<Self>() as u32) }; |
There was a problem hiding this comment.
you can use try_into here instead of just casting to a u32. maybe using a usize which is the same because of target_ptr_width = 32 could be an option
| // Read the reply from IOS. | ||
| let armmsg = read32(HW_IPC_ARMMSG); | ||
| let command = unsafe { Box::from_raw((armmsg | 0x8000_0000) as *mut Ipc) }; | ||
| assert_eq!(command.command, Command::Async); |
There was a problem hiding this comment.
I don't think Command::Async is the right name for this. Maybe change Async to Reply ?
| use luma_core::ios; | ||
|
|
||
| fn main() { | ||
| let fd = ios::open("/dev/stm/immediate\0", ios::Mode::None).unwrap(); |
There was a problem hiding this comment.
Maybe using CStr instead of providing the null bytes is a better option here
|
|
||
| fn main() { | ||
| let fd = ios::open("/dev/stm/immediate\0", ios::Mode::None).unwrap(); | ||
| ios::ioctl(fd, 0x2003, &[], &[]).unwrap(); |
There was a problem hiding this comment.
This is hard to read, maybe move 0x2003 to a named const eg. const SOME_IOCTL: u32 = 0x2003
This lets us open file descriptors and perform actions on them.
MINI uses a different protocol, so this can’t currently be used to talk with this Starlet firmware.
There is also an example for shutting down the Wii, using the /dev/stm/immediate device.
TODO: Figure out why it only works on Dolphin and not on a real Wii.