Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
Fix compilation error, warnings and migrate to 2018 edition (#2)
Browse files Browse the repository at this point in the history
* Fix compilation errors by using repr(u32)
* Fix warnings
* Remove unstable feature `untagged_unions` by deriving basic traits
* Migrate crate and example to 2018 edition
  • Loading branch information
pheki authored Apr 16, 2021
1 parent 7be2a17 commit 876fa43
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "psp2-sys"
version = "0.2.2"
authors = ["Martin Larralde <martin.larralde@ens-cachan.fr>"]
edition = "2018"
license = "MIT"
description = "Unsafe Rust FFI bindings to the psp2 headers"
repository = "https://github.com/vita-rust/psp2-sys"
Expand All @@ -25,4 +26,3 @@ maintenance = { status = "actively-developed" }
default = []
unsafe = []
dox = []

1 change: 1 addition & 0 deletions examples/hello_rust_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "bare_metal_rust"
version = "0.1.0"
authors = ["Martin Larralde <martin.larralde@ens-cachan.fr>"]
edition = "2018"

[lib]
crate-type = ["staticlib"]
Expand Down
24 changes: 12 additions & 12 deletions examples/hello_rust_world/src/debug/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use core::fmt::Write;
use core::mem::size_of;
use core::slice::from_raw_parts_mut;

use psp2::display::sceDisplaySetFrameBuf;
use psp2::display::SceDisplayFrameBuf;
use psp2::display::SceDisplaySetBufSync::SCE_DISPLAY_SETBUF_NEXTFRAME;
use psp2::kernel::sysmem::sceKernelAllocMemBlock;
use psp2::kernel::sysmem::sceKernelGetMemBlockBase;
use psp2::kernel::sysmem::SceKernelMemBlockType::SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW;
use psp2::kernel::threadmgr::sceKernelCreateMutex;
use psp2::kernel::threadmgr::sceKernelLockMutex;
use psp2::kernel::threadmgr::sceKernelUnlockMutex;
use psp2::types::SceUID;
use psp2::void;
use crate::psp2::display::sceDisplaySetFrameBuf;
use crate::psp2::display::SceDisplayFrameBuf;
use crate::psp2::display::SceDisplaySetBufSync::SCE_DISPLAY_SETBUF_NEXTFRAME;
use crate::psp2::kernel::sysmem::sceKernelAllocMemBlock;
use crate::psp2::kernel::sysmem::sceKernelGetMemBlockBase;
use crate::psp2::kernel::sysmem::SceKernelMemBlockType::SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW;
use crate::psp2::kernel::threadmgr::sceKernelCreateMutex;
use crate::psp2::kernel::threadmgr::sceKernelLockMutex;
use crate::psp2::kernel::threadmgr::sceKernelUnlockMutex;
use crate::psp2::types::SceUID;
use crate::psp2::void;

use super::font::DEBUG_FONT;

Expand Down Expand Up @@ -136,7 +136,7 @@ impl<'a> DebugScreen<'a> {
continue;
}

let mut vram = &mut self.base[self.coord_x + self.coord_y * SCREEN_FB_WIDTH..];
let vram = &mut self.base[self.coord_x + self.coord_y * SCREEN_FB_WIDTH..];
let mut font =
&DEBUG_FONT.glyphs[(chr - DEBUG_FONT.first) as usize * bytes_per_glyph..];
let mut mask = 1 << 7;
Expand Down
8 changes: 4 additions & 4 deletions examples/hello_rust_world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(dead_code, unused_imports, unused_variables, unused_macros, unused_parens)]
#![feature(lang_items, core_intrinsics, panic_handler, start, used, const_fn)]
#![feature(lang_items, core_intrinsics, start)]
#![no_std]

extern crate psp2_sys as psp2;
Expand All @@ -17,15 +17,15 @@ pub extern "C" fn eh_personality() {}
#[panic_handler]
#[no_mangle]
fn panic(_info: &PanicInfo) -> ! {
unsafe { intrinsics::abort() }
intrinsics::abort()
}

#[no_mangle]
pub unsafe fn main(_argc: isize, _argv: *const *const u8) -> isize {
let mut screen = debug::screen::DebugScreen::new();
write!(screen, "This bare-metal is starting to rust!\n");
write!(screen, "This bare-metal is starting to rust!\n").ok();
psp2::kernel::threadmgr::sceKernelDelayThread(1 * 1000000); // Wait for 1 second
write!(screen, "See ? I told you !\n");
write!(screen, "See ? I told you !\n").ok();
psp2::kernel::threadmgr::sceKernelDelayThread(3 * 1000000);
psp2::kernel::processmgr::sceKernelExitProcess(0);
return 0;
Expand Down
7 changes: 1 addition & 6 deletions src/ctrl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use crate::types::SceUChar8;
use crate::types::SceUInt;
use crate::types::SceUInt64;
use crate::types::SceUInt8;

#[repr(C)]
#[repr(u32)]
pub enum SceCtrlErrorCode {
SCE_CTRL_ERROR_INVALID_ARG = 0x80340001,
SCE_CTRL_ERROR_PRIV_REQUIRED = 0x80340002,
Expand Down
18 changes: 9 additions & 9 deletions src/dialog/common.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use graphics::gxm::SceGxmColorFormat;
use graphics::gxm::SceGxmColorSurfaceType;
use graphics::gxm::SceGxmSyncObject;
use system_param::SceSystemParamEnterButtonAssign;
use system_param::SceSystemParamLang;
use types::SceInt32;
use types::ScePVoid;
use types::SceUInt32;
use types::SceUInt8;
use crate::graphics::gxm::SceGxmColorFormat;
use crate::graphics::gxm::SceGxmColorSurfaceType;
use crate::graphics::gxm::SceGxmSyncObject;
use crate::system_param::SceSystemParamEnterButtonAssign;
use crate::system_param::SceSystemParamLang;
use crate::types::SceInt32;
use crate::types::ScePVoid;
use crate::types::SceUInt32;
use crate::types::SceUInt8;

#[repr(u32)]
pub enum SceCommonDialogErrorCode {
Expand Down
8 changes: 4 additions & 4 deletions src/dialog/message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use types::SceChar8;
use types::SceInt32;
use types::SceUInt32;
use crate::types::SceChar8;
use crate::types::SceInt32;
use crate::types::SceUInt32;

use super::common::SceCommonDialogParam;
use super::common::SceCommonDialogStatus;

#[repr(C)]
#[repr(u32)]
pub enum SceMsgDialogErrorCode {
SCE_MSG_DIALOG_ERROR_PARAM = 0x80100A01, // Illegal parameter
}
Expand Down
16 changes: 8 additions & 8 deletions src/display.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use types::SceSize;
use types::SceUID;
use crate::types::SceSize;
use crate::types::SceUID;

#[repr(u32)]
pub enum SceDisplayErrorCode {
Expand Down Expand Up @@ -29,12 +29,12 @@ pub enum SceDisplaySetBufSync {

#[repr(C)]
pub struct SceDisplayFrameBuf {
pub size: SceSize, // sizeof(SceDisplayFrameBuf)
pub base: *mut ::void, // Pointer to framebuffer
pub pitch: u32, // pitch pixels
pub pixelformat: u32, // pixel format (one of ::SceDisplayPixelFormat)
pub width: u32, // framebuffer width
pub height: u32, // framebuffer height
pub size: SceSize, // sizeof(SceDisplayFrameBuf)
pub base: *mut crate::void, // Pointer to framebuffer
pub pitch: u32, // pitch pixels
pub pixelformat: u32, // pixel format (one of ::SceDisplayPixelFormat)
pub width: u32, // framebuffer width
pub height: u32, // framebuffer height
}

#[cfg_attr(
Expand Down
20 changes: 10 additions & 10 deletions src/io/devctl.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use types::SceOff;
use types::SceSize;
use types::SceUID;
use crate::types::SceOff;
use crate::types::SceSize;
use crate::types::SceUID;

#[repr(C)]
pub struct SceIoDevInfo {
pub max_size: SceOff,
pub free_size: SceOff,
pub cluster_size: SceSize,
pub unk: *mut ::void,
pub unk: *mut crate::void,
}

#[cfg_attr(
Expand All @@ -18,25 +18,25 @@ extern "C" {
pub fn sceIoDevctl(
dev: *const u8,
cmd: u32,
indata: *mut ::void,
indata: *mut crate::void,
inlen: i32,
outdata: *mut ::void,
outdata: *mut crate::void,
outlen: i32,
) -> i32;
pub fn sceIoIoctl(
fd: SceUID,
cmd: u32,
indata: *mut ::void,
indata: *mut crate::void,
inlen: i32,
outdata: *mut ::void,
outdata: *mut crate::void,
outlen: i32,
) -> i32;
pub fn sceIoIoctlAsync(
fd: SceUID,
cmd: u32,
indata: *mut ::void,
indata: *mut crate::void,
inlen: i32,
outdata: *mut ::void,
outdata: *mut crate::void,
outlen: i32,
) -> i32;
}
4 changes: 2 additions & 2 deletions src/io/dirent.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use types::SceUID;
use crate::types::SceUID;

use super::stat::SceIoStat;

#[repr(C)]
pub struct SceIoDirent {
pub d_stat: SceIoStat,
pub d_name: [u8; 256],
pub d_private: *mut ::void,
pub d_private: *mut crate::void,
pub dummy: i32,
}

Expand Down
18 changes: 9 additions & 9 deletions src/io/fcntl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use types::SceOff;
use types::SceSize;
use types::SceUID;
use crate::types::SceOff;
use crate::types::SceSize;
use crate::types::SceUID;

#[repr(i32)]
pub enum SceIoMode {
Expand Down Expand Up @@ -50,12 +50,12 @@ extern "C" {
pub fn sceIoOpenAsync(file: *const u8, flags: i32, mode: SceIoMode) -> SceUID;
pub fn sceIoClose(fd: SceUID) -> i32;
pub fn sceIoCloseAsync(fd: SceUID) -> i32;
pub fn sceIoRead(fd: SceUID, data: *mut ::void, size: SceSize) -> i32;
pub fn sceIoReadAsync(fd: SceUID, data: *mut ::void, size: SceSize) -> i32;
pub fn sceIoPread(fd: SceUID, data: *mut ::void, size: SceSize, offset: SceOff) -> i32;
pub fn sceIoWrite(fd: SceUID, data: *const ::void, size: SceSize) -> i32;
pub fn sceIoWriteAsync(fd: SceUID, data: *const ::void, size: SceSize) -> i32;
pub fn sceIoPwrite(fd: SceUID, data: *const ::void, size: SceSize, offset: SceOff) -> i32;
pub fn sceIoRead(fd: SceUID, data: *mut crate::void, size: SceSize) -> i32;
pub fn sceIoReadAsync(fd: SceUID, data: *mut crate::void, size: SceSize) -> i32;
pub fn sceIoPread(fd: SceUID, data: *mut crate::void, size: SceSize, offset: SceOff) -> i32;
pub fn sceIoWrite(fd: SceUID, data: *const crate::void, size: SceSize) -> i32;
pub fn sceIoWriteAsync(fd: SceUID, data: *const crate::void, size: SceSize) -> i32;
pub fn sceIoPwrite(fd: SceUID, data: *const crate::void, size: SceSize, offset: SceOff) -> i32;
pub fn sceIoLseek(fd: SceUID, offset: SceOff, whence: SceIoSeekMode) -> SceOff;
pub fn sceIoLseekAsync(fd: SceUID, offset: SceOff, whence: SceIoSeekMode) -> SceOff;
pub fn sceIoLseek32(fd: SceUID, offset: i32, whence: SceIoSeekMode) -> SceOff;
Expand Down
8 changes: 4 additions & 4 deletions src/io/stat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use types::SceDateTime;
use types::SceMode;
use types::SceOff;
use types::SceUID;
use crate::types::SceDateTime;
use crate::types::SceMode;
use crate::types::SceOff;
use crate::types::SceUID;

#[repr(i32)]
pub enum SceIoAccessMode {
Expand Down
10 changes: 5 additions & 5 deletions src/kernel/clib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use types::SceSize;
use crate::types::SceSize;

#[cfg_attr(
not(feature = "dox"),
Expand All @@ -9,7 +9,7 @@ extern "C" {
pub type va_list;

pub fn sceClibStrcmp(s1: *const u8, s2: *const u8) -> i32;
pub fn sceClibStrncmp(s1: *const u8, s2: *const u8, n: SceSize) -> *mut ::void;
pub fn sceClibStrncmp(s1: *const u8, s2: *const u8, n: SceSize) -> *mut crate::void;
pub fn sceClibStrncasecmp(s1: *const u8, s2: *const u8) -> i32;
pub fn sceClibStrncpy(dest: *mut u8, src: *const u8, n: SceSize) -> *mut u8;
pub fn sceClibStrncat(dest: *mut u8, src: *const u8, n: SceSize) -> *mut u8;
Expand All @@ -20,7 +20,7 @@ extern "C" {
pub fn sceClibSnprintf(s: *mut u8, size: SceSize, format: *const u8, ...) -> i32;
pub fn sceClibVsnprintf(s: *mut u8, size: SceSize, format: *const u8, ap: va_list) -> i32;

pub fn sceClibMemset(s: *mut ::void, c: i32, n: SceSize) -> *mut ::void;
pub fn sceClibMemcpy(dest: *mut ::void, src: *const ::void, n: SceSize) -> *mut ::void;
pub fn sceClibMemmove(dest: *mut ::void, src: *const ::void, n: SceSize) -> *mut ::void;
pub fn sceClibMemset(s: *mut crate::void, c: i32, n: SceSize) -> *mut crate::void;
pub fn sceClibMemcpy(dest: *mut crate::void, src: *const crate::void, n: SceSize) -> *mut crate::void;
pub fn sceClibMemmove(dest: *mut crate::void, src: *const crate::void, n: SceSize) -> *mut crate::void;
}
2 changes: 1 addition & 1 deletion src/kernel/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
link(kind = "static", name = "SceLibKernel_stub")
)]
extern "C" {
pub fn sceKernelGetRandomNumber(output: *mut ::void, size: u32);
pub fn sceKernelGetRandomNumber(output: *mut crate::void, size: u32);
}
18 changes: 9 additions & 9 deletions src/kernel/sysmem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use types::SceSize;
use types::SceUID;
use types::SceUInt32;
use crate::types::SceSize;
use crate::types::SceUID;
use crate::types::SceUInt32;

#[repr(i32)]
pub enum SceKernelMemBlockType {
Expand Down Expand Up @@ -43,7 +43,7 @@ pub enum SceKernelModel {
#[repr(C)]
pub struct SceKernelMemBlockInfo {
pub size: SceSize,
pub mappedBase: *mut ::void,
pub mappedBase: *mut crate::void,
pub mappedSize: SceSize,
pub memory_type: SceKernelMemoryType,
pub access: SceUInt32,
Expand Down Expand Up @@ -75,19 +75,19 @@ extern "C" {
optp: *mut SceKernelAllocMemBlockOpt,
) -> SceUID;
pub fn sceKernelFreeMemBlock(uid: SceUID) -> i32;
pub fn sceKernelGetMemBlockBase(uid: SceUID, basep: *mut *mut ::void) -> i32;
pub fn sceKernelFindMemBlockByAddr(addr: *const ::void, size: SceSize) -> SceUID;
pub fn sceKernelGetMemBlockBase(uid: SceUID, basep: *mut *mut crate::void) -> i32;
pub fn sceKernelFindMemBlockByAddr(addr: *const crate::void, size: SceSize) -> SceUID;
pub fn sceKernelGetMemBlockInfoByAddr(
base: *mut ::void,
base: *mut crate::void,
info: *mut SceKernelMemBlockInfo,
) -> i32;
pub fn sceKernelGetMemBlockInfoByRange(
base: *mut ::void,
base: *mut crate::void,
size: SceSize,
info: *mut SceKernelMemBlockInfo,
) -> i32;
pub fn sceKernelAllocMemBlockForVM(name: *const u8, size: SceSize) -> SceUID;
pub fn sceKernelSyncVMDomain(uid: SceUID, data: *const ::void, size: SceSize) -> i32;
pub fn sceKernelSyncVMDomain(uid: SceUID, data: *const crate::void, size: SceSize) -> i32;
pub fn sceKernelOpenVMDomain() -> i32;
pub fn sceKernelCloseVMDomain() -> i32;
pub fn sceKernelOpenMemBlock(name: *const u8, flags: i32) -> i32;
Expand Down
16 changes: 8 additions & 8 deletions src/kernel/threadmgr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use types::SceSize;
use types::SceUID;
use types::SceUInt;
use types::SceUInt32;
use types::SceUInt64;
use crate::types::SceSize;
use crate::types::SceUID;
use crate::types::SceUInt;
use crate::types::SceUInt32;
use crate::types::SceUInt64;

type SceKernelSysClock = SceUInt64;

Expand Down Expand Up @@ -33,7 +33,7 @@ pub enum SceKernelMutexAttribute {

// Threads

type SceKernelThreadEntry = extern "C" fn(SceSize, *mut ::void) -> i32;
type SceKernelThreadEntry = extern "C" fn(SceSize, *mut crate::void) -> i32;

#[repr(C)]
pub struct SceKernelThreadOptParam {
Expand All @@ -49,7 +49,7 @@ pub struct SceKernelThreadInfo {
pub attr: SceUInt,
pub status: i32,
pub entry: SceKernelThreadEntry,
pub stack: *mut ::void,
pub stack: *mut crate::void,
pub stackSize: i32,
pub initPriority: i32,
pub currentPriority: i32,
Expand Down Expand Up @@ -146,7 +146,7 @@ extern "C" {
option: *const SceKernelThreadOptParam,
) -> SceUID;
pub fn sceKernelDeleteThread(thid: SceUID) -> i32;
pub fn sceKernelStartThread(thid: SceUID, arglen: SceSize, argp: *mut ::void) -> i32;
pub fn sceKernelStartThread(thid: SceUID, arglen: SceSize, argp: *mut crate::void) -> i32;
pub fn sceKernelWaitThreadEnd(thid: SceUID, stat: *mut i32, timeout: *mut SceUInt) -> i32;
pub fn sceKernelWaitThreadEndCB(thid: SceUID, stat: *mut i32, timeout: *mut SceUInt) -> i32;
pub fn sceKernelDelayThread(delay: SceUInt) -> i32;
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(untagged_unions)]
#![feature(extern_types)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
Expand Down
Loading

0 comments on commit 876fa43

Please sign in to comment.