Skip to content

Commit aed3efa

Browse files
committed
Added support for STREXB instruction
1 parent 7d5e6d1 commit aed3efa

6 files changed

Lines changed: 79 additions & 2 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Here is a list of instructions that are not implemented yet for ArmV7-M archiect
5151
- PSSBB: Physical Speculative Store Bypass Barrier
5252
- SSBB: Speculative Store Bypass Barrier
5353
- STRBT: Store Register Byte Unprivileged
54-
- STREXB: Store Register Exclusive Byte
5554
- STREXH: Store Register Exclusive Halfword
5655
- STRHT: Store Register Halfword Unprivileged
5756
- STRT: Store Register Unprivileged
@@ -151,7 +150,6 @@ Here is the list of instructions that are not implemented yet for ArmV8-M archit
151150
- STLEXH: Store-Release Exclusive Halfword
152151
- STLH: Store-Release Halfword
153152
- STRBT: Store Register Byte Unprivileged
154-
- STREXB: Store Register Exclusive Byte
155153
- STREXH: Store Register Exclusive Halfword
156154
- STRHT: Store Register Halfword Unprivileged
157155
- STRT: Store Register Unprivileged

src/decoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ impl BasicInstructionDecoder {
407407
dec.insert::<instructions::strb::StrbReg>(version);
408408
dec.insert::<instructions::strd::StrdImm>(version);
409409
dec.insert::<instructions::strex::Strex>(version);
410+
dec.insert::<instructions::strexb::Strexb>(version);
410411
dec.insert::<instructions::strh::StrhImm>(version);
411412
dec.insert::<instructions::strh::StrhReg>(version);
412413
dec.insert::<instructions::sub::SubImm>(version);

src/instructions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub mod str;
104104
pub mod strb;
105105
pub mod strd;
106106
pub mod strex;
107+
pub mod strexb;
107108
pub mod strh;
108109
pub mod sub;
109110
pub mod svc;

src/instructions/strexb.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//! Implements STREXB (Store Register Exclusive Byte) instruction.
2+
3+
use super::{Encoding::T1, Pattern};
4+
use crate::{
5+
core::{
6+
ArmVersion::{V7EM, V7M, V8M},
7+
Effect, ItState, Processor, RunError,
8+
},
9+
decoder::DecodeError,
10+
instructions::{unpredictable, DecodeHelper, Encoding, Instruction},
11+
registers::RegisterIndex,
12+
};
13+
14+
/// STREXB instruction.
15+
///
16+
/// Store Register Exclusive Byte.
17+
pub struct Strexb {
18+
/// Destination register for the returned status value.
19+
rd: RegisterIndex,
20+
/// Source register.
21+
rt: RegisterIndex,
22+
/// Base register.
23+
rn: RegisterIndex,
24+
}
25+
26+
impl Instruction for Strexb {
27+
fn patterns() -> &'static [Pattern] {
28+
&[Pattern {
29+
encoding: T1,
30+
versions: &[V7M, V7EM, V8M],
31+
expression: "111010001100xxxxxxxx(1)(1)(1)(1)0100xxxx",
32+
}]
33+
}
34+
35+
fn try_decode(encoding: Encoding, ins: u32, _state: ItState) -> Result<Self, DecodeError> {
36+
debug_assert_eq!(encoding, T1);
37+
let rd = ins.reg4(0);
38+
let rt = ins.reg4(12);
39+
let rn = ins.reg4(16);
40+
unpredictable(rd.is_sp_or_pc() || rt.is_sp_or_pc() || rn.is_pc())?;
41+
unpredictable(rd == rn || rd == rt)?;
42+
Ok(Self { rd, rt, rn })
43+
}
44+
45+
fn execute(&self, proc: &mut Processor) -> Result<Effect, RunError> {
46+
let address = proc[self.rn];
47+
if proc.exclusive_monitors_pass(address, 1)? {
48+
let value = proc[self.rt] as u8;
49+
proc.write_u8(address, value)?;
50+
proc.set(self.rd, 0);
51+
} else {
52+
proc.set(self.rd, 1);
53+
}
54+
Ok(Effect::None)
55+
}
56+
57+
fn name(&self) -> String {
58+
"strexb".into()
59+
}
60+
61+
fn args(&self, _pc: u32) -> String {
62+
format!("{}, {}, [{}]", self.rd, self.rt, self.rn)
63+
}
64+
}

src/test_decoder.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,11 @@ e4e98c26 strd r2, r6, [r4, #560]!
888888
44e8ffca strex r10, r12, [r4, #1020]
889889
44e8ff29 strex r9, r2, [r4, #1020]
890890
4de8ff7c strex r12, r7, [sp, #1020]
891+
c9e8403f strexb r0, r3, [r9]
892+
c6e847af strexb r7, r10, [r6]
893+
c7e84c9f strexb r12, r9, [r7]
894+
cee8430f strexb r3, r0, [lr]
895+
c1e8462f strexb r6, r2, [r1]
891896
0880 strh r0, [r1]
892897
ba80 strh r2, [r7, #4]
893898
dd83 strh r5, [r3, #30]

tests/encode.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,14 @@ strex r10, r12, [r4, #1020]
14311431
strex r9, r2, [r4, #1020]
14321432
strex r12, r7, [r13, #1020]
14331433

1434+
// STREXB
1435+
// T1
1436+
strexb r0, r3, [r9]
1437+
strexb r7, r10, [r6]
1438+
strexb r12, r9, [r7]
1439+
strexb r3, r0, [r14]
1440+
strexb r6, r2, [r1]
1441+
14341442
// STRH (immediate)
14351443
// T1
14361444
strh.n r0, [r1]

0 commit comments

Comments
 (0)