Skip to content

Conversation

@linkmauve
Copy link
Collaborator

@linkmauve linkmauve commented Apr 21, 2023

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.

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
Copy link
Collaborator

@ProfElements ProfElements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hard to read, maybe move 0x2003 to a named const eg. const SOME_IOCTL: u32 = 0x2003

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.

2 participants