1 // Copyright 2020 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use data_model::DataInit; 6 7 #[repr(packed)] 8 #[derive(Clone, Copy, Default)] 9 pub struct RSDP { 10 pub signature: [u8; 8], 11 pub checksum: u8, 12 pub oem_id: [u8; 6], 13 pub revision: u8, 14 _rsdt_addr: u32, 15 pub length: u32, 16 pub xsdt_addr: u64, 17 pub extended_checksum: u8, 18 _reserved: [u8; 3], 19 } 20 21 // Safe as RSDP structure only contains raw data 22 unsafe impl DataInit for RSDP {} 23 24 impl RSDP { new(oem_id: [u8; 6], xsdt_addr: u64) -> Self25 pub fn new(oem_id: [u8; 6], xsdt_addr: u64) -> Self { 26 let mut rsdp = RSDP { 27 signature: *b"RSD PTR ", 28 checksum: 0, 29 oem_id, 30 revision: 2, 31 _rsdt_addr: 0, 32 length: std::mem::size_of::<RSDP>() as u32, 33 xsdt_addr, 34 extended_checksum: 0, 35 _reserved: [0; 3], 36 }; 37 38 rsdp.checksum = super::generate_checksum(&rsdp.as_slice()[0..19]); 39 rsdp.extended_checksum = super::generate_checksum(&rsdp.as_slice()); 40 rsdp 41 } 42 len() -> usize43 pub fn len() -> usize { 44 std::mem::size_of::<RSDP>() 45 } 46 } 47 48 #[cfg(test)] 49 mod tests { 50 use super::RSDP; 51 use data_model::DataInit; 52 53 #[test] test_rsdp()54 fn test_rsdp() { 55 let rsdp = RSDP::new(*b"CHYPER", 0xdead_beef); 56 let sum = rsdp 57 .as_slice() 58 .iter() 59 .fold(0u8, |acc, x| acc.wrapping_add(*x)); 60 assert_eq!(sum, 0); 61 let sum: u8 = rsdp 62 .as_slice() 63 .iter() 64 .fold(0u8, |acc, x| acc.wrapping_add(*x)); 65 assert_eq!(sum, 0); 66 } 67 } 68