9
9
* - For failing tests, print out a nice summary of the errors for each file
10
10
*/
11
11
12
- use acpi:: aml:: { namespace:: AmlName , AmlError , Handle , Interpreter } ;
12
+ use acpi:: {
13
+ address:: MappedGas ,
14
+ aml:: { namespace:: AmlName , object:: Object , AmlError , Interpreter } ,
15
+ Handle ,
16
+ PhysicalMapping ,
17
+ } ;
13
18
use clap:: { Arg , ArgAction , ArgGroup } ;
14
- use log:: info;
19
+ use log:: { error , info} ;
15
20
use pci_types:: PciAddress ;
16
21
use std:: {
17
22
collections:: HashSet ,
@@ -20,7 +25,9 @@ use std::{
20
25
io:: { Read , Write } ,
21
26
path:: { Path , PathBuf } ,
22
27
process:: Command ,
28
+ ptr:: NonNull ,
23
29
str:: FromStr ,
30
+ sync:: Arc ,
24
31
} ;
25
32
26
33
enum CompilationOutcome {
@@ -145,8 +152,7 @@ fn main() -> std::io::Result<()> {
145
152
. collect :: < Vec < _ > > ( ) ;
146
153
147
154
let combined_test = matches. get_flag ( "combined" ) ;
148
-
149
- let mut interpreter = Interpreter :: new ( Handler , 2 ) ;
155
+ let mut interpreter = new_interpreter ( ) ;
150
156
151
157
let ( passed, failed) = aml_files. into_iter ( ) . fold ( ( 0 , 0 ) , |( passed, failed) , file_entry| {
152
158
print ! ( "Testing AML file: {:?}... " , file_entry) ;
@@ -160,7 +166,7 @@ fn main() -> std::io::Result<()> {
160
166
file. read_to_end ( & mut contents) . unwrap ( ) ;
161
167
162
168
if !combined_test {
163
- interpreter = Interpreter :: new ( Handler , 2 ) ;
169
+ interpreter = new_interpreter ( ) ;
164
170
}
165
171
166
172
const AML_TABLE_HEADER_LENGTH : usize = 36 ;
@@ -214,9 +220,72 @@ fn main() -> std::io::Result<()> {
214
220
Ok ( ( ) )
215
221
}
216
222
223
+ fn new_interpreter ( ) -> Interpreter < Handler > {
224
+ let fake_registers = Arc :: new ( acpi:: registers:: FixedRegisters {
225
+ pm1_event_registers : acpi:: registers:: Pm1EventRegisterBlock {
226
+ pm1_event_length : 8 ,
227
+ pm1a : unsafe {
228
+ MappedGas :: map_gas (
229
+ acpi:: address:: GenericAddress {
230
+ address_space : acpi:: address:: AddressSpace :: SystemIo ,
231
+ bit_width : 32 ,
232
+ bit_offset : 0 ,
233
+ access_size : 1 ,
234
+ address : 0x400 ,
235
+ } ,
236
+ & Handler ,
237
+ )
238
+ . unwrap ( )
239
+ } ,
240
+ pm1b : None ,
241
+ } ,
242
+ pm1_control_registers : acpi:: registers:: Pm1ControlRegisterBlock {
243
+ pm1a : unsafe {
244
+ MappedGas :: map_gas (
245
+ acpi:: address:: GenericAddress {
246
+ address_space : acpi:: address:: AddressSpace :: SystemIo ,
247
+ bit_width : 32 ,
248
+ bit_offset : 0 ,
249
+ access_size : 1 ,
250
+ address : 0x600 ,
251
+ } ,
252
+ & Handler ,
253
+ )
254
+ . unwrap ( )
255
+ } ,
256
+ pm1b : None ,
257
+ } ,
258
+ } ) ;
259
+ let fake_facs = PhysicalMapping {
260
+ physical_start : 0x0 ,
261
+ virtual_start : NonNull :: new ( 0x8000_0000_0000_0000 as * mut acpi:: sdt:: facs:: Facs ) . unwrap ( ) ,
262
+ region_length : 32 ,
263
+ mapped_length : 32 ,
264
+ handler : Handler ,
265
+ } ;
266
+ Interpreter :: new ( Handler , 2 , fake_registers, fake_facs)
267
+ }
268
+
217
269
fn run_test ( stream : & [ u8 ] , interpreter : & mut Interpreter < Handler > ) -> Result < ( ) , AmlError > {
218
270
interpreter. load_table ( stream) ?;
219
- interpreter. evaluate_if_present ( AmlName :: from_str ( "\\ MAIN" ) . unwrap ( ) , vec ! [ ] )
271
+
272
+ if let Some ( result) = interpreter. evaluate_if_present ( AmlName :: from_str ( "\\ MAIN" ) . unwrap ( ) , vec ! [ ] ) ? {
273
+ match * result {
274
+ Object :: Integer ( 0 ) => Ok ( ( ) ) ,
275
+ Object :: Integer ( other) => {
276
+ error ! ( "Test _MAIN returned non-zero exit code: {}" , other) ;
277
+ // TODO: wrong error - this should probs return a more complex err type
278
+ Err ( AmlError :: NoCurrentOp )
279
+ }
280
+ _ => {
281
+ error ! ( "Test _MAIN returned unexpected object type: {}" , * result) ;
282
+ // TODO: wrong error
283
+ Err ( AmlError :: NoCurrentOp )
284
+ }
285
+ }
286
+ } else {
287
+ Ok ( ( ) )
288
+ }
220
289
}
221
290
222
291
fn find_tests ( matches : & clap:: ArgMatches ) -> std:: io:: Result < Vec < PathBuf > > {
@@ -312,9 +381,16 @@ impl log::Log for Logger {
312
381
}
313
382
}
314
383
384
+ #[ derive( Clone ) ]
315
385
struct Handler ;
316
386
317
- impl acpi:: aml:: Handler for Handler {
387
+ impl acpi:: Handler for Handler {
388
+ unsafe fn map_physical_region < T > ( & self , physical_address : usize , size : usize ) -> PhysicalMapping < Self , T > {
389
+ todo ! ( )
390
+ }
391
+
392
+ fn unmap_physical_region < T > ( _region : & PhysicalMapping < Self , T > ) { }
393
+
318
394
fn read_u8 ( & self , address : usize ) -> u8 {
319
395
println ! ( "read_u8 {address:#x}" ) ;
320
396
0
@@ -392,7 +468,7 @@ impl acpi::aml::Handler for Handler {
392
468
}
393
469
394
470
fn handle_debug ( & self , object : & acpi:: aml:: object:: Object ) {
395
- info ! ( "Debug store: {:? }" , object) ;
471
+ info ! ( "Debug store: {}" , object) ;
396
472
}
397
473
398
474
fn nanos_since_boot ( & self ) -> u64 {
0 commit comments