-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from rust-wii/ios
❇️ feat(IOS): Add IOS module.
- Loading branch information
Showing
8 changed files
with
884 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
[package] | ||
name = "template" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[profile] | ||
dev = { panic = "abort" } | ||
release = { panic = "abort", lto = true, codegen-units = 1, strip = "symbols", opt-level = "s" } | ||
|
||
[dependencies] | ||
ogc-rs = { path = "../../" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::process::Command; | ||
fn main() { | ||
let dkp_path = std::env::var("DEVKITPRO").expect("Please set $DEVKITPRO"); | ||
println!("cargo:rustc-link-search=native={}/libogc/lib/wii", dkp_path); | ||
|
||
//checks if the build folder exists. If it does, it deletes it. | ||
let _ = std::fs::remove_dir_all("build"); | ||
|
||
let _ = std::fs::create_dir("build"); | ||
|
||
|
||
let libgcc_location = match Command::new("powerpc-eabi-gcc").arg("-print-libgcc-file-name").output() { | ||
Ok(output) => output, | ||
Err(_e) => panic!("Could not find powerpc-eabi-gcc or the libgcc on the host machine!"), | ||
}; | ||
let output = libgcc_location.stdout; | ||
let parsed_output = | ||
String::from_utf8(output).expect("powerpc-eabi-gcc command output returned a non-utf8 string.").replace("\n", ""); | ||
|
||
let _ = match Command::new("powerpc-eabi-ar").arg("x").arg(parsed_output).arg("crtresxfpr.o").arg("crtresxgpr.o").output() { | ||
Ok(output) => output, | ||
Err(_e) => panic!("powerpc-eabi-ar command failed"), | ||
}; | ||
|
||
std::fs::rename("crtresxgpr.o", "build/crtresxgpr.o").expect("Could not move crtresxgpr.o"); | ||
std::fs::rename("crtresxfpr.o", "build/crtresxfpr.o").expect("Could not move crtresxfpr.o"); | ||
|
||
println!("cargo::rustc-link-arg=build/crtresxgpr.o"); | ||
println!("cargo::rustc-link-arg=build/crtresxfpr.o"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"arch": "powerpc", | ||
"cpu": "750", | ||
"data-layout": "E-m:e-p:32:32-Fn32-i64:64-n32", | ||
"dynamic-linking": false, | ||
"env": "newlib", | ||
"executables": true, | ||
"has-elf-tls": false, | ||
"has-rpath": true, | ||
"llvm-target": "powerpc-unknown-eabi", | ||
"linker": "powerpc-eabi-gcc", | ||
"linker-flavor": "gcc", | ||
"linker-is-gnu": true, | ||
"os": "rvl-ios", | ||
"pre-link-args": { | ||
"gcc": [ | ||
"-mrvl", | ||
"-meabi", | ||
"-mhard-float" | ||
] | ||
}, | ||
"panic-strategy": "abort", | ||
"relocation-model": "static", | ||
"target-endian": "big", | ||
"target-family": "unix", | ||
"target-mcount": "_mcount", | ||
"target-c-int-width": "32", | ||
"target-pointer-width": "32", | ||
"vendor": "nintendo" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#![no_std] | ||
#![feature(start)] | ||
|
||
use alloc::vec; | ||
use ogc_rs::{ | ||
ios::{self, Mode, SeekMode}, | ||
print, println, | ||
}; | ||
|
||
extern crate alloc; | ||
|
||
#[start] | ||
fn main(_argc: isize, _argv: *const *const u8) -> isize { | ||
// Try to open SYSCONF | ||
if let Ok(fd) = ios::open(c"/shared2/sys/SYSCONF", Mode::Read) { | ||
// Try to grab size or default to 0; | ||
const GET_FILE_STATS: i32 = 11; | ||
let mut out_buf = [0u8; 8]; | ||
let (size, seek_pos) = if ios::ioctl(fd, GET_FILE_STATS, &[], &mut out_buf).is_ok() { | ||
( | ||
usize::try_from(u32::from_be_bytes(out_buf[0..4].try_into().unwrap())).unwrap(), | ||
usize::try_from(u32::from_be_bytes(out_buf[4..8].try_into().unwrap())).unwrap(), | ||
) | ||
} else { | ||
(0usize, 0usize) | ||
}; | ||
println!("{:?}, {:?}", size, seek_pos); | ||
|
||
if seek_pos != 0 { | ||
// Try to seek to the start | ||
let _ = ios::seek(fd, 0, SeekMode::Start); | ||
} | ||
|
||
let mut bytes = vec![0; size]; | ||
if let Ok(bytes_read) = ios::read(fd, &mut bytes) { | ||
// SAFETY: I read this much bytes | ||
unsafe { bytes.set_len(bytes_read) }; | ||
}; | ||
|
||
println!("{:?}", bytes); | ||
|
||
let _ = ios::close(fd); | ||
} | ||
|
||
loop { | ||
core::hint::spin_loop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
"pre-link-args": { | ||
"gcc": [ | ||
"-mrvl", | ||
"-mcpu=750", | ||
"-meabi", | ||
"-msdata=eabi", | ||
"-mhard-float" | ||
] | ||
}, | ||
|
Oops, something went wrong.