acpi can run in kfs-3

This commit is contained in:
wescande 2018-03-19 11:23:53 +01:00
parent 4863945042
commit cdea287ecd
6 changed files with 30 additions and 18 deletions

View file

@ -31,13 +31,13 @@ asm_object := $(patsubst src/arch/$(arch)/%.asm, build/arch/$(arch)/%.o, $(asm_
KERNEL_RUN := $(QEMU) -curses -cdrom $(iso) KERNEL_RUN := $(QEMU) -curses -cdrom $(iso)
MONITOR := sleep 0.5;\ MONITOR := sleep 0.5;\
telnet 127.0.0.1 $(PORT);\ telnet 127.0.0.1 $(PORT);\
kill \`ps -x | grep \"[g]db\" | cut -d \ -f 1 \`;\ kill \`ps -x | grep \"[g]db -q\" | cut -d \ -f 1 \`;\
kill \`ps -x | grep \"[g]db\" | cut -d \ -f 2 \` kill \`ps -x | grep \"[g]db -q\" | cut -d \ -f 2 \`
GDB := gdb -q\ GDB := gdb -q\
-ex \"set arch i386:x86-64\"\ -ex \"set arch i386:x86-64\"\
-ex \"file $(kernel)\"\ -ex \"file $(kernel)\"\
-ex \"target remote :$(PORTG)\" -ex \"target remote :$(PORTG)\"\
# -ex \"continue\" -ex \"continue\"
all: $(kernel) all: $(kernel)

View file

@ -50,6 +50,7 @@ impl DSDT {
self.slp_typ_b = (unsafe {*(ptr as *const u8)} as u16) << 10; self.slp_typ_b = (unsafe {*(ptr as *const u8)} as u16) << 10;
} }
} }
fn is_init() -> Result <(), &'static str> { fn is_init() -> Result <(), &'static str> {
match unsafe {DSDT.valid} { match unsafe {DSDT.valid} {
true => Ok(()), true => Ok(()),

View file

@ -2,7 +2,7 @@ use super::{ACPISDTHeader,ACPISDTIter};
use cpuio; use cpuio;
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug, Clone)]
struct GenericAddressStructure { struct GenericAddressStructure {
addressspace: u8, addressspace: u8,
bitwidth: u8, bitwidth: u8,
@ -13,7 +13,7 @@ struct GenericAddressStructure {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug, Clone)]
struct FADT struct FADT
{ {
header: ACPISDTHeader, header: ACPISDTHeader,
@ -83,15 +83,15 @@ struct FADT
} }
static mut FADT: Option<&'static FADT> = None; static mut FADT: Option<FADT> = None;
/// ## Initialize Fixed ACPI Description Table (FADT) /// ## Initialize Fixed ACPI Description Table (FADT)
/// input param addr is contain in other ptr of rsdt /// input param addr is contain in other ptr of rsdt
pub fn init(sdt_iter: ACPISDTIter) -> Result <(), &'static str> { pub fn init(sdt_iter: ACPISDTIter) -> Result <(), &'static str> {
for sdt_ptr in sdt_iter { for sdt_ptr in sdt_iter {
if ACPISDTHeader::valid(sdt_ptr, "FACP") { // Where is "FADT"? Shut up is magic if ACPISDTHeader::valid(sdt_ptr, "FACP") { // Where is "FADT"? Shut up is magic
let ref fadt_tmp: &FADT = unsafe{ &(*(sdt_ptr as *const FADT)) }; let fadt_tmp: FADT = unsafe{ (*(sdt_ptr as *const FADT)).clone() };
unsafe {FADT = Some(fadt_tmp)}; unsafe {FADT = Some(fadt_tmp.clone())};
if !is_enable()? { // TODO do i have to check if enabled before init ??? if !is_enable()? { // TODO do i have to check if enabled before init ???
let smi_cmd = fadt_tmp.smi_commandport as u16; // TODO WHY DO I NEED THIS FUCKING CAST let smi_cmd = fadt_tmp.smi_commandport as u16; // TODO WHY DO I NEED THIS FUCKING CAST
let acpi_enable = fadt_tmp.acpi_enable; let acpi_enable = fadt_tmp.acpi_enable;
@ -103,8 +103,8 @@ pub fn init(sdt_iter: ACPISDTIter) -> Result <(), &'static str> {
return Err("Can not find Fixed ACPI Description Table (FADT)."); return Err("Can not find Fixed ACPI Description Table (FADT).");
} }
fn is_init() -> Result <&'static FADT, &'static str> { fn is_init() -> Result <FADT, &'static str> {
match unsafe {FADT} { match unsafe {FADT.clone()} {
Some(fadt) => Ok(fadt), Some(fadt) => Ok(fadt),
None => Err("Fixed ACPI Description Table (FADT) is not initialized") None => Err("Fixed ACPI Description Table (FADT) is not initialized")
} }
@ -117,7 +117,7 @@ pub fn dsdtaddr() -> Result <u32, &'static str> {
return Ok(fadt.dsdt); return Ok(fadt.dsdt);
} }
fn get_cnt(fadt: &'static FADT) -> [u16; 2] { fn get_cnt(fadt: FADT) -> [u16; 2] {
[fadt.pm1acontrolblock as u16, fadt.pm1bcontrolblock as u16] // TODO WHY DO I NEED THIS FUCKING CAST [fadt.pm1acontrolblock as u16, fadt.pm1bcontrolblock as u16] // TODO WHY DO I NEED THIS FUCKING CAST
} }
@ -138,6 +138,9 @@ pub fn get_controlblock() -> Result <[u16; 2], &'static str> {
if !is_enable()? { if !is_enable()? {
Err("ACPI is not enabled") Err("ACPI is not enabled")
} else { } else {
// println!("HALT");
// flush!();
// cpuio::halt();
Ok(get_cnt(is_init()?)) // TODO redondant call to is_init Ok(get_cnt(is_init()?)) // TODO redondant call to is_init
} }
} }

View file

@ -2,6 +2,7 @@ use super::{check_signature,check_checksum};
use core::mem; use core::mem;
#[repr(C)] #[repr(C)]
#[derive(Clone)]
struct RSDP { struct RSDP {
signature: [u8; 8], signature: [u8; 8],
checksum: u8, checksum: u8,
@ -11,6 +12,7 @@ struct RSDP {
} }
#[repr(C)] #[repr(C)]
#[derive(Clone)]
pub struct RSDP20 { pub struct RSDP20 {
rsdp: RSDP, rsdp: RSDP,
length: u32, length: u32,
@ -19,7 +21,7 @@ pub struct RSDP20 {
reserved: [u8; 3], reserved: [u8; 3],
} }
static mut RSDPTR: Option<&'static RSDP20> = None; static mut RSDPTR: Option<RSDP20> = None;
/// RSDP load will check is RSDP is present at the addr sent. /// RSDP load will check is RSDP is present at the addr sent.
/// Return a bool /// Return a bool
@ -27,7 +29,7 @@ static mut RSDPTR: Option<&'static RSDP20> = None;
/// false => RSDP is V1 /// false => RSDP is V1
pub fn load(addr: u32) -> Result <bool, &'static str> { pub fn load(addr: u32) -> Result <bool, &'static str> {
if check_signature(addr, "RSD PTR ") { if check_signature(addr, "RSD PTR ") {
let ref rsdp_tmp: &RSDP20 = unsafe{ &(*(addr as *const RSDP20)) }; let rsdp_tmp: RSDP20 = unsafe{ (*(addr as *const RSDP20)).clone() };
let revision = rsdp_tmp.rsdp.revision; let revision = rsdp_tmp.rsdp.revision;
if (revision == 0 && check_checksum(addr, mem::size_of::<RSDP>())) || (revision == 2 && check_checksum(addr, mem::size_of::<RSDP20>())) { if (revision == 0 && check_checksum(addr, mem::size_of::<RSDP>())) || (revision == 2 && check_checksum(addr, mem::size_of::<RSDP20>())) {
unsafe {RSDPTR = Some(rsdp_tmp)}; unsafe {RSDPTR = Some(rsdp_tmp)};
@ -53,8 +55,8 @@ fn memory_finding(bound: u32) -> Result <bool, &'static str> {
Err("Can not find Root System Description Pointer (RSDP).") Err("Can not find Root System Description Pointer (RSDP).")
} }
fn is_init() -> Result <&'static RSDP20, &'static str> { fn is_init() -> Result <RSDP20, &'static str> {
match unsafe {RSDPTR} { match unsafe {RSDPTR.clone()} {
Some(rsdptr) => Ok(rsdptr), Some(rsdptr) => Ok(rsdptr),
None => Err("Root System Description Pointer (RSDP) is not initialized") None => Err("Root System Description Pointer (RSDP) is not initialized")
} }

View file

@ -48,6 +48,8 @@ set_up_page_tables:
cmp ecx, 20 ; if counter == 1023, the whole P2 table is mapped cmp ecx, 20 ; if counter == 1023, the whole P2 table is mapped
jne .map_p2_table ; else map the next entry jne .map_p2_table ; else map the next entry
mov eax, p2_table
mov cr3, eax
ret ret
; PSE (Page Size Extension) allows huge pages to exist ; PSE (Page Size Extension) allows huge pages to exist
@ -61,8 +63,6 @@ enable_pse:
enable_paging: enable_paging:
; load P2 to cr3 register (cpu uses this to access the P2 table) ; load P2 to cr3 register (cpu uses this to access the P2 table)
mov eax, p2_table
mov cr3, eax
; enable paging in the cr0 register ; enable paging in the cr0 register
mov eax, cr0 mov eax, cr0

View file

@ -32,7 +32,9 @@ pub mod x86;
#[no_mangle] #[no_mangle]
pub extern fn kmain(multiboot_info_addr: usize) -> ! { pub extern fn kmain(multiboot_info_addr: usize) -> ! {
acpi::init().unwrap(); acpi::init().unwrap();
let boot_info = unsafe { multiboot2::load(multiboot_info_addr) }; let boot_info = unsafe { multiboot2::load(multiboot_info_addr) };
enable_paging();
enable_write_protect_bit(); enable_write_protect_bit();
memory::init(&boot_info); memory::init(&boot_info);
@ -53,6 +55,10 @@ pub extern fn kmain(multiboot_info_addr: usize) -> ! {
loop { keyboard::kbd_callback(); } loop { keyboard::kbd_callback(); }
} }
fn enable_paging() {
unsafe { x86::cr0_write(x86::cr0() | (1 << 31)) };
}
fn enable_write_protect_bit() { fn enable_write_protect_bit() {
unsafe { x86::cr0_write(x86::cr0() | (1 << 16)) }; unsafe { x86::cr0_write(x86::cr0() | (1 << 16)) };
} }