acpi - start implementing acpi
This commit is contained in:
parent
31e53e88b9
commit
4d52bac946
4 changed files with 76 additions and 114 deletions
|
@ -73,11 +73,9 @@ void kmain(void) {
|
||||||
|
|
||||||
gdt_init(&kstack[8192]);
|
gdt_init(&kstack[8192]);
|
||||||
idt_init();
|
idt_init();
|
||||||
fpu_activate();
|
|
||||||
sse_init();
|
|
||||||
|
|
||||||
pmm_init();
|
pmm_init();
|
||||||
vmm_init();
|
vmm_init();
|
||||||
|
|
||||||
kernel_vma_context = vma_create_context(vmm_kernel_pm);
|
kernel_vma_context = vma_create_context(vmm_kernel_pm);
|
||||||
if (!kernel_vma_context) {
|
if (!kernel_vma_context) {
|
||||||
log("kernel - vma ctx creation failed. halting\n");
|
log("kernel - vma ctx creation failed. halting\n");
|
||||||
|
@ -86,9 +84,10 @@ void kmain(void) {
|
||||||
asm("hlt");
|
asm("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
acpi_init();
|
||||||
syscall_init();
|
syscall_init();
|
||||||
pit_init(1000);
|
//pit_init(1000);
|
||||||
sched_init();
|
//sched_init();
|
||||||
|
|
||||||
//vfs_init();
|
//vfs_init();
|
||||||
|
|
||||||
|
|
|
@ -3,48 +3,38 @@
|
||||||
#include "sys/log.h"
|
#include "sys/log.h"
|
||||||
#include <mm/memop.h>
|
#include <mm/memop.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <sys/acpi.h>
|
#include <sys/acpi.h>
|
||||||
|
#include <sys/errhnd/panic.h>
|
||||||
|
|
||||||
__attribute__((
|
__attribute__((
|
||||||
used,
|
used,
|
||||||
section(".limine_requests"))) static volatile struct limine_rsdp_request
|
section(".limine_requests"))) static volatile struct limine_rsdp_request
|
||||||
rsdp_req = {.revision = 0, .id = LIMINE_RSDP_REQUEST};
|
rsdp_req = {.revision = 0, .id = LIMINE_RSDP_REQUEST};
|
||||||
|
|
||||||
rsdp_t *rsdp;
|
static int __acpi_uses_xsdt = 0;
|
||||||
int acpi_available = 0;
|
static void *__acpi_rsdt_ptr;
|
||||||
|
|
||||||
int is_xsdt = 0;
|
void *acpi_find_table(const char *name) {
|
||||||
xsdt_t *xsdt;
|
if (!__acpi_uses_xsdt) {
|
||||||
rsdt_t *rsdt;
|
acpi_rsdt *rsdt = (acpi_rsdt *)__acpi_rsdt_ptr;
|
||||||
int item_count = 0;
|
uint32_t entries = (rsdt->sdt.len - sizeof(rsdt->sdt)) / 4;
|
||||||
|
|
||||||
static int acpi_validate_rsdp(char *byte_array, size_t size) {
|
for (uint32_t i = 0; i < entries; i++) {
|
||||||
uint32_t sum = 0;
|
acpi_sdt *sdt = (acpi_sdt *)HIGHER_HALF(*((uint32_t *)rsdt->table + i));
|
||||||
for (int i = 0; i < size; i++) {
|
if (!memcmp(sdt->sign, name, 4))
|
||||||
sum += byte_array[i];
|
return (void *)sdt;
|
||||||
}
|
|
||||||
return (sum & 0xFF) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *acpi_find_table(char *sign, int sign_size) {
|
|
||||||
if (!acpi_available)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (is_xsdt) {
|
|
||||||
for (int i = 0; i < item_count; i++) {
|
|
||||||
uint64_t *lst =
|
|
||||||
(uint64_t *)HIGHER_HALF((uint64_t)xsdt->PointerToOtherSDT);
|
|
||||||
acpi_table_header_t *ptr = (acpi_table_header_t *)HIGHER_HALF(lst[i]);
|
|
||||||
|
|
||||||
if (!memcmp(ptr->Signature, sign, sign_size))
|
|
||||||
return (void *)ptr;
|
|
||||||
}
|
}
|
||||||
} else {
|
return NULL;
|
||||||
for (int i = 0; i < item_count; i++) {
|
}
|
||||||
acpi_table_header_t *ptr = (acpi_table_header_t *)HIGHER_HALF(
|
|
||||||
(uint64_t)rsdt->PointerToOtherSDT[i]);
|
acpi_xsdt *xsdt = (acpi_xsdt *)__acpi_rsdt_ptr;
|
||||||
if (!memcmp(ptr->Signature, sign, sign_size))
|
uint32_t entries = (xsdt->sdt.len - sizeof(xsdt->sdt)) / 8;
|
||||||
return (void *)ptr;
|
|
||||||
|
for (uint32_t i = 0; i < entries; i++) {
|
||||||
|
acpi_sdt *sdt = (acpi_sdt *)HIGHER_HALF(*((uint64_t *)xsdt->table + i));
|
||||||
|
if (!memcmp(sdt->sign, name, 4)) {
|
||||||
|
return (void *)sdt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,44 +42,17 @@ void *acpi_find_table(char *sign, int sign_size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void acpi_init() {
|
void acpi_init() {
|
||||||
rsdp_t *rsdp = (rsdp_t *)HIGHER_HALF(rsdp_req.response->address);
|
acpi_rsdp *rsdp = (acpi_rsdp *)rsdp_req.response->address;
|
||||||
|
|
||||||
if (!rsdp) {
|
if (memcmp(rsdp->sign, "RSD PTR", 7))
|
||||||
log("acpi - not available: RSDP is NULL!\n");
|
panic("acpi: Invalid RSDP signature!");
|
||||||
|
|
||||||
|
if (rsdp->revision != 0) {
|
||||||
|
__acpi_uses_xsdt = 1;
|
||||||
|
acpi_xsdp *xsdp = (acpi_xsdp *)rsdp;
|
||||||
|
__acpi_rsdt_ptr = (acpi_xsdt *)HIGHER_HALF((uint64_t)xsdp->xsdt_addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rsdp->rev < 2) {
|
__acpi_rsdt_ptr = (acpi_rsdt *)HIGHER_HALF((uint64_t)rsdp->rsdt_addr);
|
||||||
if (!acpi_validate_rsdp((char *)rsdp, sizeof(rsdp_t))) {
|
|
||||||
log("acpi - not available: Was the RSDP hijacked?\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
rsdt = (rsdt_t *)HIGHER_HALF((uint64_t)rsdp->rsdt_addr);
|
|
||||||
log("acpi - RSDT found at %p\n", rsdt);
|
|
||||||
item_count = (rsdt->h.Length - sizeof(acpi_table_header_t)) / 4;
|
|
||||||
log("acpi - RSDT contains %d entries\n", item_count);
|
|
||||||
} else {
|
|
||||||
is_xsdt = 1;
|
|
||||||
if (!acpi_validate_rsdp((char *)rsdp, sizeof(xsdp_t))) {
|
|
||||||
log("acpi - not available: Was the XSDP hijacked?\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
xsdt = (xsdt_t *)HIGHER_HALF((uint64_t)((xsdp_t *)rsdp)->xsdt_addr);
|
|
||||||
log("acpi - XSDT found at %p\n", xsdt);
|
|
||||||
item_count = (xsdt->h.Length - sizeof(acpi_table_header_t)) / 8;
|
|
||||||
log("acpi - XSDT contains %d entries\n", item_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
acpi_available = 1;
|
|
||||||
|
|
||||||
void *fadt = acpi_find_table("FACP", 4);
|
|
||||||
if (!fadt) {
|
|
||||||
log("acpi - FADT not found\n");
|
|
||||||
acpi_available = 0;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
log("acpi - FADT found at %p\n", fadt);
|
|
||||||
log("acpi - ACPI initialized successfully\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -5,47 +5,48 @@
|
||||||
#define ACPI_RSDP_SIGNATURE "RSD PTR "
|
#define ACPI_RSDP_SIGNATURE "RSD PTR "
|
||||||
#define ACPI_RSDP_SIGNATURE_LEN 7
|
#define ACPI_RSDP_SIGNATURE_LEN 7
|
||||||
|
|
||||||
typedef struct __acpi_table_header {
|
typedef struct {
|
||||||
char Signature[4];
|
char sign[8];
|
||||||
uint32_t Length;
|
uint8_t checksum;
|
||||||
uint8_t Revision;
|
char oem_id[6];
|
||||||
uint8_t Checksum;
|
uint8_t revision;
|
||||||
char OEMID[6];
|
|
||||||
char OEMTableID[8];
|
|
||||||
uint32_t OEMRevision;
|
|
||||||
uint32_t CreatorID;
|
|
||||||
uint32_t CreatorRevision;
|
|
||||||
} acpi_table_header_t;
|
|
||||||
|
|
||||||
typedef struct __rsdp {
|
|
||||||
char signature[8];
|
|
||||||
uint8_t chksum;
|
|
||||||
char oemid[6];
|
|
||||||
uint8_t rev;
|
|
||||||
uint32_t rsdt_addr;
|
uint32_t rsdt_addr;
|
||||||
} __attribute__((packed)) rsdp_t;
|
} __attribute__((packed)) acpi_rsdp;
|
||||||
|
|
||||||
typedef struct __xsdp {
|
typedef struct {
|
||||||
char signature[8];
|
char sign[8];
|
||||||
uint8_t chksum;
|
uint8_t checksum;
|
||||||
char oemid[6];
|
char oem_id[6];
|
||||||
uint8_t rev;
|
uint8_t revision;
|
||||||
uint32_t rsdt_addr; // deprecated since version 2.0
|
uint32_t resv;
|
||||||
|
|
||||||
uint32_t len;
|
uint32_t length;
|
||||||
uint64_t xsdt_addr;
|
uint64_t xsdt_addr;
|
||||||
uint8_t chksum_ex;
|
uint8_t extended_checksum;
|
||||||
uint8_t reserved[3];
|
uint8_t resv1[3];
|
||||||
} __attribute__((packed)) xsdp_t;
|
} __attribute__((packed)) acpi_xsdp;
|
||||||
|
|
||||||
typedef struct __rsdt {
|
typedef struct {
|
||||||
acpi_table_header_t h;
|
char sign[4];
|
||||||
uint32_t *PointerToOtherSDT;
|
uint32_t len;
|
||||||
} rsdt_t;
|
uint8_t revision;
|
||||||
|
uint8_t checksum;
|
||||||
|
char oem_id[6];
|
||||||
|
char oem_table_id[8];
|
||||||
|
uint32_t oem_revision;
|
||||||
|
uint32_t creator_id;
|
||||||
|
uint32_t creator_revision;
|
||||||
|
} __attribute__((packed)) acpi_sdt;
|
||||||
|
|
||||||
typedef struct __xsdt {
|
typedef struct {
|
||||||
acpi_table_header_t h;
|
acpi_sdt sdt;
|
||||||
uint64_t *PointerToOtherSDT;
|
char table[];
|
||||||
} xsdt_t;
|
} acpi_rsdt;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
acpi_sdt sdt;
|
||||||
|
char table[];
|
||||||
|
} acpi_xsdt;
|
||||||
|
|
||||||
|
void *acpi_find_table(const char *name);
|
||||||
void acpi_init();
|
void acpi_init();
|
|
@ -39,14 +39,13 @@ void idt_init() {
|
||||||
idt_set_descriptor(vector, isr_stub_table[vector], 0xEE);
|
idt_set_descriptor(vector, isr_stub_table[vector], 0xEE);
|
||||||
vectors[vector] = 1;
|
vectors[vector] = 1;
|
||||||
|
|
||||||
pic_init();
|
// Do not use the legacy PIC.
|
||||||
pic_unmask_irq(1);
|
//pic_init();
|
||||||
pic_unmask_irq(8);
|
//pic_unmask_irq(1);
|
||||||
|
//pic_unmask_irq(8);
|
||||||
|
|
||||||
__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
|
__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
|
||||||
__asm__ volatile("sti"); // set the interrupt flag
|
__asm__ volatile("sti"); // set the interrupt flag
|
||||||
|
|
||||||
// logln(progress, "kinit stage 1", "IDT initialized! Time to receive
|
|
||||||
// interrupts!\n");
|
|
||||||
log("idt - initialized\n");
|
log("idt - initialized\n");
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue