Remove warnings
Improve error information Cleanup interrupt macros
This commit is contained in:
@@ -18,14 +18,14 @@ pub fn parse_data_obj(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_computational_data,
|
||||
parse_def_package,
|
||||
parse_def_var_package
|
||||
};
|
||||
|
||||
|
||||
Err(AmlError::AmlInvalidOpCode)
|
||||
}
|
||||
|
||||
@@ -38,13 +38,13 @@ pub fn parse_data_ref_obj(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_data_obj,
|
||||
parse_term_arg
|
||||
};
|
||||
|
||||
|
||||
match parse_super_name(data, ctx) {
|
||||
Ok(res) => match res.val {
|
||||
AmlValue::String(s) => Ok(AmlParseType {
|
||||
@@ -66,7 +66,7 @@ pub fn parse_arg_obj(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
match data[0] {
|
||||
0x68 ... 0x6E => Ok(AmlParseType {
|
||||
val: AmlValue::ObjectReference(ObjectReference::ArgObj(data[0] - 0x68)),
|
||||
@@ -85,7 +85,7 @@ pub fn parse_local_obj(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
match data[0] {
|
||||
0x68 ... 0x6E => Ok(AmlParseType {
|
||||
val: AmlValue::ObjectReference(ObjectReference::LocalObj(data[0] - 0x60)),
|
||||
@@ -104,7 +104,7 @@ fn parse_computational_data(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
match data[0] {
|
||||
0x0A => Ok(AmlParseType {
|
||||
val: AmlValue::Integer(data[1] as u64),
|
||||
|
||||
@@ -42,7 +42,7 @@ pub fn parse_aml_table(sdt: &Sdt) -> Result<Vec<String>, AmlError> {
|
||||
pub fn parse_aml_with_scope(sdt: &Sdt, scope: String) -> Result<Vec<String>, AmlError> {
|
||||
let data = sdt.data();
|
||||
let mut ctx = AmlExecutionContext::new(scope);
|
||||
|
||||
|
||||
parse_term_list(data, &mut ctx)?;
|
||||
|
||||
Ok(ctx.namespace_delta)
|
||||
|
||||
@@ -4,7 +4,7 @@ use collections::btree_map::BTreeMap;
|
||||
|
||||
use super::AmlError;
|
||||
use super::parser::{ AmlParseType, ParseResult, AmlParseTypeGeneric, AmlExecutionContext, ExecutionState };
|
||||
use super::namespace::{AmlValue, ObjectReference, FieldSelector, Method, get_namespace_string,
|
||||
use super::namespace::{AmlValue, FieldSelector, Method, get_namespace_string,
|
||||
Accessor, BufferField, FieldUnit, Processor, PowerResource, OperationRegion,
|
||||
Device, ThermalZone};
|
||||
use super::namestring::{parse_name_string, parse_name_seg};
|
||||
@@ -86,7 +86,7 @@ pub fn parse_named_obj(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_def_bank_field,
|
||||
@@ -122,12 +122,12 @@ fn parse_def_bank_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x87);
|
||||
|
||||
let (pkg_length, pkg_length_len) = parse_pkg_length(&data[2..])?;
|
||||
let data = &data[2 + pkg_length_len .. 2 + pkg_length];
|
||||
|
||||
|
||||
let region_name = parse_name_string(data, ctx)?;
|
||||
let bank_name = parse_name_string(&data[2 + pkg_length_len + region_name.len .. 2 + pkg_length], ctx)?;
|
||||
|
||||
@@ -177,15 +177,15 @@ fn parse_def_create_bit_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x8D);
|
||||
|
||||
let source_buf = parse_term_arg(&data[2..], ctx)?;
|
||||
let bit_index = parse_term_arg(&data[2 + source_buf.len..], ctx)?;
|
||||
let name = parse_name_string(&data[1 + source_buf.len + bit_index.len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
|
||||
source_buf: Box::new(source_buf.val),
|
||||
index: Box::new(bit_index.val),
|
||||
@@ -207,15 +207,15 @@ fn parse_def_create_byte_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x8C);
|
||||
|
||||
let source_buf = parse_term_arg(&data[2..], ctx)?;
|
||||
let bit_index = parse_term_arg(&data[2 + source_buf.len..], ctx)?;
|
||||
let name = parse_name_string(&data[1 + source_buf.len + bit_index.len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
|
||||
source_buf: Box::new(source_buf.val),
|
||||
index: Box::new(bit_index.val),
|
||||
@@ -237,15 +237,15 @@ fn parse_def_create_word_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x8B);
|
||||
|
||||
let source_buf = parse_term_arg(&data[2..], ctx)?;
|
||||
let bit_index = parse_term_arg(&data[2 + source_buf.len..], ctx)?;
|
||||
let name = parse_name_string(&data[1 + source_buf.len + bit_index.len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
|
||||
source_buf: Box::new(source_buf.val),
|
||||
index: Box::new(bit_index.val),
|
||||
@@ -267,15 +267,15 @@ fn parse_def_create_dword_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x8A);
|
||||
|
||||
let source_buf = parse_term_arg(&data[2..], ctx)?;
|
||||
let bit_index = parse_term_arg(&data[2 + source_buf.len..], ctx)?;
|
||||
let name = parse_name_string(&data[1 + source_buf.len + bit_index.len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
|
||||
source_buf: Box::new(source_buf.val),
|
||||
index: Box::new(bit_index.val),
|
||||
@@ -297,15 +297,15 @@ fn parse_def_create_qword_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x8F);
|
||||
|
||||
let source_buf = parse_term_arg(&data[2..], ctx)?;
|
||||
let bit_index = parse_term_arg(&data[2 + source_buf.len..], ctx)?;
|
||||
let name = parse_name_string(&data[1 + source_buf.len + bit_index.len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
|
||||
source_buf: Box::new(source_buf.val),
|
||||
index: Box::new(bit_index.val),
|
||||
@@ -327,22 +327,22 @@ fn parse_def_create_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x13);
|
||||
|
||||
let source_buf = parse_term_arg(&data[2..], ctx)?;
|
||||
let bit_index = parse_term_arg(&data[2 + source_buf.len..], ctx)?;
|
||||
let num_bits = parse_term_arg(&data[2 + source_buf.len + bit_index.len..], ctx)?;
|
||||
let name = parse_name_string(&data[2 + source_buf.len + bit_index.len + num_bits.len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
|
||||
source_buf: Box::new(source_buf.val),
|
||||
index: Box::new(bit_index.val),
|
||||
length: Box::new(num_bits.val)
|
||||
}))?;
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::None,
|
||||
len: 2 + name.len + source_buf.len + bit_index.len + num_bits.len
|
||||
@@ -358,7 +358,7 @@ fn parse_def_data_region(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// TODO: Find the actual offset and length, once table mapping is implemented
|
||||
parser_opcode_extended!(data, 0x88);
|
||||
|
||||
@@ -374,8 +374,8 @@ fn parse_def_data_region(data: &[u8],
|
||||
offset: Box::new(AmlValue::IntegerConstant(0)),
|
||||
len: Box::new(AmlValue::IntegerConstant(0)),
|
||||
accessor: Accessor {
|
||||
read: |x| 0 as u64,
|
||||
write: |x, y| ()
|
||||
read: |_x| 0 as u64,
|
||||
write: |_x, _y| ()
|
||||
},
|
||||
accessed_by: None
|
||||
}))?;
|
||||
@@ -395,11 +395,11 @@ fn parse_def_event(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x02);
|
||||
|
||||
let name = parse_name_string(&data[2..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::Event(0))?;
|
||||
|
||||
@@ -418,16 +418,16 @@ fn parse_def_device(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// TODO: How to handle local context deferreds
|
||||
parser_opcode_extended!(data, 0x82);
|
||||
|
||||
let (pkg_length, pkg_length_len) = parse_pkg_length(&data[2..])?;
|
||||
let name = parse_name_string(&data[2 + pkg_length_len .. 2 + pkg_length], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
let mut local_ctx = AmlExecutionContext::new(local_scope_string.clone());
|
||||
|
||||
|
||||
parse_object_list(&data[2 + pkg_length_len + name.len .. 2 + pkg_length], &mut local_ctx)?;
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::Device(Device {
|
||||
@@ -450,7 +450,7 @@ fn parse_def_op_region(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x80);
|
||||
|
||||
let name = parse_name_string(&data[2..], ctx)?;
|
||||
@@ -478,8 +478,8 @@ fn parse_def_op_region(data: &[u8],
|
||||
offset: Box::new(offset.val),
|
||||
len: Box::new(len.val),
|
||||
accessor: Accessor {
|
||||
read: |x| 0 as u64,
|
||||
write: |x, y| ()
|
||||
read: |_x| 0 as u64,
|
||||
write: |_x, _y| ()
|
||||
},
|
||||
accessed_by: None
|
||||
}))?;
|
||||
@@ -499,7 +499,7 @@ fn parse_def_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x81);
|
||||
|
||||
let (pkg_length, pkg_length_len) = parse_pkg_length(&data[2..])?;
|
||||
@@ -544,7 +544,7 @@ fn parse_def_index_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x86);
|
||||
|
||||
let (pkg_length, pkg_length_len) = parse_pkg_length(&data[2..])?;
|
||||
@@ -596,14 +596,14 @@ fn parse_field_list(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let mut current_offset: usize = 0;
|
||||
let mut field_offset: usize = 0;
|
||||
let mut connection = AmlValue::Uninitialized;
|
||||
|
||||
while current_offset < data.len() {
|
||||
let res = parse_field_element(&data[current_offset..], ctx, selector.clone(), &mut connection, flags, &mut field_offset)?;
|
||||
|
||||
|
||||
match ctx.state {
|
||||
ExecutionState::EXECUTING => (),
|
||||
_ => return Ok(AmlParseType {
|
||||
@@ -611,7 +611,7 @@ fn parse_field_list(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
current_offset += res.len;
|
||||
}
|
||||
|
||||
@@ -634,10 +634,10 @@ fn parse_field_element(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let length = if let Ok(field) = parse_named_field(data, ctx) {
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), AmlValue::String(field.val.name.clone()))?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::FieldUnit(FieldUnit {
|
||||
selector: selector.clone(),
|
||||
connection: Box::new(connection.clone()),
|
||||
@@ -657,7 +657,7 @@ fn parse_field_element(data: &[u8],
|
||||
flags.access_type = AccessType::BufferAcc(field.val.access_attrib.clone()),
|
||||
ref a => flags.access_type = a.clone()
|
||||
}
|
||||
|
||||
|
||||
field.len
|
||||
} else if let Ok(field) = parse_connect_field(data, ctx) {
|
||||
*connection = field.val.clone();
|
||||
@@ -665,15 +665,14 @@ fn parse_field_element(data: &[u8],
|
||||
} else {
|
||||
return Err(AmlError::AmlInvalidOpCode);
|
||||
};
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::None,
|
||||
len: length
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_named_field(data: &[u8],
|
||||
ctx: &mut AmlExecutionContext) -> Result<AmlParseTypeGeneric<NamedField>, AmlError> {
|
||||
fn parse_named_field(data: &[u8], _ctx: &mut AmlExecutionContext) -> Result<AmlParseTypeGeneric<NamedField>, AmlError> {
|
||||
let (name_seg, name_seg_len) = parse_name_seg(&data[0..4])?;
|
||||
let name = match String::from_utf8(name_seg) {
|
||||
Ok(s) => s,
|
||||
@@ -687,8 +686,7 @@ fn parse_named_field(data: &[u8],
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_reserved_field(data: &[u8],
|
||||
ctx: &mut AmlExecutionContext) -> Result<AmlParseTypeGeneric<usize>, AmlError> {
|
||||
fn parse_reserved_field(data: &[u8], _ctx: &mut AmlExecutionContext) -> Result<AmlParseTypeGeneric<usize>, AmlError> {
|
||||
parser_opcode!(data, 0x00);
|
||||
|
||||
let (length, length_len) = parse_pkg_length(&data[1..])?;
|
||||
@@ -698,8 +696,7 @@ fn parse_reserved_field(data: &[u8],
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_access_field(data: &[u8],
|
||||
ctx: &mut AmlExecutionContext) -> Result<AmlParseTypeGeneric<AccessField>, AmlError> {
|
||||
fn parse_access_field(data: &[u8], _ctx: &mut AmlExecutionContext) -> Result<AmlParseTypeGeneric<AccessField>, AmlError> {
|
||||
parser_opcode!(data, 0x01, 0x03);
|
||||
|
||||
let flags_raw = data[1];
|
||||
@@ -753,7 +750,7 @@ fn parse_connect_field(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x02);
|
||||
|
||||
if let Ok(e) = parse_def_buffer(&data[1..], ctx) {
|
||||
@@ -779,7 +776,7 @@ fn parse_def_method(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x14);
|
||||
|
||||
let (pkg_len, pkg_len_len) = parse_pkg_length(&data[1..])?;
|
||||
@@ -791,7 +788,7 @@ fn parse_def_method(data: &[u8],
|
||||
let sync_level = flags & 0xF0 >> 4;
|
||||
|
||||
let term_list = &data[2 + pkg_len_len + name.len .. 1 + pkg_len];
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::Method(Method {
|
||||
arg_count,
|
||||
@@ -815,13 +812,13 @@ fn parse_def_mutex(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x01);
|
||||
|
||||
let name = parse_name_string(&data[2 ..], ctx)?;
|
||||
let flags = data[2 + name.len];
|
||||
let sync_level = flags & 0x0F;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::Mutex((sync_level, None)))?;
|
||||
|
||||
@@ -840,13 +837,13 @@ fn parse_def_power_res(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// TODO: How to handle local context deferreds
|
||||
parser_opcode_extended!(data, 0x84);
|
||||
|
||||
let (pkg_len, pkg_len_len) = parse_pkg_length(&data[2..])?;
|
||||
let name = parse_name_string(&data[2 + pkg_len_len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
let system_level = data[2 + pkg_len_len + name.len];
|
||||
@@ -855,7 +852,7 @@ fn parse_def_power_res(data: &[u8],
|
||||
|
||||
let mut local_ctx = AmlExecutionContext::new(local_scope_string.clone());
|
||||
parse_object_list(&data[5 + pkg_len_len + name.len .. 2 + pkg_len], &mut local_ctx)?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::PowerResource(PowerResource {
|
||||
system_level,
|
||||
resource_order,
|
||||
@@ -877,14 +874,14 @@ fn parse_def_processor(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x83);
|
||||
|
||||
let (pkg_len, pkg_len_len) = parse_pkg_length(&data[2..])?;
|
||||
let name = parse_name_string(&data[2 + pkg_len_len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
|
||||
let proc_id = data[2 + pkg_len_len + name.len];
|
||||
let p_blk_addr: u32 = (data[3 + pkg_len_len + name.len] as u32) +
|
||||
((data[4 + pkg_len_len + name.len] as u32) << 8) +
|
||||
@@ -917,17 +914,17 @@ fn parse_def_thermal_zone(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
parser_opcode_extended!(data, 0x85);
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x85);
|
||||
|
||||
let (pkg_len, pkg_len_len) = parse_pkg_length(&data[2..])?;
|
||||
let name = parse_name_string(&data[2 + pkg_len_len .. 2 + pkg_len], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
let mut local_ctx = AmlExecutionContext::new(local_scope_string.clone());
|
||||
let mut local_ctx = AmlExecutionContext::new(local_scope_string.clone());
|
||||
parse_object_list(&data[2 + pkg_len_len + name.len .. 2 + pkg_len], &mut local_ctx)?;
|
||||
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::ThermalZone(ThermalZone {
|
||||
obj_list: local_ctx.namespace_delta.clone(),
|
||||
notify_methods: BTreeMap::new()
|
||||
@@ -948,7 +945,7 @@ fn parse_def_external(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x15);
|
||||
|
||||
let object_name = parse_name_string(&data[1..], ctx)?;
|
||||
|
||||
@@ -163,7 +163,7 @@ impl AmlValue {
|
||||
_ => String::new()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_type(&self, t: AmlValue) -> Result<AmlValue, AmlError> {
|
||||
match t {
|
||||
AmlValue::None => Ok(AmlValue::None),
|
||||
@@ -229,7 +229,7 @@ impl AmlValue {
|
||||
if idx + len > buf.len() {
|
||||
return Err(AmlError::AmlValueError);
|
||||
}
|
||||
|
||||
|
||||
Ok(buf[idx .. idx + len].to_vec())
|
||||
},
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
@@ -272,14 +272,14 @@ impl AmlValue {
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_event(&self) -> Result<u64, AmlError> {
|
||||
match *self {
|
||||
AmlValue::Event(ref e) => Ok(e.clone()),
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_field_unit(&self) -> Result<FieldUnit, AmlError> {
|
||||
match *self {
|
||||
AmlValue::FieldUnit(ref e) => Ok(e.clone()),
|
||||
@@ -327,14 +327,14 @@ impl AmlValue {
|
||||
Err(AmlError::AmlValueError)
|
||||
},
|
||||
AmlValue::String(ref s) => {
|
||||
let mut s = s.clone()[0..8].to_string().to_uppercase();
|
||||
let s = s.clone()[0..8].to_string().to_uppercase();
|
||||
let mut i: u64 = 0;
|
||||
|
||||
for c in s.chars() {
|
||||
if !c.is_digit(16) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
i <<= 8;
|
||||
i += c.to_digit(16).unwrap() as u64;
|
||||
}
|
||||
@@ -372,21 +372,21 @@ impl AmlValue {
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_operation_region(&self) -> Result<OperationRegion, AmlError> {
|
||||
match *self {
|
||||
AmlValue::OperationRegion(ref p) => Ok(p.clone()),
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_package(&self) -> Result<Vec<AmlValue>, AmlError> {
|
||||
match *self {
|
||||
AmlValue::Package(ref p) => Ok(p.clone()),
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_string(&self) -> Result<String, AmlError> {
|
||||
match *self {
|
||||
AmlValue::String(ref s) => Ok(s.clone()),
|
||||
@@ -400,28 +400,28 @@ impl AmlValue {
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_power_resource(&self) -> Result<PowerResource, AmlError> {
|
||||
match *self {
|
||||
AmlValue::PowerResource(ref p) => Ok(p.clone()),
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_processor(&self) -> Result<Processor, AmlError> {
|
||||
match *self {
|
||||
AmlValue::Processor(ref p) => Ok(p.clone()),
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_raw_data_buffer(&self) -> Result<Vec<u8>, AmlError> {
|
||||
match *self {
|
||||
AmlValue::RawDataBuffer(ref p) => Ok(p.clone()),
|
||||
_ => Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_as_thermal_zone(&self) -> Result<ThermalZone, AmlError> {
|
||||
match *self {
|
||||
AmlValue::ThermalZone(ref p) => Ok(p.clone()),
|
||||
@@ -447,7 +447,7 @@ impl Method {
|
||||
|
||||
pub fn get_namespace_string(current: String, modifier_v: AmlValue) -> Result<String, AmlError> {
|
||||
let mut modifier = modifier_v.get_as_string()?;
|
||||
|
||||
|
||||
if current.len() == 0 {
|
||||
return Ok(modifier);
|
||||
}
|
||||
@@ -455,7 +455,7 @@ pub fn get_namespace_string(current: String, modifier_v: AmlValue) -> Result<Str
|
||||
if modifier.len() == 0 {
|
||||
return Ok(current);
|
||||
}
|
||||
|
||||
|
||||
if modifier.starts_with("\\") {
|
||||
return Ok(modifier);
|
||||
}
|
||||
@@ -486,6 +486,6 @@ pub fn get_namespace_string(current: String, modifier_v: AmlValue) -> Result<Str
|
||||
if !namespace.ends_with("\\") {
|
||||
namespace.push('.');
|
||||
}
|
||||
|
||||
|
||||
Ok(namespace + &modifier)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::AmlError;
|
||||
use super::parser::{AmlParseType, ParseResult, AmlExecutionContext, ExecutionState};
|
||||
use super::namespace::{AmlValue, ObjectReference, get_namespace_string};
|
||||
use super::namespace::{AmlValue, get_namespace_string};
|
||||
use super::pkglength::parse_pkg_length;
|
||||
use super::namestring::parse_name_string;
|
||||
use super::termlist::parse_term_list;
|
||||
@@ -15,7 +15,7 @@ pub fn parse_namespace_modifier(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_alias_op,
|
||||
@@ -35,17 +35,17 @@ fn parse_alias_op(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x06);
|
||||
|
||||
let source_name = parse_name_string(&data[1..], ctx)?;
|
||||
let alias_name = parse_name_string(&data[1 + source_name.len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), source_name.val)?;
|
||||
let local_alias_string = get_namespace_string(ctx.scope.clone(), alias_name.val)?;
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, AmlValue::Alias(local_alias_string))?;
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::None,
|
||||
len: 1 + source_name.len + alias_name.len
|
||||
@@ -61,16 +61,16 @@ fn parse_name_op(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x08);
|
||||
|
||||
|
||||
let name = parse_name_string(&data[1..], ctx)?;
|
||||
let data_ref_obj = parse_data_ref_obj(&data[1 + name.len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
|
||||
|
||||
ctx.add_to_namespace(local_scope_string, data_ref_obj.val)?;
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::None,
|
||||
len: 1 + name.len + data_ref_obj.len
|
||||
@@ -86,15 +86,15 @@ fn parse_scope_op(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x10);
|
||||
|
||||
let (pkg_length, pkg_length_len) = parse_pkg_length(&data[1..])?;
|
||||
let name = parse_name_string(&data[1 + pkg_length_len..], ctx)?;
|
||||
|
||||
|
||||
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val.clone())?;
|
||||
let containing_scope_string = ctx.scope.clone();
|
||||
|
||||
|
||||
ctx.scope = local_scope_string;
|
||||
parse_term_list(&data[1 + pkg_length_len + name.len .. 1 + pkg_length], ctx)?;
|
||||
ctx.scope = containing_scope_string;
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn parse_name_string(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let mut characters: Vec<u8> = vec!();
|
||||
let mut starting_index: usize = 0;
|
||||
|
||||
@@ -127,7 +127,7 @@ fn parse_multi_name_path(data: &[u8]) -> Result<(Vec<u8>, usize), AmlError> {
|
||||
let mut current_seg = 0;
|
||||
let mut characters: Vec<u8> = vec!();
|
||||
let mut multi_len: usize = 2;
|
||||
|
||||
|
||||
while current_seg < seg_count {
|
||||
match parse_name_seg(&data[(current_seg as usize * 4) + 2 ..]) {
|
||||
Ok((mut v, len)) => {
|
||||
@@ -156,7 +156,7 @@ pub fn parse_super_name(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_simple_name,
|
||||
@@ -176,7 +176,7 @@ fn parse_debug_obj(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x31);
|
||||
|
||||
Ok(AmlParseType {
|
||||
@@ -194,7 +194,7 @@ pub fn parse_simple_name(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_name_string,
|
||||
@@ -214,7 +214,7 @@ pub fn parse_target(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if data[0] == 0x00 {
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::None,
|
||||
|
||||
@@ -41,7 +41,7 @@ impl AmlExecutionContext {
|
||||
let id: u64 = *idptr;
|
||||
|
||||
*idptr += 1;
|
||||
|
||||
|
||||
AmlExecutionContext {
|
||||
scope: scope,
|
||||
local_vars: [AmlValue::Uninitialized,
|
||||
@@ -69,11 +69,11 @@ impl AmlExecutionContext {
|
||||
|
||||
pub fn wait_for_event(&mut self, event_ptr: AmlValue) -> Result<bool, AmlError> {
|
||||
let mut namespace_ptr = self.prelock();
|
||||
let mut namespace = match *namespace_ptr {
|
||||
let namespace = match *namespace_ptr {
|
||||
Some(ref mut n) => n,
|
||||
None => return Err(AmlError::AmlHardFatal)
|
||||
};
|
||||
|
||||
|
||||
let mutex_idx = match event_ptr {
|
||||
AmlValue::String(ref s) => s.clone(),
|
||||
AmlValue::ObjectReference(ref o) => match *o {
|
||||
@@ -103,12 +103,12 @@ impl AmlExecutionContext {
|
||||
|
||||
pub fn signal_event(&mut self, event_ptr: AmlValue) -> Result<(), AmlError> {
|
||||
let mut namespace_ptr = self.prelock();
|
||||
let mut namespace = match *namespace_ptr {
|
||||
let namespace = match *namespace_ptr {
|
||||
Some(ref mut n) => n,
|
||||
None => return Err(AmlError::AmlHardFatal)
|
||||
};
|
||||
|
||||
|
||||
|
||||
let mutex_idx = match event_ptr {
|
||||
AmlValue::String(ref s) => s.clone(),
|
||||
AmlValue::ObjectReference(ref o) => match *o {
|
||||
@@ -126,23 +126,22 @@ impl AmlExecutionContext {
|
||||
match mutex {
|
||||
AmlValue::Event(count) => {
|
||||
namespace.insert(mutex_idx, AmlValue::Event(count + 1));
|
||||
return Ok(());
|
||||
},
|
||||
_ => return Err(AmlError::AmlValueError)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub fn release_mutex(&mut self, mutex_ptr: AmlValue) -> Result<(), AmlError> {
|
||||
let id = self.ctx_id;
|
||||
|
||||
|
||||
let mut namespace_ptr = self.prelock();
|
||||
let mut namespace = match *namespace_ptr {
|
||||
let namespace = match *namespace_ptr {
|
||||
Some(ref mut n) => n,
|
||||
None => return Err(AmlError::AmlHardFatal)
|
||||
};
|
||||
|
||||
|
||||
let mutex_idx = match mutex_ptr {
|
||||
AmlValue::String(ref s) => s.clone(),
|
||||
AmlValue::ObjectReference(ref o) => match *o {
|
||||
@@ -156,7 +155,7 @@ impl AmlExecutionContext {
|
||||
Some(s) => s.clone(),
|
||||
None => return Err(AmlError::AmlValueError)
|
||||
};
|
||||
|
||||
|
||||
match mutex {
|
||||
AmlValue::Mutex((sync_level, owner)) => {
|
||||
if let Some(o) = owner {
|
||||
@@ -177,7 +176,7 @@ impl AmlExecutionContext {
|
||||
if o == id {
|
||||
let mut new_region = region.clone();
|
||||
new_region.accessed_by = None;
|
||||
|
||||
|
||||
namespace.insert(mutex_idx, AmlValue::OperationRegion(new_region));
|
||||
return Ok(());
|
||||
} else {
|
||||
@@ -192,10 +191,10 @@ impl AmlExecutionContext {
|
||||
}
|
||||
|
||||
pub fn acquire_mutex(&mut self, mutex_ptr: AmlValue) -> Result<bool, AmlError> {
|
||||
let id = self.ctx_id;
|
||||
|
||||
let id = self.ctx_id;
|
||||
|
||||
let mut namespace_ptr = self.prelock();
|
||||
let mut namespace = match *namespace_ptr {
|
||||
let namespace = match *namespace_ptr {
|
||||
Some(ref mut n) => n,
|
||||
None => return Err(AmlError::AmlHardFatal)
|
||||
};
|
||||
@@ -212,17 +211,17 @@ impl AmlExecutionContext {
|
||||
Some(s) => s.clone(),
|
||||
None => return Err(AmlError::AmlValueError)
|
||||
};
|
||||
|
||||
|
||||
match mutex {
|
||||
AmlValue::Mutex((sync_level, owner)) => {
|
||||
if owner == None {
|
||||
if sync_level < self.sync_level {
|
||||
return Err(AmlError::AmlValueError);
|
||||
}
|
||||
|
||||
|
||||
namespace.insert(mutex_idx, AmlValue::Mutex((sync_level, Some(id))));
|
||||
self.sync_level = sync_level;
|
||||
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
},
|
||||
@@ -243,7 +242,7 @@ impl AmlExecutionContext {
|
||||
|
||||
pub fn add_to_namespace(&mut self, name: String, value: AmlValue) -> Result<(), AmlError> {
|
||||
let mut namespace = ACPI_TABLE.namespace.write();
|
||||
|
||||
|
||||
if let Some(ref mut namespace) = *namespace {
|
||||
if let Some(obj) = namespace.get(&name) {
|
||||
match *obj {
|
||||
@@ -256,7 +255,7 @@ impl AmlExecutionContext {
|
||||
_ => return Err(AmlError::AmlValueError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
self.namespace_delta.push(name.clone());
|
||||
namespace.insert(name, value);
|
||||
|
||||
@@ -339,10 +338,10 @@ impl AmlExecutionContext {
|
||||
if indices.len() != 1 {
|
||||
return Err(AmlError::AmlValueError);
|
||||
}
|
||||
|
||||
|
||||
let mut bytes = string.clone().into_bytes();
|
||||
bytes[indices[0] as usize] = value.get_as_integer()? as u8;
|
||||
|
||||
|
||||
let string = String::from_utf8(bytes).unwrap();
|
||||
|
||||
Ok(AmlValue::String(string))
|
||||
@@ -351,7 +350,7 @@ impl AmlExecutionContext {
|
||||
if indices.len() != 1 {
|
||||
return Err(AmlError::AmlValueError);
|
||||
}
|
||||
|
||||
|
||||
let mut b = b.clone();
|
||||
b[indices[0] as usize] = value.get_as_integer()? as u8;
|
||||
|
||||
@@ -373,7 +372,7 @@ impl AmlExecutionContext {
|
||||
if indices.len() < 0 {
|
||||
return Err(AmlError::AmlValueError);
|
||||
}
|
||||
|
||||
|
||||
let mut p = p.clone();
|
||||
|
||||
if indices.len() == 1 {
|
||||
@@ -381,7 +380,7 @@ impl AmlExecutionContext {
|
||||
} else {
|
||||
p[indices[0] as usize] = self.modify_index_core(p[indices[0] as usize].clone(), value, indices[1..].to_vec())?;
|
||||
}
|
||||
|
||||
|
||||
Ok(AmlValue::Package(p))
|
||||
},
|
||||
_ => return Err(AmlError::AmlValueError)
|
||||
@@ -470,8 +469,8 @@ impl AmlExecutionContext {
|
||||
if indices.len() != 1 {
|
||||
return Err(AmlError::AmlValueError);
|
||||
}
|
||||
|
||||
let mut bytes = string.clone().into_bytes();
|
||||
|
||||
let bytes = string.clone().into_bytes();
|
||||
Ok(AmlValue::Integer(bytes[indices[0] as usize] as u64))
|
||||
},
|
||||
AmlValue::Buffer(ref b) => {
|
||||
|
||||
@@ -20,6 +20,6 @@ pub fn parse_pkg_length(data: &[u8]) -> Result<(usize, usize), AmlError> {
|
||||
pkg_len += (data[1 + current_byte] as u32 * 16 * (256 as u32).pow(current_byte as u32)) as usize;
|
||||
current_byte += 1;
|
||||
}
|
||||
|
||||
|
||||
return Ok((pkg_len, count_bytes + 1));
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ pub fn parse_term_list(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let mut current_offset: usize = 0;
|
||||
|
||||
while current_offset < data.len() {
|
||||
let res = parse_term_obj(&data[current_offset..], ctx)?;
|
||||
|
||||
|
||||
match ctx.state {
|
||||
ExecutionState::EXECUTING => (),
|
||||
_ => return Ok(AmlParseType {
|
||||
@@ -32,7 +32,7 @@ pub fn parse_term_list(data: &[u8],
|
||||
len: data.len()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
current_offset += res.len;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn parse_term_arg(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_local_obj,
|
||||
@@ -72,12 +72,12 @@ pub fn parse_object_list(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let mut current_offset: usize = 0;
|
||||
|
||||
while current_offset < data.len() {
|
||||
let res = parse_object(&data[current_offset..], ctx)?;
|
||||
|
||||
|
||||
match ctx.state {
|
||||
ExecutionState::EXECUTING => (),
|
||||
_ => return Ok(AmlParseType {
|
||||
@@ -85,7 +85,7 @@ pub fn parse_object_list(data: &[u8],
|
||||
len: data.len()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
current_offset += res.len;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ fn parse_object(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_namespace_modifier,
|
||||
@@ -123,7 +123,7 @@ pub fn parse_method_invocation(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let name = parse_name_string(data, ctx)?;
|
||||
let method = ctx.get(name.val.clone())?;
|
||||
|
||||
@@ -131,15 +131,15 @@ pub fn parse_method_invocation(data: &[u8],
|
||||
AmlValue::None => return Err(AmlError::AmlDeferredLoad),
|
||||
_ => method.get_as_method()?
|
||||
};
|
||||
|
||||
|
||||
let mut cur = 0;
|
||||
let mut params: Vec<AmlValue> = vec!();
|
||||
|
||||
let mut current_offset = name.len;
|
||||
|
||||
|
||||
while cur < method.arg_count {
|
||||
let res = parse_term_arg(&data[current_offset..], ctx)?;
|
||||
|
||||
|
||||
current_offset += res.len;
|
||||
cur += 1;
|
||||
|
||||
@@ -161,7 +161,7 @@ fn parse_term_obj(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_namespace_modifier,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::AmlError;
|
||||
use super::parser::{AmlParseType, ParseResult, AmlExecutionContext, ExecutionState};
|
||||
use super::namespace::{AmlValue, ObjectReference, OperationRegion};
|
||||
use super::namespace::AmlValue;
|
||||
use super::pkglength::parse_pkg_length;
|
||||
use super::termlist::{parse_term_arg, parse_term_list};
|
||||
use super::namestring::{parse_name_string, parse_super_name};
|
||||
@@ -19,7 +19,7 @@ pub fn parse_type1_opcode(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_def_break,
|
||||
@@ -52,7 +52,7 @@ fn parse_def_break(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0xA5);
|
||||
ctx.state = ExecutionState::BREAK;
|
||||
|
||||
@@ -71,7 +71,7 @@ fn parse_def_breakpoint(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0xCC);
|
||||
|
||||
Ok(AmlParseType {
|
||||
@@ -89,7 +89,7 @@ fn parse_def_continue(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x9F);
|
||||
ctx.state = ExecutionState::CONTINUE;
|
||||
|
||||
@@ -108,7 +108,7 @@ fn parse_def_noop(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0xA3);
|
||||
|
||||
Ok(AmlParseType {
|
||||
@@ -126,7 +126,7 @@ fn parse_def_fatal(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x32);
|
||||
|
||||
let fatal_type = data[2];
|
||||
@@ -145,7 +145,7 @@ fn parse_def_load(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x20);
|
||||
|
||||
let name = parse_name_string(&data[2..], ctx)?;
|
||||
@@ -158,7 +158,7 @@ fn parse_def_load(data: &[u8],
|
||||
load_table(get_sdt_signature(sdt));
|
||||
let delta = parse_aml_table(sdt)?;
|
||||
ctx.modify(ddb_handle_object.val, AmlValue::DDBHandle((delta, get_sdt_signature(sdt))));
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::None,
|
||||
len: 2 + name.len + ddb_handle_object.len
|
||||
@@ -177,7 +177,7 @@ fn parse_def_notify(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x86);
|
||||
|
||||
let object = parse_super_name(&data[1..], ctx)?;
|
||||
@@ -225,12 +225,12 @@ fn parse_def_release(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x27);
|
||||
|
||||
let obj = parse_super_name(&data[2..], ctx)?;
|
||||
ctx.release_mutex(obj.val);
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::None,
|
||||
len: 2 + obj.len
|
||||
@@ -246,7 +246,7 @@ fn parse_def_reset(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x26);
|
||||
|
||||
let object = parse_super_name(&data[2..], ctx)?;
|
||||
@@ -269,7 +269,7 @@ fn parse_def_signal(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x24);
|
||||
let object = parse_super_name(&data[2..], ctx)?;
|
||||
|
||||
@@ -289,19 +289,19 @@ fn parse_def_sleep(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x22);
|
||||
|
||||
let time = parse_term_arg(&data[2..], ctx)?;
|
||||
let timeout = time.val.get_as_integer()?;
|
||||
|
||||
|
||||
let (seconds, nanoseconds) = monotonic();
|
||||
let starting_time_ns = nanoseconds + (seconds * 1000000000);
|
||||
|
||||
|
||||
loop {
|
||||
let (seconds, nanoseconds) = monotonic();
|
||||
let current_time_ns = nanoseconds + (seconds * 1000000000);
|
||||
|
||||
|
||||
if current_time_ns - starting_time_ns > timeout as u64 * 1000000 {
|
||||
break;
|
||||
}
|
||||
@@ -322,19 +322,19 @@ fn parse_def_stall(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x21);
|
||||
|
||||
let time = parse_term_arg(&data[2..], ctx)?;
|
||||
let timeout = time.val.get_as_integer()?;
|
||||
|
||||
|
||||
let (seconds, nanoseconds) = monotonic();
|
||||
let starting_time_ns = nanoseconds + (seconds * 1000000000);
|
||||
|
||||
|
||||
loop {
|
||||
let (seconds, nanoseconds) = monotonic();
|
||||
let current_time_ns = nanoseconds + (seconds * 1000000000);
|
||||
|
||||
|
||||
if current_time_ns - starting_time_ns > timeout as u64 * 1000 {
|
||||
break;
|
||||
}
|
||||
@@ -355,7 +355,7 @@ fn parse_def_unload(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x2A);
|
||||
|
||||
let object = parse_super_name(&data[2..], ctx)?;
|
||||
@@ -384,12 +384,12 @@ fn parse_def_if_else(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0xA0);
|
||||
|
||||
let (pkg_length, pkg_length_len) = parse_pkg_length(&data[1..])?;
|
||||
let if_condition = parse_term_arg(&data[1 + pkg_length_len .. 1 + pkg_length], ctx)?;
|
||||
|
||||
|
||||
let (else_length, else_length_len) = if data.len() > 1 + pkg_length && data[1 + pkg_length] == 0xA1 {
|
||||
parse_pkg_length(&data[2 + pkg_length..])?
|
||||
} else {
|
||||
@@ -417,7 +417,7 @@ fn parse_def_while(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0xA2);
|
||||
|
||||
let (pkg_length, pkg_length_len) = parse_pkg_length(&data[1..])?;
|
||||
@@ -427,7 +427,7 @@ fn parse_def_while(data: &[u8],
|
||||
if predicate.val.get_as_integer()? == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
parse_term_list(&data[1 + pkg_length_len + predicate.len .. 1 + pkg_length], ctx)?;
|
||||
|
||||
match ctx.state {
|
||||
@@ -443,7 +443,7 @@ fn parse_def_while(data: &[u8],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::None,
|
||||
len: 1 + pkg_length
|
||||
@@ -459,7 +459,7 @@ fn parse_def_return(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0xA4);
|
||||
|
||||
let arg_object = parse_term_arg(&data[1..], ctx)?;
|
||||
|
||||
@@ -4,14 +4,14 @@ use collections::vec::Vec;
|
||||
|
||||
use super::{AmlError, parse_aml_with_scope};
|
||||
use super::parser::{AmlParseType, ParseResult, AmlExecutionContext, ExecutionState};
|
||||
use super::namespace::{AmlValue, ObjectReference, OperationRegion};
|
||||
use super::namespace::{AmlValue, ObjectReference};
|
||||
use super::pkglength::parse_pkg_length;
|
||||
use super::termlist::{parse_term_arg, parse_method_invocation};
|
||||
use super::namestring::{parse_super_name, parse_target, parse_name_string, parse_simple_name};
|
||||
use super::dataobj::parse_data_ref_obj;
|
||||
|
||||
use time::monotonic;
|
||||
use acpi::{ACPI_TABLE, SDT_POINTERS};
|
||||
use acpi::SDT_POINTERS;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum MatchOpcode {
|
||||
@@ -32,7 +32,7 @@ pub fn parse_type2_opcode(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_def_increment,
|
||||
@@ -99,7 +99,7 @@ pub fn parse_type6_opcode(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
parse_def_deref_of,
|
||||
@@ -120,7 +120,7 @@ pub fn parse_def_object_type(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x8E);
|
||||
parser_selector! {
|
||||
data, ctx,
|
||||
@@ -142,7 +142,7 @@ pub fn parse_def_package(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// TODO: Handle deferred loads in here
|
||||
parser_opcode!(data, 0x12);
|
||||
|
||||
@@ -157,7 +157,7 @@ pub fn parse_def_package(data: &[u8],
|
||||
elements.push(AmlValue::Uninitialized);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::Package(elements),
|
||||
len: 1 + pkg_length
|
||||
@@ -173,7 +173,7 @@ pub fn parse_def_var_package(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// TODO: Handle deferred loads in here
|
||||
parser_opcode!(data, 0x13);
|
||||
|
||||
@@ -191,7 +191,7 @@ pub fn parse_def_var_package(data: &[u8],
|
||||
elements.push(AmlValue::Uninitialized);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::Package(elements),
|
||||
len: 1 + pkg_length
|
||||
@@ -207,7 +207,7 @@ fn parse_package_elements_list(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let mut current_offset: usize = 0;
|
||||
let mut elements: Vec<AmlValue> = vec!();
|
||||
|
||||
@@ -241,14 +241,14 @@ pub fn parse_def_buffer(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x11);
|
||||
|
||||
let (pkg_length, pkg_length_len) = parse_pkg_length(&data[1..])?;
|
||||
let buffer_size = parse_term_arg(&data[1 + pkg_length_len..], ctx)?;
|
||||
let mut byte_list = data[1 + pkg_length_len + buffer_size.len .. 1 + pkg_length].to_vec().clone();
|
||||
|
||||
byte_list.truncate(buffer_size.val.get_as_integer()? as usize);
|
||||
byte_list.truncate(buffer_size.val.get_as_integer()? as usize);
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::Buffer(byte_list),
|
||||
@@ -265,7 +265,7 @@ fn parse_def_ref_of(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x71);
|
||||
|
||||
let obj = parse_super_name(&data[1..], ctx)?;
|
||||
@@ -279,7 +279,7 @@ fn parse_def_ref_of(data: &[u8],
|
||||
AmlValue::ObjectReference(ref o) => o.clone(),
|
||||
_ => return Err(AmlError::AmlValueError)
|
||||
};
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::ObjectReference(res),
|
||||
len: 1 + obj.len
|
||||
@@ -295,7 +295,7 @@ fn parse_def_deref_of(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x83);
|
||||
|
||||
let obj = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -319,7 +319,7 @@ fn parse_def_acquire(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x23);
|
||||
|
||||
let obj = parse_super_name(&data[1..], ctx)?;
|
||||
@@ -341,7 +341,7 @@ fn parse_def_acquire(data: &[u8],
|
||||
} else {
|
||||
let (seconds, nanoseconds) = monotonic();
|
||||
let current_time_ns = nanoseconds + (seconds * 1000000000);
|
||||
|
||||
|
||||
if current_time_ns - starting_time_ns > timeout as u64 * 1000000 {
|
||||
return Ok(AmlParseType {
|
||||
val: AmlValue::Integer(1),
|
||||
@@ -362,15 +362,15 @@ fn parse_def_increment(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x75);
|
||||
|
||||
let obj = parse_super_name(&data[1..], ctx)?;
|
||||
|
||||
let mut namespace = ctx.prelock();
|
||||
|
||||
let mut _namespace = ctx.prelock();
|
||||
let value = AmlValue::Integer(ctx.get(obj.val.clone())?.get_as_integer()? + 1);
|
||||
ctx.modify(obj.val, value.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: value,
|
||||
len: 1 + obj.len
|
||||
@@ -386,7 +386,7 @@ fn parse_def_index(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x88);
|
||||
|
||||
let obj = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -395,7 +395,7 @@ fn parse_def_index(data: &[u8],
|
||||
|
||||
let reference = AmlValue::ObjectReference(ObjectReference::Index(Box::new(obj.val), Box::new(idx.val)));
|
||||
ctx.modify(target.val, reference.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: reference,
|
||||
len: 1 + obj.len + idx.len + target.len
|
||||
@@ -411,14 +411,14 @@ fn parse_def_land(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x90);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
|
||||
let result = if lhs.val.get_as_integer()? > 0 && rhs.val.get_as_integer()? > 0 { 1 } else { 0 };
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::IntegerConstant(result),
|
||||
len: 1 + lhs.len + rhs.len
|
||||
@@ -434,14 +434,14 @@ fn parse_def_lequal(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x93);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
|
||||
let result = if lhs.val.get_as_integer()? == rhs.val.get_as_integer()? { 1 } else { 0 };
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::IntegerConstant(result),
|
||||
len: 1 + lhs.len + rhs.len
|
||||
@@ -457,14 +457,14 @@ fn parse_def_lgreater(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x94);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
|
||||
let result = if lhs.val.get_as_integer()? > rhs.val.get_as_integer()? { 1 } else { 0 };
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::IntegerConstant(result),
|
||||
len: 1 + lhs.len + rhs.len
|
||||
@@ -480,14 +480,14 @@ fn parse_def_lless(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x95);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
|
||||
let result = if lhs.val.get_as_integer()? < rhs.val.get_as_integer()? { 1 } else { 0 };
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::IntegerConstant(result),
|
||||
len: 1 + lhs.len + rhs.len
|
||||
@@ -503,12 +503,12 @@ fn parse_def_lnot(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x92);
|
||||
|
||||
let operand = parse_term_arg(&data[1..], ctx)?;
|
||||
let result = if operand.val.get_as_integer()? == 0 { 1 } else { 0 };
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::IntegerConstant(result),
|
||||
len: 1 + operand.len
|
||||
@@ -524,14 +524,14 @@ fn parse_def_lor(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x91);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
|
||||
let result = if lhs.val.get_as_integer()? > 0 || rhs.val.get_as_integer()? > 0 { 1 } else { 0 };
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::IntegerConstant(result),
|
||||
len: 1 + lhs.len + rhs.len
|
||||
@@ -547,7 +547,7 @@ fn parse_def_to_hex_string(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x98);
|
||||
|
||||
let operand = parse_term_arg(&data[2..], ctx)?;
|
||||
@@ -588,7 +588,7 @@ fn parse_def_to_buffer(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x96);
|
||||
|
||||
let operand = parse_term_arg(&data[2..], ctx)?;
|
||||
@@ -612,12 +612,12 @@ fn parse_def_to_bcd(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x29);
|
||||
|
||||
let operand = parse_term_arg(&data[2..], ctx)?;
|
||||
let target = parse_target(&data[2 + operand.len..], ctx)?;
|
||||
|
||||
|
||||
let mut i = operand.val.get_as_integer()?;
|
||||
let mut result = 0;
|
||||
|
||||
@@ -626,7 +626,7 @@ fn parse_def_to_bcd(data: &[u8],
|
||||
result += i % 10;
|
||||
i /= 10;
|
||||
}
|
||||
|
||||
|
||||
let result = AmlValue::Integer(result);
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
@@ -685,7 +685,7 @@ fn parse_def_to_integer(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x99);
|
||||
|
||||
let operand = parse_term_arg(&data[2..], ctx)?;
|
||||
@@ -710,7 +710,7 @@ fn parse_def_to_string(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x9C);
|
||||
|
||||
let operand = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -743,7 +743,7 @@ fn parse_def_subtract(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x74);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -753,7 +753,7 @@ fn parse_def_subtract(data: &[u8],
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? - rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -769,7 +769,7 @@ fn parse_def_size_of(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x87);
|
||||
|
||||
let name = parse_super_name(&data[1..], ctx)?;
|
||||
@@ -781,7 +781,7 @@ fn parse_def_size_of(data: &[u8],
|
||||
AmlValue::Package(ref p) => p.len(),
|
||||
_ => return Err(AmlError::AmlValueError)
|
||||
};
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::Integer(res as u64),
|
||||
len: 1 + name.len
|
||||
@@ -797,14 +797,14 @@ fn parse_def_store(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x70);
|
||||
|
||||
let operand = parse_term_arg(&data[1..], ctx)?;
|
||||
let target = parse_super_name(&data[1 + operand.len..], ctx)?;
|
||||
|
||||
ctx.modify(target.val.clone(), operand.val);
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: target.val,
|
||||
len: 1 + operand.len + target.len
|
||||
@@ -820,17 +820,17 @@ fn parse_def_or(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x7D);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
let target = parse_target(&data[1 + lhs.len + rhs.len..], ctx)?;
|
||||
|
||||
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? | rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -846,17 +846,17 @@ fn parse_def_shift_left(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x79);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
let target = parse_target(&data[1 + lhs.len + rhs.len..], ctx)?;
|
||||
|
||||
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? >> rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -872,7 +872,7 @@ fn parse_def_shift_right(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x7A);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -882,7 +882,7 @@ fn parse_def_shift_right(data: &[u8],
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? << rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -898,17 +898,17 @@ fn parse_def_add(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x72);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
let target = parse_target(&data[1 + lhs.len + rhs.len..], ctx)?;
|
||||
|
||||
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? + rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -924,17 +924,17 @@ fn parse_def_and(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x7B);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
let target = parse_target(&data[1 + lhs.len + rhs.len..], ctx)?;
|
||||
|
||||
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? & rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -950,17 +950,17 @@ fn parse_def_xor(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x7F);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
|
||||
let target = parse_target(&data[1 + lhs.len + rhs.len..], ctx)?;
|
||||
|
||||
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? ^ rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -976,7 +976,7 @@ fn parse_def_concat_res(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x84);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -993,7 +993,7 @@ fn parse_def_concat_res(data: &[u8],
|
||||
if buf1.len() >= 2 && buf1[buf1.len() - 2] == 0x79 {
|
||||
buf1 = buf1[0..buf1.len() - 2].to_vec();
|
||||
}
|
||||
|
||||
|
||||
if buf2.len() >= 2 && buf2[buf2.len() - 2] == 0x79 {
|
||||
buf2 = buf2[0..buf2.len() - 2].to_vec();
|
||||
}
|
||||
@@ -1009,10 +1009,10 @@ fn parse_def_concat_res(data: &[u8],
|
||||
|
||||
checksum = (!checksum) + 1;
|
||||
buf1.push(checksum);
|
||||
|
||||
|
||||
let res = AmlValue::Buffer(buf1);
|
||||
ctx.modify(target.val, res.clone())?;
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: res,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -1028,7 +1028,7 @@ fn parse_def_wait(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x25);
|
||||
|
||||
let obj = parse_super_name(&data[2..], ctx)?;
|
||||
@@ -1052,7 +1052,7 @@ fn parse_def_wait(data: &[u8],
|
||||
} else {
|
||||
let (seconds, nanoseconds) = monotonic();
|
||||
let current_time_ns = nanoseconds + (seconds * 1000000000);
|
||||
|
||||
|
||||
if current_time_ns - starting_time_ns > timeout as u64 * 1000000 {
|
||||
return Ok(AmlParseType {
|
||||
val: AmlValue::Integer(1),
|
||||
@@ -1073,7 +1073,7 @@ fn parse_def_cond_ref_of(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x12);
|
||||
|
||||
let obj = parse_super_name(&data[2..], ctx)?;
|
||||
@@ -1094,7 +1094,7 @@ fn parse_def_cond_ref_of(data: &[u8],
|
||||
};
|
||||
|
||||
ctx.modify(target.val, AmlValue::ObjectReference(res));
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::Integer(1),
|
||||
len: 1 + obj.len + target.len
|
||||
@@ -1110,7 +1110,7 @@ fn parse_def_copy_object(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// TODO: Compute the result
|
||||
// TODO: Store the result
|
||||
parser_opcode!(data, 0x9D);
|
||||
@@ -1135,7 +1135,7 @@ fn parse_def_concat(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x73);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -1143,7 +1143,7 @@ fn parse_def_concat(data: &[u8],
|
||||
let target = parse_target(&data[1 + lhs.len + rhs.len..], ctx)?;
|
||||
|
||||
let result = match lhs.val {
|
||||
AmlValue::Integer(i) => {
|
||||
AmlValue::Integer(_i) => {
|
||||
let j = AmlValue::Integer(rhs.val.get_as_integer()?);
|
||||
|
||||
let mut first = lhs.val.get_as_buffer()?.clone();
|
||||
@@ -1203,15 +1203,15 @@ fn parse_def_decrement(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x76);
|
||||
|
||||
let obj = parse_super_name(&data[1..], ctx)?;
|
||||
|
||||
let mut namespace = ctx.prelock();
|
||||
|
||||
let namespace = ctx.prelock();
|
||||
let value = AmlValue::Integer(ctx.get(obj.val.clone())?.get_as_integer()? - 1);
|
||||
ctx.modify(obj.val, value.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: value,
|
||||
len: 1 + obj.len
|
||||
@@ -1227,7 +1227,7 @@ fn parse_def_divide(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x78);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -1243,7 +1243,7 @@ fn parse_def_divide(data: &[u8],
|
||||
|
||||
ctx.modify(target_remainder.val, AmlValue::Integer(remainder));
|
||||
ctx.modify(target_quotient.val, AmlValue::Integer(quotient));
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::Integer(quotient),
|
||||
len: 1 + lhs.len + rhs.len + target_remainder.len + target_quotient.len
|
||||
@@ -1259,7 +1259,7 @@ fn parse_def_find_set_left_bit(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x81);
|
||||
|
||||
let operand = parse_term_arg(&data[2..], ctx)?;
|
||||
@@ -1267,7 +1267,7 @@ fn parse_def_find_set_left_bit(data: &[u8],
|
||||
|
||||
let mut first_bit = 32;
|
||||
let mut test = operand.val.get_as_integer()?;
|
||||
|
||||
|
||||
while first_bit > 0{
|
||||
if test & 0x8000000000000000 > 0 {
|
||||
break;
|
||||
@@ -1279,7 +1279,7 @@ fn parse_def_find_set_left_bit(data: &[u8],
|
||||
|
||||
let result = AmlValue::Integer(first_bit);
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + operand.len + target.len
|
||||
@@ -1295,7 +1295,7 @@ fn parse_def_find_set_right_bit(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x82);
|
||||
|
||||
let operand = parse_term_arg(&data[2..], ctx)?;
|
||||
@@ -1303,7 +1303,7 @@ fn parse_def_find_set_right_bit(data: &[u8],
|
||||
|
||||
let mut first_bit = 1;
|
||||
let mut test = operand.val.get_as_integer()?;
|
||||
|
||||
|
||||
while first_bit <= 32 {
|
||||
if test & 1 > 0 {
|
||||
break;
|
||||
@@ -1335,7 +1335,7 @@ fn parse_def_load_table(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// TODO: Clean up
|
||||
parser_opcode_extended!(data, 0x1F);
|
||||
|
||||
@@ -1359,13 +1359,13 @@ fn parse_def_load_table(data: &[u8],
|
||||
};
|
||||
|
||||
let sdt_signature = (sig_str, oem_str, oem_table_str);
|
||||
|
||||
|
||||
let sdt = ptrs.get(&sdt_signature);
|
||||
|
||||
|
||||
if let Some(sdt) = sdt {
|
||||
let hdl = parse_aml_with_scope(sdt, root_path.val.get_as_string()?)?;
|
||||
ctx.modify(parameter_path.val, parameter_data.val);
|
||||
|
||||
|
||||
return Ok(AmlParseType {
|
||||
val: AmlValue::DDBHandle((hdl, sdt_signature)),
|
||||
len: 2 + signature.len + oem_id.len + oem_table_id.len + root_path.len + parameter_path.len + parameter_data.len
|
||||
@@ -1388,11 +1388,11 @@ fn parse_def_match(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x28);
|
||||
|
||||
|
||||
let search_pkg = parse_term_arg(&data[1..], ctx)?;
|
||||
|
||||
|
||||
let first_operation = match data[1 + search_pkg.len] {
|
||||
0 => MatchOpcode::MTR,
|
||||
1 => MatchOpcode::MEQ,
|
||||
@@ -1414,7 +1414,7 @@ fn parse_def_match(data: &[u8],
|
||||
_ => return Err(AmlError::AmlParseError("DefMatch - Invalid Opcode"))
|
||||
};
|
||||
let second_operand = parse_term_arg(&data[3 + search_pkg.len + first_operand.len..], ctx)?;
|
||||
|
||||
|
||||
let start_index = parse_term_arg(&data[3 + search_pkg.len + first_operand.len + second_operand.len..], ctx)?;
|
||||
|
||||
let pkg = search_pkg.val.get_as_package()?;
|
||||
@@ -1532,7 +1532,7 @@ fn parse_def_from_bcd(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x28);
|
||||
|
||||
let operand = parse_term_arg(&data[2..], ctx)?;
|
||||
@@ -1545,7 +1545,7 @@ fn parse_def_from_bcd(data: &[u8],
|
||||
if i & 0x0F > 10 {
|
||||
return Err(AmlError::AmlValueError);
|
||||
}
|
||||
|
||||
|
||||
result *= 10;
|
||||
result += i & 0x0F;
|
||||
i >>= 4;
|
||||
@@ -1554,7 +1554,7 @@ fn parse_def_from_bcd(data: &[u8],
|
||||
let result = AmlValue::Integer(result);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 2 + operand.len + target.len
|
||||
@@ -1570,7 +1570,7 @@ fn parse_def_mid(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x9E);
|
||||
|
||||
let source = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -1580,7 +1580,7 @@ fn parse_def_mid(data: &[u8],
|
||||
|
||||
let idx = index.val.get_as_integer()? as usize;
|
||||
let mut len = length.val.get_as_integer()? as usize;
|
||||
|
||||
|
||||
let result = match source.val {
|
||||
AmlValue::String(s) => {
|
||||
if idx > s.len() {
|
||||
@@ -1602,7 +1602,7 @@ fn parse_def_mid(data: &[u8],
|
||||
// Additionally, any type that can be converted to a buffer can also be converted to a
|
||||
// string, so no information is lost
|
||||
let b = source.val.get_as_buffer()?;
|
||||
|
||||
|
||||
if idx > b.len() {
|
||||
AmlValue::Buffer(vec!())
|
||||
} else {
|
||||
@@ -1614,7 +1614,7 @@ fn parse_def_mid(data: &[u8],
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
Ok(AmlParseType {
|
||||
@@ -1632,7 +1632,7 @@ fn parse_def_mod(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x85);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -1646,7 +1646,7 @@ fn parse_def_mod(data: &[u8],
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? % rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -1662,7 +1662,7 @@ fn parse_def_multiply(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// TODO: Handle overflow
|
||||
parser_opcode!(data, 0x77);
|
||||
|
||||
@@ -1673,7 +1673,7 @@ fn parse_def_multiply(data: &[u8],
|
||||
let result = AmlValue::Integer(lhs.val.get_as_integer()? * rhs.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -1689,7 +1689,7 @@ fn parse_def_nand(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x7C);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -1699,7 +1699,7 @@ fn parse_def_nand(data: &[u8],
|
||||
let result = AmlValue::Integer(!(lhs.val.get_as_integer()? & rhs.val.get_as_integer()?));
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -1715,7 +1715,7 @@ fn parse_def_nor(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x7E);
|
||||
|
||||
let lhs = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -1725,7 +1725,7 @@ fn parse_def_nor(data: &[u8],
|
||||
let result = AmlValue::Integer(!(lhs.val.get_as_integer()? | rhs.val.get_as_integer()?));
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + lhs.len + rhs.len + target.len
|
||||
@@ -1741,7 +1741,7 @@ fn parse_def_not(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode!(data, 0x80);
|
||||
|
||||
let operand = parse_term_arg(&data[1..], ctx)?;
|
||||
@@ -1750,7 +1750,7 @@ fn parse_def_not(data: &[u8],
|
||||
let result = AmlValue::Integer(!operand.val.get_as_integer()?);
|
||||
|
||||
ctx.modify(target.val, result.clone());
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: result,
|
||||
len: 1 + operand.len + target.len
|
||||
@@ -1766,12 +1766,12 @@ fn parse_def_timer(data: &[u8],
|
||||
len: 0 as usize
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
parser_opcode_extended!(data, 0x33);
|
||||
|
||||
let (seconds, nanoseconds) = monotonic();
|
||||
let monotonic_ns = nanoseconds + (seconds * 1000000000);
|
||||
|
||||
|
||||
Ok(AmlParseType {
|
||||
val: AmlValue::Integer(monotonic_ns),
|
||||
len: 2 as usize
|
||||
|
||||
@@ -5,7 +5,7 @@ use self::drhd::Drhd;
|
||||
use memory::Frame;
|
||||
use paging::{entry, ActivePageTable, PhysicalAddress};
|
||||
|
||||
use super::{ACPI_TABLE, SDT_POINTERS, get_sdt, find_sdt, load_table, get_sdt_signature};
|
||||
use super::{find_sdt, load_table, get_sdt_signature};
|
||||
|
||||
pub mod drhd;
|
||||
|
||||
@@ -28,7 +28,7 @@ impl Dmar {
|
||||
println!("Unable to find DMAR");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
if let Some(dmar) = dmar {
|
||||
println!(" DMAR: {}: {}", dmar.addr_width, dmar.flags);
|
||||
|
||||
@@ -50,7 +50,7 @@ impl Dmar {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn new(sdt: &'static Sdt) -> Option<Dmar> {
|
||||
if &sdt.signature == b"DMAR" && sdt.data_len() >= 12 { //Not valid if no local address and flags
|
||||
let addr_width = unsafe { *(sdt.data_address() as *const u8) };
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use core::{mem, ptr};
|
||||
use collections::string::String;
|
||||
|
||||
use super::sdt::Sdt;
|
||||
use super::{ACPI_TABLE, SDT_POINTERS, get_sdt, find_sdt, get_sdt_signature, load_table};
|
||||
@@ -97,7 +96,7 @@ impl Fadt {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn init(active_table: &mut ActivePageTable) {
|
||||
let fadt_sdt = find_sdt("FACP");
|
||||
let fadt = if fadt_sdt.len() == 1 {
|
||||
@@ -110,7 +109,7 @@ impl Fadt {
|
||||
|
||||
if let Some(fadt) = fadt {
|
||||
println!(" FACP: {:X}", fadt.dsdt);
|
||||
|
||||
|
||||
let dsdt_sdt = get_sdt(fadt.dsdt as usize, active_table);
|
||||
|
||||
let signature = get_sdt_signature(dsdt_sdt);
|
||||
|
||||
@@ -6,7 +6,7 @@ use memory::Frame;
|
||||
use paging::{entry, ActivePageTable, PhysicalAddress, Page, VirtualAddress};
|
||||
|
||||
use super::sdt::Sdt;
|
||||
use super::{ACPI_TABLE, SDT_POINTERS, get_sdt, find_sdt, load_table, get_sdt_signature};
|
||||
use super::{ACPI_TABLE, find_sdt, load_table, get_sdt_signature};
|
||||
|
||||
#[repr(packed)]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
@@ -44,15 +44,15 @@ impl Hpet {
|
||||
println!("Unable to find HPET");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
if let Some(hpet) = hpet {
|
||||
println!(" HPET: {:X}", hpet.hpet_number);
|
||||
|
||||
|
||||
let mut hpet_t = ACPI_TABLE.hpet.write();
|
||||
*hpet_t = Some(hpet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn new(sdt: &'static Sdt, active_table: &mut ActivePageTable) -> Option<Hpet> {
|
||||
if &sdt.signature == b"HPET" && sdt.length as usize >= mem::size_of::<Hpet>() {
|
||||
let s = unsafe { ptr::read((sdt as *const Sdt) as *const Hpet) };
|
||||
@@ -71,7 +71,7 @@ impl GenericAddressStructure {
|
||||
let result = active_table.map_to(page, frame, entry::PRESENT | entry::WRITABLE | entry::NO_EXECUTE);
|
||||
result.flush(active_table);
|
||||
}
|
||||
|
||||
|
||||
pub unsafe fn read_u64(&self, offset: usize) -> u64{
|
||||
volatile_load((self.address as usize + offset) as *const u64)
|
||||
}
|
||||
|
||||
@@ -4,20 +4,10 @@ use memory::{allocate_frames, Frame};
|
||||
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
|
||||
|
||||
use super::sdt::Sdt;
|
||||
use super::{ACPI_TABLE, SDT_POINTERS, AP_STARTUP, TRAMPOLINE, find_sdt, load_table, get_sdt_signature};
|
||||
use super::{AP_STARTUP, TRAMPOLINE, find_sdt, load_table, get_sdt_signature};
|
||||
|
||||
use core::intrinsics::{atomic_load, atomic_store};
|
||||
use core::sync::atomic::Ordering;
|
||||
use collections::btree_map::BTreeMap;
|
||||
use collections::string::String;
|
||||
use collections::vec::Vec;
|
||||
use alloc::boxed::Box;
|
||||
|
||||
use syscall::io::{Io, Pio};
|
||||
|
||||
use spin::RwLock;
|
||||
|
||||
use stop::kstop;
|
||||
|
||||
use device::local_apic::LOCAL_APIC;
|
||||
use interrupt;
|
||||
@@ -41,7 +31,7 @@ impl Madt {
|
||||
println!("Unable to find MADT");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
if let Some(madt) = madt {
|
||||
println!(" APIC: {:>08X}: {}", madt.local_address, madt.flags);
|
||||
|
||||
@@ -148,7 +138,7 @@ impl Madt {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn new(sdt: &'static Sdt) -> Option<Madt> {
|
||||
if &sdt.signature == b"APIC" && sdt.data_len() >= 8 { //Not valid if no local address and flags
|
||||
let local_address = unsafe { *(sdt.data_address() as *const u32) };
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
//! # ACPI
|
||||
//! Code to parse the ACPI tables
|
||||
|
||||
use core::intrinsics::{atomic_load, atomic_store};
|
||||
use core::sync::atomic::Ordering;
|
||||
use collections::btree_map::BTreeMap;
|
||||
use collections::string::String;
|
||||
use collections::vec::Vec;
|
||||
@@ -14,15 +12,12 @@ use spin::RwLock;
|
||||
|
||||
use stop::kstop;
|
||||
|
||||
use device::local_apic::LOCAL_APIC;
|
||||
use interrupt;
|
||||
use memory::{allocate_frames, Frame};
|
||||
use memory::Frame;
|
||||
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
|
||||
use start::{kstart_ap, CPU_COUNT, AP_READY};
|
||||
|
||||
use self::dmar::{Dmar, DmarEntry};
|
||||
use self::dmar::Dmar;
|
||||
use self::fadt::Fadt;
|
||||
use self::madt::{Madt, MadtEntry};
|
||||
use self::madt::Madt;
|
||||
use self::rsdt::Rsdt;
|
||||
use self::sdt::Sdt;
|
||||
use self::xsdt::Xsdt;
|
||||
@@ -30,7 +25,7 @@ use self::hpet::Hpet;
|
||||
use self::rxsdt::Rxsdt;
|
||||
use self::rsdp::RSDP;
|
||||
|
||||
use self::aml::{is_aml_table, parse_aml_table, AmlError, AmlValue};
|
||||
use self::aml::{parse_aml_table, AmlError, AmlValue};
|
||||
|
||||
pub mod hpet;
|
||||
mod dmar;
|
||||
@@ -97,7 +92,7 @@ fn init_namespace() {
|
||||
let mut namespace = ACPI_TABLE.namespace.write();
|
||||
*namespace = Some(BTreeMap::new());
|
||||
}
|
||||
|
||||
|
||||
let dsdt = find_sdt("DSDT");
|
||||
if dsdt.len() == 1 {
|
||||
print!(" DSDT");
|
||||
@@ -107,7 +102,7 @@ fn init_namespace() {
|
||||
println!("Unable to find DSDT");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
let ssdts = find_sdt("SSDT");
|
||||
|
||||
for ssdt in ssdts {
|
||||
@@ -128,7 +123,7 @@ pub unsafe fn init(active_table: &mut ActivePageTable) {
|
||||
let mut order = SDT_ORDER.write();
|
||||
*order = Some(vec!());
|
||||
}
|
||||
|
||||
|
||||
// Search for RSDP
|
||||
if let Some(rsdp) = RSDP::get_rsdp(active_table) {
|
||||
let rxsdt = get_sdt(rsdp.sdt_address(), active_table);
|
||||
@@ -146,12 +141,12 @@ pub unsafe fn init(active_table: &mut ActivePageTable) {
|
||||
println!("UNKNOWN RSDT OR XSDT SIGNATURE");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
rxsdt.map_all(active_table);
|
||||
|
||||
|
||||
for sdt_address in rxsdt.iter() {
|
||||
let sdt = unsafe { &*(sdt_address as *const Sdt) };
|
||||
|
||||
|
||||
let signature = get_sdt_signature(sdt);
|
||||
if let Some(ref mut ptrs) = *(SDT_POINTERS.write()) {
|
||||
ptrs.insert(signature, sdt);
|
||||
@@ -171,7 +166,7 @@ pub unsafe fn init(active_table: &mut ActivePageTable) {
|
||||
pub fn set_global_s_state(state: u8) {
|
||||
if state == 5 {
|
||||
let fadt = ACPI_TABLE.fadt.read();
|
||||
|
||||
|
||||
if let Some(ref fadt) = *fadt {
|
||||
let port = fadt.pm1a_control_block as u16;
|
||||
let mut val = 1 << 13;
|
||||
@@ -183,10 +178,10 @@ pub fn set_global_s_state(state: u8) {
|
||||
if let Ok(p) = s.get_as_package() {
|
||||
let slp_typa = p[0].get_as_integer().expect("SLP_TYPa is not an integer");
|
||||
let slp_typb = p[1].get_as_integer().expect("SLP_TYPb is not an integer");
|
||||
|
||||
|
||||
println!("Shutdown SLP_TYPa {:X}, SLP_TYPb {:X}", slp_typa, slp_typb);
|
||||
val |= slp_typa as u16;
|
||||
|
||||
|
||||
println!("Shutdown with ACPI outw(0x{:X}, 0x{:X})", port, val);
|
||||
Pio::<u16>::new(port).write(val);
|
||||
}
|
||||
@@ -202,7 +197,7 @@ pub static SDT_ORDER: RwLock<Option<Vec<SdtSignature>>> = RwLock::new(None);
|
||||
|
||||
pub fn find_sdt(name: &str) -> Vec<&'static Sdt> {
|
||||
let mut sdts: Vec<&'static Sdt> = vec!();
|
||||
|
||||
|
||||
if let Some(ref ptrs) = *(SDT_POINTERS.read()) {
|
||||
for (signature, sdt) in ptrs {
|
||||
if signature.0 == name {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use memory::{allocate_frames, Frame};
|
||||
use memory::Frame;
|
||||
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
|
||||
|
||||
/// RSDP
|
||||
@@ -18,10 +18,10 @@ pub struct RSDP {
|
||||
|
||||
impl RSDP {
|
||||
/// Search for the RSDP
|
||||
pub fn get_rsdp(active_table: &mut ActivePageTable) -> Option<RSDP> {
|
||||
pub fn get_rsdp(active_table: &mut ActivePageTable) -> Option<RSDP> {
|
||||
let start_addr = 0xE0000;
|
||||
let end_addr = 0xFFFFF;
|
||||
|
||||
|
||||
// Map all of the ACPI RSDP space
|
||||
{
|
||||
let start_frame = Frame::containing_address(PhysicalAddress::new(start_addr));
|
||||
@@ -35,7 +35,7 @@ impl RSDP {
|
||||
|
||||
RSDP::search(start_addr, end_addr)
|
||||
}
|
||||
|
||||
|
||||
fn search(start_addr: usize, end_addr: usize) -> Option<RSDP> {
|
||||
for i in 0 .. (end_addr + 1 - start_addr)/16 {
|
||||
let rsdp = unsafe { &*((start_addr + i * 16) as *const RSDP) };
|
||||
|
||||
@@ -13,11 +13,11 @@ pub trait Rxsdt {
|
||||
get_sdt(sdt, active_table);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn find(&self, signature: [u8; 4], oem_id: [u8; 6], oem_table_id: [u8; 8]) -> Option<&'static Sdt> {
|
||||
for sdt in self.iter() {
|
||||
let sdt = unsafe { &*(sdt as *const Sdt) };
|
||||
|
||||
|
||||
if sdt.match_pattern(signature, oem_id, oem_table_id) {
|
||||
return Some(sdt);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ impl Sdt {
|
||||
pub fn data(&self) -> &[u8] {
|
||||
unsafe { slice::from_raw_parts(self.data_address() as *const u8, self.data_len()) }
|
||||
}
|
||||
|
||||
|
||||
pub fn match_pattern(&self, signature: [u8; 4], oem_id: [u8; 6], oem_table_id: [u8; 8]) -> bool{
|
||||
self.signature == signature && self.oem_id == oem_id && self.oem_table_id == oem_table_id
|
||||
}
|
||||
|
||||
@@ -5,119 +5,140 @@ extern {
|
||||
fn ksignal(signal: usize);
|
||||
}
|
||||
|
||||
interrupt_stack!(divide_by_zero, stack, {
|
||||
println!("Divide by zero fault at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(divide_by_zero, stack, {
|
||||
println!("Divide by zero");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGFPE);
|
||||
});
|
||||
|
||||
interrupt_stack!(debug, stack, {
|
||||
println!("Debug trap at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
println!("Debug trap");
|
||||
stack.dump();
|
||||
ksignal(SIGTRAP);
|
||||
});
|
||||
|
||||
interrupt_stack!(non_maskable, stack, {
|
||||
println!("Non-maskable interrupt at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
println!("Non-maskable interrupt");
|
||||
stack.dump();
|
||||
});
|
||||
|
||||
interrupt_stack!(breakpoint, stack, {
|
||||
println!("Breakpoint trap at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
println!("Breakpoint trap");
|
||||
stack.dump();
|
||||
ksignal(SIGTRAP);
|
||||
});
|
||||
|
||||
interrupt_stack!(overflow, stack, {
|
||||
println!("Overflow trap at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(overflow, stack, {
|
||||
println!("Overflow trap");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGFPE);
|
||||
});
|
||||
|
||||
interrupt_stack!(bound_range, stack, {
|
||||
println!("Bound range exceeded fault at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(bound_range, stack, {
|
||||
println!("Bound range exceeded fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGSEGV);
|
||||
});
|
||||
|
||||
interrupt_stack!(invalid_opcode, stack, {
|
||||
println!("Invalid opcode fault at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(invalid_opcode, stack, {
|
||||
println!("Invalid opcode fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGILL);
|
||||
});
|
||||
|
||||
interrupt_stack!(device_not_available, stack, {
|
||||
println!("Device not available fault at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(device_not_available, stack, {
|
||||
println!("Device not available fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGILL);
|
||||
});
|
||||
|
||||
interrupt_error!(double_fault, stack, {
|
||||
println!("Double fault: {:X} at {:>02X}:{:>016X}", stack.code, stack.cs, stack.rip);
|
||||
interrupt_error_p!(double_fault, stack, {
|
||||
println!("Double fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGSEGV);
|
||||
});
|
||||
|
||||
interrupt_error!(invalid_tss, stack, {
|
||||
println!("Invalid TSS fault: {:X} at {:>02X}:{:>016X}", stack.code, stack.cs, stack.rip);
|
||||
interrupt_error_p!(invalid_tss, stack, {
|
||||
println!("Invalid TSS fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGSEGV);
|
||||
});
|
||||
|
||||
interrupt_error!(segment_not_present, stack, {
|
||||
println!("Segment not present fault: {:X} at {:>02X}:{:>016X}", stack.code, stack.cs, stack.rip);
|
||||
interrupt_error_p!(segment_not_present, stack, {
|
||||
println!("Segment not present fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGSEGV);
|
||||
});
|
||||
|
||||
interrupt_error!(stack_segment, stack, {
|
||||
println!("Stack segment fault: {:X} at {:>02X}:{:>016X}", stack.code, stack.cs, stack.rip);
|
||||
interrupt_error_p!(stack_segment, stack, {
|
||||
println!("Stack segment fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGSEGV);
|
||||
});
|
||||
|
||||
interrupt_error!(protection, stack, {
|
||||
println!("Protection fault: {:X} at {:>02X}:{:>016X}", stack.code, stack.cs, stack.rip);
|
||||
interrupt_error_p!(protection, stack, {
|
||||
println!("Protection fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGSEGV);
|
||||
});
|
||||
|
||||
interrupt_error!(page, stack, {
|
||||
interrupt_error_p!(page, stack, {
|
||||
let cr2: usize;
|
||||
asm!("mov rax, cr2" : "={rax}"(cr2) : : : "intel", "volatile");
|
||||
println!("Page fault: {:>02X}:{:>016X} at {:>02X}:{:>016X}", stack.code, cr2, stack.cs, stack.rip);
|
||||
println!("Page fault: {:>016X}", cr2);
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGSEGV);
|
||||
});
|
||||
|
||||
interrupt_stack!(fpu, stack, {
|
||||
println!("FPU floating point fault at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(fpu, stack, {
|
||||
println!("FPU floating point fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGFPE);
|
||||
});
|
||||
|
||||
interrupt_error!(alignment_check, stack, {
|
||||
println!("Alignment check fault: {:X} at {:>02X}:{:>016X}", stack.code, stack.cs, stack.rip);
|
||||
interrupt_error_p!(alignment_check, stack, {
|
||||
println!("Alignment check fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGBUS);
|
||||
});
|
||||
|
||||
interrupt_stack!(machine_check, stack, {
|
||||
println!("Machine check fault at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(machine_check, stack, {
|
||||
println!("Machine check fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGBUS);
|
||||
});
|
||||
|
||||
interrupt_stack!(simd, stack, {
|
||||
println!("SIMD floating point fault at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(simd, stack, {
|
||||
println!("SIMD floating point fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGFPE);
|
||||
});
|
||||
|
||||
interrupt_stack!(virtualization, stack, {
|
||||
println!("Virtualization fault at {:>02X}:{:>016X}", stack.cs, stack.rip);
|
||||
interrupt_stack_p!(virtualization, stack, {
|
||||
println!("Virtualization fault");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGBUS);
|
||||
});
|
||||
|
||||
interrupt_error!(security, stack, {
|
||||
println!("Security exception: {:X} at {:>02X}:{:>016X}", stack.code, stack.cs, stack.rip);
|
||||
interrupt_error_p!(security, stack, {
|
||||
println!("Security exception");
|
||||
stack.dump();
|
||||
stack_trace();
|
||||
ksignal(SIGBUS);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use core::{mem, str};
|
||||
use core::mem;
|
||||
use goblin::elf::sym;
|
||||
|
||||
use paging::{ActivePageTable, VirtualAddress};
|
||||
|
||||
@@ -15,6 +15,149 @@ macro_rules! println {
|
||||
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(packed)]
|
||||
pub struct ScratchRegisters {
|
||||
pub r11: usize,
|
||||
pub r10: usize,
|
||||
pub r9: usize,
|
||||
pub r8: usize,
|
||||
pub rsi: usize,
|
||||
pub rdi: usize,
|
||||
pub rdx: usize,
|
||||
pub rcx: usize,
|
||||
pub rax: usize,
|
||||
}
|
||||
|
||||
impl ScratchRegisters {
|
||||
pub fn dump(&self) {
|
||||
println!("RAX: {:>016X}", self.rax);
|
||||
println!("RCX: {:>016X}", self.rcx);
|
||||
println!("RDX: {:>016X}", self.rdx);
|
||||
println!("RDI: {:>016X}", self.rdi);
|
||||
println!("RSI: {:>016X}", self.rsi);
|
||||
println!("R8: {:>016X}", self.r8);
|
||||
println!("R9: {:>016X}", self.r9);
|
||||
println!("R10: {:>016X}", self.r10);
|
||||
println!("R11: {:>016X}", self.r11);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! scratch_push {
|
||||
() => (asm!(
|
||||
"push rax
|
||||
push rcx
|
||||
push rdx
|
||||
push rdi
|
||||
push rsi
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r11"
|
||||
: : : : "intel", "volatile"
|
||||
));
|
||||
}
|
||||
|
||||
macro_rules! scratch_pop {
|
||||
() => (asm!(
|
||||
"pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rax"
|
||||
: : : : "intel", "volatile"
|
||||
));
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(packed)]
|
||||
pub struct PreservedRegisters {
|
||||
pub r15: usize,
|
||||
pub r14: usize,
|
||||
pub r13: usize,
|
||||
pub r12: usize,
|
||||
pub rbp: usize,
|
||||
pub rbx: usize,
|
||||
}
|
||||
|
||||
impl PreservedRegisters {
|
||||
pub fn dump(&self) {
|
||||
println!("RBX: {:>016X}", self.rbx);
|
||||
println!("RBP: {:>016X}", self.rbp);
|
||||
println!("R12: {:>016X}", self.r12);
|
||||
println!("R13: {:>016X}", self.r13);
|
||||
println!("R14: {:>016X}", self.r14);
|
||||
println!("R15: {:>016X}", self.r15);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! preserved_push {
|
||||
() => (asm!(
|
||||
"push rbx
|
||||
push rbp
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
push r15"
|
||||
: : : : "intel", "volatile"
|
||||
));
|
||||
}
|
||||
|
||||
macro_rules! preserved_pop {
|
||||
() => (asm!(
|
||||
"pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
pop rbp
|
||||
pop rbx"
|
||||
: : : : "intel", "volatile"
|
||||
));
|
||||
}
|
||||
|
||||
macro_rules! fs_push {
|
||||
() => (asm!(
|
||||
"push fs
|
||||
mov rax, 0x18
|
||||
mov fs, ax"
|
||||
: : : : "intel", "volatile"
|
||||
));
|
||||
}
|
||||
|
||||
macro_rules! fs_pop {
|
||||
() => (asm!(
|
||||
"pop fs"
|
||||
: : : : "intel", "volatile"
|
||||
));
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(packed)]
|
||||
pub struct IretRegisters {
|
||||
pub rip: usize,
|
||||
pub cs: usize,
|
||||
pub rflags: usize,
|
||||
}
|
||||
|
||||
impl IretRegisters {
|
||||
pub fn dump(&self) {
|
||||
println!("RFLAG: {:>016X}", self.rflags);
|
||||
println!("CS: {:>016X}", self.cs);
|
||||
println!("RIP: {:>016X}", self.rip);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! iret {
|
||||
() => (asm!(
|
||||
"iretq"
|
||||
: : : : "intel", "volatile"
|
||||
));
|
||||
}
|
||||
|
||||
/// Create an interrupt function that can safely run rust code
|
||||
#[macro_export]
|
||||
macro_rules! interrupt {
|
||||
@@ -27,36 +170,16 @@ macro_rules! interrupt {
|
||||
}
|
||||
|
||||
// Push scratch registers
|
||||
asm!("push rax
|
||||
push rcx
|
||||
push rdx
|
||||
push rdi
|
||||
push rsi
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r11
|
||||
push fs
|
||||
mov rax, 0x18
|
||||
mov fs, ax"
|
||||
: : : : "intel", "volatile");
|
||||
scratch_push!();
|
||||
fs_push!();
|
||||
|
||||
// Call inner rust function
|
||||
inner();
|
||||
|
||||
// Pop scratch registers and return
|
||||
asm!("pop fs
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rax
|
||||
iretq"
|
||||
: : : : "intel", "volatile");
|
||||
fs_pop!();
|
||||
scratch_pop!();
|
||||
iret!();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -65,18 +188,16 @@ macro_rules! interrupt {
|
||||
#[repr(packed)]
|
||||
pub struct InterruptStack {
|
||||
pub fs: usize,
|
||||
pub r11: usize,
|
||||
pub r10: usize,
|
||||
pub r9: usize,
|
||||
pub r8: usize,
|
||||
pub rsi: usize,
|
||||
pub rdi: usize,
|
||||
pub rdx: usize,
|
||||
pub rcx: usize,
|
||||
pub rax: usize,
|
||||
pub rip: usize,
|
||||
pub cs: usize,
|
||||
pub rflags: usize,
|
||||
pub scratch: ScratchRegisters,
|
||||
pub iret: IretRegisters,
|
||||
}
|
||||
|
||||
impl InterruptStack {
|
||||
pub fn dump(&self) {
|
||||
self.iret.dump();
|
||||
self.scratch.dump();
|
||||
println!("FS: {:>016X}", self.fs);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
@@ -90,19 +211,8 @@ macro_rules! interrupt_stack {
|
||||
}
|
||||
|
||||
// Push scratch registers
|
||||
asm!("push rax
|
||||
push rcx
|
||||
push rdx
|
||||
push rdi
|
||||
push rsi
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r11
|
||||
push fs
|
||||
mov rax, 0x18
|
||||
mov fs, ax"
|
||||
: : : : "intel", "volatile");
|
||||
scratch_push!();
|
||||
fs_push!();
|
||||
|
||||
// Get reference to stack variables
|
||||
let rsp: usize;
|
||||
@@ -112,18 +222,9 @@ macro_rules! interrupt_stack {
|
||||
inner(&mut *(rsp as *mut $crate::arch::x86_64::macros::InterruptStack));
|
||||
|
||||
// Pop scratch registers and return
|
||||
asm!("pop fs
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rax
|
||||
iretq"
|
||||
: : : : "intel", "volatile");
|
||||
fs_pop!();
|
||||
scratch_pop!();
|
||||
iret!();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -132,19 +233,18 @@ macro_rules! interrupt_stack {
|
||||
#[repr(packed)]
|
||||
pub struct InterruptErrorStack {
|
||||
pub fs: usize,
|
||||
pub r11: usize,
|
||||
pub r10: usize,
|
||||
pub r9: usize,
|
||||
pub r8: usize,
|
||||
pub rsi: usize,
|
||||
pub rdi: usize,
|
||||
pub rdx: usize,
|
||||
pub rcx: usize,
|
||||
pub rax: usize,
|
||||
pub scratch: ScratchRegisters,
|
||||
pub code: usize,
|
||||
pub rip: usize,
|
||||
pub cs: usize,
|
||||
pub rflags: usize,
|
||||
pub iret: IretRegisters,
|
||||
}
|
||||
|
||||
impl InterruptErrorStack {
|
||||
pub fn dump(&self) {
|
||||
self.iret.dump();
|
||||
println!("CODE: {:>016X}", self.code);
|
||||
self.scratch.dump();
|
||||
println!("FS: {:>016X}", self.fs);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
@@ -158,19 +258,8 @@ macro_rules! interrupt_error {
|
||||
}
|
||||
|
||||
// Push scratch registers
|
||||
asm!("push rax
|
||||
push rcx
|
||||
push rdx
|
||||
push rdi
|
||||
push rsi
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r11
|
||||
push fs
|
||||
mov rax, 0x18
|
||||
mov fs, ax"
|
||||
: : : : "intel", "volatile");
|
||||
scratch_push!();
|
||||
fs_push!();
|
||||
|
||||
// Get reference to stack variables
|
||||
let rsp: usize;
|
||||
@@ -180,19 +269,111 @@ macro_rules! interrupt_error {
|
||||
inner(&*(rsp as *const $crate::arch::x86_64::macros::InterruptErrorStack));
|
||||
|
||||
// Pop scratch registers, error code, and return
|
||||
asm!("pop fs
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rax
|
||||
add rsp, 8
|
||||
iretq"
|
||||
: : : : "intel", "volatile");
|
||||
fs_pop!();
|
||||
scratch_pop!();
|
||||
asm!("add rsp, 8" : : : : "intel", "volatile");
|
||||
iret!();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(packed)]
|
||||
pub struct InterruptStackP {
|
||||
pub fs: usize,
|
||||
pub preserved: PreservedRegisters,
|
||||
pub scratch: ScratchRegisters,
|
||||
pub iret: IretRegisters,
|
||||
}
|
||||
|
||||
impl InterruptStackP {
|
||||
pub fn dump(&self) {
|
||||
self.iret.dump();
|
||||
self.scratch.dump();
|
||||
self.preserved.dump();
|
||||
println!("FS: {:>016X}", self.fs);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! interrupt_stack_p {
|
||||
($name:ident, $stack: ident, $func:block) => {
|
||||
#[naked]
|
||||
pub unsafe extern fn $name () {
|
||||
#[inline(never)]
|
||||
unsafe fn inner($stack: &mut $crate::arch::x86_64::macros::InterruptStackP) {
|
||||
$func
|
||||
}
|
||||
|
||||
// Push scratch registers
|
||||
scratch_push!();
|
||||
preserved_push!();
|
||||
fs_push!();
|
||||
|
||||
// Get reference to stack variables
|
||||
let rsp: usize;
|
||||
asm!("" : "={rsp}"(rsp) : : : "intel", "volatile");
|
||||
|
||||
// Call inner rust function
|
||||
inner(&mut *(rsp as *mut $crate::arch::x86_64::macros::InterruptStackP));
|
||||
|
||||
// Pop scratch registers and return
|
||||
fs_pop!();
|
||||
preserved_pop!();
|
||||
scratch_pop!();
|
||||
iret!();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(packed)]
|
||||
pub struct InterruptErrorStackP {
|
||||
pub fs: usize,
|
||||
pub preserved: PreservedRegisters,
|
||||
pub scratch: ScratchRegisters,
|
||||
pub code: usize,
|
||||
pub iret: IretRegisters,
|
||||
}
|
||||
|
||||
impl InterruptErrorStackP {
|
||||
pub fn dump(&self) {
|
||||
self.iret.dump();
|
||||
println!("CODE: {:>016X}", self.code);
|
||||
self.scratch.dump();
|
||||
self.preserved.dump();
|
||||
println!("FS: {:>016X}", self.fs);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! interrupt_error_p {
|
||||
($name:ident, $stack:ident, $func:block) => {
|
||||
#[naked]
|
||||
pub unsafe extern fn $name () {
|
||||
#[inline(never)]
|
||||
unsafe fn inner($stack: &$crate::arch::x86_64::macros::InterruptErrorStackP) {
|
||||
$func
|
||||
}
|
||||
|
||||
// Push scratch registers
|
||||
scratch_push!();
|
||||
preserved_push!();
|
||||
fs_push!();
|
||||
|
||||
// Get reference to stack variables
|
||||
let rsp: usize;
|
||||
asm!("" : "={rsp}"(rsp) : : : "intel", "volatile");
|
||||
|
||||
// Call inner rust function
|
||||
inner(&*(rsp as *const $crate::arch::x86_64::macros::InterruptErrorStackP));
|
||||
|
||||
// Pop scratch registers, error code, and return
|
||||
fs_pop!();
|
||||
preserved_pop!();
|
||||
scratch_pop!();
|
||||
asm!("add rsp, 8" : : : : "intel", "volatile");
|
||||
iret!();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ impl Mapper {
|
||||
|
||||
/// Map a page to a frame
|
||||
pub fn map_to(&mut self, page: Page, frame: Frame, flags: EntryFlags) -> MapperFlush {
|
||||
let mut p3 = self.p4_mut().next_table_create(page.p4_index());
|
||||
let mut p2 = p3.next_table_create(page.p3_index());
|
||||
let mut p1 = p2.next_table_create(page.p2_index());
|
||||
let p3 = self.p4_mut().next_table_create(page.p4_index());
|
||||
let p2 = p3.next_table_create(page.p3_index());
|
||||
let p1 = p2.next_table_create(page.p2_index());
|
||||
|
||||
assert!(p1[page.p1_index()].is_unused(),
|
||||
"{:X}: Set to {:X}: {:?}, requesting {:X}: {:?}",
|
||||
@@ -119,9 +119,9 @@ impl Mapper {
|
||||
|
||||
/// Update flags for a page
|
||||
pub fn remap(&mut self, page: Page, flags: EntryFlags) -> MapperFlush {
|
||||
let mut p3 = self.p4_mut().next_table_mut(page.p4_index()).expect("failed to remap: no p3");
|
||||
let mut p2 = p3.next_table_mut(page.p3_index()).expect("failed to remap: no p2");
|
||||
let mut p1 = p2.next_table_mut(page.p2_index()).expect("failed to remap: no p1");
|
||||
let p3 = self.p4_mut().next_table_mut(page.p4_index()).expect("failed to remap: no p3");
|
||||
let p2 = p3.next_table_mut(page.p3_index()).expect("failed to remap: no p2");
|
||||
let p1 = p2.next_table_mut(page.p2_index()).expect("failed to remap: no p1");
|
||||
let frame = p1[page.p1_index()].pointed_frame().expect("failed to remap: not mapped");
|
||||
p1[page.p1_index()].set(frame, flags | entry::PRESENT);
|
||||
MapperFlush::new(page)
|
||||
|
||||
@@ -15,8 +15,6 @@ use memory;
|
||||
use paging::{self, entry, Page, VirtualAddress};
|
||||
use paging::mapper::MapperFlushAll;
|
||||
|
||||
use stop;
|
||||
|
||||
/// Test of zero values in BSS.
|
||||
static BSS_TEST_ZERO: usize = 0;
|
||||
/// Test of non-zero values in data.
|
||||
|
||||
@@ -251,7 +251,7 @@ impl Context {
|
||||
/// Return the file descriptor number or None if no slot was found
|
||||
pub fn add_file_min(&self, file: FileDescriptor, min: usize) -> Option<FileHandle> {
|
||||
let mut files = self.files.lock();
|
||||
for (i, mut file_option) in files.iter_mut().enumerate() {
|
||||
for (i, file_option) in files.iter_mut().enumerate() {
|
||||
if file_option.is_none() && i >= min {
|
||||
*file_option = Some(file);
|
||||
return Some(FileHandle::from(i));
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use alloc::arc::Arc;
|
||||
use spin::RwLock;
|
||||
use scheme::{self, SchemeId};
|
||||
use core::mem;
|
||||
use syscall::error::{Result, Error, EBADF};
|
||||
use scheme::FileHandle;
|
||||
use context;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
use collections::String;
|
||||
|
||||
use core::str;
|
||||
|
||||
use goblin::elf::section_header::SHT_SYMTAB;
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
|
||||
@@ -72,7 +72,7 @@ static ALLOCATOR: Mutex<Option<RecycleAllocator<BumpAllocator>>> = Mutex::new(No
|
||||
/// Must be called once, and only once,
|
||||
pub unsafe fn init(kernel_start: usize, kernel_end: usize) {
|
||||
// Copy memory map from bootloader location
|
||||
for (i, mut entry) in MEMORY_MAP.iter_mut().enumerate() {
|
||||
for (i, entry) in MEMORY_MAP.iter_mut().enumerate() {
|
||||
*entry = *(0x500 as *const MemoryArea).offset(i as isize);
|
||||
if entry._type != MEMORY_AREA_NULL {
|
||||
println!("{:?}", entry);
|
||||
|
||||
@@ -33,7 +33,7 @@ impl<T: FrameAllocator> RecycleAllocator<T> {
|
||||
fn merge(&mut self, address: usize, count: usize) -> bool {
|
||||
for i in 0 .. self.free.len() {
|
||||
let changed = {
|
||||
let mut free = &mut self.free[i];
|
||||
let free = &mut self.free[i];
|
||||
if address + count * 4096 == free.0 {
|
||||
free.0 = address;
|
||||
free.1 += count;
|
||||
|
||||
@@ -109,7 +109,7 @@ impl Scheme for EnvScheme {
|
||||
|
||||
fn read(&self, id: usize, buffer: &mut [u8]) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
let data = handle.data.lock();
|
||||
|
||||
@@ -125,7 +125,7 @@ impl Scheme for EnvScheme {
|
||||
|
||||
fn write(&self, id: usize, buffer: &[u8]) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
let mut data = handle.data.lock();
|
||||
|
||||
@@ -147,7 +147,7 @@ impl Scheme for EnvScheme {
|
||||
|
||||
fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
let len = handle.data.lock().len();
|
||||
handle.seek = match whence {
|
||||
|
||||
@@ -90,7 +90,7 @@ impl Scheme for InitFsScheme {
|
||||
|
||||
fn read(&self, id: usize, buffer: &mut [u8]) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
let mut i = 0;
|
||||
while i < buffer.len() && handle.seek < handle.data.len() {
|
||||
@@ -104,7 +104,7 @@ impl Scheme for InitFsScheme {
|
||||
|
||||
fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
handle.seek = match whence {
|
||||
SEEK_SET => cmp::min(handle.data.len(), pos),
|
||||
|
||||
@@ -124,7 +124,7 @@ impl Scheme for SysScheme {
|
||||
|
||||
fn read(&self, id: usize, buffer: &mut [u8]) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
let mut i = 0;
|
||||
while i < buffer.len() && handle.seek < handle.data.len() {
|
||||
@@ -138,7 +138,7 @@ impl Scheme for SysScheme {
|
||||
|
||||
fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
handle.seek = match whence {
|
||||
SEEK_SET => cmp::min(handle.data.len(), pos),
|
||||
|
||||
@@ -282,7 +282,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> {
|
||||
// If not cloning files, dup to get a new number from scheme
|
||||
// This has to be done outside the context lock to prevent deadlocks
|
||||
if flags & CLONE_FILES == 0 {
|
||||
for (_fd, mut file_option) in files.lock().iter_mut().enumerate() {
|
||||
for (_fd, file_option) in files.lock().iter_mut().enumerate() {
|
||||
let new_file_option = if let Some(ref file) = *file_option {
|
||||
Some(FileDescriptor {
|
||||
description: Arc::clone(&file.description),
|
||||
@@ -402,9 +402,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> {
|
||||
// Copy percpu mapping
|
||||
for cpu_id in 0..::cpu_count() {
|
||||
extern {
|
||||
/// The starting byte of the thread data segment
|
||||
// The starting byte of the thread data segment
|
||||
static mut __tdata_start: u8;
|
||||
/// The ending byte of the thread BSS segment
|
||||
// The ending byte of the thread BSS segment
|
||||
static mut __tbss_end: u8;
|
||||
}
|
||||
|
||||
@@ -840,20 +840,20 @@ pub fn exit(status: usize) -> ! {
|
||||
context.id
|
||||
};
|
||||
|
||||
/// Files must be closed while context is valid so that messages can be passed
|
||||
// Files must be closed while context is valid so that messages can be passed
|
||||
for (fd, file_option) in close_files.drain(..).enumerate() {
|
||||
if let Some(file) = file_option {
|
||||
let _ = file.close(FileHandle::from(fd));
|
||||
}
|
||||
}
|
||||
|
||||
/// PPID must be grabbed after close, as context switches could change PPID if parent exits
|
||||
// PPID must be grabbed after close, as context switches could change PPID if parent exits
|
||||
let ppid = {
|
||||
let context = context_lock.read();
|
||||
context.ppid
|
||||
};
|
||||
|
||||
/// Transfer child processes to parent
|
||||
// Transfer child processes to parent
|
||||
{
|
||||
let contexts = context::contexts();
|
||||
for (_id, context_lock) in contexts.iter() {
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize
|
||||
|
||||
unsafe { context::switch(); }
|
||||
|
||||
if let Some(mut rem) = rem_opt {
|
||||
if let Some(rem) = rem_opt {
|
||||
//TODO let current = time::monotonic();
|
||||
rem.tv_sec = 0;
|
||||
rem.tv_nsec = 0;
|
||||
|
||||
Reference in New Issue
Block a user