Skip to content

Commit 35fcd63

Browse files
committed
WIP
1 parent 888afe8 commit 35fcd63

File tree

6 files changed

+61
-22
lines changed

6 files changed

+61
-22
lines changed

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ vitasdk-sys = { version = "0.3.2", features = [
5353
# "SceRazorCapture_stub",
5454
] }
5555

56+
[profile.release-debug]
57+
inherits = "dev"
58+
opt-level = 3
59+
overflow-checks = true
60+
debug-assertions = true
61+
debug = true
62+
panic = "abort"
63+
64+
[profile.release.package."*"]
65+
opt-level = 3
66+
5667
[profile.release]
5768
panic = "abort"
5869
lto = "fat"

build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
use bindgen::Formatter;
2+
use std::fs::File;
3+
use std::io::Write;
24
use std::path::PathBuf;
35
use std::process::Command;
46
use std::{env, fs};
57

68
fn main() {
9+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
10+
11+
let build_profile_name = out_path.to_str().unwrap().split(std::path::MAIN_SEPARATOR).nth_back(3).unwrap();
12+
let build_profile_name_file = out_path.join("build_profile_name");
13+
File::create(build_profile_name_file).unwrap().write_all(build_profile_name.as_bytes()).unwrap();
14+
715
let target = env::var("TARGET").unwrap();
816
if target != "armv7-sony-vita-newlibeabihf" {
917
// Running IDE on anything other than linux will fail, so ignore compile error
@@ -17,7 +25,6 @@ fn main() {
1725
let vitasdk_include_path = vitasdk_path.join("arm-vita-eabi").join("include");
1826
let vitasdk_lib_path = vitasdk_path.join("arm-vita-eabi").join("lib");
1927

20-
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
2128
let bindings_file = out_path.join("imgui_bindings.rs");
2229

2330
const IMGUI_HEADERS: [&str; 3] = ["imgui.h", "imgui_internal.h", "imgui_impl_vitagl.h"];

src/core/cpu_regs.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ struct InterruptFlags(u32);
4848

4949
impl Debug for InterruptFlags {
5050
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
51-
let mut flags = f.debug_set();
51+
let mut debug_set = f.debug_set();
5252
for i in 0..=InterruptFlag::Wifi as u8 {
5353
if self.0 & (1 << i) != 0 {
54-
flags.entry(&InterruptFlag::from(i));
54+
let flag = InterruptFlag::from(i);
55+
debug_set.entry(&flag);
5556
}
5657
}
57-
flags.finish()
58+
debug_set.finish()
5859
}
5960
}
6061

@@ -112,7 +113,7 @@ impl CpuRegs {
112113
}
113114

114115
pub fn set_irf(&mut self, mask: u32, value: u32) {
115-
debug_println!("{:?} set irf {:?}", self.cpu_type, InterruptFlags(value & mask));
116+
// debug_println!("{:?} set irf {:?}", self.cpu_type, InterruptFlags(value & mask));
116117
self.irf &= !(value & mask);
117118
}
118119

src/jit/jit_asm.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::logging::debug_println;
1414
use crate::{get_jit_asm_ptr, DEBUG_LOG, DEBUG_LOG_BRANCH_OUT};
1515
use std::arch::asm;
1616
use std::cell::UnsafeCell;
17+
use std::hint::unreachable_unchecked;
1718
use std::intrinsics::unlikely;
1819
use std::{mem, ptr};
1920

@@ -111,22 +112,22 @@ impl JitRuntimeData {
111112

112113
pub extern "C" fn hle_bios_uninterrupt<const CPU: CpuType>(store_host_sp: bool) {
113114
let asm = unsafe { get_jit_asm_ptr::<CPU>().as_mut().unwrap_unchecked() };
114-
bios::uninterrupt::<CPU>(asm.emu);
115+
if DEBUG_LOG_BRANCH_OUT {
116+
asm.runtime_data.branch_out_pc = get_regs!(asm.emu, CPU).pc;
117+
}
115118
asm.runtime_data.return_stack_ptr = 0;
116119
asm.runtime_data.accumulated_cycles += 3;
120+
bios::uninterrupt::<CPU>(asm.emu);
117121
if unlikely(get_cpu_regs!(asm.emu, CPU).is_halted()) {
118-
if DEBUG_LOG_BRANCH_OUT {
119-
asm.runtime_data.branch_out_pc = get_regs!(asm.emu, CPU).pc;
120-
}
121122
if !store_host_sp {
122123
// r4-r12,pc since we need an even amount of registers for 8 byte alignment, in case the compiler decides to use neon instructions
123124
unsafe {
124125
asm!(
125-
"mov sp, {}",
126-
"pop {{r4-r12,pc}}",
127-
in(reg) asm.runtime_data.host_sp
126+
"mov sp, {}",
127+
"pop {{r4-r12,pc}}",
128+
in(reg) asm.runtime_data.host_sp
128129
);
129-
std::hint::unreachable_unchecked();
130+
unreachable_unchecked();
130131
}
131132
}
132133
} else {
@@ -198,7 +199,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
198199
block_asm.restore_reg(Reg::CPSR);
199200
}
200201

201-
// if guest_pc == 0x20b2688 {
202+
// if guest_pc == 0x2001b5e {
202203
// block_asm.bkpt(2);
203204
// }
204205

@@ -207,7 +208,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
207208
asm.jit_buf.current_pc = guest_pc + (i << if THUMB { 1 } else { 2 }) as u32;
208209
debug_println!("{CPU:?} emitting {:?} at pc: {:x}", asm.jit_buf.current_inst(), asm.jit_buf.current_pc);
209210

210-
// if asm.jit_buf.current_pc == 0x20216e2 {
211+
// if asm.jit_buf.current_pc == 0x2001b5c {
211212
// block_asm.bkpt(1);
212213
// }
213214

@@ -217,11 +218,11 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
217218
asm.emit(&mut block_asm);
218219
}
219220

220-
// if DEBUG_LOG {
221-
// block_asm.save_context();
222-
// block_asm.call2(debug_after_exec_op::<CPU> as *const (), asm.jit_buf.current_pc, asm.jit_buf.current_inst().opcode);
223-
// block_asm.restore_reg(Reg::CPSR);
224-
// }
221+
if DEBUG_LOG {
222+
block_asm.save_context();
223+
block_asm.call2(debug_after_exec_op::<CPU> as *const (), asm.jit_buf.current_pc, asm.jit_buf.current_inst().opcode);
224+
block_asm.restore_reg(Reg::CPSR);
225+
}
225226
}
226227

227228
let opcodes = block_asm.finalize(guest_pc, THUMB);

src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::jit::jit_asm::JitAsm;
2323
use crate::logging::debug_println;
2424
use crate::presenter::{PresentEvent, Presenter, PRESENTER_AUDIO_BUF_SIZE};
2525
use crate::settings::Settings;
26-
use crate::utils::{set_thread_prio_affinity, HeapMemU32, ThreadAffinity, ThreadPriority};
26+
use crate::utils::{const_str_equal, set_thread_prio_affinity, HeapMemU32, ThreadAffinity, ThreadPriority};
2727
use std::cell::UnsafeCell;
2828
use std::cmp::min;
2929
use std::intrinsics::{likely, unlikely};
@@ -46,7 +46,8 @@ mod presenter;
4646
mod settings;
4747
mod utils;
4848

49-
pub const DEBUG_LOG: bool = cfg!(debug_assertions);
49+
const BUILD_PROFILE_NAME: &str = include_str!(concat!(env!("OUT_DIR"), "/build_profile_name"));
50+
pub const DEBUG_LOG: bool = const_str_equal(BUILD_PROFILE_NAME, "debug");
5051
pub const DEBUG_LOG_BRANCH_OUT: bool = DEBUG_LOG;
5152

5253
fn run_cpu(

src/utils.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,21 @@ pub fn rgb6_to_float8(color: u32) -> (f32, f32, f32) {
260260
let b = ((color >> 12) & 0x3F) as f32;
261261
(r / 63f32, g / 63f32, b / 63f32)
262262
}
263+
264+
pub const fn const_bytes_equal(lhs: &[u8], rhs: &[u8]) -> bool {
265+
if lhs.len() != rhs.len() {
266+
return false;
267+
}
268+
let mut i = 0;
269+
while i < lhs.len() {
270+
if lhs[i] != rhs[i] {
271+
return false;
272+
}
273+
i += 1;
274+
}
275+
true
276+
}
277+
278+
pub const fn const_str_equal(lhs: &str, rhs: &str) -> bool {
279+
const_bytes_equal(lhs.as_bytes(), rhs.as_bytes())
280+
}

0 commit comments

Comments
 (0)