Skip to content

Commit

Permalink
fix(mips): only use fp registers when single-float
Browse files Browse the repository at this point in the history
  • Loading branch information
SK83RJOSH committed Jan 10, 2024
1 parent c4eca8e commit 72b8fb4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/unwinder/arch/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub const MAX_REG_RULES: usize = 188;
#[derive(Clone, Default)]
pub struct Context {
pub gp: [usize; 32],
#[cfg(target_feature = "single-float")]
pub fp: [usize; 32],
}

Expand All @@ -159,6 +160,7 @@ impl fmt::Debug for Context {
for i in 0..=31 {
fmt.field(MIPS::register_name(Register(i as _)).unwrap(), &self.gp[i]);
}
#[cfg(target_feature = "single-float")]
for i in 32..=63 {
fmt.field(
MIPS::register_name(Register(i as _)).unwrap(),
Expand All @@ -175,6 +177,7 @@ impl ops::Index<Register> for Context {
fn index(&self, reg: Register) -> &usize {
match reg {
Register(0..=31) => &self.gp[reg.0 as usize],
#[cfg(target_feature = "single-float")]
Register(32..=63) => &self.fp[(reg.0 - 32) as usize],
_ => unimplemented!(),
}
Expand All @@ -185,6 +188,7 @@ impl ops::IndexMut<gimli::Register> for Context {
fn index_mut(&mut self, reg: Register) -> &mut usize {
match reg {
Register(0..=31) => &mut self.gp[reg.0 as usize],
#[cfg(target_feature = "single-float")]
Register(32..=63) => &mut self.fp[(reg.0 - 32) as usize],
_ => unimplemented!(),
}
Expand Down Expand Up @@ -329,6 +333,7 @@ macro_rules! code {
#[naked]
pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), ptr: *mut ()) {
unsafe {
#[cfg(target_feature = "single-float")]
asm!(
"
move $t0, $sp
Expand All @@ -346,12 +351,30 @@ pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), p
",
options(noreturn)
);
#[cfg(not(target_feature = "single-float"))]
asm!(
"
move $t0, $sp
add $sp, $sp, -0x80
",
code!(save_gp),
"
move $t0, $a0
move $a0, $sp
jalr $t0
lw $ra, 0x7C($sp)
add $sp, $sp, 0x80
jr $ra
",
options(noreturn)
);
}
}

#[naked]
pub unsafe extern "C" fn restore_context(ctx: &Context) -> ! {
unsafe {
#[cfg(target_feature = "single-float")]
asm!(
code!(restore_fp),
code!(restore_gp),
Expand All @@ -361,5 +384,14 @@ pub unsafe extern "C" fn restore_context(ctx: &Context) -> ! {
",
options(noreturn)
);
#[cfg(not(target_feature = "single-float"))]
asm!(
code!(restore_gp),
"
lw $a0, 0x10($sp)
jr $ra
",
options(noreturn)
);
}
}

0 comments on commit 72b8fb4

Please sign in to comment.