GithubHelp home page GithubHelp logo

overdrivenpotato / rust-psp Goto Github PK

View Code? Open in Web Editor NEW
555.0 16.0 31.0 7.75 MB

Rust on PSP. Panic and allocation support. Access PSP system libraries.

License: Other

Rust 98.74% Makefile 0.17% Shell 1.10%
psp pspsdk rust-psp eboot homebrew playstation-portable game game-development graphics rust

rust-psp's Introduction

rust-psp

A library for building full PSP modules, including both PRX plugins and regular homebrew apps.

#![no_std]
#![no_main]

psp::module!("sample_module", 1, 1);

fn psp_main() {
    psp::enable_home_button();
    psp::dprintln!("Hello PSP from rust!");
}

See examples directory for sample programs.

What about PSPSDK?

This project is a completely new SDK, with no dependency on the original C/C++ PSPSDK. It aims to be a complete replacement, with more efficient implementations of graphics functions, and the addition of missing libraries.

Features / Roadmap

  • core support
  • PSP system library support
  • alloc support
  • panic = "unwind" support
  • Macro-based VFPU assembler
  • Full 3D graphics support (faster than PSPSDK in some cases!)
  • No dependency on PSPSDK / PSPToolchain
  • Reach full parity with user mode support in PSPSDK
  • Port definitions to libc crate
  • Add support for creating kernel mode modules
  • Add std support
  • Automatically sign EBOOT.PBP files to run on unmodified PSPs
  • Implement / reverse undiscovered libraries

Dependencies

To compile for the PSP, you will need a Rust nightly version equal to or later than 2024-03-05 and the rust-src component. Please install Rust using https://rustup.rs/

Use the following if you are new to Rust. (Feel free to set an override manually per-project instead).

$ rustup default nightly && rustup component add rust-src

You also need cargo-psp installed:

$ cargo install cargo-psp

Running Examples

Enter one of the example directories, examples/hello-world for instance, and run cargo psp.

This will create an EBOOT.PBP file under target/mipsel-sony-psp/debug/

Assuming you have a PSP with custom firmware installed, you can simply copy this file into a new directory under PSP/GAME on your memory stick, and it will show up in your XMB menu.

.
└── PSP
    └── GAME
        └── hello-world
            └── EBOOT.PBP

If you do not have a PSP, we recommend using the PPSSPP emulator. Note that graphics code is very sensitive so if you're writing graphics code we recommend developing on real hardware. PPSSPP is more relaxed in some aspects.

Advanced usage: PRXEncrypter

If you don't have a PSP with CFW installed, you can manually sign the PRX using PRXEncrypter, and then re-package it using pack-pbp.

Advanced usage: PSPLink

If you have the PSPSDK installed and have built a working copy PSPLink manually, you can also use psplink and pspsh to run the .prx under target/mipsel-sony-psp/debug/ if you prefer. Refer to the installation and usage guides for those programs.

Debugging

Using the latest version of psplink and psp-gdb from the pspdev github organization (psplinkusb v3.1.0 and GNU gdb (GDB) 11.0.50.20210718-git or later), Rust types are fully supported, providing a rich debugging experience. Enable debug symbols in your release binaries

Cargo.toml

[profile.release]
debug = true

and follow the instructions in part 6 of the PSPlink manual

Usage

To use the psp crate in your own Rust programs, add it to Cargo.toml like any other dependency:

[dependencies]
psp = "x.y.z"

In your main.rs file, you need to setup a basic skeleton like so:

#![no_std]
#![no_main]

// Create a module named "sample_module" with version 1.0
psp::module!("sample_module", 1, 0);

fn psp_main() {
    psp::enable_home_button();
    psp::dprintln!("Hello PSP from rust!");
}

Now you can simply run cargo psp to build your EBOOT.PBP file. You can also invoke cargo psp --release to create a release build.

If you would like to customize your EBOOT with e.g. an icon or new title, you can create a Psp.toml file in the root of your project. Note that all keys are optional:

title = "XMB title"
xmb_icon_png = "path/to/24bit_144x80_image.png"
xmb_background_png = "path/to/24bit_480x272_background.png"
xmb_music_at3 = "path/to/ATRAC3_audio.at3"

More options can be found in the schema defintion here.

error[E0460]: found possibly newer version of crate ...

If you get an error like this:

error[E0460]: found possibly newer version of crate `panic_unwind` which `psp` depends on
 --> src/main.rs:4:5
  |
4 | use psp::dprintln;
  |     ^^^
  |
  = note: perhaps that crate needs to be recompiled?

Simply clean your target directory and it will be fixed:

$ cargo clean

rust-psp's People

Contributors

ayrtonm avatar doodlewind avatar flovangh avatar iridescentrose avatar lorenzofelletti avatar maxverevkin avatar mrawesome avatar overdrivenpotato avatar rogerahuntley avatar sajattack avatar sk83rjosh avatar waveywaves avatar zetanumbers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-psp's Issues

linking with `rust-lld`failed

Hi,

I'm currently working on a PR to bump up the embedded-graphics version to 0.7.1. I tried to compile the embedded-graphics example with cargo psp on macOS and on manjaro linux. On both I get the error linking with rust-lld failed ... rust-lld: error undefined ymbol: fmodf.

Add std support

This can be done via a fork for now, but ideally we can upstream this to the official rust repo. Depends on #49

Cannot Build `examples/rust-std-hello-world`

I am encountering errors when trying to build examples/rust-std-hello-world. Here is my environment.

PC: M2 MacBookAir
Rust Version: cargo 1.74.0-nightly (414d9e3a6 2023-09-22)
Build Command: RUST_PSP_BUILD_STD=1 cargo psp
Log:

❯ RUST_PSP_BUILD_STD=1 cargo psp
[NOTE]: Detected RUST_PSP_BUILD_STD env var, using "build-std".
   Compiling compiler_builtins v0.1.101
   Compiling core v0.0.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.148
   Compiling cc v1.0.79
   Compiling memchr v2.5.0
   Compiling proc-macro2 v1.0.78
   Compiling std v0.0.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/std)
   Compiling unicode-ident v1.0.12
   Compiling syn v1.0.109
   Compiling paste v1.0.14
   Compiling libm v0.2.8
   Compiling psp v0.3.7 (/Users/aethiopicuschan/tmp/rust-psp/psp)
   Compiling unstringify v0.1.4
   Compiling quote v1.0.35
   Compiling unwind v0.0.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/unwind)
   Compiling num_enum_derive v0.5.11
   Compiling rustc-std-workspace-core v1.99.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling adler v1.0.2
   Compiling rustc-demangle v0.1.23
   Compiling rustc-std-workspace-alloc v1.99.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling panic_unwind v0.0.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_unwind)
   Compiling panic_abort v0.0.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_abort)
   Compiling gimli v0.28.0
   Compiling std_detect v0.1.5 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling hashbrown v0.14.0
   Compiling object v0.32.0
   Compiling miniz_oxide v0.7.1
   Compiling addr2line v0.21.0
   Compiling proc_macro v0.0.0 (/Users/aethiopicuschan/.rustup/toolchains/nightly-2023-09-26-aarch64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling bitflags v1.3.2
   Compiling num_enum v0.5.11
error[E0658]: use of unstable library feature 'restricted_std'
  |
  = help: add `#![feature(restricted_std)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'restricted_std'
  --> /Users/aethiopicuschan/tmp/rust-psp/psp/src/lib.rs:88:9
   |
88 | pub use std::panic::catch_unwind;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: add `#![feature(restricted_std)]` to the crate attributes to enable

error[E0635]: unknown feature `psp_std`
  --> /Users/aethiopicuschan/tmp/rust-psp/psp/src/lib.rs:20:38
   |
20 | #![cfg_attr(feature = "std", feature(psp_std))]
   |                                      ^^^^^^^

Some errors have detailed explanations: E0635, E0658.
For more information about an error, try `rustc --explain E0635`.
error: could not compile `psp` (lib) due to 3 previous errors
`cargo build` command exited with status: ExitStatus(unix_wait_status(25856))

Is the issue I'm encountering related to my environment or the specific command I'm using? Alternatively, could this be attributed to a bug or features that are not yet implemented in the toolchain or library? Any insights or guidance on how to proceed would be greatly appreciated.

Thanks.

Problem with rust-lld

Hello there.

When I try to compile with cargo psp I get stuck on this error

error: linking with `rust-lld` failed: exit status: 1
= note: rust-lld: error: undefined symbol: strlen
          >>> referenced by c_str.rs:408 (src/ffi/c_str.rs:408)
          >>>               alloc-65f2e8dec69d54dc.alloc.1e0b9b8f-cgu.6.rcgu.o:(alloc::ffi::c_str::CString::from_raw::hf8e528a7891a1756) in archive /Users/mrcesar107/Documents/psp-dev/rust/target/mipsel-sony-psp/debug/deps/liballoc-65f2e8dec69d54dc.rlib

I'm trying to use it in a mac with m1 chip and also with a linux x64 computer

  • rustup 1.24.3 (ce5817a94 2021-05-31)
  • info: The currently active rustc version is rustc 1.63.0-nightly (490324f7b 2022-05-26)
  • [dependencies]
    psp = "0.2.0"

I'll appreciate a lot if anyone can help me with this problem. Thank you ;)

cannot build

Fails with this log

PS C:\Users\conziebonzie\Desktop\psp> cargo psp
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
   Compiling psp v0.2.2
error[E0557]: feature has been removed
 --> C:\Users\conziebonzie\.cargo\registry\src\index.crates.io-6f17d22bba15001f\psp-0.2.2\src\lib.rs:6:5
  |
6 |     untagged_unions,
  |     ^^^^^^^^^^^^^^^ feature has been removed
  |
  = note: unions with `Copy` and `ManuallyDrop` fields are stable; there is no intent to stabilize more

error[E0432]: unresolved import `core::panic::BoxMeUp`
  --> C:\Users\conziebonzie\.cargo\registry\src\index.crates.io-6f17d22bba15001f\psp-0.2.2\src\panic.rs:12:68
   |
12 | use core::{mem::{self, ManuallyDrop}, any::Any, panic::{PanicInfo, BoxMeUp, Location}};
   |                                                                    ^^^^^^^ no `BoxMeUp` in `panic`

error: unwinding panics are not supported without std
  |
  = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
  = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem

Some errors have detailed explanations: E0432, E0557.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `psp` (lib) due to 3 previous errors
`cargo build` command exited with status: ExitStatus(ExitStatus(101))
PS C:\Users\conziebonzie\Desktop\psp>

psp-hello-world-example rust-lld: error: --strip-all and --emit-relocs may not be used together

Fresh install, was looking to get started homebrewing somewhere. I still have a PSP, but what sold the deal was the incredible integration into Rust! Just like developing a normal Rust program.

Compiling the hello world example, however, failed with this.

Environment:

Default host: x86_64-unknown-linux-gnu
rustup home:  /home/shinichi/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)
bpf

installed targets for active toolchain
--------------------------------------

wasm32-unknown-unknown
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.59.0-nightly (efec54529 2021-12-04)

Error

   Compiling psp-hello-world-example v0.1.0 (/home/shinichi/source/rust-psp/examples/hello-world)
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: "rust-lld" "-flavor" "gnu" "--emit-relocs" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.1dvxhiqozxhnax6p.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.1jbozp62rdtspcki.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.2f4y6geg7q8tmzzl.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.2n939cxqcyvkm4zm.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.35zh3xdcf9mnlahg.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.4l8q58w309e8uxl7.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.4tzohso5uud2lmu2.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.4uizm1it4n5rvmyj.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.4zw6ef1533g1n0n1.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.5a1sk7asrejlxhvz.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.j6mffm6lx6dvy5j.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.jup3vqfcmegl9vk.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.tbsnez2jyccmt29.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.tvoskcf6h0i6x3i.rcgu.o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a.3ugzb26hdj0rwsm3.rcgu.o" "--as-needed" "-L" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps" "-L" "/home/shinichi/source/rust-psp/examples/hello-world/target/debug/deps" "-L" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/build/psp-5331f3a82de138d9/out" "-L" "/home/shinichi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-sony-psp/lib" "--start-group" "-Bstatic" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libpsp-1b097d29e42403d7.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libbitflags-e76b5db384bd4099.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libnum_enum-bb71ad21b1bf98e3.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libpanic_unwind-0ad6e09684aafd6d.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libunwind-9f962eaf1c8fee42.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/liblibc-9919ce7872eb5b4e.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libcfg_if-a68ee819c51dc776.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/liballoc-f52b6509161d11ab.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libpaste-728a443b7a53f844.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/librustc_std_workspace_core-3ad2d07ae1915367.rlib" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libcore-3219c33cda6fbcc2.rlib" "--end-group" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/libcompiler_builtins-59551438213631d6.rlib" "-Bdynamic" "--script" "/tmp/rustcnxutzJ/rustc-mipsel-sony-psp-linkfile.ld" "--eh-frame-hdr" "-znoexecstack" "-L" "/home/shinichi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-sony-psp/lib" "-o" "/home/shinichi/source/rust-psp/examples/hello-world/target/mipsel-sony-psp/debug/deps/psp_hello_world_example-0fdc2911ce5c492a" "-O1" "-s"
  = note: rust-lld: error: --strip-all and --emit-relocs may not be used together
          

error: could not compile `psp-hello-world-example` due to previous error

cargo psp doesn't seem to work in workspaces

I get the following error

   Compiling bitflags v1.3.2
   Compiling num_enum v0.5.11
   Compiling psp-test v0.1.0 ($DIR/workspacetest/psp-test)
    Finished dev [unoptimized + debuginfo] target(s) in 10.76s
Saved to $DIR/workspacetest/target/mipsel-sony-psp/debug/EBOOT.PBP
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-psp-0.2.2/src/fix_imports.rs:27:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrac

Here's a reproduction script:

#!/bin/bash -xe

cargo new workspacetest
cd workspacetest
cargo new psp-test
echo '
[workspace]
members = ["psp-test"]

' >> Cargo.toml

cd psp-test
cargo add psp

echo '#![no_std]
#![no_main]

// Create a module named "sample_module" with version 1.0
psp::module!("sample_module", 1, 0);

fn psp_main() {
    psp::enable_home_button();
    psp::dprintln!("Hello PSP from rust!");
}' > src/main.rs

cd ..
cargo psp -p psp-test

For whatever reason, this is producing EBOOT.PBP file, so it might not be that bad. But my real project for unknown to me reason does not have this line "Saved to ...EBOOT.PBP" at all. Investigating still, but would apreciate what to do with just what's described.

How to send HTTP requests?

Is there a way to send HTTP requests with this crate?
I would really like to, but can't figure out how.
Can somebody please help me?

Improve CI

@overdrivenpotato had some ideas on improving the Rust/Bash code for the CI test scripts and I want to file this tracking issue to make sure they don't get forgotten.

cargo psp issue

Is rust-psp not supported on Windows or did I do something wrong?

I am using the rustup-init.exe(64-bit) installer

toolchain info:

PS C:\Users\diamant3\Desktop\psp-controller> rustup show  
Default host: x86_64-pc-windows-msvc
rustup home:  C:\Users\diamant3\.rustup

installed toolchains
--------------------

stable-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc (default)

active toolchain
----------------

nightly-x86_64-pc-windows-msvc (default)
rustc 1.64.0-nightly (93ffde6f0 2022-07-23)

systeminfo:

PS C:\Users\diamant3\Desktop\psp-controller> systeminfo

Host Name:                 MSI
OS Name:                   Microsoft Windows 11 Home Single Language
OS Version:                10.0.22000 N/A Build 22000
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          diamant3

bug:

PS C:\Users\diamant3\Desktop\psp-controller> cargo psp
   Compiling psp v0.3.1
   Compiling cfg-if v0.1.10
   Compiling alloc v0.0.0 (C:\Users\diamant3\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc)
error[E0433]: failed to resolve: could not find `unix` in `os`
 --> C:\Users\diamant3\.cargo\registry\src\github.com-1ecc6299db9ec823\psp-0.3.1\build.rs:1:20
  |
1 | use std::{env, os::unix::prelude::OsStrExt, path::Path};
  |                    ^^^^ could not find `unix` in `os`

   Compiling unwind v0.0.0 (C:\Users\diamant3\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\unwind)
error[E0599]: no method named `as_bytes` found for struct `OsString` in the current scope
  --> C:\Users\diamant3\.cargo\registry\src\github.com-1ecc6299db9ec823\psp-0.3.1\build.rs:15:10
   |
15 |         .as_bytes()
   |          ^^^^^^^^ method not found in `OsString`

Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `psp` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
PS C:\Users\diamant3\Desktop\psp-controller> 

Set up intra-doc links

Intra-doc links just hit stable rust. This allows us to make links in the docs, which would be very helpful for doc comments like this one:

/// Wait until display list has finished executing
///
/// # Parameters
///
/// - `mode`: What to wait for, one of `GuSyncMode`
/// - `behavior`: How to sync, one of `GuSyncBehavior`
///

If someone out there wants an easy way to get started contributing to rust-psp, this is it.

More info:
https://blog.rust-lang.org/2020/11/19/Rust-1.48.html#easier-linking-in-rustdoc
https://doc.rust-lang.org/stable/rustdoc/linking-to-items-by-name.html

Create a 1.0 Milestone

It's nice to make the aims of the project clear to users and contributors alike. A milestone will be able to keep track of the progress made on the features in the Roadmap in a clear and concise way.

This also creates a chance to pool the relevant information for each feature and write up mentoring instructions to get the ball rolling.

  • User mode support (Was this #41?)
  • Kernel mode support
  • libc shim
  • std support
  • Complete EBOOT.PBP generation
    • Signing
  • Cleaning everything up
  • Tests
    • A remote debugger? 🥺

I'd also like to suggest keeping a knowledge base (maybe a Book) of what is known about the PSP. prx.md already contains the beginnings of this, and I think it'd be good to lay things out for future maintainers. I'd be happy to compile what we have at the moment if you can point me to what's been used in the implementation so far.

cargo-psp tries to build the .prx and EBOOT.PBP for a non-PSP binary in a workspace

Context

I have a workspace set up like this:

.
├── Cargo.toml
├── embedded_frontend/  // Graphic rendering with embedded-graphics
├── pc_app/             // PC-only app
├── psp_app/            // PSP-only app
└── src/                // backend library

pc_app and psp_app are binaries while the root crate and embedded_frontend are libraries (both imported by the binary crates).

Cargo.toml workspace:

[workspace]
members = ["pc_app", "embedded_frontend", "psp_app"]

Problem

When trying to compile the PSP app from the psp_app directory with __CARGO_TESTS_ONLY_SRC_ROOT=/path/to/rust/src/ cargo +nightly-2022-06-11 psp --release, I get the error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', cargo-psp/src/fix_imports.rs:27:42

Editing the cargo-psp source to add dbg!(&path.as_ref()); before the panic shows this: [cargo-psp/src/fix_imports.rs:27] &path.as_ref() = "[my workspace path]/target/mipsel-sony-psp/release/pc_app". But the PC app obviously can't be compiled for the PSP, and even if it was, it's not what I'm trying to build here.

In the meantime, I can exclude psp_app from the workspace but this breaks rust-analyzer on psp_app's source files.

I could make a pull request so that cargo-psp doesn't panic if a binary isn't present.

Figure out a debugging story

psp-gdb somewhat works for now, but it is a hefty dependency as it requires the C toolchain to be compiled and installed. It also does not support printing Rust types.

psp::math::cosf32 crashes PSP

Using the psp::math::cosf32 function crashes my PSP. It works fine in an emulator, but the moment I use that function on a real PSP, the console freezes and turns off after a few seconds.

Kernel Mode Support

There is currently no support for kernel mode functions. It would be nice to have an (off by default) kernel feature in this crate to enable all the missing kernel mode functions.

Unable to compile hello world

whenever i attempt to compile any of the example applications, it errors out, i tried the steps in this comment but that did not seem to help

error.log

Edit: If i downgrade to toolchain version to nightly-2021-11-17 it works fine, so it seems to be from the newer nightlies

Fix Panic/Exception Support

It seems with a recent nightly change panic/exception support has broken and resulted in any/all panics causing an invalid memory access deep within libunwind.

I have invested a couple of weeks investigating, and unfortunately haven't been able to find an easy solution to the problem. Though I have made some findings in the process which I'll dump below:

  • It seems that .eh_frame / .eh_frame_hdr have valid data
  • The data in both sections seems to expect RA/PC to be in a 0x00000000 - PROGRAM_SIZE range
  • This causes issues with both unwinding/libunwinding since they do not expect .text to be relocated
  • A workaround for unwinding is to manually patch RA/PC by subtracting 0x8804000
  • This causes stack traces/stack unwinding to work, but not raising exceptions, due to other pointers in both sections being incorrect (leading to an invalid memory access)
  • I'm not sure if this is a linker bug, or an issue with relocations, as we technically want/need vaddr to be at 0x0

At this stage, I'm not sure how to proceed, as fixing up the eh_frame data could be done during prx generation - but is likely to be a non-trivial amount of work. Similarly, forcing the linker to set a vaddr of 0x8804000 for .text might fix this issue as well, but also means a non-trivial amount of work. I'm not familiar with how the PSP relocates executables at runtime, so I'm not confident in either of these approaches being a one-size-fits-all solution.

If we're able to resolve the issue with frame data, we can also switch to unwinding as I've done here + upstream support to std similar to xous. Which will significantly reduce the complexity of panic handling, as we won't need to ship a patched libunwind or need nearly as much boilerplate.

Core support

In the README it mentions core support.
Doing cargo psp -Z build-std=core fails, however, and so does cargo psp -Z build-std=core,alloc (without alloc, I get a few more errors about alloc not being available, I imagine to use core I also have to enable the alloc crate).
I'm using the latest version of the library, with the embedded-graphics feature enabled.

I get the following error:

error[E0463]: can't find crate for `panic_unwind`
  --> C:\Users\luukv\.cargo\registry\src\github.com-1ecc6299db9ec823\psp-0.2.1\src\lib.rs:25:36
   |
25 | #[cfg(not(feature = "stub-only"))] extern crate panic_unwind;
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: language item required, but not found: `eh_personality`
  |
  = note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
  = help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`

Any idea what this means?

builds failed

cannot build my program and also an example program

to reproduce:

rustup default nightly && rustup component add rust-src
cargo install cargo-psp
git clone https://github.com/overdrivenpotato/rust-psp.git
cd rust-psp/examples/hello-world
cargo psp

expected approach

successful build

actual approach

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
   --> /home/cofeek-codes/Desktop/codes/rustlang/rust-psp/psp/src/panic.rs:109:20
    |
109 |     let mut info = PanicInfo::internal_constructor(message, location, can_unwind);
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------- an argument of type `bool` is missing
    |
note: associated function defined here
   --> /home/cofeek-codes/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/panic_info.rs:42:12
    |
42  |     pub fn internal_constructor(
    |            ^^^^^^^^^^^^^^^^^^^^
help: provide the argument
    |
109 |     let mut info = PanicInfo::internal_constructor(message, location, can_unwind, /* bool */);
    |                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0061`.
warning: `psp` (lib) generated 1 warning
error: could not compile `psp` (lib) due to previous error; 1 warning emitted
`cargo build` command exited with status: ExitStatus(unix_wait_status(25856))

Matrices are transposed

Hello! First of all, great work on this awesome library! Really easy to use and get started with.

However, I've been trying to do some VFPU stuff and ran into some issues. I made a commit at gardell@273a9af that should show the problem.

I'm loading a ScePspFMatrix4 into the columns C000, C010, C020 and C030 then perform a vtfm4.q on the M100 register. But when I look at the result, it is as if the matrix was transposed. If I use E100 I get the results that I want.

Looking at http://hitmen.c02.at/files/yapspd/psp_doc/chap4.html section 4.5.1 Registers it is explained that C000, C010, C020 and C030 are indeed the columns of the matrix M100 and that E100 is the transpose of M100.

I also set up the example matrices from the above commit in Wolfram Alpha to double check:
https://www.wolframalpha.com/input?i=transpose%28%7B%7B1%2C+2%2C+3%2C+4%7D%2C+%7B5%2C+6%2C+7%2C+8%7D%2C+%7B9%2C+10%2C+11%2C+12%7D%2C+%7B13%2C+14%2C+15%2C+16%7D%7D%29+*+%7B%7B17%7D%2C+%7B18%7D%2C+%7B19%7D%2C+%7B20%7D%7D
note that Wolfram Alpha uses row-major order, so a transpose() there is needed. To have row-major order with the VFPU I could have used R000, R001, R002, R003 when loading the matrix in my example above..

Doesn't this mean that, in this library the symbols M100 and E100 should swap places?

Thanks,
Johan

Cannot build

I want to make a project on v0.3.3, but build fails:

Compiling psp v0.3.3
error[E0605]: non-primitive cast: `*mut &mut dyn BoxMeUp` as `&mut dyn BoxMeUp`
   --> /home/slendi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/psp-0.3.3/src/panic.rs:151:42
    |
151 |         panic_unwind::__rust_start_panic(obj as _)
    |                                          ^^^^^^^^ invalid cast
    |
help: consider borrowing the value
    |
151 |         panic_unwind::__rust_start_panic(&mut *obj as _)
    |                                          ++++++

error[E0277]: the trait bound `&mut dyn BoxMeUp: BoxMeUp` is not satisfied
   --> /home/slendi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/psp-0.3.3/src/panic.rs:151:42
    |
151 |         panic_unwind::__rust_start_panic(obj as _)
    |                                          ^^^ the trait `BoxMeUp` is not implemented for `&mut dyn BoxMeUp`
    |
    = help: the trait `BoxMeUp` is implemented for `PanicPayload<'a>`
    = note: required for the cast from `&mut dyn BoxMeUp` to the object type `dyn BoxMeUp`

Some errors have detailed explanations: E0277, E0605.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `psp` (lib) due to 2 previous errors

Same error also happens on v0.3.2.

System Libraries Needed

TODO List

  • atrac3
  • audio
  • ctrl
  • display
  • ge
  • gu
  • gum
  • hprm
  • jpeg
  • kernel - In Progress
  • mp3
  • mpeg
  • nand
  • net
  • openpsid
  • power
  • registry
  • rtc
  • sircs
  • umd
  • usb
  • usbCam
  • usbstor
  • user - In Progress
  • utility
  • vfpu
  • video
  • wlan

TO (probably not) DO List

  • vsh

Reverse Engineering Checklist

  • sceGuDebugPrint - Puzzle Bobble
  • sceGim - Image Loading - Puzzle Bobble
  • sceWave - Audio Loading - Puzzle Bobble
  • sceSas - Seems like a software implementation of a basic synth - Yu-Gi-Oh
  • sceVfpu - Vfpu intrinsics - Yu-Gi-Oh
  • sceCcc - Character conversion (utf8 et-al) - Yu-Gi-Oh
  • sceFpu - Fpu math - Yu-Gi-Oh
  • sceGup - Similar to Gu - Yu-Gi-Oh
    sceLibFont - Font loading and rendering, NID based - Yu-Gi-Oh (in PPSSPP)
  • sceMd5 - Statically linked MD5 functions - Adventure Player
  • sceGmo - Models - Rengoku
  • sceSs - More synth type stuff - Jan Sangoku Musou
  • sceGiq - Seems similar to sceGim - Star Driver
  • sceGmq - Seems similar to sceGmo - Star Driver
  • scePaf - C++ Utilities? https://wiki.henkaku.xyz/vita/ScePaf, used in vsh modules
    sceMp4 - obviously mp4 - Star Driver (in PPSSPP)

Missing VFPU Instructions

After #160 is merged, we are missing the following.

Missing Instructions (0/14)

? Inst Ops Enc
bvf vfpu-branch vfpu-branch
bvfl vfpu-branch vfpu-branch
bvt vfpu-branch vfpu-branch
bvtl vfpu-branch vfpu-branch
lvl.q vfpu-load16 vfpu-memory-quad
lvr.q vfpu-load16 vfpu-memory-quad
svl.q vfpu-store16 vfpu-memory-quad
svr.q vfpu-store16 vfpu-memory-quad
vcmovf vfpu-condmove vfpu-condmove
vcmovt vfpu-condmove vfpu-condmove
vcmp vfpu-compare vfpu-alu-compare
vmfvc vfpu-control-read vfpu-read-control
vmtvc vfpu-control-write vfpu-write-control
vwbn vector-unary-mod vector-imm8

Do note that lvl.q / lvr.q corrupt registers and when implemented, we should probably add a mitigation to save/restore the affected COP1 register. Shouldn't be too difficult to do with the existing macro magic.

can't build any program

situation is like #151, but another error

cargo psp
    Blocking waiting for file lock on package cache
   Compiling psp v0.3.6 (/home/cofeek/Desktop/codes/rustlang/rust-psp/psp)
error[E0432]: unresolved import `core::panic::BoxMeUp`
  --> /home/cofeek/Desktop/codes/rustlang/rust-psp/psp/src/panic.rs:15:13
   |
15 |     panic::{BoxMeUp, Location, PanicInfo},
   |             ^^^^^^^ no `BoxMeUp` in `panic`

warning: the feature `lang_items` is internal to the compiler or standard library
  --> /home/cofeek/Desktop/codes/rustlang/rust-psp/psp/src/lib.rs:10:5
   |
10 |     lang_items
   |     ^^^^^^^^^^
   |
   = note: using it is strongly discouraged
   = note: `#[warn(internal_features)]` on by default

For more information about this error, try `rustc --explain E0432`.
warning: `psp` (lib) generated 1 warning
error: could not compile `psp` (lib) due to previous error; 1 warning emitted
`cargo build` command exited with status: ExitStatus(unix_wait_status(25856))

Compilation exited abnormally with code 101 at Sat Sep 23 22:40:16

Add support for missing libm functions

The following code will not compile due to a link error, as fmodf is missing:

fn psp_main() {
    psp::dprintln!("{}", 10f32 % core::hint::black_box(2.0));
}

This can likely be resolved by linking in the libm crate, which has an implementation of fmodf. This should fix any additional missing functions.

Alternatively it may be possible to somehow natively compile this, if the PSP can support such an instruction (perhaps even through VFPU). This would result in much faster code.

Upstream all function definitions to the libc crate

Once #47 is complete, we should upstream our definitions to libc. This should be done via an automated script to avoid any errors.

Unresolved: What do we do about bitflags! invocations?

Some options:

  • Revert to original constant names
  • Adopt a new naming scheme

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.