-
Notifications
You must be signed in to change notification settings - Fork 12
psx/hw/cop: Support cfc2 and ctc2 op codes to access GTE Control Registers #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7199300
84fa88e
1ab40ed
1c0507e
a0d06c2
ff2d012
eb3d107
df4c708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,47 @@ impl<T: Primitive, const COP: u32, const REG: u32> AsMut<T> for CopRegister<T, C | |
| } | ||
| } | ||
|
|
||
| macro_rules! cop_move { | ||
| ("m", from, $cop:expr, $reg:expr) => { | ||
| concat!( | ||
| "mfc", $cop, " {}, $", $reg, "\n", | ||
| "nop\n", | ||
| "nop", // 2 delay slots required to ensure value is in out(reg) | ||
| ) | ||
| }; | ||
| ("m", to, $cop:expr, $reg:expr) => { | ||
| concat!("mtc", $cop, " {}, $", $reg, "\n", | ||
| "nop\n", | ||
| "nop" | ||
| ) | ||
| }; | ||
| ("c", from, $cop:expr, $reg:expr) => { | ||
| //concat!("cfc", $cop, " {}, $", $reg) # Not currently supported by LLVM | ||
| concat!( | ||
| // cop n CF rt=$at rd=$reg - 32 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you expand on this comment? I understand what the |
||
| ".long 1<<30 | ", $cop, "<<26 | 2<<21 | 1<<16 | (", $reg, "-32)<<11 # cfc", $cop, "\n", | ||
| "nop\n", | ||
| "nop\n", | ||
| "addiu {}, $at, 0" | ||
| ) | ||
| }; | ||
| ("c", to, $cop:expr, $reg:expr) => { | ||
| //concat!("ctc", $cop, " {}, $", $reg) # Not currently supported by LLVM | ||
| concat!( | ||
| "addiu $at, {}, 0\n", | ||
| // cop n CT rt=$at rd=$reg - 32 | ||
| ".long 1<<30 | ", $cop, "<<26 | 6<<21 | 1<<16 | (", $reg, "-32)<<11 # ctc", $cop, "\n", | ||
| "nop\n", | ||
| "nop", | ||
| ) | ||
| }; | ||
| } | ||
|
|
||
| macro_rules! define_cop { | ||
| ($(#[$($meta:meta)*])* $name:ident <$ty:ty>; COP: $cop:expr; R: $reg:expr $(,)?) => { | ||
| define_cop!($(#[$($meta)*])* $name<$ty>; COP: $cop; R: $reg; "m"); | ||
| }; | ||
| ($(#[$($meta:meta)*])* $name:ident <$ty:ty>; COP: $cop:expr; R: $reg:expr; $cop_ty:literal $(,)?) => { | ||
| ($(#[$($meta:meta)*])* $name:ident <$ty:ty>; COP: $cop:expr; R: $reg:expr; $cop_ty:tt $(,)?) => { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $(#[$($meta)*])* | ||
| pub type $name = crate::hw::cop::CopRegister<$ty, $cop, $reg>; | ||
|
|
||
|
|
@@ -35,7 +71,7 @@ macro_rules! define_cop { | |
| unsafe { | ||
| core::arch::asm! { | ||
| ".set noat", | ||
| concat!($cop_ty, "fc", $cop, " {}, $", $reg), | ||
| cop_move!($cop_ty, from, $cop, $reg), | ||
| ".set at", | ||
| out(reg) self.value, | ||
| options(nomem, nostack) | ||
|
|
@@ -48,7 +84,7 @@ macro_rules! define_cop { | |
| unsafe { | ||
| core::arch::asm! { | ||
| ".set noat", | ||
| concat!($cop_ty, "tc", $cop, " {}, $", $reg), | ||
| cop_move!($cop_ty, to, $cop, $reg), | ||
| ".set at", | ||
| in(reg) self.value, | ||
| options(nomem, nostack) | ||
|
|
@@ -58,7 +94,7 @@ macro_rules! define_cop { | |
| } | ||
| } | ||
| }; | ||
| ($(#[$($meta:meta)*])* $name:ident <$ty:ty>; COP: $cop:expr; R: $reg:expr $(;$cop_ty:literal)?, $($others:tt)*) => { | ||
| ($(#[$($meta:meta)*])* $name:ident <$ty:ty>; COP: $cop:expr; R: $reg:expr $(;$cop_ty:tt)?, $($others:tt)*) => { | ||
| define_cop!($(#[$($meta)*])* $name<$ty>; COP: $cop; R: $reg $(;$cop_ty)*); | ||
| define_cop!($($others)*); | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just cfc2/ctc2 instructions that aren't supported by LLVM right? I think this comment would be clearer if it just said that instead of having the commented out
concat!....