Skip to content

Commit 3f616f5

Browse files
committed
aml: general cleanup
1 parent 97861f8 commit 3f616f5

File tree

4 files changed

+33
-52
lines changed

4 files changed

+33
-52
lines changed

acpi/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ pub struct AcpiTables<H: AcpiHandler> {
193193
handler: H,
194194
}
195195

196+
unsafe impl<H> Send for AcpiTables<H> where H: AcpiHandler + Send {}
197+
unsafe impl<H> Sync for AcpiTables<H> where H: AcpiHandler + Send {}
198+
196199
impl<H> AcpiTables<H>
197200
where
198201
H: AcpiHandler,

acpi/src/madt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl Madt {
330330
}
331331

332332
pub fn supports_8259(&self) -> bool {
333-
self.flags.get_bit(0)
333+
{ self.flags }.get_bit(0)
334334
}
335335
}
336336

aml/src/lib.rs

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
#![no_std]
2-
#![feature(let_chains, vec_pop_if)]
2+
#![feature(let_chains, inherent_str_constructors)]
33

4-
#[cfg(test)]
5-
extern crate std;
64

75
extern crate alloc;
86

97
pub mod namespace;
108
pub mod object;
119
pub mod op_region;
1210

13-
use alloc::{boxed::Box, sync::Arc, vec, vec::Vec};
11+
use alloc::{
12+
boxed::Box,
13+
string::{String, ToString},
14+
sync::Arc,
15+
vec,
16+
vec::Vec,
17+
};
1418
use bit_field::BitField;
15-
use core::{mem, str};
19+
use core::mem;
1620
use namespace::{AmlName, Namespace, NamespaceLevelKind};
17-
use object::{MethodFlags, Object, ObjectType};
21+
use object::{MethodFlags, Object, ObjectType, ReferenceKind};
1822
use op_region::{OpRegion, RegionSpace};
1923
use spinning_top::Spinlock;
2024

@@ -24,6 +28,9 @@ pub struct Interpreter {
2428
context_stack: Spinlock<Vec<MethodContext>>,
2529
}
2630

31+
unsafe impl Send for Interpreter {}
32+
unsafe impl Sync for Interpreter {}
33+
2734
impl Interpreter {
2835
pub fn new<H>(handler: H) -> Interpreter
2936
where
@@ -172,11 +179,7 @@ impl Interpreter {
172179
);
173180
context.current_block.pc += buffer_len;
174181

175-
if let Some(prev_op) = context.in_flight.last_mut() {
176-
if prev_op.arguments.len() < prev_op.expected_arguments {
177-
prev_op.arguments.push(Argument::Object(Arc::new(Object::Buffer(buffer))));
178-
}
179-
}
182+
context.contribute_arg(Argument::Object(Arc::new(Object::Buffer(buffer))));
180183
}
181184
Opcode::Package => {
182185
let mut elements = Vec::with_capacity(op.expected_arguments);
@@ -199,14 +202,7 @@ impl Interpreter {
199202
assert_eq!(context.current_block.kind, BlockKind::Package);
200203
assert_eq!(context.peek(), Err(AmlError::RunOutOfStream));
201204
context.current_block = context.block_stack.pop().unwrap();
202-
203-
if let Some(prev_op) = context.in_flight.last_mut() {
204-
if prev_op.arguments.len() < prev_op.expected_arguments {
205-
prev_op.arguments.push(Argument::Object(Arc::new(Object::Package(elements))));
206-
} else {
207-
panic!("Random package floating around?");
208-
}
209-
}
205+
context.contribute_arg(Argument::Object(Arc::new(Object::Package(elements))));
210206
}
211207
Opcode::If => {
212208
let [
@@ -322,12 +318,7 @@ impl Interpreter {
322318

323319
if let Some(last) = self.context_stack.lock().pop() {
324320
context = last;
325-
326-
if let Some(prev_op) = context.in_flight.last_mut() {
327-
if prev_op.arguments.len() < prev_op.expected_arguments {
328-
prev_op.arguments.push(Argument::Object(object.clone()));
329-
}
330-
}
321+
context.contribute_arg(Argument::Object(object.clone()));
331322
} else {
332323
/*
333324
* If this is the top-most context, this is a `Return` from the actual
@@ -362,11 +353,7 @@ impl Interpreter {
362353
ObjectType::RawDataBuffer => todo!(),
363354
};
364355

365-
if let Some(prev_op) = context.in_flight.last_mut() {
366-
if prev_op.arguments.len() < prev_op.expected_arguments {
367-
prev_op.arguments.push(Argument::Object(Arc::new(Object::Integer(typ))));
368-
}
369-
}
356+
context.contribute_arg(Argument::Object(Arc::new(Object::Integer(typ))));
370357
}
371358
_ => panic!("Unexpected operation has created in-flight op!"),
372359
}
@@ -861,15 +848,7 @@ impl Interpreter {
861848
};
862849

863850
*target.gain_mut() = Object::Integer(value);
864-
865-
// TODO: this is probs a slightly scuffed way of working out if the
866-
// prev op wants our result
867-
if let Some(prev_op) = context.in_flight.last_mut() {
868-
if prev_op.arguments.len() < prev_op.expected_arguments {
869-
prev_op.arguments.push(Argument::Object(Arc::new(Object::Integer(left + right))));
870-
}
871-
}
872-
851+
context.contribute_arg(Argument::Object(Arc::new(Object::Integer(value))));
873852
Ok(())
874853
}
875854

@@ -899,9 +878,7 @@ impl Interpreter {
899878
_ => panic!(),
900879
};
901880

902-
if let Some(prev_op) = context.in_flight.last_mut() {
903-
if prev_op.arguments.len() < prev_op.expected_arguments {
904-
prev_op.arguments.push(Argument::Object(Arc::new(Object::Integer(result as u64))));
881+
context.contribute_arg(Argument::Object(Arc::new(Object::Integer(result as u64))));
905882
}
906883
}
907884

@@ -929,7 +906,7 @@ impl Interpreter {
929906
let value = u64::from_le_bytes(buffer);
930907
*target = value;
931908
}
932-
_ => panic!(),
909+
_ => panic!("Store to integer from unsupported object: {:?}", object),
933910
},
934911
Object::BufferField { .. } => match object.gain_mut() {
935912
Object::Integer(value) => {
@@ -991,8 +968,6 @@ struct Block {
991968
kind: BlockKind,
992969
}
993970

994-
// TODO: we might need to impl Send + Sync for Block?
995-
996971
impl Block {
997972
fn stream(&self) -> &[u8] {
998973
unsafe { &*self.stream }
@@ -1077,13 +1052,19 @@ impl MethodContext {
10771052
}
10781053
}
10791054

1055+
fn contribute_arg(&mut self, arg: Argument) {
1056+
if let Some(in_flight) = self.in_flight.last_mut() {
1057+
if in_flight.arguments.len() < in_flight.expected_arguments {
1058+
in_flight.arguments.push(arg);
1059+
}
1060+
}
1061+
}
1062+
10801063
fn start_in_flight_op(&mut self, op: OpInFlight) {
1081-
println!("Starting in-flight op of type: {:?}", op);
10821064
self.in_flight.push(op);
10831065
}
10841066

10851067
fn start_new_block(&mut self, kind: BlockKind, length: usize) {
1086-
println!("Starting new block at pc={}, length={}, kind={:?}", self.current_block.pc, length, kind);
10871068
let block = Block {
10881069
stream: &self.current_block.stream()[..(self.current_block.pc + length)] as *const [u8],
10891070
pc: self.current_block.pc,
@@ -1546,7 +1527,7 @@ pub trait Handler: Send + Sync {
15461527
#[cfg(test)]
15471528
mod tests {
15481529
use super::*;
1549-
use std::str::FromStr;
1530+
use core::str::FromStr;
15501531

15511532
struct TestHandler;
15521533
#[rustfmt::skip]

aml/src/object.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ mod tests {
180180
let mut dst = [0b1110_0001, 0, 0, 0, 0];
181181

182182
copy_bits(&src, 0, &mut dst, 2, 15);
183-
for i in 0..dst.len() {
184-
print!("{:08b} ", dst[i]);
185-
}
186183
assert_eq!(dst, [0b1111_1101, 0b1101_1110, 0b0000_0001, 0b0000_0000, 0b0000_0000]);
187184
}
188185
}

0 commit comments

Comments
 (0)