Skip to content

Commit

Permalink
Merge branch 'trunk' into feature/lisp-hex-num
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Nov 12, 2023
2 parents eb45c7e + 74df746 commit 234547c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 78 deletions.
21 changes: 4 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ video = []
serial = []

[dependencies]
acpi = "4.1.0"
acpi = "5.0.0"
aml = "0.16.4"
base64 = { version = "0.13.1", default-features = false }
bit_field = "0.10.2"
Expand Down
76 changes: 21 additions & 55 deletions src/sys/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,11 @@ use core::ptr::NonNull;
use x86_64::PhysAddr;
use x86_64::instructions::port::Port;

#[allow(dead_code)]
#[repr(u64)]
enum FADT {
SciInterrupt = 46, // u16,
SmiCmdPort = 48, // u32,
AcpiEnable = 52, // u8,
AcpiDisable = 53, // u8,
S4biosReq = 54, // u8,
PstateControl = 55, // u8,
Pm1aEventBlock = 56, // u32,
Pm1bEventBlock = 60, // u32,
Pm1aControlBlock = 64, // u32,
Pm1bControlBlock = 68, // u32,
}

fn read_addr<T>(physical_address: usize) -> T where T: Copy {
let virtual_address = sys::mem::phys_to_virt(PhysAddr::new(physical_address as u64));
unsafe { *virtual_address.as_ptr::<T>() }
}

fn read_fadt<T>(address: usize, offset: FADT) -> T where T: Copy {
read_addr::<T>(address + offset as usize)
}

pub fn shutdown() {
let mut pm1a_control_block = 0;
let mut slp_typa = 0;
Expand All @@ -42,47 +23,32 @@ pub fn shutdown() {
let res = unsafe { AcpiTables::search_for_rsdp_bios(MorosAcpiHandler) };
match res {
Ok(acpi) => {
//debug!("ACPI Found RDSP in BIOS");
for (sign, sdt) in acpi.sdts {
if sign.as_str() == "FACP" {
//debug!("ACPI Found FACP at {:#x}", sdt.physical_address);

/*
// Enable ACPI
let smi_cmd_port = read_fadt::<u16>(sdt.physical_address, FADT::SmiCmdPort);
let acpi_enable = read_fadt::<u8>(sdt.physical_address, FADT::AcpiEnable);
let mut port: Port<u8> = Port::new(smi_cmd_port);
unsafe { port.write(acpi_enable); }
sys::time::sleep(3.0);
*/

pm1a_control_block = read_fadt::<u32>(sdt.physical_address, FADT::Pm1aControlBlock);
if let Ok(fadt) = acpi.find_table::<acpi::fadt::Fadt>() {
if let Ok(block) = fadt.pm1a_control_block() {
pm1a_control_block = block.address as u32;
//debug!("ACPI Found PM1a Control Block: {:#x}", pm1a_control_block);
}
}
match &acpi.dsdt {
Some(dsdt) => {
let address = sys::mem::phys_to_virt(PhysAddr::new(dsdt.address as u64));
//debug!("ACPI Found DSDT at {:#x} {:#x}", dsdt.address, address);
let table = unsafe { core::slice::from_raw_parts(address.as_ptr(), dsdt.length as usize) };
if aml.parse_table(table).is_ok() {
let name = AmlName::from_str("\\_S5").unwrap();
if let Ok(AmlValue::Package(s5)) = aml.namespace.get_by_path(&name) {
//debug!("ACPI Found \\_S5 in DSDT");
if let AmlValue::Integer(value) = s5[0] {
slp_typa = value as u16;
//debug!("ACPI Found SLP_TYPa in \\_S5: {}", slp_typa);
}
if let Ok(dsdt) = &acpi.dsdt() {
let address = sys::mem::phys_to_virt(PhysAddr::new(dsdt.address as u64));
//debug!("ACPI Found DSDT at {:#x} {:#x}", dsdt.address, address);
let table = unsafe { core::slice::from_raw_parts(address.as_ptr(), dsdt.length as usize) };
if aml.parse_table(table).is_ok() {
let name = AmlName::from_str("\\_S5").unwrap();
if let Ok(AmlValue::Package(s5)) = aml.namespace.get_by_path(&name) {
//debug!("ACPI Found \\_S5 in DSDT");
if let AmlValue::Integer(value) = s5[0] {
slp_typa = value as u16;
//debug!("ACPI Found SLP_TYPa in \\_S5: {}", slp_typa);
}
} else {
debug!("ACPI Failed to parse AML in DSDT");
// FIXME: AML parsing works on QEMU and Bochs but not
// on VirtualBox at the moment, so we use the following
// hardcoded value:
slp_typa = (5 & 7) << 10;
}
},
None => {},
} else {
debug!("ACPI Failed to parse AML in DSDT");
// FIXME: AML parsing works on QEMU and Bochs but not
// on VirtualBox at the moment, so we use the following
// hardcoded value:
slp_typa = (5 & 7) << 10;
}
}
}
Err(_e) => {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn dispatcher(n: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize)
let buf_len = arg3;
let buf = unsafe { core::slice::from_raw_parts_mut(buf_ptr, buf_len) };
if let Ok(addr) = service::accept(handle) {
buf[0..buf_len].clone_from_slice(&addr.as_bytes());
buf[0..buf_len].clone_from_slice(addr.as_bytes());
0
} else {
-1 as isize as usize
Expand Down
2 changes: 1 addition & 1 deletion src/usr/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
print!("{}", csi_reset);
}
let req = req.join("");
syscall::write(handle, &req.as_bytes());
syscall::write(handle, req.as_bytes());

let mut response_state = ResponseState::Headers;
loop {
Expand Down
4 changes: 2 additions & 2 deletions src/usr/lisp/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub fn lisp_slice(args: &[Exp]) -> Result<Exp, Err> {
};
match &args[0] {
Exp::List(l) => {
let l: Vec<Exp> = l.iter().skip(a).cloned().take(b).collect();
let l: Vec<Exp> = l.iter().skip(a).take(b).cloned().collect();
Ok(Exp::List(l))
}
Exp::Str(s) => {
Expand Down Expand Up @@ -413,7 +413,7 @@ pub fn lisp_file_size(args: &[Exp]) -> Result<Exp, Err> {
let path = string(&args[0])?;
match syscall::info(&path) {
Some(info) => Ok(Exp::Num(Number::from(info.size() as usize))),
None => return could_not!("open file"),
None => could_not!("open file"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/usr/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
if let Some((h, _)) = syscall::poll(&list) {
if h == stdin {
let line = io::stdin().read_line().replace("\n", "\r\n");
syscall::write(handle, &line.as_bytes());
syscall::write(handle, line.as_bytes());
} else {
let mut data = vec![0; buf_len];
if let Some(bytes) = syscall::read(handle, &mut data) {
Expand Down

0 comments on commit 234547c

Please sign in to comment.