1
1
#![ no_std]
2
- #![ feature( let_chains, vec_pop_if ) ]
2
+ #![ feature( let_chains, inherent_str_constructors ) ]
3
3
4
- #[ cfg( test) ]
5
- extern crate std;
6
4
7
5
extern crate alloc;
8
6
9
7
pub mod namespace;
10
8
pub mod object;
11
9
pub mod op_region;
12
10
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
+ } ;
14
18
use bit_field:: BitField ;
15
- use core:: { mem, str } ;
19
+ use core:: mem;
16
20
use namespace:: { AmlName , Namespace , NamespaceLevelKind } ;
17
- use object:: { MethodFlags , Object , ObjectType } ;
21
+ use object:: { MethodFlags , Object , ObjectType , ReferenceKind } ;
18
22
use op_region:: { OpRegion , RegionSpace } ;
19
23
use spinning_top:: Spinlock ;
20
24
@@ -24,6 +28,9 @@ pub struct Interpreter {
24
28
context_stack : Spinlock < Vec < MethodContext > > ,
25
29
}
26
30
31
+ unsafe impl Send for Interpreter { }
32
+ unsafe impl Sync for Interpreter { }
33
+
27
34
impl Interpreter {
28
35
pub fn new < H > ( handler : H ) -> Interpreter
29
36
where
@@ -172,11 +179,7 @@ impl Interpreter {
172
179
) ;
173
180
context. current_block . pc += buffer_len;
174
181
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) ) ) ) ;
180
183
}
181
184
Opcode :: Package => {
182
185
let mut elements = Vec :: with_capacity ( op. expected_arguments ) ;
@@ -199,14 +202,7 @@ impl Interpreter {
199
202
assert_eq ! ( context. current_block. kind, BlockKind :: Package ) ;
200
203
assert_eq ! ( context. peek( ) , Err ( AmlError :: RunOutOfStream ) ) ;
201
204
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) ) ) ) ;
210
206
}
211
207
Opcode :: If => {
212
208
let [
@@ -322,12 +318,7 @@ impl Interpreter {
322
318
323
319
if let Some ( last) = self . context_stack . lock ( ) . pop ( ) {
324
320
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 ( ) ) ) ;
331
322
} else {
332
323
/*
333
324
* If this is the top-most context, this is a `Return` from the actual
@@ -362,11 +353,7 @@ impl Interpreter {
362
353
ObjectType :: RawDataBuffer => todo ! ( ) ,
363
354
} ;
364
355
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) ) ) ) ;
370
357
}
371
358
_ => panic ! ( "Unexpected operation has created in-flight op!" ) ,
372
359
}
@@ -861,15 +848,7 @@ impl Interpreter {
861
848
} ;
862
849
863
850
* 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) ) ) ) ;
873
852
Ok ( ( ) )
874
853
}
875
854
@@ -899,9 +878,7 @@ impl Interpreter {
899
878
_ => panic ! ( ) ,
900
879
} ;
901
880
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 ) ) ) ) ;
905
882
}
906
883
}
907
884
@@ -929,7 +906,7 @@ impl Interpreter {
929
906
let value = u64:: from_le_bytes ( buffer) ;
930
907
* target = value;
931
908
}
932
- _ => panic ! ( ) ,
909
+ _ => panic ! ( "Store to integer from unsupported object: {:?}" , object ) ,
933
910
} ,
934
911
Object :: BufferField { .. } => match object. gain_mut ( ) {
935
912
Object :: Integer ( value) => {
@@ -991,8 +968,6 @@ struct Block {
991
968
kind : BlockKind ,
992
969
}
993
970
994
- // TODO: we might need to impl Send + Sync for Block?
995
-
996
971
impl Block {
997
972
fn stream ( & self ) -> & [ u8 ] {
998
973
unsafe { & * self . stream }
@@ -1077,13 +1052,19 @@ impl MethodContext {
1077
1052
}
1078
1053
}
1079
1054
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
+
1080
1063
fn start_in_flight_op ( & mut self , op : OpInFlight ) {
1081
- println ! ( "Starting in-flight op of type: {:?}" , op) ;
1082
1064
self . in_flight . push ( op) ;
1083
1065
}
1084
1066
1085
1067
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) ;
1087
1068
let block = Block {
1088
1069
stream : & self . current_block . stream ( ) [ ..( self . current_block . pc + length) ] as * const [ u8 ] ,
1089
1070
pc : self . current_block . pc ,
@@ -1546,7 +1527,7 @@ pub trait Handler: Send + Sync {
1546
1527
#[ cfg( test) ]
1547
1528
mod tests {
1548
1529
use super :: * ;
1549
- use std :: str:: FromStr ;
1530
+ use core :: str:: FromStr ;
1550
1531
1551
1532
struct TestHandler ;
1552
1533
#[ rustfmt:: skip]
0 commit comments