Skip to content

Commit

Permalink
implement syscall 605 (#427)
Browse files Browse the repository at this point in the history
Co-authored-by: tompro <tomas.prochazka@apertia.cz>
  • Loading branch information
SuchAFuriousDeath and SuchAFuriousDeath authored Nov 11, 2023
1 parent 453cd5b commit b6bffba
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/kernel/src/regmgr/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ impl RegKey {
pub const AUDIOOUT_CONNECTOR_TYPE: Self = Self(0x0B060000);
pub const AUDIOOUT_CODEC: Self = Self(0x0B070000);
pub const NET_WIFI_FREQ_BAND: Self = Self(0x141E0500);
pub const NP_DEBUG: Self = Self(0x19810000);
pub const BROWSER_DEBUG_NOTIFICATION: Self = Self(0x3CC80700);
pub const DEVENV_TOOL_BOOT_PARAM: Self = Self(0x78020300);
pub const DEVENV_TOOL_TRC_NOTIFY: Self = Self(0x78026400);
pub const DEVENT_TOOL_USE_DEFAULT_LIB: Self = Self(0x78028300);
pub const DEVENV_TOOL_SYS_PRX_PRELOAD: Self = Self(0x78028A00);
pub const DEVENV_TOOL_GAME_INTMEM_DBG: Self = Self(0x7802BF00);

pub(super) const fn new(v: u32) -> Self {
Expand Down
47 changes: 47 additions & 0 deletions src/kernel/src/regmgr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub use self::key::*;

use crate::errno::EINVAL;
use crate::process::VThread;
use crate::syscalls::{SysErr, SysIn, SysOut, Syscalls};
use crate::ucred::Ucred;
use crate::{info, warn};
use std::fmt::{Display, Formatter};
use std::num::NonZeroI32;
use std::ptr::read;
use std::sync::Arc;
use thiserror::Error;
Expand All @@ -19,6 +21,7 @@ impl RegMgr {
let mgr = Arc::new(Self {});

sys.register(532, &mgr, Self::sys_regmgr_call);
sys.register(605, &mgr, Self::sys_workaround8849);

mgr
}
Expand Down Expand Up @@ -154,6 +157,23 @@ impl RegMgr {
}
}

/// See `sceRegMgrGetInt` on the PS4 for a reference.
fn get_int(&self, key: RegKey, out: &mut i32) -> Result<i32, RegError> {
let mut buf = [0u8; 4];

if let Err(e) = self.check_param(key, 0, buf.len()) {
todo!("sceRegMgrGetInt with regMgrComCheckParam({key}, 0, 4) = Err({e})");
}

match self.get_value(key, &mut buf) {
Ok(v) => {
*out = i32::from_le_bytes(buf);
Ok(v)
}
Err(e) => todo!("sceRegMgrGetInt({key}) with regMgrComSetReg() = {e}"),
}
}

/// See `sceRegMgrSetInt` on the PS4 for a reference.
fn set_int(&self, key: RegKey, value: i32) -> Result<i32, RegError> {
let value = value.to_le_bytes();
Expand Down Expand Up @@ -299,6 +319,33 @@ impl RegMgr {

None
}

fn sys_workaround8849(self: &Arc<Self>, i: &SysIn) -> Result<SysOut, SysErr> {
let key = {
let arg: usize = i.args[0].into();
let key: u32 = arg.try_into().unwrap();

RegKey::new(key)
};

match key {
RegKey::NP_DEBUG
| RegKey::BROWSER_DEBUG_NOTIFICATION
| RegKey::DEVENV_TOOL_TRC_NOTIFY
| RegKey::DEVENT_TOOL_USE_DEFAULT_LIB
| RegKey::DEVENV_TOOL_SYS_PRX_PRELOAD => {
let mut out = 0;
let ret = self.get_int(key, &mut out).unwrap();

if ret == 0 {
Ok(out.into())
} else {
Err(SysErr::Raw(unsafe { NonZeroI32::new_unchecked(ret) }))
}
}
_ => Err(SysErr::Raw(EINVAL)),
}
}
}

/// Contains information for a registry entry.
Expand Down

0 comments on commit b6bffba

Please sign in to comment.